ionflux.org | Impressum

Ionflux::Tools::Template Class Reference
[Template processor]

Template processor. More...

#include <Template.hpp>

Inheritance diagram for Ionflux::Tools::Template:

Inheritance graph
[legend]
Collaboration diagram for Ionflux::Tools::Template:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Template ()
 Constructor.
virtual ~Template ()
 Destructor.
virtual void readTemplate (const std::string &templateFileName, std::vector< TemplateElement * > &target)
 Read template file.
virtual void readTemplate (const std::string &templateFileName)
 Read template file.
virtual void setTemplate (const std::string &newTemplate, std::vector< TemplateElement * > &target)
 Set template.
virtual void setTemplate (const std::string &newTemplate)
 Set template.
virtual std::string process (const std::string &newTemplate="", Node *newConfig=0)
 Process template.
virtual void setMaxNestingDepth (unsigned int newMaxNestingDepth)
 Set maximum nesting depth.
virtual unsigned int getMaxNestingDepth ()
 Get maximum nesting depth.
virtual void printElementDebugInfo ()
 Print debug information.
virtual Reporter & getLog ()
 Get Console output/logging facility.

Static Public Attributes

static const std::string ITERATION_COUNTER = "__i"
 Iteration counter node name.
static const std::string NUM_ITERATIONS = "__n"
 Number of iterations node name.
static const std::string CONDITION_NODE = "__cond"
 Condition node name.
static const TokenType TT_TEMPLATE_TAG_OPEN
 Token type: Template tag marker (open).
static const TokenType TT_TEMPLATE_TAG_CLOSE
 Token type: Template tag marker (close).
static const TokenType TT_VAR_MARKER
 Token type: Variable marker.
static const TokenType TT_COMMENT
 Token type: Comment character.
static const TokenType TT_TREEPATH
 Token type: Tree path element.
static const TokenType TT_END_TAG_MARKER
 Token type: End tag marker.
static const TokenType TT_OPERATOR_NSO
 Token type: Operator (excluding slash and OR-sign).
static const std::string TAG_FOREACH = "foreach"
 Tag keyword: foreach.
static const std::string TAG_FOREACH_ELSE = "empty"
 Tag keyword: (foreach) else.
static const std::string TAG_FOREACH_IN = "in"
 Tag keyword: (foreach) in.
static const std::string TAG_IF = "if"
 Tag keyword: if.
static const std::string TAG_IF_ELSE = "else"
 Tag keyword: (if) else.
static const std::string TAG_FIRST = "first"
 Tag keyword: first.
static const std::string TAG_MID = "mid"
 Tag keyword: mid.
static const std::string TAG_LAST = "last"
 Tag keyword: last.
static const std::string TAG_SINGLE = "single"
 Tag keyword: single.
static const std::string TAG_NOTFIRST = "notfirst"
 Tag keyword: notfirst.
static const std::string TAG_NOTMID = "notmid"
 Tag keyword: notmid.
static const std::string TAG_NOTLAST = "notlast"
 Tag keyword: notlast.
static const std::string TAG_NOTSINGLE = "notsingle"
 Tag keyword: notsingle.
static const std::string TAG_INCLUDE = "include"
 Tag keyword: include.
static const std::string TAG_SWRAP = "swrap"
 Tag keyword: swrap.
static const std::string TAG_SECTION = "section"
 Tag keyword: section.
static const std::string TAG_REF = "ref"
 Tag keyword: ref.
static const std::string SWRAP_DEFAULT_LINE_WIDTH = "78"
 SWrap default line width.
static const std::string SWRAP_DEFAULT_LINE_TERM = "\n"
 SWrap default line terminator.
static const unsigned int DEFAULT_MAX_NESTING_DEPTH = 999
 Default maximum nesting depth.

Protected Member Functions

virtual void clearElements ()
 Clear element vector.
virtual bool parse (std::vector< TemplateElement * > &target)
 Parse template.
virtual bool parse ()
 Parse template input.
virtual void addCharacterData (const std::string &characterData, std::vector< TemplateElement * > &target)
 Add character data.
virtual bool addTemplateTag (const std::string &tagData, std::vector< TemplateElement * > &target)
 Add template tag.
virtual bool preprocess (std::vector< TemplateElement * > &target)
 Preprocess template elements.
virtual std::string process (unsigned int from, unsigned int to, TagNestingLevel depth)
 Process template.

Protected Attributes

Ionflux::Tools::Reporter log
 Console output/logging.
std::string templateInput
 Template input.
Tokenizer tok
 Template tokenizer.
Tokenizer tagTok
 Template tag tokenizer.
std::vector< TemplateElement * > elements
 Template elements.
TemplateSectionMap sections
 Template sections.
unsigned int maxNestingDepth
 Maximum nesting depth.

Detailed Description

Template processor.

Create a representation of data dynamically from a template.


Constructor & Destructor Documentation

Ionflux::Tools::Template::Template (   ) 
 

Constructor.

Construct new Template object.

Ionflux::Tools::Template::~Template (   )  [virtual]
 

Destructor.

Destruct Template object.


Member Function Documentation

void Ionflux::Tools::Template::addCharacterData (  const std::string &  characterData,
std::vector< TemplateElement * > &  target
)  [protected, virtual]
 

Add character data.

Creates a new template element for the specified character data. No element will be added if the character data is empty.

Parameters:
characterData Character data.
target Where to store new template elements.

bool Ionflux::Tools::Template::addTemplateTag (  const std::string &  tagData,
std::vector< TemplateElement * > &  target
)  [protected, virtual]
 

Add template tag.

Creates a new template element for the specified template tag data. No element will be added if the tag data is empty.

Parameters:
tagData Template tag data.
target Where to store new template elements.
Returns:
true if the tag data is valid and a template element has been added, false otherwise.

void Ionflux::Tools::Template::clearElements (   )  [protected, virtual]
 

Clear element vector.

Reporter & Ionflux::Tools::Template::getLog (   )  [virtual]
 

Get Console output/logging facility.

Returns:
The console output/logging facility used by this object.

Reimplemented from Ionflux::Tools::Tree.

unsigned int Ionflux::Tools::Template::getMaxNestingDepth (   )  [virtual]
 

Get maximum nesting depth.

Get the maximum nesting depth for template processing.

Returns:
Maximum nesting depth.

bool Ionflux::Tools::Template::parse (   )  [protected, virtual]
 

Parse template input.

Parses the template input into template elements.

Returns:
true on success, false otherwise.

bool Ionflux::Tools::Template::parse (  std::vector< TemplateElement * > &  target  )  [protected, virtual]
 

Parse template.

Parses the template input into a target vector of template elements.

Note:
Any memory allocated for template elements by this function must be managed by the caller.
Parameters:
target Where to store the resulting template elements.
Returns:
true on success, false otherwise.

bool Ionflux::Tools::Template::preprocess (  std::vector< TemplateElement * > &  target  )  [protected, virtual]
 

Preprocess template elements.

Preprocesses template elements.

Parameters:
target Template elements to be preprocessed.
Returns:
true on success, false otherwise.

void Ionflux::Tools::Template::printElementDebugInfo (   )  [virtual]
 

Print debug information.

std::string Ionflux::Tools::Template::process (  const std::string &  newTemplate = "",
Node *  newConfig = 0
)  [virtual]
 

Process template.

Generate a data representation from the template.

Returns:
Data representation.

std::string Ionflux::Tools::Template::process (  unsigned int  from,
unsigned int  to,
TagNestingLevel  depth
)  [protected, virtual]
 

Process template.

Generate a data representation from the specified template element range.

Parameters:
from First template element of the range.
to Last template element of the range.
depth The nesting levels of this call.
Returns:
Data representation.

void Ionflux::Tools::Template::readTemplate (  const std::string &  templateFileName  )  [virtual]
 

Read template file.

Reads a template from a file.

Parameters:
templateFileName Template file name.

void Ionflux::Tools::Template::readTemplate (  const std::string &  templateFileName,
std::vector< TemplateElement * > &  target
)  [virtual]
 

Read template file.

Reads a template from a file.

Parameters:
templateFileName Template file name.
target Where to store new template elements.

void Ionflux::Tools::Template::setMaxNestingDepth (  unsigned int  newMaxNestingDepth  )  [virtual]
 

Set maximum nesting depth.

Set the maximum nesting depth for template processing.

Parameters:
newMaxNestingDepth Maximum nesting depth.

void Ionflux::Tools::Template::setTemplate (  const std::string &  newTemplate  )  [virtual]
 

Set template.

Sets the template to the specified byte string.

Parameters:
newTemplate Template.

void Ionflux::Tools::Template::setTemplate (  const std::string &  newTemplate,
std::vector< TemplateElement * > &  target
)  [virtual]
 

Set template.

Sets the template to the specified byte string.

Parameters:
newTemplate Template.
target Where to store new template elements.


Member Data Documentation

const std::string Ionflux::Tools::Template::CONDITION_NODE = "__cond" [static]
 

Condition node name.

This node name is reserved for storing conditions.

const unsigned int Ionflux::Tools::Template::DEFAULT_MAX_NESTING_DEPTH = 999 [static]
 

Default maximum nesting depth.

std::vector<TemplateElement *> Ionflux::Tools::Template::elements [protected]
 

Template elements.

const std::string Ionflux::Tools::Template::ITERATION_COUNTER = "__i" [static]
 

Iteration counter node name.

This node name is reserved for iteration counting. You can access the iteration counters in a template by accessing the node data entry <ITERATION_COUNTER>[<nesting level>], starting from 0.

Ionflux::Tools::Reporter Ionflux::Tools::Template::log [protected]
 

Console output/logging.

Reimplemented from Ionflux::Tools::Tree.

unsigned int Ionflux::Tools::Template::maxNestingDepth [protected]
 

Maximum nesting depth.

const std::string Ionflux::Tools::Template::NUM_ITERATIONS = "__n" [static]
 

Number of iterations node name.

This node name is reserved for storing the number of iterations. You can access the number of iterations in a template by accessing the node data entry <NUM_ITERATIONS>[<nesting level>], starting from 0.

TemplateSectionMap Ionflux::Tools::Template::sections [protected]
 

Template sections.

const std::string Ionflux::Tools::Template::SWRAP_DEFAULT_LINE_TERM = "\n" [static]
 

SWrap default line terminator.

const std::string Ionflux::Tools::Template::SWRAP_DEFAULT_LINE_WIDTH = "78" [static]
 

SWrap default line width.

const std::string Ionflux::Tools::Template::TAG_FIRST = "first" [static]
 

Tag keyword: first.

const std::string Ionflux::Tools::Template::TAG_FOREACH = "foreach" [static]
 

Tag keyword: foreach.

const std::string Ionflux::Tools::Template::TAG_FOREACH_ELSE = "empty" [static]
 

Tag keyword: (foreach) else.

const std::string Ionflux::Tools::Template::TAG_FOREACH_IN = "in" [static]
 

Tag keyword: (foreach) in.

const std::string Ionflux::Tools::Template::TAG_IF = "if" [static]
 

Tag keyword: if.

const std::string Ionflux::Tools::Template::TAG_IF_ELSE = "else" [static]
 

Tag keyword: (if) else.

const std::string Ionflux::Tools::Template::TAG_INCLUDE = "include" [static]
 

Tag keyword: include.

const std::string Ionflux::Tools::Template::TAG_LAST = "last" [static]
 

Tag keyword: last.

const std::string Ionflux::Tools::Template::TAG_MID = "mid" [static]
 

Tag keyword: mid.

const std::string Ionflux::Tools::Template::TAG_NOTFIRST = "notfirst" [static]
 

Tag keyword: notfirst.

const std::string Ionflux::Tools::Template::TAG_NOTLAST = "notlast" [static]
 

Tag keyword: notlast.

const std::string Ionflux::Tools::Template::TAG_NOTMID = "notmid" [static]
 

Tag keyword: notmid.

const std::string Ionflux::Tools::Template::TAG_NOTSINGLE = "notsingle" [static]
 

Tag keyword: notsingle.

const std::string Ionflux::Tools::Template::TAG_REF = "ref" [static]
 

Tag keyword: ref.

const std::string Ionflux::Tools::Template::TAG_SECTION = "section" [static]
 

Tag keyword: section.

const std::string Ionflux::Tools::Template::TAG_SINGLE = "single" [static]
 

Tag keyword: single.

const std::string Ionflux::Tools::Template::TAG_SWRAP = "swrap" [static]
 

Tag keyword: swrap.

Tokenizer Ionflux::Tools::Template::tagTok [protected]
 

Template tag tokenizer.

std::string Ionflux::Tools::Template::templateInput [protected]
 

Template input.

Tokenizer Ionflux::Tools::Template::tok [protected]
 

Template tokenizer.

const TokenType Ionflux::Tools::Template::TT_COMMENT [static]
 

Initial value:

 {
    TokenType::USERTYPE_ID + 104, "#", false, 1}
Token type: Comment character.

const TokenType Ionflux::Tools::Template::TT_END_TAG_MARKER [static]
 

Initial value:

 {
    TokenType::USERTYPE_ID + 106, "/", false, 0}
Token type: End tag marker.

const TokenType Ionflux::Tools::Template::TT_OPERATOR_NSO [static]
 

Initial value:

 {
    TokenType::USERTYPE_ID + 107, "+-*=<>&!~%^", false, 0}
Token type: Operator (excluding slash and OR-sign).

const TokenType Ionflux::Tools::Template::TT_TEMPLATE_TAG_CLOSE [static]
 

Initial value:

 {
    TokenType::USERTYPE_ID + 102, "}", false, 1}
Token type: Template tag marker (close).

const TokenType Ionflux::Tools::Template::TT_TEMPLATE_TAG_OPEN [static]
 

Initial value:

 {
    TokenType::USERTYPE_ID + 101, "{", false, 1}
Token type: Template tag marker (open).

const TokenType Ionflux::Tools::Template::TT_TREEPATH [static]
 

Initial value:

 {
    TokenType::USERTYPE_ID + 105, ".[]()", false, 0}
Token type: Tree path element.

const TokenType Ionflux::Tools::Template::TT_VAR_MARKER [static]
 

Initial value:

 {
    TokenType::USERTYPE_ID + 103, "$@", false, 1}
Token type: Variable marker.


The documentation for this class was generated from the following files:
Generated on Tue Mar 14 21:11:16 2006 for Ionflux Tools Class Library (iftools) by  doxygen 1.4.6