27 #if !defined(BASEPARAMETERS_H) && !defined(DMRGPARAMETERS_H)
28 #define BASEPARAMETERS_H
34 #include <boost/tokenizer.hpp>
35 #include <boost/lexical_cast.hpp>
36 #include <boost/regex.hpp>
37 #include <boost/algorithm/string.hpp>
39 #include <alps/parameter.h>
45 namespace parameters {
48 value () : val_(
""), empty_(true) { }
52 : val_(boost::lexical_cast<std::string>(val))
56 std::string
get()
const {
return val_;}
57 bool empty()
const {
return empty_;}
77 alps::Parameters temp(param_file);
78 *
static_cast<alps::Parameters*
>(
this) = temp;
79 }
catch (std::exception & e) {
80 maquis::cerr <<
"Exception thrown when parsing parameters:" << std::endl;
81 maquis::cerr << e.what() << std::endl;
90 bool is_set (std::string
const & key)
const
98 std::map<std::string, std::string>::const_iterator match =
defaults.find(key);
100 alps::Parameters::operator[](key) = match->second;
102 boost::throw_exception(std::runtime_error(
"parameter " + key +
" not defined"));
107 template<
class T> T
get(std::string
const & key)
113 template<
class T>
void set(std::string
const & key, T
const & value)
115 alps::Parameters::operator[](key) = boost::lexical_cast<std::string>(value);
122 boost::regex expression(
"^(.*)\\[" + var +
"\\]$");
124 for (alps::Parameters::const_iterator it=this->begin();it != this->end();++it) {
125 std::string key = it->key();
126 if (boost::regex_match(key, what, expression)) {
127 std::vector<value_type> v = (*this)[key];
129 p.
set(what.str(1), v[val]);
131 p.
set(what.str(1), *(v.rbegin()));
140 for (alps::Parameters::const_iterator it=p.begin(); it!=p.end(); ++it)
141 alps::Parameters::operator[](it->key()) = it->value();
149 std::string
const & desc,
parameters::proxy operator[](std::string const &key)
bool is_set(std::string const &key) const
void set(std::string const &key, T const &value)
BaseParameters & operator<<(BaseParameters const &p)
std::map< std::string, std::string > descriptions
BaseParameters iteration_params(std::string const &var, std::size_t val)
std::map< std::string, std::string > defaults
BaseParameters(std::istream ¶m_file)
void add_option(std::string const &name, std::string const &desc, parameters::value const &val=parameters::value())
BaseParameters(alps::Parameters const &p)