Reference documentation for deal.II version 8.1.0
Public Types | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
ParameterHandler Class Reference

#include <parameter_handler.h>

Inheritance diagram for ParameterHandler:
[legend]

Public Types

enum  OutputStyle {
  Text = 1, LaTeX = 2, Description = 3, XML = 4,
  JSON = 5, ShortText = 193
}
 

Public Member Functions

 ParameterHandler ()
 
virtual ~ParameterHandler ()
 
virtual bool read_input (std::istream &input, const std::string &filename="input file")
 
virtual bool read_input (const std::string &filename, const bool optional=false, const bool write_stripped_file=false)
 
virtual bool read_input_from_string (const char *s)
 
virtual bool read_input_from_xml (std::istream &input)
 
void clear ()
 
void declare_entry (const std::string &entry, const std::string &default_value, const Patterns::PatternBase &pattern=Patterns::Anything(), const std::string &documentation=std::string())
 
void enter_subsection (const std::string &subsection)
 
bool leave_subsection ()
 
std::string get (const std::string &entry_string) const
 
long int get_integer (const std::string &entry_string) const
 
double get_double (const std::string &entry_name) const
 
bool get_bool (const std::string &entry_name) const
 
void set (const std::string &entry_name, const std::string &new_value)
 
void set (const std::string &entry_name, const char *new_value)
 
void set (const std::string &entry_name, const long int &new_value)
 
void set (const std::string &entry_name, const double &new_value)
 
void set (const std::string &entry_name, const bool &new_value)
 
std::ostream & print_parameters (std::ostream &out, const OutputStyle style)
 
void print_parameters_section (std::ostream &out, const OutputStyle style, const unsigned int indent_level)
 
void log_parameters (LogStream &out)
 
void log_parameters_section (LogStream &out)
 
std::size_t memory_consumption () const
 
template<class Archive >
void save (Archive &ar, const unsigned int version) const
 
template<class Archive >
void load (Archive &ar, const unsigned int version)
 
bool operator== (const ParameterHandler &prm2) const
 
 DeclException1 (ExcEntryAlreadyExists, std::string,<< "The following entry already exists: "<< arg1)
 
 DeclException2 (ExcValueDoesNotMatchPattern, std::string, std::string,<< "The string <"<< arg1<< "> does not match the given pattern <"<< arg2<< ">")
 
 DeclException0 (ExcAlreadyAtTopLevel)
 
 DeclException1 (ExcEntryUndeclared, std::string,<< "You can't ask for entry <"<< arg1<< "> you have not yet declared")
 
 DeclException1 (ExcConversionError, std::string,<< "Error when trying to convert the following string: "<< arg1)
 
- Public Member Functions inherited from Subscriptor
 Subscriptor ()
 
 Subscriptor (const Subscriptor &)
 
virtual ~Subscriptor ()
 
Subscriptoroperator= (const Subscriptor &)
 
void subscribe (const char *identifier=0) const
 
void unsubscribe (const char *identifier=0) const
 
unsigned int n_subscriptions () const
 
void list_subscribers () const
 
 DeclException3 (ExcInUse, int, char *, std::string &,<< "Object of class "<< arg2<< " is still used by "<< arg1<< " other objects.\n"<< "(Additional information: "<< arg3<< ")\n"<< "Note the entry in the Frequently Asked Questions of "<< "deal.II (linked to from http://www.dealii.org/) for "<< "more information on what this error means.")
 
 DeclException2 (ExcNoSubscriber, char *, char *,<< "No subscriber with identifier \""<< arg2<< "\" did subscribe to this object of class "<< arg1)
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 

Private Member Functions

 ParameterHandler (const ParameterHandler &)
 
ParameterHandleroperator= (const ParameterHandler &)
 
std::string get_current_path () const
 
std::string get_current_full_path (const std::string &name) const
 
bool scan_line (std::string line, const std::string &input_filename, const unsigned int lineno)
 

Static Private Member Functions

static std::string mangle (const std::string &s)
 
static std::string demangle (const std::string &s)
 
static bool is_parameter_node (const boost::property_tree::ptree &)
 

Private Attributes

std::auto_ptr< boost::property_tree::ptree > entries
 
std::vector< std_cxx1x::shared_ptr< const Patterns::PatternBase > > patterns
 
std::vector< std::string > subsection_path
 

Static Private Attributes

static const char path_separator = '.'
 

Friends

class MultipleParameterLoop
 

Detailed Description

The ParameterHandler class provides a standard interface to an input file which provides at run-time for program parameters such as time step sizes, geometries, right hand sides etc. The input for the program is given in files, streams or strings in memory using text like

set Time step size = 0.3
set Geometry = [0,1]x[0,3]

Input may be sorted into subsection trees in order to give the input a logical structure, and input files may include other files.

The ParameterHandler class is discussed in detail in the step-19 example program, and is used in more realistic situations in step-29, step-33 and step-34.

Declaring entries

In order to use the facilities of a ParameterHandler object, one first has to make known the different entries the input file may or may not contain. This is done in the following way:

...
ParameterHandler prm;
prm.declare_entry ("Time step size",
"0.2",
"Some documentation");
prm.declare_entry ("Geometry",
"[0,1]x[0,1]",
...

Each entry is declared using the function declare_entry(). The first parameter is the name of the entry (in short: the entry). The second is the default answer to be taken in case the entry is not specified in the input file. The third parameter is a regular expression which the input (and the default answer) has to match. Several such regular expressions are defined in Patterns. This parameter can be omitted, in which case it will default to Patterns::Anything, i.e. a pattern that matches every input string. The fourth parameter can be used to document the intent or expected format of an entry; its value is printed as a comment when writing all entries of a ParameterHandler object using the print_parameters() function to allow for easier understanding of a parameter file. It can be omitted as well, in which case no such documentation will be printed.

Entries may be located in subsections which form a kind of input tree. For example input parameters for linear solver routines should be classified in a subsection named Linear solver or any other suitable name. This is accomplished in the following way:

...
LinEq eq;
eq.declare_parameters (prm);
...
void LinEq::declare_parameters (ParameterHandler &prm) {
prm.enter_subsection("Linear solver");
{
prm.declare_entry ("Solver",
"CG",
Patterns::Selection("CG|GMRES|GaussElim"),
"Name of a linear solver for the inner iteration");
prm.declare_entry ("Maximum number of iterations",
"20",
ParameterHandler::RegularExpressions::Integer());
...
}
}

Subsections may be nested. For example a nonlinear solver may have a linear solver as member object. Then the function call tree would be something like (if the class NonLinEq has a member variables eq of type LinEq):

void NonLinEq::declare_parameters (ParameterHandler &prm) {
prm.enter_subsection ("Nonlinear solver");
{
prm.declare_entry ("Nonlinear method",
"Newton-Raphson",
ParameterHandler::RegularExpressions::Anything());
eq.declare_parameters (prm);
}
}

For class member functions which declare the different entries we propose to use the common name declare_parameters. In normal cases this method can be static since the entries will not depend on any previous knowledge. Classes for which entries should logically be grouped into subsections should declare these subsections themselves. If a class has two or more member variables of the same type both of which should have their own parameters, this parent class' method declare_parameters is responsible to group them into different subsections:

void NonLinEq::declare_parameters (ParameterHandler &prm) {
prm.enter_subsection ("Nonlinear solver");
{
prm.enter_subsection ("Linear solver 1");
{
eq1.declare_parameters (prm);
}
prm.enter_subsection ("Linear solver 2");
{
eq2.declare_parameters (prm);
}
}
}

Input files and special characters

For the first example above the input file would look like the following:

...
subsection Nonlinear solver
set Nonlinear method = Gradient
# this is a comment
subsection Linear solver
set Solver = CG
set Maxmimum number of iterations = 30
end
end
... # other stuff

The words subsection, set and end may be either written in lowercase or uppercase letters. Leading and trailing whitespace is removed, multiple whitespace is condensed into only one. Since the latter applies also to the name of an entry, an entry name will not be recognized if in the declaration multiple whitespace is used.

In entry names and values the following characters are not allowed: #, {, }, |. Their use is reserved for the MultipleParameterLoop class.

Comments starting with # are skipped.

We propose to use the following scheme to name entries: start the first word with a capital letter and use lowercase letters further on. The same applies to the possible entry values to the right of the = sign.

Including other input files

An input file can include other include files using the syntax

...
include some_other_file.prm
...

The file so referenced is searched for relative to the current directory (not relative to the directory in which the including parameter file is located, since this is not known to all three versions of the read_input() function).

Reading data from input sources

In order to read input there are three possibilities: reading from an std::istream object, reading from a file of which the name is given and reading from a string in memory in which the lines are separated by \n characters. These possibilities are used as follows:

...
// declaration of entries
...
prm.read_input (cin); // read input from standard in,
// or
prm.read_input ("simulation.in");
// or
char *in = "set Time step size = 0.3 \n ...";
...

You can use several sources of input successively. Entries which are changed more than once will be overwritten every time they are used.

You should not try to declare entries using declare_entry() and enter_subsection() with as yet unknown subsection names after using read_input(). The results in this case are unspecified.

If an error occurs upon reading the input, error messages are written to std::cerr and the reader function returns with a return value of false. This is opposed to almost all other functions in deal.II, which would normally throw an exception if an error occurs; this difference in behavior is a relic of the fact that this class predates deal.II and had previously been written for a different project.

Using the ParameterHandler Graphical User Interface

An alternative to using the hand-written input files shown above is to use the graphical user interface (GUI) that accompanies this class. For this, you first need to write a description of all the parameters, their default values, patterns and documentation strings into a file in a format that the GUI can understand; this is done using the ParameterHandler::print_parameters() function with ParameterHandler::XML as second argument, as discussed in more detail below in the Representation of Parameters section. This file can then be loaded using the executable for the GUI, which should be located in lib/bin/dealii_parameter_gui of your deal.II installation, assuming that you have a sufficiently recent version of the Qt toolkit installed.

Once loaded, the GUI displays subsections and individual parameters in tree form (see also the discussion in the Representation of Parameters section below). Here is a screen shot with some sub-sections expanded and one parameter selected for editing:

parameter_gui.png
Parameter GUI

Using the GUI, you can edit the values of individual parameters and save the result in the same format as before. It can then be read in using the ParameterHandler::read_input_from_xml() function.

Getting entry values out of a ParameterHandler object

Each class gets its data out of a ParameterHandler object by calling the get() member functions like this:

void NonLinEq::get_parameters (ParameterHandler &prm) {
prm.enter_subsection ("Nonlinear solver");
std::string method = prm.get ("Nonlinear method");
eq.get_parameters (prm);
}

get() returns the value of the given entry. If the entry was not specified in the input source(s), the default value is returned. You have to enter and leave subsections exactly as you did when declaring subsection. You may chose the order in which to transverse the subsection tree.

It is guaranteed that only entries matching the given regular expression are returned, i.e. an input entry value which does not match the regular expression is not stored.

You can use get() to retrieve the parameter in text form, get_integer() to get an integer or get_double() to get a double. You can also use get_bool(). It will cause an internal error if the string could not be converted to an integer, double or a bool. This should, though, not happen if you correctly specified the regular expression for this entry; you should not try to get out an integer or a double from an entry for which no according regular expression was set. The internal error is raised through the Assert() macro family which only works in debug mode.

If you want to print out all user selectable features, use the print_parameters() function. It is generally a good idea to print all parameters at the beginning of a log file, since this way input and output are together in one file which makes matching at a later time easier. Additionally, the function also print those entries which have not been modified in the input file und are thus set to default values; since default values may change in the process of program development, you cannot know the values of parameters not specified in the input file.

Style guide for data retrieval

We propose that every class which gets data out of a ParameterHandler object provides a function named get_parameters. This should be declared virtual. get_parameters functions in derived classes should call the BaseClass::get_parameters function.

Experience with large parameter lists

Experience has shown that in programs defining larger numbers of parameters (more than, say, fifty) it is advantageous to define an additional class holding these parameters. This class is more like a C-style structure, having a large number of variables, usually public. It then has at least two functions, which declare and parse the parameters. In the main program, the main class has an object of this parameter class and delegates declaration and parsing of parameters to this object.

The advantage of this approach is that you can keep out the technical details (declaration and parsing) out of the main class and additionally don't clutter up your main class with dozens or more variables denoting the parameters.

Worked Example

This is the code:

#include <iostream>
#include "../include/parameter_handler.h"
using namespace dealii;
class LinEq {
public:
static void declare_parameters (ParameterHandler &prm);
void get_parameters (ParameterHandler &prm);
private:
std::string Method;
int MaxIterations;
};
class Problem {
private:
LinEq eq1, eq2;
std::string Matrix1, Matrix2;
std::string outfile;
public:
static void declare_parameters (ParameterHandler &prm);
void get_parameters (ParameterHandler &prm);
};
void LinEq::declare_parameters (ParameterHandler &prm) {
// declare parameters for the linear
// solver in a subsection
prm.enter_subsection ("Linear solver");
prm.declare_entry ("Solver",
"CG",
Patterns::Selection("CG|BiCGStab|GMRES"),
"Name of a linear solver for the inner iteration");
prm.declare_entry ("Maximum number of iterations",
"20",
}
void LinEq::get_parameters (ParameterHandler &prm) {
prm.enter_subsection ("Linear solver");
Method = prm.get ("Solver");
MaxIterations = prm.get_integer ("Maximum number of iterations");
std::cout << " LinEq: Method=" << Method << ", MaxIterations=" << MaxIterations << std::endl;
}
void Problem::declare_parameters (ParameterHandler &prm) {
// first some global parameter entries
prm.declare_entry ("Output file",
"out",
"Name of the output file, either relative to the present"
"path or absolute");
prm.declare_entry ("Equation 1",
"Laplace",
"String identifying the equation we want to solve");
prm.declare_entry ("Equation 2",
"Elasticity",
// declare parameters for the
// first equation
prm.enter_subsection ("Equation 1");
prm.declare_entry ("Matrix type",
"Sparse",
Patterns::Selection("Full|Sparse|Diagonal"),
"Type of the matrix to be used, either full,"
"sparse, or diagonal");
LinEq::declare_parameters (prm); // for eq1
// declare parameters for the
// second equation
prm.enter_subsection ("Equation 2");
prm.declare_entry ("Matrix type",
"Sparse",
Patterns::Selection("Full|Sparse|Diagonal"));
LinEq::declare_parameters (prm); // for eq2
}
void Problem::get_parameters (ParameterHandler &prm) {
// entries of the problem class
outfile = prm.get ("Output file");
std::string equation1 = prm.get ("Equation 1"),
equation2 = prm.get ("Equation 2");
// get parameters for the
// first equation
prm.enter_subsection ("Equation 1");
Matrix1 = prm.get ("Matrix type");
eq1.get_parameters (prm); // for eq1
// get parameters for the
// second equation
prm.enter_subsection ("Equation 2");
Matrix2 = prm.get ("Matrix type");
eq2.get_parameters (prm); // for eq2
std::cout << " Problem: outfile=" << outfile << std::endl
<< " eq1=" << equation1 << ", eq2=" << equation2 << std::endl
<< " Matrix1=" << Matrix1 << ", Matrix2=" << Matrix2 << std::endl;
}
void main () {
Problem p;
p.declare_parameters (prm);
// read input from "prmtest.prm"; giving
// argv[1] would also be a good idea
prm.read_input ("prmtest.prm");
// print parameters to std::cout as ASCII text
std::cout << std::endl << std::endl;
// get parameters into the program
std::cout << std::endl << std::endl
<< "Getting parameters:" << std::endl;
p.get_parameters (prm);
// now run the program with these
// input parameters
p.do_something ();
}

This is the input file (named "prmtest.prm"):

# first declare the types of equations
set Equation 1 = Poisson
set Equation 2 = Navier-Stokes
subsection Equation 1
set Matrix type = Sparse
subsection Linear solver # parameters for linear solver 1
set Solver = Gauss-Seidel
set Maximum number of iterations = 40
end
end
subsection Equation 2
set Matrix type = Full
subsection Linear solver
set Solver = CG
set Maximum number of iterations = 100
end
end

And here is the output of the program:

Line 8:
The entry value
Gauss-Seidel
for the entry named
Solver
does not match the given regular expression
CG|BiCGStab|GMRES
Listing of Parameters
---------------------
set Equation 1 = Poisson # Laplace
set Equation 2 = Navier-Stokes # Elasticity
set Output file = out
subsection Equation 1
set Matrix type = Sparse # Sparse
subsection Linear solver
set Maximum number of iterations = 40 # 20
set Solver = CG
end
end
subsection Equation 2
set Matrix type = Full # Sparse
subsection Linear solver
set Maximum number of iterations = 100 # 20
set Solver = CG # CG
end
end
Getting parameters:
LinEq: Method=CG, MaxIterations=40
LinEq: Method=CG, MaxIterations=100
Problem: outfile=out
eq1=Poisson, eq2=Navier-Stokes
Matrix1=Sparse, Matrix2=Full

Representation of Parameters

Here is some more internal information about the repesentation of parameters:

Logically, parameters and the nested sections they are arranged in can be thought of as a hierarchical directory structure, or a tree. Take, for example, the following code declaring a set of parameters and sections they live in:

prm.declare_entry ("Maximal number of iterations",
"10",
Patterns::Integer (1, 1000),
"A parameter that describes the maximal number of "
"iterations the CG method is to take before giving "
"up on a matrix.");
prm.enter_subsection ("Preconditioner");
{
prm.declare_entry ("Kind",
"SSOR",
Patterns::Selection ("SSOR|Jacobi"),
"A string that describes the kind of preconditioner "
"to use.");
prm.declare_entry ("Relaxation factor",
"1.0",
"The numerical value (between zero and one) for the "
"relaxation factor to use in the preconditioner.");
}

We can think of the parameters so arranged as a file system in which every parameter is a directory. The name of this directory is the name of the parameter, and in this directory lie files that describe the parameter. These files are:

Alternatively, a directory in this file system may not have a file called value in it. In that case, the directory represents a subsection as declared above, and the directory's name will correspond to the name of the subsection. It will then have no files in it at all, but it may have further directories in it: some of these directories will be parameters (indicates by the presence of files) or further nested subsections.

Given this explanation, the code above will lead to a hierarchical representation of data that looks like this (the content of files is indicated at the right in a different font):

parameter_handler.png

Once parameters have been read in, the contents of the value "files" may be different while the other files remain untouched.

Using the ParameterHandler::print_parameters() function with ParameterHandler::XML as second argument, we can get a complete representation of this data structure in XML. It will look like this:

<?xml version="1.0" encoding="utf-8"?>
<Maximal_20number_20of_20iterations>
<value>10</value>
<default_value>10</default_value>
<documentation>A parameter that describes the maximal number of iterations the CG method is to take before giving up on a matrix.</documentation>
<pattern>0</pattern>
<pattern_description>[Integer range 1...1000 (inclusive)]</pattern_description>
</Maximal_20number_20of_20iterations>
<Preconditioner>
<Kind><value>SSOR</value>
<default_value>SSOR</default_value>
<documentation>A string that describes the kind of preconditioner to use.</documentation>
<pattern>1</pattern>
<pattern_description>SSOR|Jacobi</pattern_description>
</Kind>
<Relaxation_20factor>
<value>1.0</value>
<default_value>1.0</default_value>
<documentation>The numerical value (between zero and one) for the relaxation factor to use in the preconditioner.</documentation>
<pattern>2</pattern>
<pattern_description>[Floating point range 0...1 (inclusive)]</pattern_description>
</Relaxation_20factor>
</Preconditioner>

This representation closely resembles the directory/file structure discussed above. The only difference is that directory and file names are mangled: since they should only contain letters and numbers, every character in their names that is not a letter or number is replaced by an underscore followed by its two-digit hexadecimal representation. In addition, the special name "value" is mangled when used as the name of a parameter, given that this name is also used to name special files in the hierarchy structure. Finally, the entire tree is wrapped into a tag ParameterHandler to satisfy the XML requirement that there be only a single top-level construct in each file.

The tree structure (and its XML representation) is what the graphical user interface (see above) uses to represent parameters like a directory/file collection.

Author
Wolfgang Bangerth, October 1997, revised February 1998, 2010, 2011

Definition at line 1517 of file parameter_handler.h.

Member Enumeration Documentation

List of possible output formats.

The formats down the list with prefix Short and bit 6 and 7 set reproduce the old behavior of not writing comments or original values to the files.

Enumerator
Text 

Write human readable output suitable to be read by ParameterHandler again.

LaTeX 

Write parameters as a LaTeX table.

Description 

Write out declared parameters with description and possible values.

XML 

Write out everything as an XML file.

See the general documentation of this class for an example of output.

JSON 

Write out everything as a JSON file.

ShortText 

Write input for ParameterHandler without comments or changed default values.

Definition at line 1538 of file parameter_handler.h.

Constructor & Destructor Documentation

ParameterHandler::ParameterHandler ( const ParameterHandler )
private

Inhibit automatic CopyConstructor.

ParameterHandler::ParameterHandler ( )

Constructor.

virtual ParameterHandler::~ParameterHandler ( )
virtual

Destructor. Declare this only to have a virtual destructor, which is safer as we have virtual functions. It actually does nothing spectacular.

Member Function Documentation

ParameterHandler& ParameterHandler::operator= ( const ParameterHandler )
private

Inhibit automatic assignment operator.

virtual bool ParameterHandler::read_input ( std::istream &  input,
const std::string &  filename = "input file" 
)
virtual

Read input from a stream until the stream returns the eof condition or error. The second argument can be used to denote the name of the file (if that's what the input stream represents) we are reading from; this is only used when creating output for error messages.

Return whether the read was successful.

Reimplemented in MultipleParameterLoop.

virtual bool ParameterHandler::read_input ( const std::string &  filename,
const bool  optional = false,
const bool  write_stripped_file = false 
)
virtual

Read input from a file the name of which is given. The PathSearch class "PARAMETERS" is used to find the file.

Return whether the read was successful.

Unless optional is true, this function will automatically generate the requested file with default values if the file did not exist. This file will not contain additional comments if write_stripped_file is true.

Reimplemented in MultipleParameterLoop.

virtual bool ParameterHandler::read_input_from_string ( const char *  s)
virtual

Read input from a string in memory. The lines in memory have to be separated by \n characters.

Return whether the read was successful.

Reimplemented in MultipleParameterLoop.

virtual bool ParameterHandler::read_input_from_xml ( std::istream &  input)
virtual

Read a parameter file in XML format. This could be from a file originally written by the print_parameters() function using the XML output style and then modified by hand as necessary; or from a file written using this method and then modified by the graphical parameter GUI (see the general documentation of this class).

Return whether the read was successful.

void ParameterHandler::clear ( )

Clear all contents.

void ParameterHandler::declare_entry ( const std::string &  entry,
const std::string &  default_value,
const Patterns::PatternBase pattern = Patterns::Anything(),
const std::string &  documentation = std::string() 
)

Declare a new entry with name entry, default and for which any input has to match the pattern (default: any pattern).

The last parameter defaulting to an empty string is used to add a documenting text to each entry which will be printed as a comment when this class is asked to write out all declarations to a stream using the print_parameters() function.

The function generates an exception of type ExcValueDoesNotMatchPattern if the default value doesn't match the given pattern, using the C++ throw mechanism. However, this exception is only generated after the entry has been created; if you have code where no sensible default value for a parameter is possible, you can then catch and ignore this exception.

Note
An entry can be declared more than once without generating an error, for example to override an earlier default value.
void ParameterHandler::enter_subsection ( const std::string &  subsection)

Enter a subsection; if not yet existent, declare it.

bool ParameterHandler::leave_subsection ( )

Leave present subsection. Return false if there is no subsection to leave; true otherwise.

std::string ParameterHandler::get ( const std::string &  entry_string) const

Return value of entry entry_string. If the entry was changed, then the changed value is returned, otherwise the default value. If the value of an undeclared entry is required, an exception will be thrown.

long int ParameterHandler::get_integer ( const std::string &  entry_string) const

Return value of entry entry_string as long int. (A long int is chosen so that even very large unsigned values can be returned by this function).

double ParameterHandler::get_double ( const std::string &  entry_name) const

Return value of entry entry_name as double.

bool ParameterHandler::get_bool ( const std::string &  entry_name) const

Return value of entry entry_name as bool. The entry may be "true" or "yes" for true, "false" or "no" for false respectively.

void ParameterHandler::set ( const std::string &  entry_name,
const std::string &  new_value 
)

Change the value presently stored for entry_name to the one given in the second argument.

The parameter must already exist in the present subsection.

The function throws an exception of type ExcValueDoesNotMatchPattern if the new value does not conform to the pattern for this entry.

void ParameterHandler::set ( const std::string &  entry_name,
const char *  new_value 
)

Same as above, but an overload where the second argument is a character pointer. This is necessary, since otherwise the call to set("abc","def") will be mapped to the function taking one string and a bool as arguments, which is certainly not what is most often intended.

The function throws an exception of type ExcValueDoesNotMatchPattern if the new value does not conform to the pattern for this entry.

void ParameterHandler::set ( const std::string &  entry_name,
const long int new_value 
)

Change the value presently stored for entry_name to the one given in the second argument.

The parameter must already exist in the present subsection.

The function throws an exception of type ExcValueDoesNotMatchPattern if the new value does not conform to the pattern for this entry.

void ParameterHandler::set ( const std::string &  entry_name,
const double new_value 
)

Change the value presently stored for entry_name to the one given in the second argument.

The parameter must already exist in the present subsection.

For internal purposes, the new value needs to be converted to a string. This is done using 16 digits of accuracy, so the set value and the one you can get back out using get_double() may differ in the 16th digit.

The function throws an exception of type ExcValueDoesNotMatchPattern if the new value does not conform to the pattern for this entry.

void ParameterHandler::set ( const std::string &  entry_name,
const bool new_value 
)

Change the value presently stored for entry_name to the one given in the second argument.

The parameter must already exist in the present subsection.

The function throws an exception of type ExcValueDoesNotMatchPattern if the new value does not conform to the pattern for this entry.

std::ostream& ParameterHandler::print_parameters ( std::ostream &  out,
const OutputStyle  style 
)

Print all parameters with the given style to out. Presently only Text and LaTeX are implemented.

In Text format, the output is formatted in such a way that it is possible to use it for later input again. This is most useful to record the parameters for a specific run, since if you output the parameters using this function into a log file, you can always recover the results by simply copying the output to your input file.

Besides the name and value of each entry, the output also contains the default value of entries if it is different from the actual value, as well as the documenting string given to the declare_entry() function if available.

In Text format, the output contains the same information but in a format so that the resulting file can be input into a latex document such as a manual for the code for which this object handles run-time parameters. The various sections of parameters are then represented by latex section and subsection commands as well as by nested enumerations.

In addition, all parameter names are listed with \index statements in two indices called prmindex (where the name of each parameter is listed in the index) and prmindexfull where parameter names are listed sorted by the section in which they exist. By default, the LaTeX program ignores these \index commands, but they can be used to generate an index by using the following commands in the preamble of the latex file :

\usepackage{imakeidx}
\makeindex[name=prmindex, title=Index of run-time parameter entries]
\makeindex[name=prmindexfull, title=Index of run-time parameters with section names]

and at the end of the file this:

\printindex[prmindex]
\printindex[prmindexfull]
void ParameterHandler::print_parameters_section ( std::ostream &  out,
const OutputStyle  style,
const unsigned int  indent_level 
)

Print out the parameters of the present subsection as given by the subsection_path member variable. This variable is controlled by entering and leaving subsections through the enter_subsection() and leave_subsection() functions.

In most cases, you will not want to use this function directly, but have it called recursively by the previous function.

void ParameterHandler::log_parameters ( LogStream out)

Print parameters to a logstream. This function allows to print all parameters into a log-file. Sections will be indented in the usual log-file style.

void ParameterHandler::log_parameters_section ( LogStream out)

Log parameters in the present subsection. The subsection is determined by the subsection_path member variable. This variable is controlled by entering and leaving subsections through the enter_subsection() and leave_subsection() functions.

In most cases, you will not want to use this function directly, but have it called recursively by the previous function.

std::size_t ParameterHandler::memory_consumption ( ) const

Determine an estimate for the memory consumption (in bytes) of this object.

template<class Archive >
void ParameterHandler::save ( Archive &  ar,
const unsigned int  version 
) const
inline

Write the data of this object to a stream for the purpose of serialization.

Definition at line 2395 of file parameter_handler.h.

template<class Archive >
void ParameterHandler::load ( Archive &  ar,
const unsigned int  version 
)
inline

Read the data of this object from a stream for the purpose of serialization.

Definition at line 2415 of file parameter_handler.h.

bool ParameterHandler::operator== ( const ParameterHandler prm2) const

Test for equality.

static std::string ParameterHandler::mangle ( const std::string &  s)
staticprivate

Mangle a string so that it doesn't contain any special characters or spaces.

static std::string ParameterHandler::demangle ( const std::string &  s)
staticprivate

Unmangle a string into its original form.

static bool ParameterHandler::is_parameter_node ( const boost::property_tree::ptree &  )
staticprivate

Return whether a given node is a parameter node or a subsection node.

std::string ParameterHandler::get_current_path ( ) const
private

Return the string that identifies the current path into the property tree. This is only a path, i.e. it is not terminated by the path_separator character.

std::string ParameterHandler::get_current_full_path ( const std::string &  name) const
private

Given the name of an entry as argument, the function computes a full path into the parameter tree using the current subsection.

bool ParameterHandler::scan_line ( std::string  line,
const std::string &  input_filename,
const unsigned int  lineno 
)
private

Scan one line of input. input_filename and lineno are the name of the input file and the current number of the line presently scanned (for the logs if there are messages). Return false if line contained stuff that could not be understood, the uppermost subsection was to be left by an END or end statement, a value for a non-declared entry was given or the entry value did not match the regular expression. true otherwise.

The function modifies its argument, but also takes it by value, so the caller's variable is not changed.

Member Data Documentation

const char ParameterHandler::path_separator = '.'
staticprivate

The separator used when accessing elements of a path into the parameter tree.

Definition at line 1910 of file parameter_handler.h.

std::auto_ptr<boost::property_tree::ptree> ParameterHandler::entries
private

The complete tree of sections and entries. See the general documentation of this class for a description how data is stored in this variable.

The variable is a pointer so that we can use an incomplete type, rather than having to include all of the property_tree stuff from boost. This works around a problem with gcc 4.5.

Definition at line 1921 of file parameter_handler.h.

std::vector<std_cxx1x::shared_ptr<const Patterns::PatternBase> > ParameterHandler::patterns
private

A list of patterns that are used to describe the parameters of this object. The are indexed by nodes in the property tree.

Definition at line 1927 of file parameter_handler.h.

std::vector<std::string> ParameterHandler::subsection_path
private

Path of presently selected subsections; empty list means top level

Definition at line 1948 of file parameter_handler.h.


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