Dune Core Modules (unstable)

Dune::ParameterTree Class Reference

Hierarchical structure of string parameters. More...

#include <dune/common/parametertree.hh>

Public Types

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

Public Member Functions

 ParameterTree ()
 Create new empty ParameterTree.
 
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, bool fail_if_missing=false) 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...
 

Detailed Description

Hierarchical structure of string parameters.

Member Function Documentation

◆ get() [1/4]

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, hasKey(), and Dune::Exception::what().

◆ get() [2/4]

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().

◆ get() [3/4]

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().

Referenced by Dune::SolverFactory< Operator >::get().

◆ get() [4/4]

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().

◆ getSubKeys()

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

◆ getValueKeys()

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

◆ hasKey()

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(), DUNE_THROW, hasKey(), and sub().

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

◆ hasSub()

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(), DUNE_THROW, hasSub(), and sub().

Referenced by hasSub().

◆ operator[]() [1/2]

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(), and sub().

◆ operator[]() [2/2]

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(), and sub().

◆ report()

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

◆ sub() [1/2]

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

get substructure by name

Parameters
subsubstructure name
Returns
reference to substructure

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

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

◆ sub() [2/2]

const ParameterTree & ParameterTree::sub ( const std::string &  sub,
bool  fail_if_missing = false 
) const

get const substructure by name

Parameters
subsubstructure name
fail_if_missingif true, throw an error if substructure is missing
Returns
reference to substructure

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


The documentation for this class was generated from the following files:
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (Mar 27, 23:31, 2024)