dune-common  2.4.1-rc2
Classes | Public Types | Public Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
Dune::ParameterTree Class Reference

Hierarchical structure of string parameters. More...

#include <dune/common/parametertree.hh>

Classes

struct  Parser< array< T, n > >
 
struct  Parser< bool >
 
struct  Parser< FieldVector< T, n > >
 
struct  Parser< std::basic_string< char, traits, Allocator > >
 
struct  Parser< std::bitset< n > >
 
struct  Parser< std::vector< T, A > >
 

Public Types

typedef std::vector< std::string > KeyVector
 storage for key lists More...
 

Public Member Functions

 ParameterTree ()
 Create new empty ParameterTree. More...
 
bool hasKey (const std::string &key) const
 test for key More...
 
bool hasSub (const std::string &sub) const
 test for substructure More...
 
std::string & operator[] (const std::string &key)
 get value reference for key More...
 
const std::string & operator[] (const std::string &key) const
 get value reference for key More...
 
void report (std::ostream &stream=std::cout, const std::string &prefix="") const
 print distinct substructure to stream More...
 
ParameterTreesub (const std::string &sub)
 get substructure by name More...
 
const ParameterTreesub (const std::string &sub) const
 get const substructure by name More...
 
std::string get (const std::string &key, const std::string &defaultValue) const
 get value as string More...
 
std::string get (const std::string &key, const char *defaultValue) const
 get value as string More...
 
template<typename T >
get (const std::string &key, const T &defaultValue) const
 get value converted to a certain type More...
 
template<class T >
get (const std::string &key) const
 Get value. More...
 
const KeyVectorgetValueKeys () const
 get value keys More...
 
const KeyVectorgetSubKeys () const
 get substructure keys More...
 

Static Protected Member Functions

static std::string ltrim (const std::string &s)
 
static std::string rtrim (const std::string &s)
 
static std::vector< std::string > split (const std::string &s)
 
template<class Iterator >
static void parseRange (const std::string &str, Iterator it, const Iterator &end)
 

Protected Attributes

std::string prefix_
 
KeyVector valueKeys_
 
KeyVector subKeys_
 
std::map< std::string, std::string > values_
 
std::map< std::string, ParameterTreesubs_
 

Detailed Description

Hierarchical structure of string parameters.

Member Typedef Documentation

typedef std::vector<std::string> Dune::ParameterTree::KeyVector

storage for key lists

Constructor & Destructor Documentation

ParameterTree::ParameterTree ( )

Create new empty ParameterTree.

Member Function Documentation

std::string ParameterTree::get ( const std::string &  key,
const std::string &  defaultValue 
) const

get value as string

Returns pure string value for given key.

Parameters
keykey name
defaultValuedefault if key does not exist
Returns
value as string

References hasKey().

std::string ParameterTree::get ( const std::string &  key,
const char *  defaultValue 
) const

get value as string

Returns pure string value for given key.

Todo:
This is a hack so get("my_key", "xyz") compiles (without this method "xyz" resolves to bool instead of std::string)
Parameters
keykey name
defaultValuedefault if key does not exist
Returns
value as string

References hasKey().

template<typename T >
T Dune::ParameterTree::get ( const std::string &  key,
const T &  defaultValue 
) const
inline

get value converted to a certain type

Returns value as type T for given key.

Template Parameters
Ttype of returned value.
Parameters
keykey name
defaultValuedefault if key does not exist
Returns
value converted to T

References hasKey().

template<class T >
T Dune::ParameterTree::get ( const std::string &  key) const
inline

Get value.

Template Parameters
TType of the value
Parameters
keyKey name
Exceptions
RangeErrorif key does not exist
NotImplementedType is not supported
Returns
value as T

References DUNE_THROW, getSubKeys(), getValueKeys(), hasKey(), prefix_, and Dune::Exception::what().

const ParameterTree::KeyVector & ParameterTree::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

References subKeys_.

Referenced by get().

const ParameterTree::KeyVector & ParameterTree::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

References valueKeys_.

Referenced by get().

bool ParameterTree::hasKey ( const std::string &  key) const

test for key

Tests whether given key exists.

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

References Dune::dot(), hasKey(), sub(), subs_, and values_.

Referenced by get(), hasKey(), operator[](), and Dune::ParameterTreeParser::readINITree().

bool ParameterTree::hasSub ( const std::string &  sub) const

test for substructure

Tests whether given substructure exists.

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

References Dune::dot(), hasSub(), sub(), and subs_.

Referenced by hasSub(), and operator[]().

std::string ParameterTree::ltrim ( const std::string &  s)
staticprotected
std::string & ParameterTree::operator[] ( const std::string &  key)

get value reference for key

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

Parameters
keykey name
Returns
reference to corresponding value

References Dune::dot(), hasKey(), hasSub(), sub(), subKeys_, subs_, valueKeys_, and values_.

const std::string & ParameterTree::operator[] ( const std::string &  key) const

get value reference for key

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

Parameters
keykey name
Returns
reference to corresponding value
Exceptions
Dune::RangeErrorif key is not found

References Dune::dot(), DUNE_THROW, hasKey(), prefix_, sub(), and values_.

template<class Iterator >
static void Dune::ParameterTree::parseRange ( const std::string &  str,
Iterator  it,
const Iterator &  end 
)
inlinestaticprotected
void ParameterTree::report ( std::ostream &  stream = std::cout,
const std::string &  prefix = "" 
) const

print distinct substructure to stream

Prints all entries with given prefix.

Parameters
streamStream to print to
prefixfor key and substructure names

References prefix_, subs_, and values_.

std::string ParameterTree::rtrim ( const std::string &  s)
staticprotected
std::vector< std::string > ParameterTree::split ( const std::string &  s)
staticprotected
ParameterTree & ParameterTree::sub ( const std::string &  sub)

get substructure by name

Parameters
subsubstructure name
Returns
reference to substructure

References Dune::dot(), prefix_, sub(), subKeys_, and subs_.

Referenced by hasKey(), hasSub(), operator[](), Dune::ParameterTree::Parser< std::bitset< n > >::parse(), Dune::ParameterTree::Parser< std::vector< T, A > >::parse(), and sub().

const ParameterTree & ParameterTree::sub ( const std::string &  sub) const

get const substructure by name

Parameters
subsubstructure name
Returns
reference to substructure

References Dune::dot(), DUNE_THROW, prefix_, sub(), and subs_.

Member Data Documentation

std::string Dune::ParameterTree::prefix_
protected

Referenced by get(), operator[](), report(), and sub().

KeyVector Dune::ParameterTree::subKeys_
protected

Referenced by getSubKeys(), operator[](), and sub().

std::map<std::string, ParameterTree> Dune::ParameterTree::subs_
protected

Referenced by hasKey(), hasSub(), operator[](), report(), and sub().

KeyVector Dune::ParameterTree::valueKeys_
protected

Referenced by getValueKeys(), and operator[]().

std::map<std::string, std::string> Dune::ParameterTree::values_
protected

Referenced by hasKey(), operator[](), and report().


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