Documentation for OpenFLUID 2.2.0
openfluid::tools::TemplateProcessor Class Reference

Detailed Description

Class for rendering templates from string, files or directories.

Example of use

{"key1","value #1"},
{"key2","value #2"}
};
// construction of the processor using the ${datakey} pattern
// where datakey can be keys in the Data structure
// file rendering
TplProc.renderFile("/path/to/template/file.tpl","/path/to/rendered/file.txt",Data,Errors);
// recursive directory rendering
TplProc.renderDirectory("/path/to/template/directory","/path/to/rendered/directory",Data,Errors);
Definition: TemplateProcessor.hpp:79
std::set< std::string > Errors
Definition: TemplateProcessor.hpp:101
std::map< std::string, std::string > Data
Definition: TemplateProcessor.hpp:96

#include <tools/TemplateProcessor.hpp>

Public Types

using Data = std::map< std::string, std::string >
 
using Errors = std::set< std::string >
 

Public Member Functions

 TemplateProcessor ()=delete
 
 TemplateProcessor (const std::string &Begin, const std::string &End)
 
virtual ~TemplateProcessor ()=default
 
void enableAutoComment (const std::string &CommentStr)
 
void ignoreUnknown (bool Enabled)
 
std::string renderString (const std::string &Str, const Data &D, Errors &E)
 
std::string renderFile (const std::string &InFile, const Data &D, Errors &E)
 
void renderFile (const std::string &InFile, const std::string &OutFile, const Data &D, Errors &E)
 
void renderDirectory (const std::string &InDir, const std::string &OutDir, const Data &D, Errors &E)
 

Member Typedef Documentation

◆ Data

using openfluid::tools::TemplateProcessor::Data = std::map<std::string,std::string>

Type for the input data used to resolve the template, as a key-value structure

◆ Errors

using openfluid::tools::TemplateProcessor::Errors = std::set<std::string>

Type for the resolution errors returned at render time, containing unresolved patterns found in the template

Constructor & Destructor Documentation

◆ TemplateProcessor() [1/2]

openfluid::tools::TemplateProcessor::TemplateProcessor ( )
delete

◆ TemplateProcessor() [2/2]

openfluid::tools::TemplateProcessor::TemplateProcessor ( const std::string &  Begin,
const std::string &  End 
)

Constructs a template processor, giving the beginning end ending delimiters used ath rendering time

Parameters
[in]BeginThe beginning delimiter
[in]EndThe ending delimiter
Exceptions
openfluid::base::FrameworkExceptionif the beginning or ending delimiter is empty

◆ ~TemplateProcessor()

virtual openfluid::tools::TemplateProcessor::~TemplateProcessor ( )
virtualdefault

Member Function Documentation

◆ enableAutoComment()

void openfluid::tools::TemplateProcessor::enableAutoComment ( const std::string &  CommentStr)

Enables automatic comment mode. When enabled, the '#KEYNAME' pattern is replaced by a comment string during the rendering process if 'KEYNAME' is empty or does not exist.

Parameters
[in]CommentStrThe comment string to use

◆ ignoreUnknown()

void openfluid::tools::TemplateProcessor::ignoreUnknown ( bool  Enabled)

Enables or disables the ignore unknown mode. When enabled, unknown keys are ignored and removed during the rendering process.

◆ renderDirectory()

void openfluid::tools::TemplateProcessor::renderDirectory ( const std::string &  InDir,
const std::string &  OutDir,
const Data D,
Errors E 
)

Renders a template directory into another directory recursively.

Parameters
[in]InDirThe template directory path
[in]OutDirThe rendered directory path
[in]DThe data to resolve the template
[in,out]EThe unresolved patterns if any
Exceptions
openfluid::base::FrameworkExceptionif the output directory is an existing file or if rendering fails

◆ renderFile() [1/2]

std::string openfluid::tools::TemplateProcessor::renderFile ( const std::string &  InFile,
const Data D,
Errors E 
)

Renders a template file into a string

Parameters
[in]InFileThe template file path
[in]DThe data to resolve the template
[in,out]EThe unresolved patterns if any
Returns
The resolved template as a string
Exceptions
openfluid::base::FrameworkExceptionif the template file cannot be open

◆ renderFile() [2/2]

void openfluid::tools::TemplateProcessor::renderFile ( const std::string &  InFile,
const std::string &  OutFile,
const Data D,
Errors E 
)

Renders a template file into another file

Parameters
[in]InFileThe template file path
[in]OutFileThe rendered file path
[in]DThe data to resolve the template
[in,out]EThe unresolved patterns if any
Exceptions
openfluid::base::FrameworkExceptionif the output file is an existing directory or if rendering fails

◆ renderString()

std::string openfluid::tools::TemplateProcessor::renderString ( const std::string &  Str,
const Data D,
Errors E 
)

Renders a template string into a string

Parameters
[in]StrThe template content
[in]DThe data to resolve the template
[in,out]EThe unresolved patterns if any
Returns
The resolved template as a string

The documentation for this class was generated from the following file: