ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
BaseParameters Class Reference

#include <BaseParameters.h>

Inheritance diagram for BaseParameters:
DmrgParameters ModelParameters

Public Member Functions

 BaseParameters ()
 
 BaseParameters (std::istream &param_file)
 
 BaseParameters (alps::Parameters const &p)
 
bool is_set (std::string const &key) const
 
parameters::proxy operator[] (std::string const &key)
 
template<class T >
get (std::string const &key)
 
template<class T >
void set (std::string const &key, T const &value)
 
BaseParameters iteration_params (std::string const &var, std::size_t val)
 
BaseParametersoperator<< (BaseParameters const &p)
 

Protected Member Functions

void add_option (std::string const &name, std::string const &desc, parameters::value const &val=parameters::value())
 

Protected Attributes

std::map< std::string,
std::string > 
defaults
 
std::map< std::string,
std::string > 
descriptions
 

Detailed Description

Definition at line 65 of file BaseParameters.h.

Constructor & Destructor Documentation

BaseParameters::BaseParameters ( )
inline

Definition at line 69 of file BaseParameters.h.

70  : alps::Parameters()
71  { }
BaseParameters::BaseParameters ( std::istream &  param_file)
inline

Definition at line 73 of file BaseParameters.h.

74  : alps::Parameters()
75  {
76  try {
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;
82  exit(1);
83  }
84  }
BaseParameters::BaseParameters ( alps::Parameters const &  p)
inline

Definition at line 86 of file BaseParameters.h.

87  : alps::Parameters(p)
88  { }

Member Function Documentation

void BaseParameters::add_option ( std::string const &  name,
std::string const &  desc,
parameters::value const &  val = parameters::value() 
)
inlineprotected

Definition at line 148 of file BaseParameters.h.

151  {
152  if (!val.empty())
153  defaults[name] = val.get();
154  descriptions[name] = desc;
155  }
std::map< std::string, std::string > descriptions
std::map< std::string, std::string > defaults
template<class T >
T BaseParameters::get ( std::string const &  key)
inline

Definition at line 107 of file BaseParameters.h.

108  {
109  parameters::proxy const& p = (*this)[key];
110  return p.as<T>();
111  }
bool BaseParameters::is_set ( std::string const &  key) const
inline

Definition at line 90 of file BaseParameters.h.

91  {
92  return defined(key);
93  }
BaseParameters BaseParameters::iteration_params ( std::string const &  var,
std::size_t  val 
)
inline

Definition at line 118 of file BaseParameters.h.

119  {
120  BaseParameters p;
121 
122  boost::regex expression("^(.*)\\[" + var + "\\]$");
123  boost::smatch what;
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];
128  if (val < v.size())
129  p.set(what.str(1), v[val]);
130  else
131  p.set(what.str(1), *(v.rbegin()));
132  }
133  }
134  p.set(var, val);
135  return p;
136  }
void set(std::string const &key, T const &value)
BaseParameters& BaseParameters::operator<< ( BaseParameters const &  p)
inline

Definition at line 138 of file BaseParameters.h.

139  {
140  for (alps::Parameters::const_iterator it=p.begin(); it!=p.end(); ++it)
141  alps::Parameters::operator[](it->key()) = it->value();
142  defaults.insert(p.defaults.begin(), p.defaults.end());
143 
144  return *this;
145  }
std::map< std::string, std::string > defaults
parameters::proxy BaseParameters::operator[] ( std::string const &  key)
inline

Definition at line 95 of file BaseParameters.h.

96  {
97  if (!defined(key)) {
98  std::map<std::string, std::string>::const_iterator match = defaults.find(key);
99  if (match != defaults.end())
100  alps::Parameters::operator[](key) = match->second;
101  else
102  boost::throw_exception(std::runtime_error("parameter " + key + " not defined"));
103  }
104  return parameters::proxy(alps::Parameters::operator[](key));
105  }
std::map< std::string, std::string > defaults
template<class T >
void BaseParameters::set ( std::string const &  key,
T const &  value 
)
inline

Definition at line 113 of file BaseParameters.h.

114  {
115  alps::Parameters::operator[](key) = boost::lexical_cast<std::string>(value);
116  }

Member Data Documentation

std::map<std::string, std::string> BaseParameters::defaults
protected

Definition at line 157 of file BaseParameters.h.

std::map<std::string, std::string> BaseParameters::descriptions
protected

Definition at line 158 of file BaseParameters.h.


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