lbm_reference
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
confparser::ConfBlock Class Reference

Data structure corresponding to one block in the hierarchical configuration file. More...

#include <confparser/ConfBlock.h>

+ Collaboration diagram for confparser::ConfBlock:

Public Types

typedef std::multimap
< std::string, ConfBlock >
::iterator 
childIter
 Iterator type for the children of the block. More...
 
typedef std::pair< childIter,
childIter
childIterPair
 
typedef std::map< std::string,
std::string >::iterator 
propIter
 

Public Member Functions

ConfBlockaddChild (std::string blockName)
 Add a child with given name to children of current block. More...
 
bool addParam (std::string key, std::string value)
 Add a key value pair. More...
 
 ConfBlock ()
 Default constructor to create a new (empty) block. More...
 
bool empty ()
 Check whether the block is empty. More...
 
ConfBlockfind (std::string blockName)
 Find a block with given name among the children. More...
 
std::pair< childIter, childIterfindAll (std::string blockName)
 Find all blocks with given name among the children. More...
 
template<typename T >
getParam (std::string key) throw ( std::invalid_argument )
 Retrieve parameter as certain type. More...
 
template<typename T >
bool getParam (std::string key, T &value) throw ( std::invalid_argument )
 Retrieve parameter as certain type. More...
 
int removeChildren (std::string blockName)
 Remove all children with given name. More...
 
bool removeParam (std::string key)
 Remove parameter with a given key. More...
 
template<typename T >
bool setParam (std::string key, T value)
 Set parameter. More...
 
void writeConfigFile (std::string fileName)
 Write out a configuration file of this block's subtree. More...
 
virtual ~ConfBlock ()
 Destructor. More...
 

Protected Member Functions

void writeConfigFileRec (std::ofstream &fileHandle, std::string indent)
 Recursive helper function to write the configuration of a subtree to a file. More...
 

Protected Attributes

std::multimap< std::string,
ConfBlock
children_
 Multimap containing the children. More...
 
std::map< std::string,
std::string > 
props_
 Map containing parameter key / value pairs defined in this block. More...
 

Friends

class ConfParser
 Declare ConfParser as friend class to give it access to internals. More...
 

Detailed Description

Data structure corresponding to one block in the hierarchical configuration file.

Definition at line 80 of file ConfBlock.h.

Member Typedef Documentation

typedef std::multimap< std::string, ConfBlock >::iterator confparser::ConfBlock::childIter

Iterator type for the children of the block.

Definition at line 90 of file ConfBlock.h.

Definition at line 92 of file ConfBlock.h.

typedef std::map< std::string, std::string >::iterator confparser::ConfBlock::propIter

Definition at line 91 of file ConfBlock.h.

Constructor & Destructor Documentation

confparser::ConfBlock::ConfBlock ( )
inline

Default constructor to create a new (empty) block.

Parameters and children will be empty

Definition at line 102 of file ConfBlock.h.

Referenced by addChild().

virtual confparser::ConfBlock::~ConfBlock ( )
inlinevirtual

Destructor.

Does nothing

Definition at line 108 of file ConfBlock.h.

Member Function Documentation

ConfBlock& confparser::ConfBlock::addChild ( std::string  blockName)
inline

Add a child with given name to children of current block.

Parameters
[in]blockNameBlock name of child to add
Returns
Reference to newly added child

Definition at line 192 of file ConfBlock.h.

References children_, and ConfBlock().

Referenced by confparser::ConfParser::parse_rec().

bool confparser::ConfBlock::addParam ( std::string  key,
std::string  value 
)
inline

Add a key value pair.

Parameters
[in]keyParameter name to add
[in]valueParameter value to add
Returns
true if a new key value pair was actually created, false if the key already existed

Definition at line 213 of file ConfBlock.h.

References props_.

Referenced by confparser::ConfParser::parse_rec().

bool confparser::ConfBlock::empty ( )
inline

Check whether the block is empty.

Returns
true if block is empty, i.e. children and parameters are empty, false otherwise

Definition at line 119 of file ConfBlock.h.

References children_, and props_.

ConfBlock* confparser::ConfBlock::find ( std::string  blockName)
inline

Find a block with given name among the children.

Parameters
[in]blockNameName of the block to retrieve
Returns
Pointer to searched for block, NULL if none was found

Definition at line 128 of file ConfBlock.h.

References children_.

Referenced by particles::ParticleSystem::setup().

std::pair< childIter, childIter > confparser::ConfBlock::findAll ( std::string  blockName)
inline

Find all blocks with given name among the children.

Parameters
[in]blockNameName of the blocks to retrieve
Returns
Pair of iterators into the children pointing to the first and after the last block found, are the same if none was found. Blocks can be retrieved by ->second property of the iterator.

Definition at line 141 of file ConfBlock.h.

References children_.

Referenced by particles::ParticleSystem::setup().

template<typename T >
T confparser::ConfBlock::getParam ( std::string  key) throw ( std::invalid_argument )
inline

Retrieve parameter as certain type.

Parameters
[in]keyParameter name to retrieve
Template Parameters
TType to retrieve parameter in
Returns
Parameter specified by key as type T

Definition at line 152 of file ConfBlock.h.

References props_, and lbm::T.

Referenced by particles::ParticleSystem::setup().

template<typename T >
bool confparser::ConfBlock::getParam ( std::string  key,
T &  value 
) throw ( std::invalid_argument )
inline

Retrieve parameter as certain type.

Parameters
[in]keyParameter name to retrieve
[out]valueVariable to store value in
Template Parameters
TType to retrieve parameter in
Returns
true if parameter was found, false if not
Note
Will not throw an exception, instead return value must be checked

Definition at line 172 of file ConfBlock.h.

References props_, and lbm::T.

int confparser::ConfBlock::removeChildren ( std::string  blockName)
inline

Remove all children with given name.

Parameters
[in]blockNameBlock name of children to remove
Returns
Number of blocks removed, 0 if none of the given name were found

Definition at line 202 of file ConfBlock.h.

References children_.

bool confparser::ConfBlock::removeParam ( std::string  key)
inline

Remove parameter with a given key.

Parameters
[in]keyParameter key to remove
Returns
true if the key / value pair was removed, false if it was not found

Definition at line 240 of file ConfBlock.h.

References props_.

template<typename T >
bool confparser::ConfBlock::setParam ( std::string  key,
value 
)
inline

Set parameter.

Parameters
[in]keyParameter name to set
[in]valueParameter value to set
Template Parameters
TType of the parameter to set (will be converted to string)
Returns
true if the parameter was actually set, false if it does not exist

Definition at line 227 of file ConfBlock.h.

References props_.

void confparser::ConfBlock::writeConfigFile ( std::string  fileName)

Write out a configuration file of this block's subtree.

Parameters
[in]fileNameName of the configuration file to write out

Definition at line 19 of file ConfBlock.cpp.

References writeConfigFileRec().

Referenced by main().

void confparser::ConfBlock::writeConfigFileRec ( std::ofstream &  fileHandle,
std::string  indent 
)
protected

Recursive helper function to write the configuration of a subtree to a file.

Parameters
[in]fileHandleStream to write to
[in]indentLevel of indentation for the current block

Definition at line 32 of file ConfBlock.cpp.

References children_, and props_.

Referenced by writeConfigFile().

Friends And Related Function Documentation

friend class ConfParser
friend

Declare ConfParser as friend class to give it access to internals.

Definition at line 84 of file ConfBlock.h.

Member Data Documentation

std::multimap< std::string, ConfBlock > confparser::ConfBlock::children_
protected

Multimap containing the children.

Definition at line 274 of file ConfBlock.h.

Referenced by addChild(), empty(), find(), findAll(), removeChildren(), and writeConfigFileRec().

std::map< std::string, std::string > confparser::ConfBlock::props_
protected

Map containing parameter key / value pairs defined in this block.

Definition at line 270 of file ConfBlock.h.

Referenced by addParam(), empty(), getParam(), removeParam(), setParam(), and writeConfigFileRec().


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