conf::Conf Class Reference

A parser for config files. More...

#include <parser.h>

List of all members.

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.
Confoperator= (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.
ConfDirfind (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.
ConfGlobalglobal () const
 Returns the ConfGlobal object associated with the parser.
ConfLoggerlogger () 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.


Detailed Description

Conf is the base class used to parse configuration directives from any istream object. Each directive is represented by a ConfDir object, and must be added to the Conf list of directives so they can be processed when encountered in the stream.


Constructor & Destructor Documentation

conf::Conf::Conf ConfLogger logger  )  [inline]
 

Constructs the parser.

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


Member Function Documentation

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.

Parameters:
[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.
Returns:
true if the directive has been successfully added, false otherwise.
See also:
remove()

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.

Parameters:
[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).
Returns:
true if initialization went well, false otherwise (in this case, you can't parse anything, and error() should have been called with an appropriate error message).
See also:
ConfDir::begin(), parse(), parsefile(), end(), global(), error()

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).

Returns:
The current context.

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.

Returns:
true if finalization went well, false otherwise (error() should have been called with an appropriate error message in that case).
See also:
ConfDir::end(), parse(), parse_file()

void void conf::Conf::error std::string const &  err  )  const
 

Logs an error message using logger().error(), with current context and line number.

Parameters:
[in] err The error message to be logged.
Returns:
Nothing.

ConfDir* conf::Conf::find std::string const &  name  ) 
 

Finds a directive in the list of valid directives.

Parameters:
[in] name The name of the directive to find.
Returns:
A pointer to the directive with the given name, or NULL if it's not found.
See also:
add()

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.

Returns:
The ConfGlobal object associated with the parser.

unsigned int conf::Conf::line  )  const [inline]
 

Returns the current line number, relative to the current context.

Returns:
The current line number.
See also:
context()

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.

bool conf::Conf::parse std::istream &  is,
std::string const &  context
 

Parses the given stream.

Precondition:
begin() has been called.
Parameters:
[in] is The input stream to parse.
[in] context An arbitrary string giving indication on the parsing location.
Returns:
true if parsing succeeded, false otherwise (error() should have been called with an appropriate error message in that case).
See also:
begin(), error()

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.

Precondition:
begin() has been called.
Parameters:
[in] filename The file to parse.
Returns:
true if parsing succeeded, false otherwise (error() should have been called with an appropriate error message in that case).
See also:
begin(), error()

bool conf::Conf::parse_string std::string const &  str,
std::string const &  context
 

Parses the given string.

Parameters:
[in] str The string to parse.
[in] context An arbitrary string giving indication on the parsing location.
Returns:
true if parsing succeeded, false otherwise (error() should have been called with an appropriate error message in that case).
See also:
begin(), error()

bool conf::Conf::remove ConfDir dir  ) 
 

Removes a directive from the list of valid directives.

Parameters:
[in] dir The configuration directive to be removed.
Returns:
true if the directive was found in the list, false otherwise.
See also:
add()

void conf::Conf::warning std::string const &  msg  )  const
 

Logs a warning message using logger().warning(), with current context and line number.

Parameters:
[in] msg The warning message to be logged.
Returns:
Nothing.


The documentation for this class was generated from the following file:
Generated on Sun May 20 21:32:19 2007 for Epona API by  doxygen 1.4.6