7 #ifndef ALPS_PARAMS_HPP_INCLUDED_00f672a032d949a7aa0e760a6b6f0602 8 #define ALPS_PARAMS_HPP_INCLUDED_00f672a032d949a7aa0e760a6b6f0602 10 #include "alps/config.hpp" 30 struct make_typestr :
public boost::static_visitor<std::string> {
32 std::string operator()(
const T&)
const {
return apply<T>(); }
35 static std::string apply() {
return detail::type_info<T>::pretty_name(); }
44 std::string& typestr() {
return typestr_; }
46 const std::string& typestr()
const {
return typestr_; }
48 std::string& descr() {
return descr_; }
50 const std::string& descr()
const {
return descr_; }
52 int defnumber()
const {
return defnumber_; }
54 int& defnumber() {
return defnumber_; }
56 td_type(
const std::string& t,
const std::string& d,
int n) : typestr_(t), descr_(d), defnumber_(n) {}
59 static td_type make_pair(
const std::string& d,
int n) {
return td_type(make_typestr::apply<T>(), d, n); }
61 td_type() : typestr_(), descr_(), defnumber_(-1) {}
64 return typestr_==rhs.typestr_ &&
66 defnumber_==rhs.defnumber_;
86 typedef std::map<std::string,std::string> strmap;
87 typedef std::vector<std::string> strvec;
98 origins_type(): data_(INIFILES) {}
99 strvec& data() {
return data_; }
100 const strvec& data()
const {
return data_; }
102 if (data_.size()<INIFILES)
103 throw std::logic_error(
"params::origins_type invariants violation");
107 typedef std::map<std::string, detail::td_type> td_map_type;
109 strmap raw_kv_content_;
112 origins_type origins_;
113 std::string help_header_;
115 void read_ini_file_(
const std::string& inifile);
116 void initialize_(
int argc,
const char*
const* argv,
const char* hdf5_path);
118 template <
typename T>
119 bool assign_to_name_(
const std::string& name,
const std::string& strval);
121 bool has_unused_(std::ostream& out,
const std::string* prefix_ptr)
const;
124 template <
typename T>
125 bool define_(
const std::string& name,
const std::string& descr);
129 params() :
dictionary(), raw_kv_content_(), td_map_(), err_status_(), origins_(), help_header_() {}
136 params(
const std::string& inifile);
186 params(
int argc,
const char*
const* argv,
const char* hdf5_path=
"/parameters");
189 std::string get_argv0()
const;
192 std::string get_ini_name(
int n)
const;
195 int get_ini_name_count()
const;
212 :
std::runtime_error(a_what) {}
217 std::vector<std::string> fnames_;
219 archive_conflict(
const std::string& a_what,
const std::string& fname1,
const std::string& fname2)
220 :
std::runtime_error(a_what+
"; name1='"+fname1+
"' name2='"+fname2+
"'"),
221 fnames_({fname1, fname2})
224 const std::string&
get_name(
unsigned int i)
const {
225 return fnames_[i % fnames_.size()];
234 bool is_restored()
const {
return !origins_.data()[origins_type::ARCHNAME].empty(); }
237 std::string get_archive_name()
const;
240 bool ok()
const {
return err_status_.empty(); }
246 bool defaulted(
const std::string& name)
const;
249 bool supplied(
const std::string& name)
const;
252 bool has_unused(std::ostream& out)
const;
260 bool has_unused(std::ostream& out,
const std::string& subsection)
const;
263 bool has_missing(std::ostream& out)
const;
266 bool help_requested()
const;
269 bool help_requested(std::ostream&)
const;
272 std::ostream& print_help(std::ostream&)
const;
279 bool defined(
const std::string& name)
const;
283 params& define(
const std::string& name,
const std::string& descr);
287 params& define(
const std::string& name,
const T& defval,
const std::string& descr);
291 return define<bool>(name,
false, descr);
295 params& description(
const std::string& message);
298 const std::string get_descr(
const std::string& name)
const;
337 initialize_(argc,argv,hdf5_path);
370 dict.broadcast(comm, root);
374 p.broadcast(comm, root);
const std::vector< std::string > & get_names() const
bool ok() const
No-errors status.
Parse sectioned INI file or HDF5 or command line, provide the results as dictionary.
void load(archive &ar, std::string const &path, T &value, std::vector< std::size_t > chunk=std::vector< std::size_t >(), std::vector< std::size_t >=std::vector< std::size_t >())
void broadcast(C const &c, P &p, int r=0)
void swap(params &p1, params &p2)
bool operator==(const dictionary &lhs, const dictionary &rhs)
Header for object-oriented interface to MPI (similar to boost::mpi)
Encapsulation of an MPI communicator and some communicator-related operations.
params()
Default ctor: creates an empty parameters object.
std::string origin_name(const params &p)
Convenience function to obtain the "origin" filename associated with the parameters object...
Exception type: attempt to restore from 2 archives.
bool has_missing() const
True if there are missing or wrong-type parameters.
params & define(const std::string &name, const std::string &descr)
Defines a flag (boolean option with default of false)
Exception type: the object was not restored from archive.
bool is_restored() const
Conveninece method: true if the object was restored from an archive.
const std::string & get_name(unsigned int i) const
archive_conflict(const std::string &a_what, const std::string &fname1, const std::string &fname2)
not_restored(const std::string &a_what)
std::ostream & operator<<(std::ostream &os, const dict_value &dv)
Print the value together with type in some human-readable format.
void save(archive &ar, std::string const &path, T const &value, std::vector< std::size_t >=std::vector< std::size_t >(), std::vector< std::size_t > chunk=std::vector< std::size_t >(), std::vector< std::size_t >=std::vector< std::size_t >())