QMCPACK
libxmldefs.h File Reference

A collection of put/get functions to read from or write to a xmlNode defined in libxml2. More...

+ Include dependency graph for libxmldefs.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

char * castXMLCharToChar (xmlChar *c)
 assign a value from a node. Use specialization for classes. More...
 
const char * castXMLCharToChar (const xmlChar *c)
 unsafe const xmlChar* to const char* cast More...
 
xmlChar * castCharToXMLChar (char *c)
 unsafe char* to xmlChar* cast More...
 
const xmlChar * castCharToXMLChar (const char *c)
 unsafe const char* to const xmlChar* cast More...
 
std::string getNodeName (xmlNodePtr cur)
 
template<class T >
bool putContent (T &a, xmlNodePtr cur)
 replaces a's value with the first "element" in the "string" returned by XMLNodeString{cur}. More...
 
template<class IT >
bool putContent (IT first, IT last, xmlNodePtr cur)
 
template<class T >
bool getContent (const T &a, xmlNodePtr cur)
 write a value to a node. More...
 
template<class T >
bool putContent (std::vector< T > &a, const xmlNodePtr cur)
 assign std::vector<T> from a node. More...
 
template<class T >
bool getContent (const std::vector< T > &a, xmlNodePtr cur)
 write std::vector<T> to node. More...
 
template<class F >
void processChildren (const xmlNodePtr cur, const F &functor)
 process through all the children of an XML element F is a lambda or functor void F/[](const std::string& cname, const xmlNodePtr element) {...} More...
 

Detailed Description

A collection of put/get functions to read from or write to a xmlNode defined in libxml2.

Definition in file libxmldefs.h.

Function Documentation

◆ castCharToXMLChar() [1/2]

xmlChar* castCharToXMLChar ( char *  c)
inline

unsafe char* to xmlChar* cast

Definition at line 70 of file libxmldefs.h.

Referenced by getXMLAttributeValue(), qmcplusplus::TEST_CASE(), qmcplusplus::test_EtOH_mw(), qmcplusplus::test_HCN(), qmcplusplus::test_He(), qmcplusplus::test_He_mw(), and qmcplusplus::test_Ne().

70 { return static_cast<xmlChar*>(static_cast<void*>(c)); }

◆ castCharToXMLChar() [2/2]

const xmlChar* castCharToXMLChar ( const char *  c)
inline

unsafe const char* to const xmlChar* cast

Definition at line 74 of file libxmldefs.h.

75 {
76  return static_cast<const xmlChar*>(static_cast<const void*>(c));
77 }

◆ castXMLCharToChar() [1/2]

char* castXMLCharToChar ( xmlChar *  c)
inline

assign a value from a node. Use specialization for classes.

Parameters
areference to a value to be assigned
curcurrent node
Returns
true if successful

If operator >> is implemented for a class, no specialization is required. For instance, no specialization is necessary for intrinsic data types. A simle class that reads the temperature from a xml node

<parameter name="temperature" condition="K">100</parameter>

struct A: public OhmmsElementBase {
double Temperature;
bool put(xmlNodePtr cur) {
putContent(Temperature,cur);
}
};

xmlChar* to char* cast certainly not typesafe but at this interface between libxml and c++ well it beats c style casts and might be more correct than a reinterpret.

This is fine with UTF-8 bytes going into a std::string.

Definition at line 62 of file libxmldefs.h.

Referenced by AGPDeterminantBuilder::createAGP(), RadialJastrowBuilder::createJ1(), getNodeName(), getXMLAttributeValue(), ParameterSet::put(), ShortRangeCuspFunctor< T >::put(), InputSection::readAttributes(), QMCDriverFactory::readSection(), QMCDriverInput::readXML(), EstimatorManagerInput::readXML(), and InputSection::readXML().

62 { return static_cast<char*>(static_cast<void*>(c)); }

◆ castXMLCharToChar() [2/2]

const char* castXMLCharToChar ( const xmlChar *  c)
inline

unsafe const xmlChar* to const char* cast

Definition at line 66 of file libxmldefs.h.

66 { return static_cast<const char*>(static_cast<const void*>(c)); }

◆ getContent() [1/2]

bool getContent ( const T &  a,
xmlNodePtr  cur 
)

write a value to a node.

Parameters
areference to a value to be copied to a node
curcurrent node to which a content is copied
Returns
true if successful

Use specialization for classes. If operator << is implemented for a class, no specialization is required. For instance, no specialization is necessary for intrinsic data types.

Definition at line 119 of file libxmldefs.h.

References qmcplusplus::Units::time::s, and XMLNodeString::setXMLNodeContent().

Referenced by OhmmsParameter< T >::add(), OhmmsParameter< bool >::add(), QMCDriver::getQMCNode(), OhmmsParameter< T >::reset(), OhmmsParameter< bool >::reset(), and QMCCostFunctionBase::updateXmlNodes().

120 {
121  if (cur->children == NULL)
122  return false;
123  std::stringstream s;
124  s.setf(std::ios::scientific, std::ios::floatfield);
125  s.precision(10);
126  s << a;
127  const XMLNodeString node_string(s.str());
128  node_string.setXMLNodeContent(cur);
129  return true;
130 }
void setXMLNodeContent(xmlNodePtr cur) const
write a string to an xmlNode
convert xmlNode contents into a std::string

◆ getContent() [2/2]

bool getContent ( const std::vector< T > &  a,
xmlNodePtr  cur 
)
inline

write std::vector<T> to node.

Each element is separated by a space.

Parameters
areference std::vector<T>
curcurrent node to which a content is copied
Returns
true if successful

Specialization for std::vector<T> with data types T with operator <<. This function is only for testing/debugging and will not perform well for large vectors. Use HDF5 library for the real data.

Definition at line 159 of file libxmldefs.h.

References qmcplusplus::Units::time::s, and XMLNodeString::setXMLNodeContent().

160 {
161  std::stringstream s;
162  s.precision(10);
163  for (int i = 0; i < a.size(); i++)
164  s << ' ' << a[i];
165  const XMLNodeString node_string(s.str());
166  node_string.setXMLNodeContent(cur);
167  return true;
168 }
void setXMLNodeContent(xmlNodePtr cur) const
write a string to an xmlNode
convert xmlNode contents into a std::string

◆ getNodeName()

◆ processChildren()

void processChildren ( const xmlNodePtr  cur,
const F &  functor 
)

process through all the children of an XML element F is a lambda or functor void F/[](const std::string& cname, const xmlNodePtr element) {...}

Definition at line 175 of file libxmldefs.h.

Referenced by HamiltonianFactory::build(), SPOSetBuilderFactory::buildSPOSetCollection(), SPOSetBuilder::createRotatedSPOSet(), LCAOrbitalBuilder::createSPOSetFromXML(), LCAOrbitalBuilder::LCAOrbitalBuilder(), QMCFixedSampleLinearOptimizeBatched::process(), QMCFixedSampleLinearOptimize::put(), XMLParticleParser::readXML(), qmcplusplus::test_lcao_spinor(), qmcplusplus::test_lcao_spinor_excited(), and qmcplusplus::test_lcao_spinor_ion_derivs().

176 {
177  xmlNodePtr element = cur->children;
178  while (element != NULL)
179  {
180  std::string cname((const char*)(element->name));
181  functor(cname, element);
182  element = element->next;
183  }
184 }

◆ putContent() [1/3]

bool putContent ( T &  a,
xmlNodePtr  cur 
)

replaces a's value with the first "element" in the "string" returned by XMLNodeString{cur}.

but if that string is empty then then doesn't touch a. See documentation of the interaction between operator>> streams and the FormattedInputFunction requirement in the c++ standard.

Definition at line 88 of file libxmldefs.h.

Referenced by BackflowBuilder::addOneBody(), SymmetryBuilder::buildByHand(), ECPComponentBuilder::buildL2(), ECPComponentBuilder::buildSemiLocalAndLocal(), WaveFunctionFactory::buildTWF(), CountingJastrowBuilder::createCJ(), ECPComponentBuilder::createGrid(), PWOrbitalSetBuilder::createPW(), SPOSetBuilder::createRotatedSPOSet(), SPOSetBuilder::createSPOSet(), EinsplineSpinorSetBuilder::createSPOSetFromXML(), CompositeSPOSetBuilder::createSPOSetFromXML(), EinsplineSetBuilder::createSPOSetFromXML(), BackflowBuilder::makeLongRange_twoBody(), LatticeParser::put(), SpinDensity::put(), ExampleHeComponent::put(), SPOSetInputInfo::put(), QMCCostFunctionBase::put(), OhmmsParameter< T >::put(), OrbitalImages::put(), PadeFunctor< T >::put(), CountingGaussian::put(), UserFunctor< T >::put(), ParticleAttribXmlNode< PAT >::put(), BsplineFunctor< REAL >::put(), ShortRangeCuspFunctor< T >::put(), Pade2ndOrderFunctor< T >::put(), PadeTwo2ndOrderFunctor< T >::put(), PolynomialFunctor3D::put(), TraceManager::put(), LCAOrbitalBuilder::putFromXML(), LCAOrbitalBuilder::putOccupation(), SpinDensityInput::readXML(), XMLParticleParser::readXML(), QMCCostFunctionBase::resetCostFunction(), WaveFunctionTester::runNodePlot(), DensityMatrices1B::set_state(), ShortRangeCuspFunctor< T >::set_variable_from_xml(), qmcplusplus::setSpeciesProperty(), and TEST_CASE().

89 {
90  std::istringstream stream(XMLNodeString{cur});
91  stream >> a;
92  return !stream.fail();
93 }
convert xmlNode contents into a std::string

◆ putContent() [2/3]

bool putContent ( IT  first,
IT  last,
xmlNodePtr  cur 
)

Definition at line 96 of file libxmldefs.h.

97 {
98  std::istringstream stream(XMLNodeString{cur});
99  bool success = true;
100  while (success && first != last)
101  {
102  stream >> *first++;
103  success = !stream.fail();
104  }
105  return success;
106 }
convert xmlNode contents into a std::string

◆ putContent() [3/3]

bool putContent ( std::vector< T > &  a,
const xmlNodePtr  cur 
)
inline

assign std::vector<T> from a node.

Create a temporary vector and make assignment.

Parameters
areference std::vector<T>
curcurrent node to which a content is copied
Returns
true if successful

Specialization for std::vector<T> with data types T with operator >>, e.g., std::vector<double>

Definition at line 141 of file libxmldefs.h.

142 {
143  if (cur->children == NULL)
144  return false;
145  a = qmcplusplus::convertStrToVec<T>(XMLNodeString{cur});
146  return true;
147 }
convert xmlNode contents into a std::string