configuration::StringConfigurationParser Class Reference

#include <confparser.h>

Inheritance diagram for configuration::StringConfigurationParser:
configuration::IConfigurationParser< std::string, std::string >

List of all members.

Public Member Functions

 StringConfigurationParser (std::istream *str)
std::string setCommentsSet (std::string set)
std::string setBlankSet (std::string set)
std::string setDeliminersSet (std::string set)
void skip ()
bool parse (std::string &key, std::string &value)
bool eod ()

Private Attributes

std::string delimiterSet
std::string commentsSet
std::string blankSet

Static Private Attributes

static const size_t LINELENGTH = 1024

Detailed Description

Simple string parser. Reads input stream by lines and split line according delimiter. Everything before delimiters member is marked as key and everything after as value.
Deliminers are specified as set of characters where each stands for separator.


Constructor & Destructor Documentation

configuration::StringConfigurationParser::StringConfigurationParser ( std::istream *  str  )  [inline]

Initialization constructor.

Parameters:
str Input stream with data.

Initializes stream field with str and initializes *Set fields with default values.

References blankSet, commentsSet, and delimiterSet.


Member Function Documentation

bool configuration::StringConfigurationParser::eod (  )  [inline, virtual]

Returns istream::eof(). If no stream is specified, returns with true.

Implements configuration::IConfigurationParser< std::string, std::string >.

References configuration::IConfigurationParser< std::string, std::string >::stream.

bool configuration::StringConfigurationParser::parse ( std::string &  key,
std::string &  value 
) [inline, virtual]

Parses valid line. Reads line from current stream position. Removes comments (everything behind membet of commentsSet character). Removes intials and trailing blanks (all characters from blankSet). If result data are empty, parses following line. Otherwise starts parsing.
Parsing process is very simple and just searches first occurence of character from delimiterSet. Everything before separator is used to initialize key parameter and everything behind to value parameter. If none from delimiterSet is found assumes that value is empty and key is whole parsed string.
Both key and value are trimed (leading and trailing blanks - all from blankSet are removed).
If any error occures while reading or end of file occured, returns with false and key, value parameters are not filled.
If no stream is set, immediately returns with false.
Note that input stream can't contain 0 characters.

Returns:
true if line was parsed or false otherwise.

Implements configuration::IConfigurationParser< std::string, std::string >.

References blankSet, commentsSet, delimiterSet, LINELENGTH, configuration::IConfigurationParser< std::string, std::string >::stream, and configuration::utils::trim().

std::string configuration::StringConfigurationParser::setBlankSet ( std::string  set  )  [inline]

Sets new blankSet.

Parameters:
set Set of characters.
Returns:
Current set value.

References blankSet.

std::string configuration::StringConfigurationParser::setCommentsSet ( std::string  set  )  [inline]

Sets new commentsSet.

Parameters:
set Set of characters.
Returns:
Current set value.

References commentsSet.

std::string configuration::StringConfigurationParser::setDeliminersSet ( std::string  set  )  [inline]

Sets new delimiterSet.

Parameters:
set Set of characters.
Returns:
Current set value.

References delimiterSet.

void configuration::StringConfigurationParser::skip (  )  [inline, virtual]

Reads one line and throw it away.

If no stream is specified, immediately returns.

Implements configuration::IConfigurationParser< std::string, std::string >.

References LINELENGTH, and configuration::IConfigurationParser< std::string, std::string >::stream.


Member Data Documentation

Set of characters for blanks. Default value contains ` ', `' characters.

Referenced by parse(), setBlankSet(), and StringConfigurationParser().

Set of characters for comments. Default value contains `', `#' characters.

Referenced by parse(), setCommentsSet(), and StringConfigurationParser().

Set of delimiters. Each character is one delimiter. Default value contains `:' character.

Referenced by parse(), setDeliminersSet(), and StringConfigurationParser().

const size_t configuration::StringConfigurationParser::LINELENGTH = 1024 [static, private]

Maximum line length constant.

Referenced by parse(), and skip().


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