QMCPACK
AttributeSet.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: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
10 //
11 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
12 //////////////////////////////////////////////////////////////////////////////////////
13 
14 
15 #ifndef OHMMS_XMLATTRIBUTESET_H
16 #define OHMMS_XMLATTRIBUTESET_H
17 
18 #include <map>
19 #include <string>
21 
22 /** class to handle a set of attributes of an xmlNode
23  */
25 {
26  std::map<std::string, std::unique_ptr<OhmmsElementBase>> m_param;
27 
28  bool get(std::ostream& os) const
29  {
30  for (const auto& [name, param] : m_param)
31  param->get(os);
32  return true;
33  }
34 
35  /** add a new attribute
36  *@param aparam reference the object which this attribute is assigned to.
37  *@param aname the name of the added attribute
38  *@param candidate_values candidate values to be checked against, the first element is the default value
39  *@param status Tag status, See OhmmsParameter.h for more details
40  */
41  template<class PDT>
42  void add(PDT& aparam,
43  const std::string& aname,
44  std::vector<PDT> candidate_values = {},
46  {
47  if (auto it = m_param.find(aname); it == m_param.end())
48  m_param[aname] = std::make_unique<OhmmsParameter<PDT>>(aparam, aname, std::move(candidate_values), status);
49  }
50 
51  /** assign attributes to the set
52  *@param cur the xml node to work on
53  *@return true, if any valid parameter is processed.
54  */
55  bool put(xmlNodePtr cur)
56  {
57  xmlAttrPtr att = cur->properties;
58  while (att != NULL)
59  {
60  std::string aname((const char*)(att->name));
61  if (auto it = m_param.find(aname); it != m_param.end())
62  {
63  std::istringstream stream((const char*)(att->children->content));
64  it->second->put(stream);
65  }
66  att = att->next;
67  }
68  return true;
69  }
70 };
71 #endif /*OHMMS_OHMMSPARAMETERSET_H*/
bool put(xmlNodePtr cur)
assign attributes to the set
Definition: AttributeSet.h:55
class to handle a set of attributes of an xmlNode
Definition: AttributeSet.h:24
std::map< std::string, std::unique_ptr< OhmmsElementBase > > m_param
Definition: AttributeSet.h:26
void add(PDT &aparam, const std::string &aname, std::vector< PDT > candidate_values={}, TagStatus status=TagStatus::OPTIONAL)
add a new attribute
Definition: AttributeSet.h:42
TagStatus
generic class for parameter xmlNode