QMCPACK
OhmmsParameter< bool > Class Template Reference

A specialization of OhmmsParameter<T> for T = boolean. More...

+ Inheritance diagram for OhmmsParameter< bool >:
+ Collaboration diagram for OhmmsParameter< bool >:

Public Member Functions

 OhmmsParameter (bool &a, const std::string &aname, std::vector< bool > &&candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
 
bool get (std::ostream &os) const override
 print to an std::ostream More...
 
bool put (xmlNodePtr cur) override
 If the content is empty, the negation of the current value is taken. Example is <parameter name="force"> to turn on the force-evaluation flag of NoPropagator. More...
 
void setValue (bool x)
 
bool put (std::istream &is) override
 read from std::istream 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 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 Attributes

bool & ref_
 reference to a value of type T More...
 
std::vector< bool > 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 OhmmsParameter< bool >

A specialization of OhmmsParameter<T> for T = boolean.

Definition at line 184 of file OhmmsParameter.h.

Constructor & Destructor Documentation

◆ OhmmsParameter()

OhmmsParameter ( bool &  a,
const std::string &  aname,
std::vector< bool > &&  candidate_values = {},
TagStatus  status = TagStatus::OPTIONAL 
)
inline
Parameters
athe boolean to be referenced.
anamethe name of this object
candidate_valuesvalid input values

Definition at line 203 of file OhmmsParameter.h.

205  {},
207  : OhmmsElementBase(aname.c_str()),
208  ref_(a),
209  candidate_values_(std::move(candidate_values)),
210  node_(NULL),
211  tag_staus_(status)
212  {
213  // set default value.
214  if (!candidate_values_.empty())
215  ref_ = candidate_values_[0];
216  }
OhmmsElementBase(const char *aname="none")
constructor with a name
std::vector< bool > candidate_values_
valid candidate values, if not empty, the first one is the default.
bool & ref_
reference to a value of type T
TagStatus tag_staus_
The status of the tag.
xmlNodePtr node_
pointer to the corresponding xmlNode
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 273 of file OhmmsParameter.h.

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

274  {
275  if (!node_)
276  {
277  node_ = xmlNewChild(parent, parent->ns, (const xmlChar*)"parameter", NULL);
278  xmlNewProp(node_, (const xmlChar*)"name", (const xmlChar*)(myName.c_str()));
280  }
281  return true;
282  }
bool getContent(const T &a, xmlNodePtr cur)
write a value to a node.
Definition: libxmldefs.h:119
std::string myName
the name of the node, corresponds to the xml tag
bool & ref_
reference to a value of type T
xmlNodePtr node_
pointer to the corresponding xmlNode

◆ get()

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

print to an std::ostream

Implements OhmmsElementBase.

Definition at line 219 of file OhmmsParameter.h.

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

220  {
221  os << "<parameter name=\"" << myName << "\"> " << (ref_ ? "yes" : "no") << " </parameter>" << std::endl;
222  return true;
223  }
std::string myName
the name of the node, corresponds to the xml tag
bool & ref_
reference to a value of type T

◆ put() [1/2]

bool put ( xmlNodePtr  cur)
inlineoverridevirtual

If the content is empty, the negation of the current value is taken. Example is <parameter name="force"> to turn on the force-evaluation flag of NoPropagator.

inline bool put(xmlNodePtr cur)

Parameters
curthe current xmlNode whose content is assigned to ref_

Implements OhmmsElementBase.

Definition at line 231 of file OhmmsParameter.h.

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

232  {
234  node_ = cur;
235  const XMLNodeString ac(cur);
236  std::istringstream stream(ac);
237  return put(stream);
238  }
void checkTagStatus(const std::string &tagname, TagStatus status)
bool put(xmlNodePtr cur) override
If the content is empty, the negation of the current value is taken. Example is <parameter name="forc...
std::string myName
the name of the node, corresponds to the xml tag
convert xmlNode contents into a std::string
TagStatus tag_staus_
The status of the tag.
xmlNodePtr node_
pointer to the corresponding xmlNode

◆ put() [2/2]

bool put ( std::istream &  is)
inlineoverridevirtual

read from std::istream

Implements OhmmsElementBase.

Definition at line 243 of file OhmmsParameter.h.

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

244  {
246  std::string input_value;
247  is >> input_value;
248  std::string input_value_lower_case = qmcplusplus::lowerCase(input_value);
249 
250  if (input_value_lower_case == "yes" || input_value_lower_case == "true")
251  ref_ = true;
252  else if (input_value_lower_case == "no" || input_value_lower_case == "false")
253  ref_ = false;
254  else if (input_value.empty())
255  throw std::runtime_error(myName + " requires a single value input.");
256  else
257  throw std::runtime_error(myName + " only accepts 'yes'/'no'/'true'/'false' but the input value is '" +
258  input_value + "'.");
259 
260  std::string dummy;
261  is >> dummy;
262  if (!dummy.empty())
263  throw std::runtime_error(myName + " only accepts a single value input.");
264  return true;
265  }
std::string lowerCase(const std::string_view s)
++17
void checkTagStatus(const std::string &tagname, TagStatus status)
std::string myName
the name of the node, corresponds to the xml tag
bool & ref_
reference to a value of type T
TagStatus tag_staus_
The status of the tag.

◆ reset()

void reset ( )
inlineoverridevirtual

reset member data

Implements OhmmsElementBase.

Definition at line 285 of file OhmmsParameter.h.

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

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

◆ setValue()

void setValue ( bool  x)
inline

Definition at line 240 of file OhmmsParameter.h.

References OhmmsParameter< T >::ref_.

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

Member Data Documentation

◆ candidate_values_

std::vector<bool> candidate_values_
private

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

Definition at line 190 of file OhmmsParameter.h.

◆ node_

xmlNodePtr node_
private

pointer to the corresponding xmlNode

Definition at line 192 of file OhmmsParameter.h.

◆ ref_

bool& ref_
private

reference to a value of type T

Definition at line 188 of file OhmmsParameter.h.

◆ tag_staus_

TagStatus tag_staus_
private

The status of the tag.

Definition at line 194 of file OhmmsParameter.h.


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