QMCPACK
OhmmsParameter< T > Class Template Reference
+ Inheritance diagram for OhmmsParameter< T >:
+ Collaboration diagram for OhmmsParameter< T >:

Public Member Functions

 OhmmsParameter (T &a, const std::string &aname, std::vector< T > &&candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
 
bool get (std::ostream &os) const override
 print to an std::ostream More...
 
bool put (xmlNodePtr cur) override
 
bool put (std::istream &is) override
 read from std::istream, used by OhmmsAttributeSet More...
 
bool add (xmlNodePtr parent) override
 This function is used by the users to add a xmlNode, when the input file does not contain the corresponding <parameter>. The content of the new xmlNode is the current value of ref_. More...
 
void setValue (T x)
 
void reset () override
 reset member data More...
 
- Public Member Functions inherited from OhmmsElementBase
 OhmmsElementBase (const char *aname="none")
 constructor with a name More...
 
virtual ~OhmmsElementBase ()
 destructor More...
 
const std::string & getName () const
 return the name More...
 
void setName (const std::string &aname)
 set name More...
 
void setIOMode (int imode)
 set iomode More...
 
void put (const std::string &s)
 read from string More...
 
virtual void begin_node (std::ostream &os) const
 write the start of a node More...
 
virtual void end_node (std::ostream &os) const
 write the end of a node More...
 

Private Member Functions

void checkValues ()
 

Private Attributes

T & ref_
 reference to a value of type T More...
 
std::vector< T > candidate_values_
 valid candidate values, if not empty, the first one is the default. More...
 
xmlNodePtr node_
 pointer to the corresponding xmlNode More...
 
TagStatus tag_staus_
 The status of the tag. More...
 

Additional Inherited Members

- Public Types inherited from OhmmsElementBase
enum  { useLIBXML = 0, useLIBXMLPP, usePLAIN }
 enumeration to choose the xml parser More...
 
- Protected Attributes inherited from OhmmsElementBase
int myIOMode
 the type of IO mode: default is useLIBXML More...
 
std::string myName
 the name of the node, corresponds to the xml tag More...
 

Detailed Description

template<class T>
class OhmmsParameter< T >

Definition at line 78 of file OhmmsParameter.h.

Constructor & Destructor Documentation

◆ OhmmsParameter()

OhmmsParameter ( T &  a,
const std::string &  aname,
std::vector< T > &&  candidate_values = {},
TagStatus  status = TagStatus::OPTIONAL 
)
inline
Parameters
athe value to be referenced
anamethe name of this object
candidate_valuescandidate values to be checked against, the first element is the default value. It can be left empty for backward compatibility or unbounded input.
statusTag status, See TagStatus enum.

Definition at line 113 of file OhmmsParameter.h.

115  {},
117  : OhmmsElementBase(aname.c_str()),
118  ref_(a),
119  candidate_values_(std::move(candidate_values)),
120  node_(NULL),
121  tag_staus_(status)
122  {
123  // set default value
124  if (status != TagStatus::REQUIRED && !candidate_values_.empty())
125  ref_ = candidate_values_[0];
126  }
std::vector< T > candidate_values_
valid candidate values, if not empty, the first one is the default.
T & ref_
reference to a value of type T
xmlNodePtr node_
pointer to the corresponding xmlNode
OhmmsElementBase(const char *aname="none")
constructor with a name
TagStatus tag_staus_
The status of the tag.
TagStatus
generic class for parameter xmlNode

Member Function Documentation

◆ add()

bool add ( xmlNodePtr  parent)
inlineoverridevirtual

This function is used by the users to add a xmlNode, when the input file does not contain the corresponding <parameter>. The content of the new xmlNode is the current value of ref_.

Parameters
parentthe parent node to which a xmlNode for this object is appended.

Reimplemented from OhmmsElementBase.

Definition at line 163 of file OhmmsParameter.h.

References getContent(), OhmmsElementBase::myName, OhmmsParameter< T >::node_, and OhmmsParameter< T >::ref_.

164  {
165  if (!node_)
166  {
167  node_ = xmlNewChild(parent, parent->ns, (const xmlChar*)"parameter", NULL);
168  xmlNewProp(node_, (const xmlChar*)"name", (const xmlChar*)(myName.c_str()));
170  }
171  return true;
172  }
std::string myName
the name of the node, corresponds to the xml tag
T & ref_
reference to a value of type T
xmlNodePtr node_
pointer to the corresponding xmlNode
bool getContent(const T &a, xmlNodePtr cur)
write a value to a node.
Definition: libxmldefs.h:119

◆ checkValues()

void checkValues ( )
inlineprivate

Definition at line 91 of file OhmmsParameter.h.

References OhmmsParameter< T >::candidate_values_, OhmmsElementBase::myName, and OhmmsParameter< T >::ref_.

Referenced by OhmmsParameter< T >::put().

92  {
93  // when the size is 1, values are unbounded and the given value is the default value
94  if (candidate_values_.size() > 1 &&
95  std::find(candidate_values_.begin(), candidate_values_.end(), ref_) == candidate_values_.end())
96  {
97  std::ostringstream msg;
98  msg << "Input tag \"" << myName << "\" value \"" << ref_ << "\" is not valid. Candidate values are : ";
99  for (const auto& value : candidate_values_)
100  msg << " \"" << value << "\"";
101  msg << std::endl;
102  throw std::runtime_error(msg.str());
103  }
104  }
std::string myName
the name of the node, corresponds to the xml tag
std::vector< T > candidate_values_
valid candidate values, if not empty, the first one is the default.
T & ref_
reference to a value of type T

◆ get()

bool get ( std::ostream &  os) const
inlineoverridevirtual

print to an std::ostream

Implements OhmmsElementBase.

Definition at line 129 of file OhmmsParameter.h.

References OhmmsElementBase::myName, and OhmmsParameter< T >::ref_.

130  {
131  os << "<parameter name=\"" << myName << "\">" << ref_ << "</parameter>" << std::endl;
132  return true;
133  }
std::string myName
the name of the node, corresponds to the xml tag
T & ref_
reference to a value of type T

◆ put() [1/2]

bool put ( xmlNodePtr  cur)
inlineoverridevirtual

inline bool put(xmlNodePtr cur), used by ParameterSet

Parameters
curthe current xmlNode whose content is assigned to ref_

Implements OhmmsElementBase.

Definition at line 138 of file OhmmsParameter.h.

References checkTagStatus(), OhmmsParameter< T >::checkValues(), OhmmsElementBase::myName, OhmmsParameter< T >::node_, putContent(), OhmmsParameter< T >::ref_, and OhmmsParameter< T >::tag_staus_.

Referenced by OhmmsParameter< bool >::put().

139  {
141  node_ = cur;
142  putContent(ref_, cur);
143  checkValues();
144  return true;
145  }
std::string myName
the name of the node, corresponds to the xml tag
T & ref_
reference to a value of type T
void checkTagStatus(const std::string &tagname, TagStatus status)
xmlNodePtr node_
pointer to the corresponding xmlNode
bool putContent(T &a, xmlNodePtr cur)
replaces a&#39;s value with the first "element" in the "string" returned by XMLNodeString{cur}.
Definition: libxmldefs.h:88
TagStatus tag_staus_
The status of the tag.

◆ put() [2/2]

bool put ( std::istream &  is)
inlineoverridevirtual

read from std::istream, used by OhmmsAttributeSet

Implements OhmmsElementBase.

Definition at line 149 of file OhmmsParameter.h.

References checkTagStatus(), OhmmsParameter< T >::checkValues(), OhmmsElementBase::myName, OhmmsParameter< T >::ref_, and OhmmsParameter< T >::tag_staus_.

150  {
152  is >> ref_;
153  checkValues();
154  return true;
155  }
std::string myName
the name of the node, corresponds to the xml tag
T & ref_
reference to a value of type T
void checkTagStatus(const std::string &tagname, TagStatus status)
TagStatus tag_staus_
The status of the tag.

◆ reset()

void reset ( )
inlineoverridevirtual

reset member data

Implements OhmmsElementBase.

Definition at line 177 of file OhmmsParameter.h.

References getContent(), OhmmsParameter< T >::node_, and OhmmsParameter< T >::ref_.

177 { getContent(ref_, node_); }
T & ref_
reference to a value of type T
xmlNodePtr node_
pointer to the corresponding xmlNode
bool getContent(const T &a, xmlNodePtr cur)
write a value to a node.
Definition: libxmldefs.h:119

◆ setValue()

void setValue ( x)
inline

Definition at line 174 of file OhmmsParameter.h.

References OhmmsParameter< T >::ref_.

174 { ref_ = x; }
T & ref_
reference to a value of type T

Member Data Documentation

◆ candidate_values_

std::vector<T> candidate_values_
private

valid candidate values, if not empty, the first one is the default.

Definition at line 84 of file OhmmsParameter.h.

Referenced by OhmmsParameter< T >::checkValues().

◆ node_

◆ ref_

◆ tag_staus_

TagStatus tag_staus_
private

The status of the tag.

Definition at line 88 of file OhmmsParameter.h.

Referenced by OhmmsParameter< T >::put(), and OhmmsParameter< bool >::put().


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