gramods
|
A wrapper for the XML parser that also creates and configures the system objects and holds temporary references to them for easy retrieval. More...
#include <Configuration.hh>
Public Member Functions | |
Configuration () | |
Creates an empty configuration. More... | |
Configuration (int &argc, char *argv[], std::vector< std::string > *error_list=nullptr) | |
Consumes arguments –config <file>, –xml <string> and –param <identifier>=<value> from the provided command line. More... | |
Configuration (std::string config, std::vector< std::string > *error_list=nullptr) | |
Loads an XML string, create objects as specified by the XML data and configure the objects. More... | |
Configuration (tinyxml2::XMLNode *node, std::vector< std::string > *error_list=nullptr) | |
Read the XML data, create objects as specified by the XML data and configure the objects. More... | |
~Configuration () | |
Cleans up and checks that all configuration variables have been read. More... | |
bool | hasParam (std::string name) |
Check if a specific parameter is available. More... | |
std::size_t | getAllParamNames (std::vector< std::string > &name) |
Adds all currently available parameter names to the specified vector and returns the count. More... | |
std::size_t | getAllObjectKeys (std::vector< std::string > &name) |
Adds all currently available object's keys to the specified vector and returns the count. More... | |
void | addParam (std::string name, std::string value) |
Add a parameter value. More... | |
template<class T > | |
bool | getParam (std::string name, T &value) const |
Retrieves a named parameter as a specified type. More... | |
template<class T > | |
std::size_t | getAllParams (std::string name, std::vector< T > &value) const |
Retrieves all parameters with a specified name. More... | |
template<class T > | |
bool | getObjectByKey (std::string key, std::shared_ptr< T > &ptr) const |
Retrieve an object by its key. More... | |
template<class T > | |
bool | getObjectByDef (std::string def, std::shared_ptr< T > &ptr) const |
Retrieve an object by its DEF name. More... | |
template<class T > | |
bool | getObject (std::shared_ptr< T > &ptr) const |
Retrieve an object by its type. More... | |
template<class T > | |
void | addObject (std::shared_ptr< T > ptr, std::string key, std::string def) |
Set an object. More... | |
template<class T > | |
std::size_t | getAllObjects (std::vector< std::shared_ptr< T >> &value) const |
Retrieve all objects of a specified type. More... | |
template<class T > | |
std::size_t | getAllObjectsByKey (std::string key, std::vector< std::shared_ptr< T >> &ptr) const |
Retrieve all objects with the specified key. More... | |
template<> | |
bool | getParam (std::string name, std::string &value) const |
template<> | |
bool | getParam (std::string name, bool &value) const |
template<> | |
std::size_t | getAllParams (std::string name, std::vector< std::string > &value) const |
template<> | |
std::size_t | getAllParams (std::string name, std::vector< bool > &value) const |
A wrapper for the XML parser that also creates and configures the system objects and holds temporary references to them for easy retrieval.
This unit will build an internal tree structure of objects that can be easily retrieved by name or by type, and lists of parameters for each object.
Typical usage:
In XML every node accepts attributes KEY, for specifying container, DEF, for specifying handle, and USE, for reusing node with specified handle.
gramods::gmCore::Configuration::Configuration | ( | ) |
Creates an empty configuration.
gramods::gmCore::Configuration::Configuration | ( | int & | argc, |
char * | argv[], | ||
std::vector< std::string > * | error_list = nullptr |
||
) |
Consumes arguments –config <file>, –xml <string> and –param <identifier>=<value> from the provided command line.
Either –config or –xml is required, upon which the specified file or XML string will be parsed, or gmCore::InvalidArgument will be thrown. Command line argument –param <identifier>=<value> will also override configuration file parameters. For example –param head.connectionString=WAND@localhost
gramods::gmCore::Configuration::Configuration | ( | std::string | config, |
std::vector< std::string > * | error_list = nullptr |
||
) |
Loads an XML string, create objects as specified by the XML data and configure the objects.
gramods::gmCore::Configuration::Configuration | ( | tinyxml2::XMLNode * | node, |
std::vector< std::string > * | error_list = nullptr |
||
) |
Read the XML data, create objects as specified by the XML data and configure the objects.
gramods::gmCore::Configuration::~Configuration | ( | ) |
Cleans up and checks that all configuration variables have been read.
void gramods::gmCore::Configuration::addObject | ( | std::shared_ptr< T > | ptr, |
std::string | key, | ||
std::string | def | ||
) |
Set an object.
void gramods::gmCore::Configuration::addParam | ( | std::string | name, |
std::string | value | ||
) |
Add a parameter value.
size_t gramods::gmCore::Configuration::getAllObjectKeys | ( | std::vector< std::string > & | name | ) |
Adds all currently available object's keys to the specified vector and returns the count.
Keys used for multiple objects will only appear once and be counted once.
std::size_t gramods::gmCore::Configuration::getAllObjects | ( | std::vector< std::shared_ptr< T >> & | value | ) | const |
Retrieve all objects of a specified type.
This function will append the retrieved objects to the specified list. Use gmCore::Object as type to retrieve all objects.
[out] | value | a vector of pointer to fill with objects |
std::size_t gramods::gmCore::Configuration::getAllObjectsByKey | ( | std::string | key, |
std::vector< std::shared_ptr< T >> & | ptr | ||
) | const |
Retrieve all objects with the specified key.
[in] | key | The key of the objects to retrieve |
[out] | ptr | A pointer to the retrieved object, if set |
size_t gramods::gmCore::Configuration::getAllParamNames | ( | std::vector< std::string > & | name | ) |
Adds all currently available parameter names to the specified vector and returns the count.
|
inline |
Retrieves all parameters with a specified name.
If the value type is not string, then this function will use stringstream to parse most types but will need specializations to parse non-standard types.
bool gramods::gmCore::Configuration::getObject | ( | std::shared_ptr< T > & | ptr | ) | const |
Retrieve an object by its type.
If there are multiple objects of the same type, then the first object will be retrieved with this function.
[out] | ptr | A pointer to the retrieved object, if set |
bool gramods::gmCore::Configuration::getObjectByDef | ( | std::string | def, |
std::shared_ptr< T > & | ptr | ||
) | const |
Retrieve an object by its DEF name.
[in] | def | The DEF name of the object to retrieve |
[out] | ptr | A pointer to the object, if set |
bool gramods::gmCore::Configuration::getObjectByKey | ( | std::string | key, |
std::shared_ptr< T > & | ptr | ||
) | const |
Retrieve an object by its key.
If there are multiple objects of the same type, then the first object will be retrieved with this function.
[in] | key | The key of the object to retrieve |
[out] | ptr | A pointer to the object, if set |
bool gramods::gmCore::Configuration::getParam | ( | std::string | name, |
T & | value | ||
) | const |
Retrieves a named parameter as a specified type.
If there are multiple parameters with the same name, there is no saying which will be retrieved with this function.
If the value type is not string, then this function will use stringstream to parse most types but will need specializations to parse non-standard types. If the parameter is not found, the value argument will not be changed.
[in] | name | name of the parameter to retrieve |
[out] | value | the parameter value, if set |
bool gramods::gmCore::Configuration::hasParam | ( | std::string | name | ) |
Check if a specific parameter is available.