Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Xml.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2010, The Cinder Project
3  All rights reserved.
4 
5  This code is designed for use with the Cinder C++ library, http://libcinder.org
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
8  the following conditions are met:
9 
10  * Redistributions of source code must retain the above copyright notice, this list of conditions and
11  the following disclaimer.
12  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
13  the following disclaimer in the documentation and/or other materials provided with the distribution.
14 
15  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
16  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
18  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
19  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22  POSSIBILITY OF SUCH DAMAGE.
23 */
24 
25 #pragma once
26 
27 #include "cinder/Cinder.h"
28 #include "cinder/Stream.h"
29 #include "cinder/DataSource.h"
30 #include "cinder/DataTarget.h"
31 #include "cinder/Exception.h"
32 #include "cinder/Utilities.h"
33 
34 #include <string>
35 #include <vector>
36 
38 namespace rapidxml {
39  template<class Ch> class xml_document;
40  template<class Ch> class xml_node;
41 };
43 
44 namespace cinder {
45 
46 class XmlTree {
47  public:
48 
50  typedef std::list<std::unique_ptr<XmlTree> > Container;
52 
54  class ConstIter {
55  public:
57  ConstIter( const Container *sequence );
58  ConstIter( const Container *sequence, Container::const_iterator iter );
59  ConstIter( const XmlTree &root, const std::string &filterPath, bool caseSensitive = false, char separator = '/' );
61 
63  const XmlTree& operator*() const { return **mIterStack.back(); }
65  const XmlTree* operator->() const { return &(**mIterStack.back()); }
66 
69  increment();
70  return *this;
71  }
72 
74  const ConstIter operator++(int) {
75  ConstIter prev( *this );
76  ++(*this);
77  return prev;
78  }
79 
80  bool operator!=( const ConstIter &rhs ) { return ( mSequenceStack.back() != rhs.mSequenceStack.back() ) || ( mIterStack.back() != rhs.mIterStack.back() ); }
81  bool operator==( const ConstIter &rhs ) { return ( mSequenceStack.back() == rhs.mSequenceStack.back() ) && ( mIterStack.back() == rhs.mIterStack.back() ); }
82 
83  protected:
85  void increment();
86  void setToEnd( const Container *seq );
87  bool isDone() const;
88 
89  std::vector<const Container*> mSequenceStack;
90  std::vector<Container::const_iterator> mIterStack;
91  std::vector<std::string> mFilter;
92  bool mCaseSensitive;
94  };
95 
97  class Iter : public XmlTree::ConstIter {
98  public:
100  Iter( Container *sequence )
101  : ConstIter( sequence )
102  {}
103 
104  Iter( Container *sequence, Container::iterator iter )
105  : ConstIter( sequence, iter )
106  {}
107 
108  Iter( XmlTree &root, const std::string &filterPath, bool caseSensitive, char separator )
109  : ConstIter( root, filterPath, caseSensitive, separator )
110  {}
112 
113 
115  XmlTree& operator*() const { return const_cast<XmlTree&>(**mIterStack.back()); }
117  XmlTree* operator->() const { return const_cast<XmlTree*>( &(**mIterStack.back()) ); }
118 
121  increment();
122  return *this;
123  }
124 
126  const Iter operator++(int) {
127  Iter prev( *this );
128  ++(*this);
129  return prev;
130  }
131 
132  bool operator!=( const Iter &rhs ) { return ( mSequenceStack.back() != rhs.mSequenceStack.back() ) || ( mIterStack.back() != rhs.mIterStack.back() ); }
133  bool operator==( const Iter &rhs ) { return ( mSequenceStack.back() == rhs.mSequenceStack.back() ) && ( mIterStack.back() == rhs.mIterStack.back() ); }
134 
135  };
136 
138  class Attr {
139  public:
141  Attr( XmlTree *xml, const std::string &name, const std::string &value )
142  : mXml( xml ), mName( name ), mValue( value )
143  {}
144 
146  operator const std::string&() const { return mValue; }
148  template<typename T>
149  Attr& operator=( const T& val ) { mValue = toString( val ); mXml->setAttribute( mName, mValue ); return *this; }
150 
151  bool operator==( const char *rhs ) const { return mValue == rhs; }
152  bool operator==( const std::string &rhs ) const { return mValue == rhs; }
153  bool operator!=( const char *rhs ) const { return mValue != rhs; }
154  bool operator!=( const std::string &rhs ) const { return mValue != rhs; }
155 
157  template<typename T>
158  T as() const { return fromString<T>( mValue ); }
159 
161  bool empty() const { return mValue.empty(); }
162 
164  const std::string& getName() const { return mName; }
166  std::string getValue() const { return mValue; }
169  template<typename T>
170  T getValue() const { return fromString<T>( mValue ); }
171 
173  void setValue( const std::string &value ) { mValue = value; }
175  template<typename T>
176  void setValue( const T &value ) { mValue = boost::lexical_cast<std::string>( value ); }
177 
178  private:
179  XmlTree *mXml;
180  std::string mName, mValue;
181  };
182 
184  class ParseOptions {
185  public:
187  ParseOptions() : mParseComments( false ), mCollapseCData( true ), mIgnoreDataChildren( true ) {}
188 
190  ParseOptions& parseComments( bool parse = true ) { mParseComments = parse; return *this; }
192  ParseOptions& collapseCData( bool collapse = true ) { mCollapseCData = collapse; return *this; }
194  ParseOptions& ignoreDataChildren( bool ignore = true ) { setIgnoreDataChildren( ignore ); return *this; }
195 
197  bool getParseComments() const { return mParseComments; }
199  void setParseComments( bool parseComments = true ) { mParseComments = parseComments; }
201  bool getCollapseCData() const { return mCollapseCData; }
203  void setCollapseCData( bool collapseCData = true ) { mCollapseCData = collapseCData; }
205  bool getIgnoreDataChildren() const { return mIgnoreDataChildren; }
207  void setIgnoreDataChildren( bool ignore = true ) { mIgnoreDataChildren = ignore; }
208 
209  private:
210  bool mParseComments, mCollapseCData, mIgnoreDataChildren;
211  };
212 
215 
217  XmlTree() : mParent( 0 ), mNodeType( NODE_ELEMENT ) {}
218 
220  XmlTree( const XmlTree &rhs );
221  XmlTree& operator=( const XmlTree &rhs );
222 
225  explicit XmlTree( DataSourceRef dataSource, ParseOptions parseOptions = ParseOptions() ) {
226  loadFromDataSource( dataSource, this, parseOptions );
227  }
228 
230  explicit XmlTree( const std::string &xmlString, ParseOptions parseOptions = ParseOptions() );
231 
233  explicit XmlTree( const std::string &tag, const std::string &value, XmlTree *parent = 0, NodeType type = NODE_ELEMENT )
234  : mTag( tag ), mValue( value ), mParent( parent ), mNodeType( type )
235  {}
236 
238  static XmlTree createDoc() { return XmlTree( "", "", 0, NODE_DOCUMENT ); }
239 
241  NodeType getNodeType() const { return mNodeType; }
243  void setNodeType( NodeType type ) { mNodeType = type; }
245  bool isDocument() const { return mNodeType == NODE_DOCUMENT; }
247  bool isElement() const { return mNodeType == NODE_ELEMENT; }
249  bool isCData() const { return mNodeType == NODE_CDATA; }
251  bool isComment() const { return mNodeType == NODE_COMMENT; }
252 
254  const std::string& getTag() const { return mTag; }
256  void setTag( const std::string &tag ) { mTag = tag; }
257 
259  std::string getValue() const { return mValue; }
261  template<typename T>
262  T getValue() const { return boost::lexical_cast<T>( mValue ); }
264  template<typename T>
265  T getValue( const T &defaultValue ) const { try { return boost::lexical_cast<T>( mValue ); } catch( ... ) { return defaultValue; } }
266 
268  void setValue( const std::string &value ) { mValue = value; }
270  template<typename T>
271  void setValue( const T &value ) { mValue = boost::lexical_cast<std::string>( value ); }
272 
274  bool hasParent() const { return mParent != NULL; }
276  XmlTree& getParent() { return *mParent; }
278  const XmlTree& getParent() const { return *mParent; }
279 
281  Iter find( const std::string &relativePath, bool caseSensitive = false, char separator = '/' ) { return Iter( *this, relativePath, caseSensitive, separator ); }
283  ConstIter find( const std::string &relativePath, bool caseSensitive = false, char separator = '/' ) const { return ConstIter( *this, relativePath, caseSensitive, separator ); }
285  bool hasChild( const std::string &relativePath, bool caseSensitive = false, char separator = '/' ) const;
286 
288  XmlTree& getChild( const std::string &relativePath, bool caseSensitive = false, char separator = '/' );
290  const XmlTree& getChild( const std::string &relativePath, bool caseSensitive = false, char separator = '/' ) const;
292  Container& getChildren() { return mChildren; }
294  const Container& getChildren() const { return mChildren; }
295 
297  std::list<Attr>& getAttributes() { return mAttributes; }
299  const std::list<Attr>& getAttributes() const { return mAttributes; }
300 
302  const Attr& getAttribute( const std::string &attrName ) const;
303 
305  const Attr operator[]( const std::string &attrName ) const { if( hasAttribute( attrName ) ) return getAttribute(attrName); else return Attr( const_cast<XmlTree*>( this ), attrName, "" ); }
307  Attr operator[]( const std::string &attrName ) { if( hasAttribute( attrName ) ) return getAttribute(attrName); else return Attr( this, attrName, "" ); }
308 
310  const XmlTree& operator/( const std::string &childName ) const { return getChild( childName ); }
312  XmlTree& operator/( const std::string &childName ) { return getChild( childName ); }
313 
316  template<typename T>
317  T getAttributeValue( const std::string &attrName ) const { return getAttribute( attrName ).getValue<T>(); }
320  template<typename T>
321  T getAttributeValue( const std::string &attrName, const T &defaultValue ) const {
322  if( hasAttribute( attrName ) ) {
323  try {
324  return getAttribute( attrName ).getValue<T>();
325  }
326  catch(...) {
327  return defaultValue;
328  }
329  }
330  else return defaultValue;
331  }
332 
334  XmlTree& setAttribute( const std::string &attrName, const std::string &value );
336  template<typename T>
337  XmlTree& setAttribute( const std::string &attrName, const T &value ) { return setAttribute( attrName, boost::lexical_cast<std::string>( value ) ); }
339  bool hasAttribute( const std::string &attrName ) const;
341  std::string getPath( char separator = '/' ) const;
342 
344  Iter begin() { return Iter( &mChildren ); }
346  Iter begin( const std::string &filterPath, bool caseSensitive = false, char separator = '/' ) { return Iter( *this, filterPath, caseSensitive, separator ); }
348  ConstIter begin() const { return ConstIter( &mChildren ); }
350  ConstIter begin( const std::string &filterPath, bool caseSensitive = false, char separator = '/' ) const { return ConstIter( *this, filterPath, caseSensitive, separator ); }
352  Iter end() { return Iter( &mChildren, mChildren.end() ); }
354  ConstIter end() const { return ConstIter( &mChildren, mChildren.end() ); }
356  void push_back( const XmlTree &newChild );
357 
359  std::string getDocType() const { return mDocType; }
361  void setDocType( const std::string &docType ) { mDocType = docType; }
362 
364  friend std::ostream& operator<<( std::ostream &out, const XmlTree &xml );
366  void write( DataTargetRef target, bool createDocument = true );
367 
369  class Exception : public cinder::Exception {
370  };
371 
374  public:
375  ExcChildNotFound( const XmlTree &node, const std::string &childPath ) throw();
376 
377  virtual const char* what() const throw() { return mMessage; }
378 
379  private:
380  char mMessage[2048];
381  };
382 
385  public:
386  ExcAttrNotFound( const XmlTree &node, const std::string &attrName ) throw();
387 
388  virtual const char* what() const throw() { return mMessage; }
389 
390  private:
391  char mMessage[2048];
392  };
393 
396  };
397 
399  std::shared_ptr<rapidxml::xml_document<char> > createRapidXmlDoc( bool createDocument = false ) const;
400 
401  private:
402  XmlTree* getNodePtr( const std::string &relativePath, bool caseSensitive, char separator ) const;
403  void appendRapidXmlNode( rapidxml::xml_document<char> &doc, rapidxml::xml_node<char> *parent ) const;
404 
405  static Container::const_iterator findNextChildNamed( const Container &sequence, Container::const_iterator firstCandidate, const std::string &searchTag, bool caseSensitive );
406 
407  NodeType mNodeType;
408  std::string mTag;
409  std::string mValue;
410  std::string mDocType; // only used on NodeType::NODE_DOCUMENT
411  XmlTree *mParent;
412  Container mChildren;
413  std::list<Attr> mAttributes;
414 
415  static void loadFromDataSource( DataSourceRef dataSource, XmlTree *result, const ParseOptions &parseOptions );
416 };
417 
418 std::ostream& operator<<( std::ostream &out, const XmlTree &xml );
419 
420 } // namespace cinder
421 
422 namespace std {
423 
425 template<>
426 struct iterator_traits<cinder::XmlTree::Iter> {
427  typedef cinder::XmlTree value_type;
428  typedef ptrdiff_t difference_type;
429  typedef forward_iterator_tag iterator_category;
430  typedef cinder::XmlTree* pointer;
431  typedef cinder::XmlTree& reference;
432 };
433 
434 template<>
435 struct iterator_traits<cinder::XmlTree::ConstIter> {
436  typedef cinder::XmlTree value_type;
437  typedef ptrdiff_t difference_type;
438  typedef forward_iterator_tag iterator_category;
439  typedef const cinder::XmlTree* pointer;
440  typedef const cinder::XmlTree& reference;
441 };
443 
444 } // namespace std
An iterator over the children of an XmlTree.
Definition: Xml.h:97
A const iterator over the children of an XmlTree.
Definition: Xml.h:54
const XmlTree & operator*() const
Returns a reference to the XmlTree the iterator currently points to.
Definition: Xml.h:63
const Container & getChildren() const
Returns a reference to the node's list of children nodes.
Definition: Xml.h:294
ConstIter begin() const
Definition: Xml.h:348
bool getCollapseCData() const
Returns whether CDATA blocks are collapsed automatically or not.
Definition: Xml.h:201
XmlTree & operator*() const
Returns a reference to the XmlTree the iterator currently points to.
Definition: Xml.h:115
const Attr & getAttribute(const std::string &attrName) const
Returns a reference to the node attribute named attrName. Throws AttrNotFoundExc if no attribute exis...
Definition: Xml.cpp:277
void write(DataTargetRef target, bool createDocument=true)
Definition: Xml.cpp:412
void setTag(const std::string &tag)
Sets the tag or name of the node to the string tag.
Definition: Xml.h:256
Container & getChildren()
Returns a reference to the node's list of children nodes.
Definition: Xml.h:292
bool operator==(const Iter &rhs)
Definition: Xml.h:133
Definition: Xml.h:214
T getValue() const
Returns the value of the node parsed as a T. Requires T to support the istream>> operator.
Definition: Xml.h:262
const Iter operator++(int)
Increments the iterator to the next child. If using a non-empty filterPath increments to the next chi...
Definition: Xml.h:126
Options for XML parsing. Passed to the XmlTree constructor.
Definition: Xml.h:184
GLsizei const GLchar ** string
Definition: GLee.h:2427
NodeType getNodeType() const
Returns the type of this node as a NodeType.
Definition: Xml.h:241
std::string getDocType() const
Definition: Xml.h:359
void push_back(const XmlTree &newChild)
Definition: Xml.cpp:325
ParseOptions()
Default options. Disables parsing comments, enables collapsing CDATA, ignores data children...
Definition: Xml.h:187
bool hasAttribute(const std::string &attrName) const
Definition: Xml.cpp:300
XmlTree(DataSourceRef dataSource, ParseOptions parseOptions=ParseOptions())
Parses XML contained in dataSource using the options parseOptions. Commonly used with the results of ...
Definition: Xml.h:225
void setValue(const T &value)
Definition: Xml.h:176
std::string toString(const T &t)
Definition: Utilities.h:81
bool operator!=(const Iter &rhs)
Definition: Xml.h:132
void setParseComments(bool parseComments=true)
Sets whether XML comments are parsed or not.
Definition: Xml.h:199
void setCollapseCData(bool collapseCData=true)
Sets whether CDATA blocks are collapsed automatically or not.
Definition: Xml.h:203
GLenum target
Definition: GLee.h:13607
const std::string & getName() const
Returns the name of the attribute as a string.
Definition: Xml.h:164
Iter begin(const std::string &filterPath, bool caseSensitive=false, char separator= '/')
Definition: Xml.h:346
Iter & operator++()
Increments the iterator to the next child. If using a non-empty filterPath increments to the next chi...
Definition: Xml.h:120
Iter find(const std::string &relativePath, bool caseSensitive=false, char separator= '/')
Returns the first child that matches relativePath or end() if none matches.
Definition: Xml.h:281
Definition: Xml.h:46
std::list< Attr > & getAttributes()
Returns a reference to the node's list of attributes.
Definition: Xml.h:297
Definition: Xml.h:214
NodeType
Enum listing all types of XML nodes understood by the parser.
Definition: Xml.h:214
void setValue(const T &value)
Sets the value of the node to value which is converted to a string first. Requires T to support the o...
Definition: Xml.h:271
bool isCData() const
Returns whether this node represents CDATA. Only possible when a document's ParseOptions disabled col...
Definition: Xml.h:249
bool hasParent() const
Returns whether this node has a parent node.
Definition: Xml.h:274
XmlTree * operator->() const
Returns a pointer to the XmlTree the iterator currently points to.
Definition: Xml.h:117
bool hasChild(const std::string &relativePath, bool caseSensitive=false, char separator= '/') const
Returns whether at least one child matches relativePath.
Definition: Xml.cpp:254
bool operator==(const char *rhs) const
Definition: Xml.h:151
Exception implying an XML node of an unknown type. Implies a low-level problem communicating with Rap...
Definition: Xml.h:395
void setNodeType(NodeType type)
Sets the type of this node to NodeType type.
Definition: Xml.h:243
bool isElement() const
Returns whether this node is an element node.
Definition: Xml.h:247
GLuint GLfloat * val
Definition: GLee.h:14636
const std::list< Attr > & getAttributes() const
Returns a reference to the node's list of attributes.
Definition: Xml.h:299
Base class for XmlTree exceptions.
Definition: Xml.h:369
Definition: Xml.h:214
ParseOptions & ignoreDataChildren(bool ignore=true)
Sets whether data nodes are created as children, in addition to being available as the value of the p...
Definition: Xml.h:194
bool operator==(const ConstIter &rhs)
Definition: Xml.h:81
T getAttributeValue(const std::string &attrName) const
Returns the value of the attribute attrName parsed as a T. Throws AttrNotFoundExc if no attribute exi...
Definition: Xml.h:317
XmlTree & setAttribute(const std::string &attrName, const T &value)
Definition: Xml.h:337
static XmlTree createDoc()
Returns an XML document node.
Definition: Xml.h:238
const XmlTree & operator/(const std::string &childName) const
Returns the first child that matches childName. Throws ExcChildNotFound if none matches.
Definition: Xml.h:310
void setDocType(const std::string &docType)
Definition: Xml.h:361
Definition: Xml.h:214
T as() const
Returns the value of the attribute cast to T using ci::fromString().
Definition: Xml.h:158
Iter end()
Definition: Xml.h:352
XmlTree()
Default constructor, creating an empty node.
Definition: Xml.h:217
void setValue(const std::string &value)
Sets the value of the node to the string value.
Definition: Xml.h:268
T getAttributeValue(const std::string &attrName, const T &defaultValue) const
Returns the value of the attribute attrName parsed as a T. Returns defaultValue if no attribute exist...
Definition: Xml.h:321
bool operator==(const std::string &rhs) const
Definition: Xml.h:152
Attr & operator=(const T &val)
Assigns the Attr a new value, and creates it if it doesn't exist. The equivalent of calling setAttrib...
Definition: Xml.h:149
ExcAttrNotFound(const XmlTree &node, const std::string &attrName)
Definition: Xml.cpp:431
const ConstIter operator++(int)
Increments the iterator to the next child. If using a non-empty filterPath increments to the next chi...
Definition: Xml.h:74
Definition: Xml.h:214
Definition: Xml.h:214
const Attr operator[](const std::string &attrName) const
Returns an Attr accessor. If the attribute does not exists its Attr's value will be an empty string...
Definition: Xml.h:305
XmlTree(const std::string &tag, const std::string &value, XmlTree *parent=0, NodeType type=NODE_ELEMENT)
Constructs an XML node with the tag tag, the value value. Optionally sets the pointer to the node's p...
Definition: Xml.h:233
GLsizei const GLfloat * value
Definition: GLee.h:2487
std::string getValue() const
Returns the value of the attribute as a string.
Definition: Xml.h:166
std::shared_ptr< rapidxml::xml_document< char > > createRapidXmlDoc(bool createDocument=false) const
Returns a shared_ptr to a RapidXML xml_document. If createDocument is true then an implicit parent NO...
Definition: Xml.cpp:381
Exception expressing the absence of an expected attribute.
Definition: Xml.h:384
GLuint GLuint GLsizei GLenum type
Definition: GLee.h:963
std::ostream & operator<<(std::ostream &lhs, const ColorT< float > &rhs)
Definition: Color.cpp:203
GLuint const GLchar * name
Definition: GLee.h:2259
ExcChildNotFound(const XmlTree &node, const std::string &childPath)
Definition: Xml.cpp:422
bool isDocument() const
Returns whether this node is a document node, meaning it is a root node.
Definition: Xml.h:245
ParseOptions & parseComments(bool parse=true)
Sets whether XML comments are parsed or not.
Definition: Xml.h:190
std::string getValue() const
Returns the value of the node as a string.
Definition: Xml.h:259
XmlTree & operator=(const XmlTree &rhs)
Definition: Xml.cpp:161
const XmlTree * operator->() const
Returns a pointer to the XmlTree the iterator currently points to.
Definition: Xml.h:65
bool operator!=(const std::string &rhs) const
Definition: Xml.h:154
void setValue(const std::string &value)
Definition: Xml.h:173
std::shared_ptr< class DataTarget > DataTargetRef
Definition: DataTarget.h:33
bool getParseComments() const
Returns whether XML comments are parsed or not.
Definition: Xml.h:197
Exception expressing the absence of an expected child node.
Definition: Xml.h:373
bool operator!=(const char *rhs) const
Definition: Xml.h:153
bool empty() const
Returns true if the Attr value is empty.
Definition: Xml.h:161
ParseOptions & collapseCData(bool collapse=true)
Sets whether CDATA blocks are collapsed automatically or not.
Definition: Xml.h:192
virtual const char * what() const
Definition: Xml.h:377
bool getIgnoreDataChildren() const
Returns whether data nodes are created as children, in addition to being available as the value of th...
Definition: Xml.h:205
XmlTree & setAttribute(const std::string &attrName, const std::string &value)
Definition: Xml.cpp:285
ConstIter end() const
Definition: Xml.h:354
ConstIter begin(const std::string &filterPath, bool caseSensitive=false, char separator= '/') const
Definition: Xml.h:350
Definition: Exception.h:32
Iter begin()
Definition: Xml.h:344
ConstIter find(const std::string &relativePath, bool caseSensitive=false, char separator= '/') const
Returns the first child that matches relativePath or end() if none matches.
Definition: Xml.h:283
Attr operator[](const std::string &attrName)
Returns an Attr accessor. If the attribute does not exists its Attr's value will be an empty string...
Definition: Xml.h:307
bool operator!=(const ConstIter &rhs)
Definition: Xml.h:80
XmlTree & operator/(const std::string &childName)
Returns the first child that matches childName. Throws ExcChildNotFound if none matches.
Definition: Xml.h:312
XmlTree & getParent()
Returns a reference to the node which is the parent of this node.
Definition: Xml.h:276
XmlTree & getChild(const std::string &relativePath, bool caseSensitive=false, char separator= '/')
Returns the first child that matches relativePath. Throws ExcChildNotFound if none matches...
Definition: Xml.cpp:268
T getValue(const T &defaultValue) const
Returns the value of the node parsed as a T. If the value is empty or fails to parse defaultValue is ...
Definition: Xml.h:265
void setIgnoreDataChildren(bool ignore=true)
Sets whether data nodes are created as children, in addition to being available as the value of the p...
Definition: Xml.h:207
std::shared_ptr< class DataSource > DataSourceRef
Definition: DataSource.h:35
bool isComment() const
Returns whether this node represents a comment. Only possible when a document's ParseOptions enabled ...
Definition: Xml.h:251
ConstIter & operator++()
Increments the iterator to the next child. If using a non-empty filterPath increments to the next chi...
Definition: Xml.h:68
friend std::ostream & operator<<(std::ostream &out, const XmlTree &xml)
std::string getPath(char separator= '/') const
Definition: Xml.cpp:309
XML attribute.
Definition: Xml.h:138
const std::string & getTag() const
Returns the tag or name of the node as a string.
Definition: Xml.h:254
Attr(XmlTree *xml, const std::string &name, const std::string &value)
Constructs an XML attribute named name with the value value.
Definition: Xml.h:141
const XmlTree & getParent() const
Returns a reference to the node which is the parent of this node.
Definition: Xml.h:278
virtual const char * what() const
Definition: Xml.h:388
T getValue() const
Returns the value of the attribute parsed as a T. Requires T to support the istream>> operator...
Definition: Xml.h:170
GLsizei const GLvoid * pointer
Definition: GLee.h:1719