QMCPACK
ParameterSet.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: D. Das, University of Illinois at Urbana-Champaign
8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
10 //
11 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
12 //////////////////////////////////////////////////////////////////////////////////////
13 
14 
15 #ifndef OHMMS_OHMMSPARAMETERSET_H
16 #define OHMMS_OHMMSPARAMETERSET_H
17 
18 #include <map>
19 #include <string>
20 #include <complex>
22 #include "string_utils.h"
23 #include "OhmmsPETE/TinyVector.h"
24 
25 /** class to handle a set of parameters
26  */
28 {
29  // public std::map<std::string, OhmmsElementBase*> {
30 
31  std::map<std::string, std::unique_ptr<OhmmsElementBase>> m_param;
32 
33  ParameterSet(const char* aname = "parameter") : OhmmsElementBase(aname) {}
34 
35  inline bool get(std::ostream& os) const override
36  {
37  for (const auto& [name, param] : m_param)
38  param->get(os);
39  return true;
40  }
41 
42  inline bool put(std::istream& is) override { return true; }
43 
44  /** assign parameters to the set
45  * @param cur the xml node to work on
46  * @return true, if any valid parameter is processed.
47  *
48  * Accept both
49  * - <aname> value </aname>
50  * - <parameter name="aname"> value </parameter>
51  * aname is converted into lower cases.
52  */
53  bool put(xmlNodePtr cur) override;
54 
55  inline void reset() override {}
56 
57  /** add a new parameter corresponding to an xmlNode <parameter/>
58  *@param aparam reference the object which this parameter is assigned to.
59  *@param aname_in the value of the name attribute
60  *@param candidate_values candidate values to be checked against, the first element is the default value
61  *@param status Tag status, See OhmmsParameter.h for more details
62  */
63  template<class PDT>
64  void add(PDT& aparam,
65  const std::string& aname_in,
66  std::vector<PDT> candidate_values = {},
68 
69  template<class PDT>
70  void setValue(const std::string& aname_in, PDT aval);
71 };
72 
73 extern template void ParameterSet::add<std::string>(std::string&,
74  const std::string&,
75  std::vector<std::string>,
76  TagStatus);
77 extern template void ParameterSet::add<qmcplusplus::astring>(qmcplusplus::astring&,
78  const std::string&,
79  std::vector<qmcplusplus::astring>,
80  TagStatus);
81 extern template void ParameterSet::add<bool>(bool&, const std::string&, std::vector<bool>, TagStatus);
82 extern template void ParameterSet::add<int>(int&, const std::string&, std::vector<int>, TagStatus);
83 extern template void ParameterSet::add<double>(double&, const std::string&, std::vector<double>, TagStatus);
84 extern template void ParameterSet::add<float>(float&, const std::string&, std::vector<float>, TagStatus);
85 extern template void ParameterSet::add<std::complex<double>>(std::complex<double>&,
86  const std::string&,
87  std::vector<std::complex<double>>,
88  TagStatus);
89 extern template void ParameterSet::add<std::complex<float>>(std::complex<float>&,
90  const std::string&,
91  std::vector<std::complex<float>>,
92  TagStatus);
93 extern template void ParameterSet::add<qmcplusplus::TinyVector<int, 3u>>(qmcplusplus::TinyVector<int, 3u>&,
94  const std::string&,
95  std::vector<qmcplusplus::TinyVector<int, 3u>>,
96  TagStatus);
97 
98 extern template void ParameterSet::setValue<int>(const std::string& aname_in, int aval);
99 
100 #endif /*OHMMS_OHMMSPARAMETERSET_H*/
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
std::map< std::string, std::unique_ptr< OhmmsElementBase > > m_param
Definition: ParameterSet.h:31
void reset() override
reset member data
Definition: ParameterSet.h:55
bool put(std::istream &is) override
read from std::istream
Definition: ParameterSet.h:42
class to handle a set of parameters
Definition: ParameterSet.h:27
Abstract class to provide xml-compatible I/O interfaces for the derived classes.
void setValue(const std::string &aname_in, PDT aval)
ParameterSet(const char *aname="parameter")
Definition: ParameterSet.h:33
virtual bool get(std::ostream &) const =0
write to a std::ostream
void add(PDT &aparam, const std::string &aname_in, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new parameter corresponding to an xmlNode <parameter>
TagStatus
generic class for parameter xmlNode