QMCPACK
OhmmsXPathObject Struct Reference

class to handle xmlXPathObject More...

+ Collaboration diagram for OhmmsXPathObject:

Public Member Functions

 OhmmsXPathObject ()
 
 OhmmsXPathObject (const char *expression, xmlXPathContextPtr context)
 constructor More...
 
 OhmmsXPathObject (const char *expression, xmlNodePtr cur)
 constructor More...
 
 ~OhmmsXPathObject ()
 
void put (const char *expression, xmlXPathContextPtr context)
 evaluate the expression and create the object More...
 
bool empty ()
 
int size ()
 
xmlNodePtr operator[] (int i)
 

Public Attributes

int NumObjects
 
xmlXPathObjectPtr result
 
xmlXPathContextPtr m_context
 

Detailed Description

class to handle xmlXPathObject

Definition at line 26 of file Libxml2Doc.h.

Constructor & Destructor Documentation

◆ OhmmsXPathObject() [1/3]

Definition at line 24 of file Libxml2Doc.cpp.

24 : NumObjects(0), result(NULL), m_context(NULL) {}
xmlXPathContextPtr m_context
Definition: Libxml2Doc.h:71
xmlXPathObjectPtr result
Definition: Libxml2Doc.h:70

◆ OhmmsXPathObject() [2/3]

OhmmsXPathObject ( const char *  expression,
xmlXPathContextPtr  context 
)

constructor

Parameters
expressionxpath expression
contextxmlXPathContext with which expression is evaluated

Definition at line 26 of file Libxml2Doc.cpp.

References put().

27  : NumObjects(0), result(NULL), m_context(NULL)
28 {
29  put(expression, context);
30 }
void put(const char *expression, xmlXPathContextPtr context)
evaluate the expression and create the object
Definition: Libxml2Doc.cpp:64
xmlXPathContextPtr m_context
Definition: Libxml2Doc.h:71
xmlXPathObjectPtr result
Definition: Libxml2Doc.h:70

◆ OhmmsXPathObject() [3/3]

OhmmsXPathObject ( const char *  expression,
xmlNodePtr  cur 
)

constructor

Parameters
expressionxpath expression
curxmlNodePtr

Create m_context

Definition at line 32 of file Libxml2Doc.cpp.

References m_context, and put().

33  : NumObjects(0), result(NULL), m_context(NULL)
34 {
35  m_context = xmlXPathNewContext(cur->doc);
36  m_context->node = cur;
37 
38  if (expression[0] == '.')
39  {
40  put(expression, m_context);
41  }
42  else
43  {
44  std::array<char, 128> local;
45  if (std::snprintf(local.data(), local.size(), ".%s", expression) < 0)
46  throw std::runtime_error("Error generating expression");
47  put(local.data(), m_context);
48  }
49 }
void put(const char *expression, xmlXPathContextPtr context)
evaluate the expression and create the object
Definition: Libxml2Doc.cpp:64
xmlXPathContextPtr m_context
Definition: Libxml2Doc.h:71
xmlXPathObjectPtr result
Definition: Libxml2Doc.h:70

◆ ~OhmmsXPathObject()

Definition at line 51 of file Libxml2Doc.cpp.

References m_context, and result.

52 {
53  if (result != NULL)
54  {
55  xmlXPathFreeObject(result);
56  }
57 
58  if (m_context != NULL)
59  {
60  xmlXPathFreeContext(m_context);
61  }
62 }
xmlXPathContextPtr m_context
Definition: Libxml2Doc.h:71
xmlXPathObjectPtr result
Definition: Libxml2Doc.h:70

Member Function Documentation

◆ empty()

bool empty ( )
inline

Definition at line 53 of file Libxml2Doc.h.

References NumObjects.

Referenced by TEST_CASE(), QMCCostFunctionBase::updateXmlNodes(), and QMCMain::validateXML().

53 { return NumObjects == 0; }

◆ operator[]()

xmlNodePtr operator[] ( int  i)
inline

Definition at line 57 of file Libxml2Doc.h.

References NumObjects, and result.

58  {
59  if (result != NULL && i < NumObjects)
60  {
61  return result->nodesetval->nodeTab[i];
62  }
63  else
64  {
65  return NULL;
66  }
67  }
xmlXPathObjectPtr result
Definition: Libxml2Doc.h:70

◆ put()

void put ( const char *  expression,
xmlXPathContextPtr  context 
)

evaluate the expression and create the object

Parameters
expressionxpath expression
contextxmlXPathContext with which expression is evaluated

Definition at line 64 of file Libxml2Doc.cpp.

References NumObjects, and result.

Referenced by OhmmsXPathObject().

65 {
66  //free the object if it has been used before
67  if (result != NULL)
68  xmlXPathFreeObject(result);
69  result = xmlXPathEvalExpression((const xmlChar*)expression, context);
70  if (xmlXPathNodeSetIsEmpty(result->nodesetval))
71  {
72  NumObjects = 0;
73  }
74  else
75  {
76  NumObjects = result->nodesetval->nodeNr;
77  }
78 }
xmlXPathObjectPtr result
Definition: Libxml2Doc.h:70

◆ size()

int size ( void  )
inline

Definition at line 55 of file Libxml2Doc.h.

References NumObjects.

Referenced by QMCMain::setMCWalkers(), TEST_CASE(), and QMCCostFunctionBase::updateXmlNodes().

55 { return NumObjects; }

Member Data Documentation

◆ m_context

xmlXPathContextPtr m_context

Definition at line 71 of file Libxml2Doc.h.

Referenced by OhmmsXPathObject(), and ~OhmmsXPathObject().

◆ NumObjects

int NumObjects

Definition at line 69 of file Libxml2Doc.h.

Referenced by empty(), operator[](), put(), and size().

◆ result

xmlXPathObjectPtr result

Definition at line 70 of file Libxml2Doc.h.

Referenced by operator[](), put(), and ~OhmmsXPathObject().


The documentation for this struct was generated from the following files: