#include <parser.h>
Public Types | |
typedef std::map < std::string, ConfDir *, misc::insensitive_less > | DirList |
Directive list type. | |
Public Member Functions | |
Conf (ConfLogger &logger) | |
Constructor. | |
Conf (Conf const &conf) | |
Copy constructor. | |
~Conf () | |
Destructor. | |
Conf & | operator= (Conf const &right) |
Assignment operator. | |
bool | add (ConfDir &dir) |
Adds a directive to the list of valid directives. | |
bool | remove (ConfDir &dir) |
Removes a directive from the list of valid directives. | |
ConfDir * | find (std::string const &name) |
Finds a directive in the list of valid directives. | |
bool | begin (ConfGlobal &global, bool reload) |
Initializes the parser. | |
bool | parse_file (std::string const &filename) |
Parses a configuration file. | |
bool | parse_string (std::string const &str, std::string const &context) |
Parses a string. | |
bool | parse (std::istream &is, std::string const &context) |
Parses a stream. | |
bool | end () |
Finalizes the parser. | |
void | warning (std::string const &msg) const |
Logs a warning message. | |
void | warningf (char const *format,...) const FORMAT(printf |
Like warning() but with a printf-like syntax. | |
void void | error (std::string const &err) const |
Logs an error message. | |
void | errorf (char const *format,...) const FORMAT(printf |
Like error() but with a printf-like syntax. | |
void DirList const & | directives () const |
Returns the directives list. | |
ConfGlobal & | global () const |
Returns the ConfGlobal object associated with the parser. | |
ConfLogger & | logger () const |
Returns the ConfLogger object associated with the parser. | |
std::string const & | context () const |
Returns the current context. | |
char const * | c_context () const |
Same as context() but returns a char const *. | |
unsigned int | line () const |
Returns the current line number. | |
bool | ready () const |
Returns whether begin(), but not end(), has been called yet. | |
bool | reloading () const |
Returns whether the configuration is being reloaded. |
conf::Conf::Conf | ( | ConfLogger & | logger | ) | [inline] |
Constructs the parser.
[in] | logger | The ConfLogger object that will be used by the debug() and error() functions to log messages. It is not copied, and must therefore remain instantiated until the parser is destroyed. |
bool conf::Conf::add | ( | ConfDir & | dir | ) |
Adds a directive to the list of valid directives. This directive will then be set when encountered by the configuration parser.
This function assumes that no directive with the same name is already in the list.
[in] | dir | The configuration directive to be added. It is NOT copied and therefore must be valid till the remove() function is called, or the object is destroyed. |
bool conf::Conf::remove | ( | ConfDir & | dir | ) |
Removes a directive from the list of valid directives.
[in] | dir | The configuration directive to be removed. |
ConfDir* conf::Conf::find | ( | std::string const & | name | ) |
Finds a directive in the list of valid directives.
[in] | name | The name of the directive to find. |
bool conf::Conf::begin | ( | ConfGlobal & | global, | |
bool | reload | |||
) |
Initializes the parser and calls the begin() member functions for all directives in the list. This function MUST be called before using the parse() and parse_file() member functions (you may call those as many times as you want without having to call begin() again). Don't forget to call end() when ALL parsing is finished.
[in] | global | Sets the ConfGlobal object associated to the parser. It will be automatically unset when end() is called. The begin() and end() functions of the global directives will be automatically called. The object is not copied, and must therefore remain valid until end() is called. |
[in] | reload | Specifies whether the configuration is being reloaded (true) or not (false). |
bool conf::Conf::parse_file | ( | std::string const & | filename | ) |
Parses the given configuration file. The parser context will be set to the name of the file.
[in] | filename | The file to parse. |
bool conf::Conf::parse_string | ( | std::string const & | str, | |
std::string const & | context | |||
) |
Parses the given string.
[in] | str | The string to parse. |
[in] | context | An arbitrary string giving indication on the parsing location. |
bool conf::Conf::parse | ( | std::istream & | is, | |
std::string const & | context | |||
) |
Parses the given stream.
[in] | is | The input stream to parse. |
[in] | context | An arbitrary string giving indication on the parsing location. |
bool conf::Conf::end | ( | ) |
Finalizes the parser (does any cleanup task) and calls the end() member functions of all directives in the list and all directives of the ConfGlobal object associated to this object. This function MUST be called after all parsing has been done through the parse() and parse_file() functions.
void conf::Conf::warning | ( | std::string const & | msg | ) | const |
void void conf::Conf::error | ( | std::string const & | err | ) | const |
ConfGlobal& conf::Conf::global | ( | ) | const [inline] |
Returns the ConfGlobal object associated with the parser. This object is used by the parser when it needs to look for defines, global directives and config files search path.
ConfLogger& conf::Conf::logger | ( | ) | const [inline] |
Returns the ConfLogger object associated with the parser. This object is used by the debug() and error() member functions to log messages.
std::string const& conf::Conf::context | ( | ) | const [inline] |
Returns the current context, i.e. a string that helps identify the current parsing location (for example, a directive name or a file).
unsigned int conf::Conf::line | ( | ) | const [inline] |
Returns the current line number, relative to the current context.