Dune::ConfigParser Class Reference
[Common]

#include <configparser.hh>

List of all members.


Detailed Description

Parser for hierarchical configuration files.

This class parses config files into a hierarchical structure. Config files should look like this

	# this file configures fruit colors in fruitsalad
	 
	
	#these are no fruit but could also appear in fruit salad
	honeydewmelon = yellow
	watermelon = green
	
	fruit.tropicalfruit.orange = orange
	
	[fruit]
	strawberry = red
	pomegranate = red
	
	[fruit.pipfruit]
	apple = green/red/yellow
	pear = green
	
	[fruit.stonefruit]
	cherry = red
	plum = purple
	
	

If a '[prefix]' statement appears all following entries use this prefix until the next '[prefix]' statement. Fruitsalads for example contain:

	honeydewmelon = yellow
	fruit.tropicalfruit.orange = orange
	fruit.pipfruit.apple = green/red/yellow
	fruit.stonefruit.cherry = red
	

All keys with a common 'prefix.' belong to the same substructure called 'prefix'.


Public Member Functions

 ConfigParser ()
 Create new ConfigParser.
void parseFile (std::string file)
 parse file
void parseCmd (int argc, char *argv[])
 parse command line
bool hasKey (const std::string &key)
 test for key
bool hasSub (const std::string &sub)
 test for substructure
std::string & operator[] (const std::string &key)
 get value reference for key
void report () const
 print structure to std::cout
void report (const std::string prefix) const
 print distinct substructure to std::cout
ConfigParsersub (const std::string &sub)
 get substructure by name
std::string get (const std::string &key, std::string defaultValue)
 get value as string
int get (const std::string &key, int defaultValue)
 get value as int
double get (const std::string &key, double defaultValue)
 get value as double
bool get (const std::string &key, bool defaultValue)
 get value as bool
const KeyVector & getValueKeys () const
 get value keys
const KeyVector & getSubKeys () const
 get substructure keys

Member Function Documentation

void ConfigParser::parseFile ( std::string  file  ) 

parse file

Parses file with given name and build hierarchical config structure.

Parameters:
file filename

void ConfigParser::parseCmd ( int  argc,
char *  argv[] 
)

parse command line

Parses command line options and build hierarchical config structure.

Parameters:
argc arg count
argv arg values

bool Dune::ConfigParser::hasKey ( const std::string &  key  ) 

test for key

Tests wether given key exists.

Parameters:
key key name
Returns:
true if key exists in structure, otherwise false

bool Dune::ConfigParser::hasSub ( const std::string &  sub  ) 

test for substructure

Tests wether given substructure exists.

Parameters:
sub substructure name
Returns:
true if substructure exists in structure, otherwise false

std::string& Dune::ConfigParser::operator[] ( const std::string &  key  ) 

get value reference for key

Returns refference to value for given key name. This creates the key, if not existent.

Parameters:
key key name
Returns:
reference to coresponding value

void Dune::ConfigParser::report ( const std::string  prefix  )  const

print distinct substructure to std::cout

Prints all entries with given prefix.

Parameters:
prefix for key and substructure names

ConfigParser& Dune::ConfigParser::sub ( const std::string &  sub  ) 

get substructure by name

Parameters:
sub substructure name
Returns:
reference to substructure

std::string Dune::ConfigParser::get ( const std::string &  key,
std::string  defaultValue 
)

get value as string

Returns pure string value for given key.

Parameters:
key key name
defaultValue default if key does not exist
Returns:
value as string

int Dune::ConfigParser::get ( const std::string &  key,
int  defaultValue 
)

get value as int

Returns value for given key interpreted as int.

Parameters:
key key name
defaultValue default if key does not exist
Returns:
value as int

double Dune::ConfigParser::get ( const std::string &  key,
double  defaultValue 
)

get value as double

Returns value for given key interpreted as double.

Parameters:
key key name
defaultValue default if key does not exist
Returns:
value as double

bool Dune::ConfigParser::get ( const std::string &  key,
bool  defaultValue 
)

get value as bool

Returns value for given key interpreted as bool.

Parameters:
key key name
defaultValue default if key does not exist
Returns:
value as bool, false if values = '0', true if value = '1'

const ConfigParser::KeyVector & ConfigParser::getValueKeys (  )  const

get value keys

Returns a vector of all keys associated to (key,values) entries in order of appearance

Returns:
reference to entry vector

const ConfigParser::KeyVector & ConfigParser::getSubKeys (  )  const

get substructure keys

Returns a vector of all keys associated to (key,substructure) entries in order of appearance

Returns:
reference to entry vector


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

Generated on 12 Dec 2007 with Doxygen (ver 1.5.1)