#include <triggerconf.h>
Public Types | |
typedef vector< string > | STRING_LIST |
A list of strings. | |
typedef STRING_LIST::iterator | STRING_LIST_ITERATOR |
Iterator to a list of strings. | |
typedef map< string, string > | ATTRIBUTE_MAP |
a map to store name-value attribute mappings | |
typedef ATTRIBUTE_MAP::iterator | ATTRIBUTE_MAP_ITERATOR |
an iterator to a ATTRIBUTE_MAP | |
typedef pair< string, string > | ATTRIBUTE_PAIR |
a string-string pair | |
Public Member Functions | |
Triggerconf (string filename, bool autocreateitems=false, bool mustexist=false) | |
Constructor for a Triggerconf object. | |
~Triggerconf () | |
Destruct and save the configuration file. | |
bool | isGood () |
Check if an error occured? | |
string | getError () |
Get the error message of the last error. | |
string | getConfigValue (string module, string submodule, string configname) |
Get the value of a configelement. | |
string | getConfigValue (string path) |
Get the value of a configelement through its path. | |
string | getConfigAttributeValue (string module, string submodule, string configname, string attributename) |
Get the value of an attribute from a configelement. | |
string | getConfigAttributeValue (string path) |
Get the value of an attribute from a configelement through its path. | |
bool | existsModule (string module) |
Check if a module exists. | |
bool | existsSubmodule (string module, string submodule) |
Check if a submodule exists. | |
bool | existsSubmodule (string path) |
Check if a submodule exists. | |
bool | existsConfigElement (string module, string submodule, string configname) |
Check if a configelement exists. | |
bool | existsConfigElement (string path) |
Check if a configelement exists. | |
bool | existsConfigAttribute (string module, string submodule, string configname, string attributename) |
Check if a configattribute exists. | |
bool | existsConfigAttribute (string path) |
Check if a configattribute exists. | |
void | createModule (string module) |
Create a new module. | |
void | createSubmodule (string module, string submodule) |
Create a new submodule. | |
void | createSubmodule (string path) |
Create a new submodule. | |
void | createConfigElement (string module, string submodule, string configname) |
Create a new configelement. | |
void | createConfigElement (string path) |
Create a new configelement. | |
void | createConfigAttribute (string module, string submodule, string configname, string attributename) |
Create a configattribute. | |
void | createConfigAttribute (string path) |
Create a configattribute. | |
void | setConfigValue (string module, string submodule, string configname, string value) |
Set the value of a configelement. | |
void | setConfigValue (string path, string value) |
Set the value of a configelement. | |
void | setConfigAttributeValue (string module, string submodule, string configname, string attributename, string value) |
Set the value of a configattribute. | |
void | setConfigAttributeValue (string path, string value) |
Set the value of a configattribute. | |
void | deleteAllModules () |
Delete all modules. | |
void | deleteModule (string module) |
Delete a module. | |
void | deleteSubmodule (string module, string submodule) |
Delete a submodule. | |
void | deleteSubmodule (string path) |
Delete a submodule. | |
void | deleteConfigElement (string module, string submodule, string configname) |
Delete a config element. | |
void | deleteConfigElement (string path) |
Delete a config element. | |
void | deleteConfigAttribute (string module, string submodule, string configname, string attributename) |
Delete a configattribute. | |
void | deleteConfigAttribute (string path) |
Delete a configattribute. | |
STRING_LIST | getModuleNames () |
Get the names of all available modules. | |
STRING_LIST | getSubmoduleNames (string module) |
Get the names of all available submodules. | |
STRING_LIST | getConfigItemNames (string module, string submodule) |
Get the names of all available configelements. | |
STRING_LIST | getConfigItemNames (string path) |
Get the names of all available configelements. | |
STRING_LIST | getConfigAttributeNames (string module, string submodule, string configname) |
Get the names of available configattributes. | |
STRING_LIST | getConfigAttributeNames (string path) |
Get the names of available configattributes. | |
ATTRIBUTE_MAP | getConfigItemAttributes (string module, string submodule, string configitem) |
get all attributes with the specified configitem | |
ATTRIBUTE_MAP | getConfigItemAttributes (string path) |
get all attributes with the specified configitem | |
Private Member Functions | |
DOMNode * | getChildOfType (DOMNode *root, short type, unsigned int index=0) |
Get child of a specified node type. | |
string | getAttributeValue (DOMNode *element, string attributename) |
Get the value of an attribute from the given node. | |
void | resetError () |
Reset the error. | |
void | setError (string err) |
Set an error. | |
DOMNode * | selectModule (string modulename) |
Select a module. | |
DOMNode * | selectSubmodule (string modulename, string submodulename) |
Select a submodule. | |
DOMNode * | selectConfigElement (string modulename, string submodulename, string configname) |
Select a configelement. | |
STRING_LIST | tokenize (string path) |
Split a string. | |
string | untokenize (STRING_LIST path) |
Concat a list of strings. | |
bool | checkItemCount (STRING_LIST path, unsigned int items) |
Check for correct pieces. | |
bool | checkItemCount (string path, unsigned int items) |
Check for correct pieces. | |
STRING_LIST | getChildsAttribute (DOMNode *root, string nodename, string attribute) |
Get all the values of childs. | |
Private Attributes | |
bool | goodstate |
The current state of the Triggerconf object. | |
string | lasterror |
The last error string that occured. | |
volatile bool | autocreate |
Autocreate modus. If true, items will be created automatically if they are needed but do not exist. | |
string | file |
The name of the file which contains the xml. | |
XercesDOMParser * | parser |
The DOM Parser. | |
ErrorHandler * | errhandler |
The ErrorHandler for the DOM Parser. | |
DOMNode * | rootnode |
The root node. This is not the document node but the triggerconf node. |
The Triggerconf class enables easy hierarchical access to config elements and config attributes. It hides the complexity of the XML library and gives easy to use manipulators for creating, reading and editing XML configuration files. The hierarchy consists of modules, submodules and configelements. Modules and submodules have unique names such that it is always possible to build a path that uniquely identifies a module, submodule or configelement. Modules and submodules just have names and no other values or attributes. Configelements have a name and value. Additionally configelements can have a arbitrary number of attributes which are made up of a name and value. All function which access/manipulate modules/submodules/configelements/configattributes can be accessed either through single parameters for each hierarchy or a path. Triggerconf uses the XercesC XML DOM library.
typedef vector<string> Triggerconf::STRING_LIST |
A list of strings.
typedef STRING_LIST::iterator Triggerconf::STRING_LIST_ITERATOR |
Iterator to a list of strings.
typedef map<string, string> Triggerconf::ATTRIBUTE_MAP |
a map to store name-value attribute mappings
typedef ATTRIBUTE_MAP::iterator Triggerconf::ATTRIBUTE_MAP_ITERATOR |
an iterator to a ATTRIBUTE_MAP
typedef pair<string,string> Triggerconf::ATTRIBUTE_PAIR |
a string-string pair
Triggerconf::Triggerconf | ( | string | filename, | |
bool | autocreateitems = false , |
|||
bool | mustexist = false | |||
) |
Constructor for a Triggerconf object.
The given configuration file will be parsed with an XML DOM Parser. If the file does not exist, it will be created.
filename | The name of the xml file to open or create. | |
autocreateitems | Chooses the autocreate mode which means that you don't have to create configelements/attributs or any of its parents when setting a value. All elements and parents are automatically created. | |
mustexist | Specify true if you don't want triggerconf to create the file if it does not exist. If the file does not exist an error will be set. Use isGood to test if the file has been found. |
Triggerconf::~Triggerconf | ( | ) |
Destruct and save the configuration file.
The destructor will save the current configuration to the file and savely terminate the XML library.
bool Triggerconf::isGood | ( | ) |
Check if an error occured?
None of the functions in triggerconf returns status codes or errors. To check wether an error occured during execution of the last function call this function.
string Triggerconf::getError | ( | ) |
Get the error message of the last error.
Returns the error message of the last error that occured. Use in conjunection with isGood.
string Triggerconf::getConfigValue | ( | string | module, | |
string | submodule, | |||
string | configname | |||
) |
Get the value of a configelement.
Returns the config value of a configelement. If the element does not exist The returned string will be empty. Use isGood to check for errors.
module | The module which the configelement belongs to. | |
submodule | The submodule which the configelement belongs to. | |
configname | The name of the configelement. |
string Triggerconf::getConfigValue | ( | string | path | ) |
Get the value of a configelement through its path.
Get the value of a configelement through a path in the form module/submodule/configelement.
string Triggerconf::getConfigAttributeValue | ( | string | module, | |
string | submodule, | |||
string | configname, | |||
string | attributename | |||
) |
Get the value of an attribute from a configelement.
Retrieve the value of an attribute in the specified module/submodule which belongs to the given configelement.
module | The module to which the configelement belongs. | |
submodule | The submodule to which the configelement belongs. | |
configname | The configelement which owns the attribute. | |
attributename | The name of the attribute for which to get the value. |
string Triggerconf::getConfigAttributeValue | ( | string | path | ) |
Get the value of an attribute from a configelement through its path.
The path must be in the form module/submodule/configelement/attributename
bool Triggerconf::existsModule | ( | string | module | ) |
Check if a module exists.
Checks if the module with the given name exists.
module | The name of the module. |
bool Triggerconf::existsSubmodule | ( | string | module, | |
string | submodule | |||
) |
Check if a submodule exists.
Checks if the submodule exists in the given module.
module | The name of the module. | |
submodule | The name of the submodule. |
bool Triggerconf::existsSubmodule | ( | string | path | ) |
Check if a submodule exists.
Checks if the submodule with the given path exists. The path must be in the form module/submodule.
path | The path to the submodule. |
bool Triggerconf::existsConfigElement | ( | string | module, | |
string | submodule, | |||
string | configname | |||
) |
Check if a configelement exists.
Checks if the configelement in the given module and submodule exists
module | The module to which the configelement belongs. | |
submodule | The module to which the configelement belongs. | |
configname | The name of the configelement. |
bool Triggerconf::existsConfigElement | ( | string | path | ) |
Check if a configelement exists.
Checks if the configelement in the given module and submodule exists. The path must be in the form module/submodule/configelement.
path | The path to the configelement in the form module/submodule/configelement. |
bool Triggerconf::existsConfigAttribute | ( | string | module, | |
string | submodule, | |||
string | configname, | |||
string | attributename | |||
) |
Check if a configattribute exists.
Checks if the configattribute in the given module, submodule and configelement exists.
module | The module in which the configattribute is. | |
submodule | The submodule in which the configattribute is. | |
configname | The configelement in which the configattribute is. | |
attributename | The name of the attribute. |
bool Triggerconf::existsConfigAttribute | ( | string | path | ) |
Check if a configattribute exists.
Checks if the configattribute in the given path exists.
path | The path to the configattribute in the form module/submodule/configelement/attributename. |
void Triggerconf::createModule | ( | string | module | ) |
Create a new module.
Create a new module with the given name. If the module already exists an error will occur. Use isGood to check for errors.
module | The name for the new module. |
void Triggerconf::createSubmodule | ( | string | module, | |
string | submodule | |||
) |
Create a new submodule.
Create a new submodule with the given name in the given modle. If the submodule already exists or the module does not exist an error will occur. Use isGood to check for errors.
module | The name of an existing module where to put the new submodule in. | |
submodule | The name for the new submodule. |
void Triggerconf::createSubmodule | ( | string | path | ) |
Create a new submodule.
Create a new submodule with the given name in the given modle. If the submodule already exists or the module does not exist an error will occur. Use isGood to check for errors.
path | The path to the new submodule in the form module/submodule. |
void Triggerconf::createConfigElement | ( | string | module, | |
string | submodule, | |||
string | configname | |||
) |
Create a new configelement.
Create a new configelement in the given module, submodule and the given name. Use isGood to check for errors.
module | The module in which to create the configelement. | |
submodule | The submodule in which to create the configelement. | |
configname | The name for the new configelement. |
void Triggerconf::createConfigElement | ( | string | path | ) |
Create a new configelement.
Create a new configelement in the given module, submodule and the given name. Use isGood to check for errors.
path | Path to the new configelement in the form module/submodule/configname. |
void Triggerconf::createConfigAttribute | ( | string | module, | |
string | submodule, | |||
string | configname, | |||
string | attributename | |||
) |
Create a configattribute.
Create a new configattribute in the given module, submodule, configelement with the given name.
module | The module in which to create the new configattribute. | |
submodule | The submodule in which to create the new configattribute. | |
configname | The configelement in which to create the new configattribute. | |
attributename | The name for the new configattribute. |
void Triggerconf::createConfigAttribute | ( | string | path | ) |
Create a configattribute.
Create a new configattribute in the given module, submodule, configelement with the given name.
path | The path for the new configattribute in the form module/submodule/configelement/attributename. |
void Triggerconf::setConfigValue | ( | string | module, | |
string | submodule, | |||
string | configname, | |||
string | value | |||
) |
Set the value of a configelement.
Set the value of a configelement. If in autocreate mode and the configelement or any of its parents does not exist, they will be created.
module | The module of the configelement. | |
submodule | The submodule of the configelement. | |
configname | The name of the configelement. | |
value | The value to set for the configelement. |
void Triggerconf::setConfigValue | ( | string | path, | |
string | value | |||
) |
Set the value of a configelement.
Set the value of a configelement. If in autocreate mode and the configelement or any of its parents does not exist, they will be created.
path | The path to the configelement in the form module/submodule/configelement. | |
value | The value to set for the configelement. |
void Triggerconf::setConfigAttributeValue | ( | string | module, | |
string | submodule, | |||
string | configname, | |||
string | attributename, | |||
string | value | |||
) |
Set the value of a configattribute.
Set the value for a configattribute. If in autocreate mode and any of the parents or the configelement does not exist it will be created.
module | The module in which the configelement is. | |
submodule | The submodule in which the configelement is. | |
configname | The name of the configelement. | |
attributename | The name of the configattribute. | |
value | The value to set. |
void Triggerconf::setConfigAttributeValue | ( | string | path, | |
string | value | |||
) |
Set the value of a configattribute.
Set the value for a configattribute. If in autocreate mode and any of the parents or the configelement does not exist it will be created.
path | The path to the configattribute in the form module/submodule/configelement/configattribute | |
value | The value to set. |
void Triggerconf::deleteAllModules | ( | ) |
void Triggerconf::deleteModule | ( | string | module | ) |
void Triggerconf::deleteSubmodule | ( | string | module, | |
string | submodule | |||
) |
Delete a submodule.
Delete a submodule in the specified module.
module | The module which contains the submodule. | |
submodule | The submodule to delete. |
void Triggerconf::deleteSubmodule | ( | string | path | ) |
Delete a submodule.
Delete a submodule in the specified module.
path | The path to the submodule in the form module/submodule. |
void Triggerconf::deleteConfigElement | ( | string | module, | |
string | submodule, | |||
string | configname | |||
) |
Delete a config element.
Delete a configelement in the given module and submodule.
module | The module which contains the configelement. | |
submodule | The submodule which contains the configelement. | |
configname | The name of the configelement. |
void Triggerconf::deleteConfigElement | ( | string | path | ) |
Delete a config element.
Delete a configelement in the given module and submodule.
path | The path to the configelement in the form module/submodule/configname. |
void Triggerconf::deleteConfigAttribute | ( | string | module, | |
string | submodule, | |||
string | configname, | |||
string | attributename | |||
) |
Delete a configattribute.
Delete a configattribute specified by its module, submodule, configelement and the name of the configattribute
module | The module which contains the configattribute. | |
submodule | The submodule which contains the configattribute. | |
configname | The name of the configelement which contains the configattribute. | |
attributename | The name of the attribute to delete. |
void Triggerconf::deleteConfigAttribute | ( | string | path | ) |
Delete a configattribute.
Delete a configattribute specified by its module, submodule, configelement and the name of the configattribute
path | The path to the configattribute in the form module/submodule/configname/attributename. |
Triggerconf::STRING_LIST Triggerconf::getModuleNames | ( | ) |
Get the names of all available modules.
Triggerconf::STRING_LIST Triggerconf::getSubmoduleNames | ( | string | module | ) |
Get the names of all available submodules.
Get the names of all available submodules in the given module.
module | The name of the module from which to retrieve the submodules. |
Triggerconf::STRING_LIST Triggerconf::getConfigItemNames | ( | string | module, | |
string | submodule | |||
) |
Get the names of all available configelements.
Gets the names of all available configelements in the given module/submodule.
module | The module from which to retrieve all configelements. | |
submodule | The submodule from which to retrieve all configelements. |
Triggerconf::STRING_LIST Triggerconf::getConfigItemNames | ( | string | path | ) |
Get the names of all available configelements.
Gets the names of all available configelements in the given module/submodule.
path | The path to the submodule from which to retrieve the configelements in the form module/submodule. |
Triggerconf::STRING_LIST Triggerconf::getConfigAttributeNames | ( | string | module, | |
string | submodule, | |||
string | configname | |||
) |
Get the names of available configattributes.
Get the names of available configattributes from the selected module, submodule, configelement.
module | The name of the module. | |
submodule | The name of the submodule. | |
configname | The name of the configelement from which to retrieve all attributes. |
Triggerconf::STRING_LIST Triggerconf::getConfigAttributeNames | ( | string | path | ) |
Get the names of available configattributes.
Get the names of available configattributes from the selected module, submodule, configelement.
path | The path to the configelement from which to retrieve all attribute names in the form module/submodule/configelement. |
Triggerconf::ATTRIBUTE_MAP Triggerconf::getConfigItemAttributes | ( | string | module, | |
string | submodule, | |||
string | configitem | |||
) |
get all attributes with the specified configitem
Retrieve all attributes that are attached to the specified configitem. The returned attributes are stored in a map with key and value type string.
module | The module in which the configitem is. | |
submodule | The submodule where the configitem is. | |
configitem | The configitem from which to get attributes. |
Triggerconf::ATTRIBUTE_MAP Triggerconf::getConfigItemAttributes | ( | string | path | ) |
get all attributes with the specified configitem
See getConfigItemAttributes(string, string, string)
path | The path to the configitem in the form module/submodule/configitem. |
DOMNode * Triggerconf::getChildOfType | ( | DOMNode * | root, | |
short | type, | |||
unsigned int | index = 0 | |||
) | [private] |
Get child of a specified node type.
Gets the child or the given root node which is of given type.
root | The root node. | |
type | The type of which the child node must be (see DOMNode::). | |
index | You can specify which child that matches the condition should be returned (first, second, ...). |
string Triggerconf::getAttributeValue | ( | DOMNode * | element, | |
string | attributename | |||
) | [private] |
Get the value of an attribute from the given node.
Return the value from the specified attribute from the given node.
element | The element from which to retrieve the attribute value. | |
attributename | the name of the attribute. |
void Triggerconf::resetError | ( | ) | [private] |
Reset the error.
Reset the error state and last error message.
void Triggerconf::setError | ( | string | err | ) | [private] |
Set an error.
Set the current state to errornous and set the error message.
err | The error message. |
DOMNode * Triggerconf::selectModule | ( | string | modulename | ) | [private] |
Select a module.
Get a module by its name. If it does not exist and in autocreate mode it will be created.
modulename | The name of the module to get. |
DOMNode * Triggerconf::selectSubmodule | ( | string | modulename, | |
string | submodulename | |||
) | [private] |
Select a submodule.
Get a submodule by its name. If it does not exist and in autocreate mode it will be created.
modulename | The name of the module which contains the submodule. | |
submodulename | The name of the submodule to get. |
DOMNode * Triggerconf::selectConfigElement | ( | string | modulename, | |
string | submodulename, | |||
string | configname | |||
) | [private] |
Select a configelement.
Get a configelement by its name. If it does not exist and in autocreate mode it will be created.
modulename | The name of the module which contains the configelement. | |
submodulename | The name of the submodule which contains the configelement. | |
configname | The name of the configelement to get. |
Triggerconf::STRING_LIST Triggerconf::tokenize | ( | string | path | ) | [private] |
Split a string.
Split a string into pieces using '/' as delimiter.
path | The string to split. |
string Triggerconf::untokenize | ( | STRING_LIST | path | ) | [private] |
Concat a list of strings.
concat a list of strings using '/' as delimiter.
path | The list of strings to concat. |
bool Triggerconf::checkItemCount | ( | STRING_LIST | path, | |
unsigned int | items | |||
) | [private] |
Check for correct pieces.
Check that the given string list contains the given count of items. If this is not the case the error state is set.
path | The list of strings. | |
items | The number to check against. |
bool Triggerconf::checkItemCount | ( | string | path, | |
unsigned int | items | |||
) | [private] |
Check for correct pieces.
Check that the given string list contains the given count of items. If this is not the case the error state is set. The given string will be split apart using the '/' delimiter.
path | The string to split and check element count. | |
items | The number of items to check against. |
Triggerconf::STRING_LIST Triggerconf::getChildsAttribute | ( | DOMNode * | root, | |
string | nodename, | |||
string | attribute | |||
) | [private] |
Get all the values of childs.
Walk the childs of the root node and select each node that has the specified xml element name of nodename. From these nodes the attribute with the given name is selected and the values of these attributes are returned.
root | The root node whose children will be walked. | |
nodename | The xml node names to select. | |
attribute | The attribute names to get the values. |
bool Triggerconf::goodstate [private] |
The current state of the Triggerconf object.
string Triggerconf::lasterror [private] |
The last error string that occured.
volatile bool Triggerconf::autocreate [private] |
Autocreate modus. If true, items will be created automatically if they are needed but do not exist.
string Triggerconf::file [private] |
The name of the file which contains the xml.
XercesDOMParser* Triggerconf::parser [private] |
The DOM Parser.
ErrorHandler* Triggerconf::errhandler [private] |
The ErrorHandler for the DOM Parser.
DOMNode* Triggerconf::rootnode [private] |
The root node. This is not the document node but the triggerconf node.