Rudiments
Public Member Functions | List of all members
templateengine Class Reference

#include <templateengine.h>

Inherits object.

Public Member Functions

 templateengine ()
 
virtual ~templateengine ()
 
void setVariableStart (const char *delimiter)
 
void setVariableEnd (const char *delimiter)
 
void setQuotedVariableStart (const char *delimiter)
 
void setQuotedVariableEnd (const char *delimiter)
 
void setDoubleQuotedVariableStart (const char *delimiter)
 
void setDoubleQuotedVariableEnd (const char *delimiter)
 
void setEscapeCharacter (char esc)
 
void setBlockStartStart (const char *delimiter)
 
void setBlockStartEnd (const char *delimiter)
 
void setBlockEndStart (const char *delimiter)
 
void setBlockEndEnd (const char *delimiter)
 
void setIncludeStart (const char *delimiter)
 
void setIncludeEnd (const char *delimiter)
 
const chargetVariableStart ()
 
const chargetVariableEnd ()
 
const chargetQuotedVariableStart ()
 
const chargetQuotedVariableEnd ()
 
const chargetDoubleQuotedVariableStart ()
 
const chargetDoubleQuotedVariableEnd ()
 
char getEscapeCharacter ()
 
const chargetBlockStartStart ()
 
const chargetBlockStartEnd ()
 
const chargetBlockEndStart ()
 
const chargetBlockEndEnd ()
 
const chargetIncludeStart ()
 
const chargetIncludeEnd ()
 
bool parse (output *out, const char *filename, fileparser *fileparsers, dictionary< const char *, const char * > *vars)
 
bool parse (output *out, const char *filename, blockparser *blockparsers, dictionary< const char *, const char * > *vars)
 
bool parse (output *out, const char *block, uint64_t blocklength, blockparser *blockparsers, dictionary< const char *, const char * > *vars)
 
const chargetError ()
 
- Public Member Functions inherited from object
virtual ~object ()
 

Detailed Description

The templateengine class provides a framework for registering user-defined methods to parse and perform replacements in marked-up files or strings.

Constructor & Destructor Documentation

◆ templateengine()

templateengine::templateengine ( )

Creates an instance of the templateengine class.

◆ ~templateengine()

virtual templateengine::~templateengine ( )
virtual

Deletes this instance of the templateengine class.

Member Function Documentation

◆ getBlockEndEnd()

const char * templateengine::getBlockEndEnd ( )

Returns the delimiter that the parse() methods look for at the end of a block-end.

The default is " -->".

For example, by defaults, blocks are delimited like:

... block ...

◆ getBlockEndStart()

const char * templateengine::getBlockEndStart ( )

Returns the delimiter that the parse() methods look for at the beginning of a block-end.

The default is "<!-- end ".

For example, by defaults, blocks are delimited like:

... block ...

◆ getBlockStartEnd()

const char * templateengine::getBlockStartEnd ( )

Returns the delimiter that the parse() methods look for at the end of a block-start.

The default is " -->".

For example, by defaults, blocks are delimited like:

... block ...

◆ getBlockStartStart()

const char * templateengine::getBlockStartStart ( )

Returns the delimiter that the parse() methods look for at beginning of a block-start.

The default is "<!-- start ".

For example, by defaults, blocks are delimited like:

... block ...

◆ getDoubleQuotedVariableEnd()

const char * templateengine::getDoubleQuotedVariableEnd ( )

Returns the delimiter that the parse() methods look for at the end of a variable whos value's double-quotes shall be escaped.

The default is ")".

For example, by defaults, variables are delimited like:

◆ getDoubleQuotedVariableStart()

const char * templateengine::getDoubleQuotedVariableStart ( )

Returns the delimiter that the parse() methods look for at the beginning of a variable whos value's double-quotes shall be escaped.

The default is "$dq(".

For example, by defaults, variables are delimited like:

◆ getError()

const char * templateengine::getError ( )

Returns the error that occurred if a parse() method returned false.

◆ getEscapeCharacter()

char templateengine::getEscapeCharacter ( )

Returns the escape character. Defaults to backslash.

◆ getIncludeEnd()

const char * templateengine::getIncludeEnd ( )

Returns the delimiter that the parse() methods look for at the end of an include.

The default is " -->".

For example, by defaults, blocks are delimited like:

◆ getIncludeStart()

const char * templateengine::getIncludeStart ( )

Returns the delimiter that the parse() methods look for at the beginning of an include.

The default is "<!-- include ".

For example, by defaults, blocks are delimited like:

◆ getQuotedVariableEnd()

const char * templateengine::getQuotedVariableEnd ( )

Returns the delimiter that the parse() methods look for at the end of a variable whos value's single-quotes shall be escaped.

The default is ")".

For example, by defaults, variables are delimited like:

◆ getQuotedVariableStart()

const char * templateengine::getQuotedVariableStart ( )

Returns the delimiter that the parse() methods look for at the beginning of a variable whos value's single-quotes shall be escaped.

The default is "$q(".

For example, by defaults, variables are delimited like:

◆ getVariableEnd()

const char * templateengine::getVariableEnd ( )

Returns the delimiter that the parse() methods look for at the end of a variable.

The default is ")".

For example, by defaults, variables are delimited like:

◆ getVariableStart()

const char * templateengine::getVariableStart ( )

Returns the delimiter that the parse() methods look for at the beginning of a variable.

The default is "$(".

For example, by defaults, variables are delimited like:

◆ parse() [1/3]

bool templateengine::parse ( output * out,
const char * block,
uint64_t blocklength,
blockparser * blockparsers,
dictionary< const char *, const char * > * vars )

Parses "length" characters of "block" and writes the out to "out". For each variable encountered, values from "vars" are substituted. For each nested block encountered, the block is looked up in "blockparsers" and the appropriate block parser method is called. The block parser method is passed "req", "resp", the name, data and character length of the block, "out" and "data" from the blockparser entry.

If a block is encountered but no block parser method is registered for it, it is parsed using "vars".

Returns false if a block parser method returns false and true otherwise.

◆ parse() [2/3]

bool templateengine::parse ( output * out,
const char * filename,
blockparser * blockparsers,
dictionary< const char *, const char * > * vars )

Parses the file at "filename" and writes the out to "out". For each variable encountered, values from "vars" are substituted. For each block encountered, the block is looked up in "blockparsers" and the appropriate block parser method is called. The block parser method is passed "req", "resp", "out", the name, data and character length of the block and "data" from the blockparser entry.

If a block is encountered but no block parser method is registered for it, it is parsed using "vars".

Returns false if a block parser method returns false and true otherwise.

◆ parse() [3/3]

bool templateengine::parse ( output * out,
const char * filename,
fileparser * fileparsers,
dictionary< const char *, const char * > * vars )

Looks up "filename" in "fileparsers", and calls the appropriate file parser method.

For each variable encountered in "filename", values from "vars" are substitued.

Returns true on success and false if the file parser method returns false or if no fileparser was found.

◆ setBlockEndEnd()

void templateengine::setBlockEndEnd ( const char * delimiter)

Sets the delimiter that the parse() methods look for at the end of a block-end to "delimiter".

Defaults to " -->".

For example, by defaults, blocks are delimited like:

... block ...

◆ setBlockEndStart()

void templateengine::setBlockEndStart ( const char * delimiter)

Sets the delimiter that the parse() methods look for at the beginning of a block-end to "delimiter".

Defaults to "<!-- end ".

For example, by defaults, blocks are delimited like:

... block ...

◆ setBlockStartEnd()

void templateengine::setBlockStartEnd ( const char * delimiter)

Sets the delimiter that the parse() methods look for at the end of a block-start to "delimiter".

Defaults to " -->".

For example, by defaults, blocks are delimited like:

... block ...

◆ setBlockStartStart()

void templateengine::setBlockStartStart ( const char * delimiter)

Sets the delimiter that the parse() methods look for at beginning of a block-start to "delimiter".

Defaults to "<!-- start ".

For example, by defaults, blocks are delimited like:

... block ...

◆ setDoubleQuotedVariableEnd()

void templateengine::setDoubleQuotedVariableEnd ( const char * delimiter)

Sets the delimiter that the parse() methods look for at the end of a variable whos value's double-quotes shall be escaped to "delimiter".

Defaults to ")".

For example, by defaults, variables are delimited like:

◆ setDoubleQuotedVariableStart()

void templateengine::setDoubleQuotedVariableStart ( const char * delimiter)

Sets the delimiter that the parse() methods look for at the beginning of a variable whos value's double-quotes shall be escaped to "delimiter".

Defaults to "$dq(".

For example, by defaults, variables are delimited like:

◆ setEscapeCharacter()

void templateengine::setEscapeCharacter ( char esc)

Sets the escape character. Defaults to backslash.

◆ setIncludeEnd()

void templateengine::setIncludeEnd ( const char * delimiter)

Sets the delimiter that the parse() methods look for at the end of an include to "delimiter".

Defaults to " -->".

For example, by defaults, blocks are delimited like:

◆ setIncludeStart()

void templateengine::setIncludeStart ( const char * delimiter)

Sets the delimiter that the parse() methods look for at the beginning of an include to "delimiter".

Defaults to "<!-- include ".

For example, by defaults, blocks are delimited like:

◆ setQuotedVariableEnd()

void templateengine::setQuotedVariableEnd ( const char * delimiter)

Sets the delimiter that the parse() methods look for at the end of a variable whos value's single-quotes shall be escaped to "delimiter".

Defaults to ")".

For example, by defaults, variables are delimited like:

◆ setQuotedVariableStart()

void templateengine::setQuotedVariableStart ( const char * delimiter)

Sets the delimiter that the parse() methods look for at the beginning of a variable whos value's single-quotes shall be escaped to "delimiter".

Defaults to "$q(".

For example, by defaults, variables are delimited like:

◆ setVariableEnd()

void templateengine::setVariableEnd ( const char * delimiter)

Sets the delimiter that the parse() methods look for at the end of a variable to "delimiter".

Defaults to ")".

For example, by defaults, variables are delimited like:

◆ setVariableStart()

void templateengine::setVariableStart ( const char * delimiter)

Sets the delimiter that the parse() methods look for at the beginning of a variable to "delimiter".

Defaults to "$(".

For example, by defaults, variables are delimited like: