3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
Public Member Functions | List of all members
Dumux::LoggingParameterTree Class Reference

A parameter tree that logs which parameters have been used. More...

#include <dumux/common/loggingparametertree.hh>

Description

A parameter tree that logs which parameters have been used.

Public Member Functions

 LoggingParameterTree ()=delete
 
 LoggingParameterTree (const Dune::ParameterTree &params, const Dune::ParameterTree &defaultParams)
 
bool hasKey (const std::string &key) const
 test for key More...
 
bool hasKeyInGroup (const std::string &key, const std::string &groupPrefix) const
 test for key in group More...
 
std::vector< std::string > getSubGroups (const std::string &subGroupName, std::string groupPrefix) const
 obtain a vector of all full group names for a specified subgroup name More...
 
void report (std::ostream &stream=std::cout) const
 print the hierarchical parameter tree to stream More...
 
void reportAll (std::ostream &stream=std::cout) const
 print distinct substructure to stream More...
 
std::string findKeyInGroup (const Dune::ParameterTree &tree, const std::string &key, const std::string &groupPrefix) const
 Do a backwards hierarchical search for a key in a group. More...
 
std::string get (const std::string &key, const std::string &defaultValue) const
 get value as string More...
 
std::string getFromGroup (const std::string &groupPrefix, const std::string &key, const std::string &defaultValue) const
 get value as string, preferably from the sub-tree corresponding to a given prefix. The sub-tree is searched backwards for the parameter until its "first" occurrence. More...
 
std::string get (const std::string &key, const char *defaultValue) const
 get value as string More...
 
std::string getFromGroup (const std::string &groupPrefix, const std::string &key, const char *defaultValue) const
 get value as string, preferably from the sub-tree corresponding to a given prefix. The sub-tree is searched for the parameter recursively until its "first" occurrence. More...
 
template<typename T >
get (const std::string &key, const T &defaultValue) const
 get value converted to a certain type More...
 
template<typename T >
getFromGroup (const std::string &groupPrefix, const std::string &key, const T &defaultValue) const
 get value as string, preferably from the sub-tree corresponding to a given prefix. The sub-tree is searched for the parameter recursively until its "first" occurrence. More...
 
template<class T >
get (const std::string &key) const
 Get value. More...
 
template<typename T >
getFromGroup (const std::string &groupPrefix, const std::string &key) const
 get value as string, preferably from the sub-tree corresponding to a given prefix. The sub-tree is searched for the parameter recursively until its "first" occurrence. More...
 
std::vector< std::string > getUnusedKeys () const
 Find the keys that haven't been used yet. More...
 

Constructor & Destructor Documentation

◆ LoggingParameterTree() [1/2]

Dumux::LoggingParameterTree::LoggingParameterTree ( )
delete

◆ LoggingParameterTree() [2/2]

Dumux::LoggingParameterTree::LoggingParameterTree ( const Dune::ParameterTree &  params,
const Dune::ParameterTree &  defaultParams 
)
inline

Member Function Documentation

◆ findKeyInGroup()

std::string Dumux::LoggingParameterTree::findKeyInGroup ( const Dune::ParameterTree &  tree,
const std::string &  key,
const std::string &  groupPrefix 
) const
inline

Do a backwards hierarchical search for a key in a group.

Note
Given a group this function starts to look from the back for dots. In G1.G2.G3 the function first looks if the key "G3.Key" exists, then "G2.Key", ... The first compound key that is found is returned. If no compound key is found an empty string is returned.
Parameters
treeThe tree to look in for keys
keyThe key
groupPrefixthe group prefix attached to the key

◆ get() [1/4]

template<class T >
T Dumux::LoggingParameterTree::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
Note
This might be quite slow so call it only once, e.g. on initialization of the class configured by runtime parameters

◆ get() [2/4]

std::string Dumux::LoggingParameterTree::get ( const std::string &  key,
const char *  defaultValue 
) const
inline

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
Note
This might be quite slow so call it only once, e.g. on initialization of the class configured by runtime parameters

◆ get() [3/4]

std::string Dumux::LoggingParameterTree::get ( const std::string &  key,
const std::string &  defaultValue 
) const
inline

get value as string

Returns pure string value for given key.

Parameters
keykey name
defaultValuedefault if key does not exist
Returns
value as string
Note
This might be quite slow so call it only once, e.g. on initialization of the class configured by runtime parameters

◆ get() [4/4]

template<typename T >
T Dumux::LoggingParameterTree::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
Note
This might be quite slow so call it only once, e.g. on initialization of the class configured by runtime parameters

◆ getFromGroup() [1/4]

template<typename T >
T Dumux::LoggingParameterTree::getFromGroup ( const std::string &  groupPrefix,
const std::string &  key 
) const
inline

get value as string, preferably from the sub-tree corresponding to a given prefix. The sub-tree is searched for the parameter recursively until its "first" occurrence.

Returns pure string value for given key.

Parameters
groupPrefixThe prefix of the sub tree the search should start in
keykey name
Returns
value as string
Note
This might be quite slow so call it only once, e.g. on initialization of the class configured by runtime parameters

◆ getFromGroup() [2/4]

std::string Dumux::LoggingParameterTree::getFromGroup ( const std::string &  groupPrefix,
const std::string &  key,
const char *  defaultValue 
) const
inline

get value as string, preferably from the sub-tree corresponding to a given prefix. The sub-tree is searched for the parameter recursively until its "first" occurrence.

Returns pure string value for given key.

Parameters
groupPrefixThe prefix of the sub tree the search should start in
keykey name
defaultValuedefault if key does not exist
Returns
value as string
Note
This might be quite slow so call it only once, e.g. on initialization of the class configured by runtime parameters

◆ getFromGroup() [3/4]

std::string Dumux::LoggingParameterTree::getFromGroup ( const std::string &  groupPrefix,
const std::string &  key,
const std::string &  defaultValue 
) const
inline

get value as string, preferably from the sub-tree corresponding to a given prefix. The sub-tree is searched backwards for the parameter until its "first" occurrence.

Returns pure string value for given key.

Parameters
groupPrefixThe prefix of the sub tree the search should start in
keykey name
defaultValuedefault if key does not exist
Returns
value as string
Note
This might be quite slow so call it only once, e.g. on initialization of the class configured by runtime parameters

◆ getFromGroup() [4/4]

template<typename T >
T Dumux::LoggingParameterTree::getFromGroup ( const std::string &  groupPrefix,
const std::string &  key,
const T &  defaultValue 
) const
inline

get value as string, preferably from the sub-tree corresponding to a given prefix. The sub-tree is searched for the parameter recursively until its "first" occurrence.

Returns pure string value for given key.

Parameters
groupPrefixThe prefix of the sub tree the search should start in
keykey name
defaultValuedefault if key does not exist
Returns
value as string
Note
This might be quite slow so call it only once, e.g. on initialization of the class configured by runtime parameters

◆ getSubGroups()

std::vector< std::string > Dumux::LoggingParameterTree::getSubGroups ( const std::string &  subGroupName,
std::string  groupPrefix 
) const
inline

obtain a vector of all full group names for a specified subgroup name

Example:

For the parameter tree

[G1] MyParam1 = 1 [G2.G1] MyParam2 = 2 [G3.G2.G1] MyParam3 = 3

and groupPrefix="G3.G2" and subGroupName="G1" this returns a vector with the entries {"G3.G2.G1", "G2.G1", "G1"}. If groupPrefix = "G2", it returns {"G2.G1", "G1"}. If groupPrefix = "" the returned vector has size 1 (containing subGroupName), or size 0 if the subgroup does not exist in the parameter tree.

Parameters
subGroupNamethe sub group to look for
groupPrefixthe group prefix name (potentially prefixing the subgroup)
Returns
a vector of fully qualified groups ordered by decreasing tree depth

◆ getUnusedKeys()

std::vector< std::string > Dumux::LoggingParameterTree::getUnusedKeys ( ) const
inline

Find the keys that haven't been used yet.

Returns
unusedParams Container storing unused keys
Note
Useful for debugging purposes

◆ hasKey()

bool Dumux::LoggingParameterTree::hasKey ( const std::string &  key) const
inline

test for key

Tests whether given key exists.

Note
This ignores defaults. Hence, if the the specified key only exists in the defaults, this function returns false
Parameters
keykey name
Returns
true if key exists in structure, otherwise false

◆ hasKeyInGroup()

bool Dumux::LoggingParameterTree::hasKeyInGroup ( const std::string &  key,
const std::string &  groupPrefix 
) const
inline

test for key in group

Tests whether given key exists in a group. Given a group this function starts to look from the back for dots. In G1.G2.G3 the function first looks if the key "G3.Key" exists, then "G2.Key", ...

Note
This ignores defaults. Hence, if the the specified key only exists in the defaults, this function returns false
Parameters
keykey name
groupPrefixthe group prefix name
Returns
true if key exists in structure, otherwise false

◆ report()

void Dumux::LoggingParameterTree::report ( std::ostream &  stream = std::cout) const
inline

print the hierarchical parameter tree to stream

Parameters
streamthe output stream to print to

◆ reportAll()

void Dumux::LoggingParameterTree::reportAll ( std::ostream &  stream = std::cout) const
inline

print distinct substructure to stream

Prints all entries with given prefix.

Parameters
streamStream to print to

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