Dune Core Modules (2.6.0)

Dune::ParameterTreeParser Class Reference

Parsers to set up a ParameterTree from various input sources. More...

#include <dune/common/parametertreeparser.hh>

Parsing methods for the INITree file format

INITree 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'. Leading and trailing spaces and tabs are removed from the values unless you use single or double quotes around them. Using single or double quotes you can also have multiline values.

static void readINITree (std::istream &in, ParameterTree &pt, bool overwrite)
 parse C++ stream More...
 
static void readINITree (std::istream &in, ParameterTree &pt, const std::string srcname="stream", bool overwrite=true)
 parse C++ stream More...
 
static void readINITree (std::string file, ParameterTree &pt, bool overwrite=true)
 parse file More...
 
static void readOptions (int argc, char *argv[], ParameterTree &pt)
 parse command line options and build hierarchical ParameterTree structure More...
 
static void readNamedOptions (int argc, char *argv[], ParameterTree &pt, std::vector< std::string > keywords, unsigned int required=std::numeric_limits< unsigned int >::max(), bool allow_more=true, bool overwrite=true, std::vector< std::string > help=std::vector< std::string >())
 read [named] command line options and build hierarchical ParameterTree structure More...
 

Detailed Description

Parsers to set up a ParameterTree from various input sources.

Member Function Documentation

◆ readINITree() [1/3]

void Dune::ParameterTreeParser::readINITree ( std::istream &  in,
ParameterTree pt,
bool  overwrite 
)
static

parse C++ stream

Parses C++ stream and build hierarchical config structure.

Parameters
inThe stream to parse
[out]ptThe parameter tree to store the config structure.
overwriteWhether to overwrite already existing values. If false, values in the stream will be ignored if the key is already present.
Note
This method is identical to parseStream(std::istream&, const std::string&, bool) with the exception that that method allows one to give a custom name for the stream.

◆ readINITree() [2/3]

void Dune::ParameterTreeParser::readINITree ( std::istream &  in,
ParameterTree pt,
const std::string  srcname = "stream",
bool  overwrite = true 
)
static

parse C++ stream

Parses C++ stream and build hierarchical config structure.

Parameters
inThe stream to parse
[out]ptThe parameter tree to store the config structure.
srcnameName of the configuration source for error messages, "stdin" or a filename.
overwriteWhether to overwrite already existing values. If false, values in the stream will be ignored if the key is already present.

References DUNE_THROW, Dune::ParameterTree::hasKey(), and Dune::GeometryTypes::line.

◆ readINITree() [3/3]

void Dune::ParameterTreeParser::readINITree ( std::string  file,
ParameterTree pt,
bool  overwrite = true 
)
static

parse file

Parses file with given name and build hierarchical config structure.

Parameters
filefilename
[out]ptThe parameter tree to store the config structure.
overwriteWhether to overwrite already existing values. If false, values in the stream will be ignored if the key is already present.

References DUNE_THROW.

◆ readNamedOptions()

void Dune::ParameterTreeParser::readNamedOptions ( int  argc,
char *  argv[],
ParameterTree pt,
std::vector< std::string >  keywords,
unsigned int  required = std::numeric_limits<unsigned int>::max(),
bool  allow_more = true,
bool  overwrite = true,
std::vector< std::string >  help = std::vector<std::string>() 
)
static

read [named] command line options and build hierarchical ParameterTree structure

Similar to pythons named options we expect the parameters in the ordering induced by keywords, but allow the user to pass named options in the form of –key=value. Optionally the user can pass an additional vector with help strings.

Parameters
argcarg count
argvarg values
[out]ptThe parameter tree to store the config structure.
keywordsvector with keywords names
requirednumber of required options (the first n keywords are required, default is all are required)
allow_moreallow more options than these listed in keywords (default = true)
overwriteallow to overwrite existing options (default = true)
helpvector containing help strings

References DUNE_THROW.

◆ readOptions()

void Dune::ParameterTreeParser::readOptions ( int  argc,
char *  argv[],
ParameterTree pt 
)
static

parse command line options and build hierarchical ParameterTree structure

The list of command line options is searched for pairs of the type -key value (note the hyphen in front of the key). For each such pair of options a key-value pair with the corresponding names is then created in the ParameterTree.

Parameters
argcarg count
argvarg values
[out]ptThe parameter tree to store the config structure.

References DUNE_THROW.


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 28, 23:30, 2024)