CT++ API
Class template_text
// Constructor
template_text(udf_fn_factory * pFactory = NULL,
const int iLine = 1,
const int iPos = 1,
const int iTabLength = 9,
const bool bDebug = false,
const bool bStrict = true,
const bool bLoopContextVars = false,
const bool bGlobalVars = false);
where:
pFactory - factory of the objects of the user functions
iLine - the number of the line of template (default - 1)
iPos - position in the line of template (default - 1)
iTabLength - size of the symbol of tabulation in spaces (default 9)
These three parameters are used as initial values in the system of the syntax analysis of template.
bDebug - enable or disable debug (default off)
bStrict - strict syntax checking (after construction <TMPL_must follow the operator of template engine CT++, default on)
bLoopContextVars - use of contextual variables in the cycle (default off)
bGlobalVars - use of global variables in the cycle (default off)
// Getting Factory
udf_fn_factory * get_fn_factory();
Getting the factory of objects. If the object of template engine создается без фабрики объектов,is created without the factory of objects, object independently creates its internal factory with the set of standard functions.
Method get_fn_factoryserves for obtaining the pointer to the factory
// Setting IncludeDir
void set_include_dir(const v_include_dir &vIncludeDir);
где:
vIncludeDir - list of catalogs for the i of the investments through <TMPL_include filename.tmpl>
If path to the file name does not begin from the slash, file consecutively searches for in all catalogs from vIncludeDir.
But if path begins from the slash, path is checked against the entry in vIncludeDir.
If path is not found in vIncludeDir or it is not possible to open file, is generated exception std::logic_error.
// Parse the template
void parse(const std::string & sData);
void parse(std::string::const_iterator & sDataBegin, std::string::const_iterator & sDataEnd);
Overloaded method. To the entrance are obtained the beginning and the end of the sequence of the symbols, which are been template, or the string of symbols.
// Insert the parameters
void param(param_data * pParamData);
Insert of the parameters into the template.
// Result output
std::string & output();
Result output to user.
// Cleaning the template
void clear_template();
Cleaning template.
// Destructor
~template_text() throw();
Class loader_base
Base class for creating its own includes loader.
// Load file
virtual void load_file(const std::string &sFileName);
Method obtains the complete name of file.
// Getting data
virtual std::string & get_data();
Returns contents of opened file.
// Destructor
virtual ~loader_base() throw();
Class udf_fn_factory
Class-installerof the user defined functions.
// Installation of user defined function
void install_udf_fn(const std::string &sFunctionName, udf_fn * pUDFFn);
Puts the object of function in the factory of objects created previously. First parameter - name of function in the template. Second parameter - pointer to the object of function.
// Removind of user defined function
void remove_udf_fn(const std::string &sFunctionName);
Removes user defined function from the factory of objects. First parameter - name of function in the template.
// Getting pointer to the function
udf_fn * get(const std::string &sFunctionName);
First parameter - name of function in the template.
// Clear factory
void clear();
Removes all function from the factoryu, including standard functions set.
// Destructor
virtual ~udf_fn_factory();
Class param_data
This class is used for the transfer of parameters to template engine.
Determinations of essences.
In template engine CTPP there are three types of the data: line, array and hash are given. Below the determination of these types:
// String
typedef std::string t_param_str;
// Array
typedef std::vector<param_data *> t_param_array;
// Hash
typedef std::map<std::string, param_data *> t_param_hash;
For the indication of the type of object serves the enumeration e_value_type:
enum e_value_type { VAR, ARRAY, HASH };
// Constructor
param_data(e_value_type eIType = VAR);
Is created object in by the assigned type.
// Pointer to the VAL
t_param_str * val();
Returns pointer to the object of the type "line". If this method inquires in the object with the type, different from VAR, is generated exception std::logic_error.
// Pointer to the ARRAY
t_param_array * array();
Returns pointer to the object of the type "array". If this method inquires in the object with the type, different from ARRAY, is generated exception std::logic_error.
// Pointer to the HASH
t_param_hash * hash();
Returns pointer to the object of the type "hash". If this method inquires in the object with the type, different from HASH, is generated exception std::logic_error.
// Type of the variable
e_value_type get_value_type();
Getting the type of object.
// Insert variable into hash
param_data * hash_insert_new_var(const std::string &sKey, const std::string &sValue);
Insert pair "key => value" в hash. Returns pointer to the created variable.
// Insert array into
param_data * hash_insert_new_array(const std::string &sKey);
Insert pair "key => array" в hash. Returns pointer to the created array.
// Insert variable into array
param_data * array_insert_new_var(const std::string &sKey);
// Insert hash into array
param_data * array_insert_new_hash();
// Removes variable from hash
void param_data::hash_erase_var(const std::string &sKey);
// Destructor
~param_data();
Copyright © 2003 - 2005 CTPP Dev. Team | http://reki.ru/products/ctpp