Triggerconf Class Reference

The Triggerconf class. More...

#include <triggerconf.h>

Collaboration diagram for Triggerconf:

Collaboration graph
[legend]

List of all members.

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.


Detailed Description

The Triggerconf class.

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.


Member Typedef Documentation

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


Constructor & Destructor Documentation

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.

Parameters:
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.


Member Function Documentation

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.

Returns:
True if no error occured, false if an error occured.
See also:
getError

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.

Returns:
Error string of the last error.
See also:
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.

Parameters:
module The module which the configelement belongs to.
submodule The submodule which the configelement belongs to.
configname The name of the configelement.
Returns:
The value for the configelement.
See also:
getConfigValue(string)

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.

See also:
getConfigValue(string, string, string)

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.

Parameters:
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.
Returns:
The value of the attribute.
See also:
getConfigAttributeValue(string)

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

See also:
getConfigAttributeValue(string, string, string, string)

bool Triggerconf::existsModule ( string  module  ) 

Check if a module exists.

Checks if the module with the given name exists.

Parameters:
module The name of the module.
Returns:
True if the module exists, false if it does not exist.

bool Triggerconf::existsSubmodule ( string  module,
string  submodule 
)

Check if a submodule exists.

Checks if the submodule exists in the given module.

Parameters:
module The name of the module.
submodule The name of the submodule.
Returns:
True if the submodule exists, false if it does not exist or the module does not exist.
See also:
existsSubmodule(string)

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.

Parameters:
path The path to the submodule.
Returns:
True if the submodule exists, false if it does not exist or the module does not exist.
See also:
existsSubmodule(string, string)

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

Parameters:
module The module to which the configelement belongs.
submodule The module to which the configelement belongs.
configname The name of the configelement.
Returns:
True if the configelement exists, else false.
See also:
existsConfigElement(string)

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.

Parameters:
path The path to the configelement in the form module/submodule/configelement.
Returns:
True if the configelement exists, else false.
See also:
existsConfigElement(string, string, string)

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.

Parameters:
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.
Returns:
True if the configattribute exists, else false.
See also:
existsConfigAttribute(string)

bool Triggerconf::existsConfigAttribute ( string  path  ) 

Check if a configattribute exists.

Checks if the configattribute in the given path exists.

Parameters:
path The path to the configattribute in the form module/submodule/configelement/attributename.
Returns:
True if the configattribute exists, else false.
See also:
existsConfigAttribute(string, string, string, string)

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.

Parameters:
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.

Parameters:
module The name of an existing module where to put the new submodule in.
submodule The name for the new submodule.
See also:
createSubmodule(string)

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.

Parameters:
path The path to the new submodule in the form module/submodule.
See also:
createSubmodule(string, string)

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.

Parameters:
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.
See also:
createConfigElement(string)

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.

Parameters:
path Path to the new configelement in the form module/submodule/configname.
See also:
createConfigElement(string)

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.

Parameters:
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.
See also:
createConfigAttribute(string)

void Triggerconf::createConfigAttribute ( string  path  ) 

Create a configattribute.

Create a new configattribute in the given module, submodule, configelement with the given name.

Parameters:
path The path for the new configattribute in the form module/submodule/configelement/attributename.
See also:
createConfigAttribute(string, string, string, string)

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.

Parameters:
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.
See also:
setConfigValue(string, string)

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.

Parameters:
path The path to the configelement in the form module/submodule/configelement.
value The value to set for the configelement.
See also:
setConfigValue(string, string)

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.

Parameters:
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.
See also:
setConfigAttributeValue(string, string)

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.

Parameters:
path The path to the configattribute in the form module/submodule/configelement/configattribute
value The value to set.
See also:
setConfigAttributeValue(string, string, string, string, string)

void Triggerconf::deleteAllModules (  ) 

Delete all modules.

Delete all available modules.

See also:
deleteModule(string)

void Triggerconf::deleteModule ( string  module  ) 

Delete a module.

Delete the module with the specified name.

See also:
deleteAllModules

void Triggerconf::deleteSubmodule ( string  module,
string  submodule 
)

Delete a submodule.

Delete a submodule in the specified module.

Parameters:
module The module which contains the submodule.
submodule The submodule to delete.
See also:
deleteSubmodule(string)

void Triggerconf::deleteSubmodule ( string  path  ) 

Delete a submodule.

Delete a submodule in the specified module.

Parameters:
path The path to the submodule in the form module/submodule.
See also:
deleteSubmodule(string, string)

void Triggerconf::deleteConfigElement ( string  module,
string  submodule,
string  configname 
)

Delete a config element.

Delete a configelement in the given module and submodule.

Parameters:
module The module which contains the configelement.
submodule The submodule which contains the configelement.
configname The name of the configelement.
See also:
deleteConfigElement(string)

void Triggerconf::deleteConfigElement ( string  path  ) 

Delete a config element.

Delete a configelement in the given module and submodule.

Parameters:
path The path to the configelement in the form module/submodule/configname.
See also:
deleteConfigElement(string, string, string)

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

Parameters:
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.
See also:
deleteConfigAttribute(string)

void Triggerconf::deleteConfigAttribute ( string  path  ) 

Delete a configattribute.

Delete a configattribute specified by its module, submodule, configelement and the name of the configattribute

Parameters:
path The path to the configattribute in the form module/submodule/configname/attributename.
See also:
deleteConfigAttribute(string, string, string, string)

Triggerconf::STRING_LIST Triggerconf::getModuleNames (  ) 

Get the names of all available modules.

Returns:
The list of module names.

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.

Parameters:
module The name of the module from which to retrieve the submodules.
Returns:
The name of the submodules in the given module.

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.

Parameters:
module The module from which to retrieve all configelements.
submodule The submodule from which to retrieve all configelements.
Returns:
The names of the configelements.
See also:
getConfigItemNames(string)

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.

Parameters:
path The path to the submodule from which to retrieve the configelements in the form module/submodule.
Returns:
The names of the configelements.
See also:
getConfigItemNames(string, string)

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.

Parameters:
module The name of the module.
submodule The name of the submodule.
configname The name of the configelement from which to retrieve all attributes.
Returns:
The names of the configattributes.

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.

Parameters:
path The path to the configelement from which to retrieve all attribute names in the form module/submodule/configelement.
Returns:
The names of the configattributes.

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.

Parameters:
module The module in which the configitem is.
submodule The submodule where the configitem is.
configitem The configitem from which to get attributes.
Returns:
The map with names and values.

Triggerconf::ATTRIBUTE_MAP Triggerconf::getConfigItemAttributes ( string  path  ) 

get all attributes with the specified configitem

See getConfigItemAttributes(string, string, string)

Parameters:
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.

Parameters:
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, ...).
Returns:
The child that matches all contitions of NULL if no child was found that matches.

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.

Parameters:
element The element from which to retrieve the attribute value.
attributename the name of the attribute.
Returns:
the value 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.

Parameters:
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.

Parameters:
modulename The name of the module to get.
Returns:
The found node or NULL if the node was not found (and not in autocreate mode).

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.

Parameters:
modulename The name of the module which contains the submodule.
submodulename The name of the submodule to get.
Returns:
The found node or NULL if the node was not found (and not in autocreate mode).

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.

Parameters:
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.
Returns:
The found node or NULL if the node was not found (and not in autocreate mode).

Triggerconf::STRING_LIST Triggerconf::tokenize ( string  path  )  [private]

Split a string.

Split a string into pieces using '/' as delimiter.

Parameters:
path The string to split.
Returns:
The pieces that were split apart.
See also:
untokenize

string Triggerconf::untokenize ( STRING_LIST  path  )  [private]

Concat a list of strings.

concat a list of strings using '/' as delimiter.

Parameters:
path The list of strings to concat.
Returns:
The concatenated pieces as one string.
See also:
tokenize

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.

Parameters:
path The list of strings.
items The number to check against.
Returns:
True if path contains items elements, else false.
See also:
checkItemCount(string, unsigned int)

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.

Parameters:
path The string to split and check element count.
items The number of items to check against.
Returns:
True if path contains items elements, else false.
See also:
checkItemCount(STRING_LISTS, unsigned int)

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.

Parameters:
root The root node whose children will be walked.
nodename The xml node names to select.
attribute The attribute names to get the values.
Returns:
The list of attribute values.


Member Data Documentation

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.


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

Generated on Wed Jun 18 09:40:47 2008 for pktanon by  doxygen 1.5.5