ALPS Project

Header file parameters.h

This header contains the Parameters a class that can store parameters, identified by name.

Synopsis

namespace alps {
class Parameters : public std::map<std::string,ValueType> {
public:
  Parameters();
  Parameters(std::istream& is);
  Parameters& operator<<(const Parameters& p ) 
  inline ValueType& operator[](const std::string& name);
  inline const ValueType& operator[](const std::string& name) const;
  inline bool defined(const std::string& name) const;
  template <class T> inline T value_or_default(const std::string& name, T x) const;

  void copy_undefined(const Parameters& p)l

  void read_xml(XMLTag tag, std::istream& xml);
};

std::ostream& operator << (oxstream& os, const Parameters& p);

std::istream& operator >> (std::istream& is, Parameters& parameters);

ODump& operator << (ODump& od, const Parameters& p);
IDump& operator >> (IDump& id, Parameters& p);

}

The Parameters class

is a std::map with a string as key-type and a ValueType object as value type. Any numerical, boolean or string value can thus be stored as value of a parameter, identified by a string.

Parameters can be read from a std::istream and be written to a std::ostream.

Parameters are defined using a C++-like syntax

identifier = value;
where the trailing ';' can be replaced by a ',' and is optional at the end of a line. Identifier names start with a letter and can contain letters, numbers and a single quote (').

Values can be integers, floating point or complex numbers, booleans or strings. Strings need to be enclosed in double quotes ("). The expressions true, TRUE, yes and YES will be parsed as boolean true values, while false, FALSE, no and NO as boolean false values.

Examples are:

Model = "Heisenberg"
L = 10, W = 2
T = 0.5
measure = yes;

Member functions

Parameters();
the default constructor
Parameters(std::istream& is);
parses parameters from an std::istream.
Parameters& operator<<(const Parameters& p ) 
copies parameter values from another parameter object.
ValueType& operator[](const std::string& name);
const ValueType& operator[](const std::string& name) const;
access the parameter with a given name. Note the const-version which extends the std::map interface
bool defined(const std::string& name) const;
returns true if a parameter value exists for the given parameter name.
template <class T> inline T value_or_default(const std::string& name, T x) const;
returns the parameter with the given name cast to type T if the parameter is defined, or the given default value x otherwise.
void copy_undefined(const Parameters& p);
sets all parameter values that are defined in the argument p to be the same as in p. This is useful to set default values from an object p.
void write_xml(std::ostream& xml) const;
void read_xml(XMLTag tag, std::istream& xml);
write and read the Parameters object using the XML schema specified on http://xml.comp-phys.org.

I/O operators

std::ostream& operator << (std::ostream& os, const Parameters& p);
writes parameter names and values to a std::ostream. Each parameter is written to a new line, in the format
identifier = value
The above example would thus be written as:
measure = true
Model = "Heisenberg"
L = 10
T = 0.5
W = 2
This allows the output to be read again .
std::istream& operator >> (std::istream& is, Parameters& parameters);
reads parameters from a std::istream
ODump& operator << (ODump& od, const Parameters& p);
IDump& operator >> (IDump& id, Parameters& p);
serialize and deserialize the Parameters object.

copyright (c) 1994-2010 by Matthias Troyer

Distributed under the Boost Software License, Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt)