Serial-TCP/IPbridge  1.0
Classes | Public Types | Static Public Member Functions | Private Member Functions | Static Private Member Functions | List of all members
ConfigParser Class Reference

Configuration parser. More...

#include <config_parser.h>

Classes

class  ParsingError
 This exception is thrown if there is an error during parsing. More...
 

Public Types

typedef std::map< std::string,
std::string > 
ParsedConfig
 Option -> values mapping. More...
 

Static Public Member Functions

static ParsedConfig parse (const std::string &rawConfig)
 Parses a configuration from the selected string. More...
 

Private Member Functions

 ConfigParser ()
 
 ConfigParser (const ConfigParser &)
 
ConfigParseroperator= (const ConfigParser &)
 
 ~ConfigParser ()
 

Static Private Member Functions

static bool isValidOptionChar (char c)
 Checks whether the selected character is a valid part of an option name. More...
 
static bool isValidValueChar (char c)
 Checks whether the selected character is a valid part of an option value. More...
 

Detailed Description

Configuration parser.

This class is used to parse a configuration string that is in format:

Comment

option1 value1

Another comment

option2 value2

Comments are not be parsed. Option values must be separated from the option name by whitespaces and are parsed until an end of line ('
'). This means that each option-value pair must be ended with a new line. Option names can contain only alphanumeric characters and the following characters: '_', '-'. Option values can contain any characters except '
'.

If there are more than one option with the same name, only the last value of this option will be taken into account.

Static helper class (aka "library class").

Member Typedef Documentation

typedef std::map<std::string, std::string> ConfigParser::ParsedConfig

Option -> values mapping.

Constructor & Destructor Documentation

ConfigParser::ConfigParser ( )
private
ConfigParser::ConfigParser ( const ConfigParser )
private
ConfigParser::~ConfigParser ( )
private

Member Function Documentation

static bool ConfigParser::isValidOptionChar ( char  c)
staticprivate

Checks whether the selected character is a valid part of an option name.

Parameters
cCharacter to be checked.
Returns
True if the selected character is a valid part of an option name, false otherwise.
static bool ConfigParser::isValidValueChar ( char  c)
staticprivate

Checks whether the selected character is a valid part of an option value.

Parameters
cCharacter to be checked.
Returns
True if the selected character is a valid part of an option value, false otherwise.
ConfigParser& ConfigParser::operator= ( const ConfigParser )
private
static ParsedConfig ConfigParser::parse ( const std::string &  rawConfig)
static

Parses a configuration from the selected string.

Parameters
rawConfigThe string from which the configuration will be parsed.
Returns
Parsed configuration, i.e. option -> values mapping.

See class description for more info about the configuration format. If there is an error during parsing, ParsingError will be thrown.

Meets the strong guarantee of exception safety.


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