#include <global.h>
Public Types | |
typedef std::list< std::string > | PathList |
Type of the path list. | |
typedef std::map< std::string, std::string, misc::insensitive_less > | VarList |
Type of defines list. | |
Public Member Functions | |
ConfGlobal (Conf &conf) | |
Constructor setting the global directives. | |
~ConfGlobal () | |
Destructor. | |
Conf & | directives () const |
Returns the global directives. | |
ConfElse & | else_directive () const |
Returns the ConfElse object. | |
PathList const & | incl_paths () const |
Returns the current include paths. | |
bool | incl_paths_add (std::string const &path, PathList::const_iterator *pi=0) |
Adds an include path. | |
bool | incl_paths_remove (std::string const &path) |
Removes an include path. | |
bool | var_get (std::string const &name, std::string *value=NULL) const |
Retrieves the value of a variable. | |
bool | var_set (std::string const &name, std::string const &value) |
Sets a variable. | |
bool | var_set (std::string const &assignment) |
Sets a variable from an assignment string. | |
bool | var_unset (std::string const &name) |
Unsets a variable. | |
Friends | |
class | Conf |
The include paths are used by Conf::parse_file() as potential paths to look into when opening a configuration file with a non-absolute (i.e. no leading /) name.
Variables are used by the configuration parser to do substitution in quoted strings (i.e. in "$(somename)", will be replaced by the value of the variable named somename).
Finally, global directives are used by the parser as an additional list of directives to look into when resolving a directive name. The local directives are checked before the global ones.
conf::ConfGlobal::ConfGlobal | ( | Conf & | conf | ) | [inline, explicit] |
This constructor will set the global directives list. Global directives are stored in a simple Conf object, so you can add and remove directives to it easily. The object is NOT copied, so it must exist until the ConfGlobal object is destructed.
You do not need to call Conf::begin() or Conf::end() on the Conf object, this is done automatically by the Conf::begin() and Conf::end() functions of the object that owns this ConfGlobal object.
When the ConfDir::set() function is called from the parser for a global directive, the directive's owning Conf object will be temporarily set to the calling Conf object, before being reset to its previous value. This in order to have a meaningful context... =) (Actually it makes it even more practical to write global directives -- they're just like standard ones.)
This constructor will add some default global directives to the list automatically.
Conf& conf::ConfGlobal::directives | ( | ) | const [inline] |
Returns the global directives list. They are stored in a simple object of the Conf class, so you may add and remove directives to it easily.
ConfElse& conf::ConfGlobal::else_directive | ( | ) | const [inline] |
Returns the ConfElse object that has been added to the global directives list as the "else" global directive. This is necessary for ConfIf (and derived) classes to call the ConfElse::can_process() function accordingly.
PathList const& conf::ConfGlobal::incl_paths | ( | ) | const [inline] |
Returns a container of the current include paths. The include paths are used by Conf::parse_file() as potential paths to look into when opening a configuration file with a non-absolute (i.e. no leading /) name.
bool conf::ConfGlobal::incl_paths_add | ( | std::string const & | path, | |
PathList::const_iterator * | pi = 0 | |||
) |
Adds an include path. Existence of the path is checked before being added to the list. If the specified path is not absolute, then it must be relative to either the process current working directory or to a path already in the list, and it is automatically converted to an absolute path.
[in] | path | The new include path. |
[in] | pi | Optional pointer to the iterator that will receive a copy of the iterator to the newly-added path in the list (only when the function returns true). |
bool conf::ConfGlobal::incl_paths_remove | ( | std::string const & | path | ) |
Removes an include path.
[in] | path | The include path to be removed. |
bool conf::ConfGlobal::var_get | ( | std::string const & | name, | |
std::string * | value = NULL | |||
) | const |
Retrieves the value of a given variable (if it exists).
[in] | name | The variable name. |
[out] | value | A pointer to the string that will have been set to the variable value when function returns. If this parameter is NULL then the function just checks whether the variable exists or not. |
bool conf::ConfGlobal::var_set | ( | std::string const & | name, | |
std::string const & | value | |||
) |
Sets a variable to a given value. If a variable with this name already exists its value is overriden.
[in] | name | The variable name. |
[in] | value | The new value of the variable. |
bool conf::ConfGlobal::var_set | ( | std::string const & | assignment | ) |
Sets a variable to a given value, using the given assignment. If a variable with this name already exists its value is overriden.
[in] | assignment | A string in the form xxxx=yyyy where xxxx is the variable name and yyyy is the value. |
bool conf::ConfGlobal::var_unset | ( | std::string const & | name | ) |
Unsets the given variable, if it exists.
[in] | name | The variable name. |