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); }
Parameters can be read from a std::istream and be written to a std::ostream.
Parameters are defined using a C++-like syntax
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 (').identifier = value;
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;
the default constructorParameters();
parses parameters from an std::istream.Parameters(std::istream& is);
copies parameter values from another parameter object.Parameters& operator<<(const Parameters& p )
access the parameter with a given name. Note the const-version which extends the std::map interfaceValueType& operator[](const std::string& name); const ValueType& operator[](const std::string& name) const;
returns true if a parameter value exists for the given parameter name.bool defined(const std::string& name) const;
returns the parameter with the given name cast to type T if the parameter is defined, or the given default value x otherwise.template <class T> inline T value_or_default(const std::string& name, T x) const;
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 copy_undefined(const Parameters& p);
write and read the Parameters object using the XML schema specified on http://xml.comp-phys.org.void write_xml(std::ostream& xml) const; void read_xml(XMLTag tag, std::istream& xml);
writes parameter names and values to a std::ostream. Each parameter is written to a new line, in the formatstd::ostream& operator << (std::ostream& os, const Parameters& p);
The above example would thus be written as:identifier = value
This allows the output to be read again .measure = true Model = "Heisenberg" L = 10 T = 0.5 W = 2
reads parameters from a std::istreamstd::istream& operator >> (std::istream& is, Parameters& parameters);
serialize and deserialize the Parameters object.ODump& operator << (ODump& od, const Parameters& p); IDump& operator >> (IDump& id, Parameters& p);
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)