ReactOS 0.4.15-dev-8119-g4fb2fdb
XMLStorage::XPathElement Struct Reference

#include <xmlstorage.h>

Collaboration diagram for XMLStorage::XPathElement:

Public Member Functions

 XPathElement ()
 
 XPathElement (const XS_String &child_name, int child_idx=-1)
 
 XPathElement (const XS_String &child_name, int child_idx, const XS_String &attr_name, const XS_String &attr_value)
 
const charparse (const char *path)
 
XMLNodefind (XMLNode *node) const
 
const XMLNodeconst_find (const XMLNode *node) const
 
bool matches (const XMLNode &node, int &n) const
 

Public Attributes

XS_String _child_name
 
int _child_idx
 
XS_String _attr_name
 
XS_String _attr_value
 

Detailed Description

Definition at line 814 of file xmlstorage.h.

Constructor & Destructor Documentation

◆ XPathElement() [1/3]

XMLStorage::XPathElement::XPathElement ( )
inline

Definition at line 816 of file xmlstorage.h.

◆ XPathElement() [2/3]

XMLStorage::XPathElement::XPathElement ( const XS_String child_name,
int  child_idx = -1 
)
inline

Definition at line 818 of file xmlstorage.h.

819 : _child_name(child_name), _child_idx(child_idx) {}

◆ XPathElement() [3/3]

XMLStorage::XPathElement::XPathElement ( const XS_String child_name,
int  child_idx,
const XS_String attr_name,
const XS_String attr_value 
)
inline

Definition at line 821 of file xmlstorage.h.

822 : _child_name(child_name), _child_idx(child_idx),
823 _attr_name(attr_name), _attr_value(attr_value)
824 {
825 }

Member Function Documentation

◆ const_find()

const XMLNode * XMLStorage::XPathElement::const_find ( const XMLNode node) const

Definition at line 195 of file xmlstorage.cpp.

196{
197 int n = 0;
198
199 for(XMLNode::Children::const_iterator it=node->_children.begin(); it!=node->_children.end(); ++it)
200 if (matches(**it, n))
201 return *it;
202
203 return NULL;
204}
#define NULL
Definition: types.h:112
GLdouble n
Definition: glext.h:7729
#define matches(FN)
Definition: match.h:70
Definition: dlist.c:348

Referenced by XMLStorage::const_XMLPos::go_down(), and XMLStorage::const_XMLPos::iterate().

◆ find()

XMLNode * XMLStorage::XPathElement::find ( XMLNode node) const

Definition at line 184 of file xmlstorage.cpp.

185{
186 int n = 0;
187
188 for(XMLNode::Children::const_iterator it=node->_children.begin(); it!=node->_children.end(); ++it)
189 if (matches(**it, n))
190 return *it;
191
192 return NULL;
193}

Referenced by XMLStorage::XMLPos::go_down(), XMLStorage::XMLPos::iterate(), and XMLStorage::XMLPos::smart_create().

◆ matches()

bool XMLStorage::XPathElement::matches ( const XMLNode node,
int n 
) const

Definition at line 206 of file xmlstorage.cpp.

207{
208 if (node != _child_name)
209 if (_child_name != XS_TEXT("*")) // use asterisk as wildcard
210 return false;
211
212 if (!_attr_name.empty())
213 if (node.get(_attr_name) != _attr_value)
214 return false;
215
216 if (_child_idx == -1)
217 return true;
218 else if (n++ == _child_idx)
219 return true;
220 else
221 return false;
222}
#define XS_TEXT(x)
Definition: xmlstorage.h:237

◆ parse()

const char * XMLStorage::XPathElement::parse ( const char path)

Definition at line 142 of file xmlstorage.cpp.

143{
144 const char* slash = strchr(path, '/');
145 if (slash == path)
146 return NULL;
147
148 size_t l = slash? slash-path: strlen(path);
149 std::string comp(path, l);
150 path += l;
151
152 // look for [n] and [@attr_name="attr_value"] expressions in path components
153 const char* bracket = strchr(comp.c_str(), '[');
154 l = bracket? bracket-comp.c_str(): comp.length();
155 _child_name.assign(comp.c_str(), l);
156
157 int n = 0;
158 if (bracket) {
159 std::string expr = unescape(bracket, '[', ']');
160 const char* p = expr.c_str();
161
162 n = atoi(p); // read index number
163
164 if (n)
165 _child_idx = n - 1; // convert into zero based index
166
167 const char* at = strchr(p, '@');
168
169 if (at) {
170 p = at + 1;
171 const char* equal = strchr(p, '=');
172
173 // read attribute name and value
174 if (equal) {
177 }
178 }
179 }
180
181 return path;
182}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strchr(const char *String, int ch)
Definition: utclib.c:501
static int bracket
Definition: adnsresfilter.c:59
r l[0]
Definition: byte_order.h:168
GLfloat GLfloat p
Definition: glext.h:8902
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
static std::string unescape(const char *s, char b, char e)
remove escape characters from zero terminated string
Definition: xmlstorage.cpp:67
#define equal(x, y)
Definition: reader.cc:56
void assign(const XS_String &s)
Definition: xmlstorage.h:338
Definition: query.h:87

Member Data Documentation

◆ _attr_name

XS_String XMLStorage::XPathElement::_attr_name

Definition at line 830 of file xmlstorage.h.

Referenced by matches(), and parse().

◆ _attr_value

XS_String XMLStorage::XPathElement::_attr_value

Definition at line 831 of file xmlstorage.h.

Referenced by matches(), and parse().

◆ _child_idx

int XMLStorage::XPathElement::_child_idx

Definition at line 828 of file xmlstorage.h.

Referenced by matches(), and parse().

◆ _child_name

XS_String XMLStorage::XPathElement::_child_name

Definition at line 827 of file xmlstorage.h.

Referenced by matches(), and parse().


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