39 template<
class Ch>
class xml_document;
40 template<
class Ch>
class xml_node;
50 typedef std::list<std::unique_ptr<XmlTree> > Container;
58 ConstIter(
const Container *sequence, Container::const_iterator iter );
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() ); }
86 void setToEnd(
const Container *seq );
89 std::vector<const Container*> mSequenceStack;
90 std::vector<Container::const_iterator> mIterStack;
91 std::vector<std::string> mFilter;
100 Iter( Container *sequence )
104 Iter( Container *sequence, Container::iterator iter )
109 :
ConstIter( root, filterPath, caseSensitive, separator )
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() ); }
142 : mXml( xml ), mName( name ), mValue( value )
151 bool operator==(
const char *rhs )
const {
return mValue == rhs; }
153 bool operator!=(
const char *rhs )
const {
return mValue != rhs; }
158 T
as()
const {
return fromString<T>( mValue ); }
161 bool empty()
const {
return mValue.empty(); }
170 T
getValue()
const {
return fromString<T>( mValue ); }
187 ParseOptions() : mParseComments( false ), mCollapseCData( true ), mIgnoreDataChildren( true ) {}
210 bool mParseComments, mCollapseCData, mIgnoreDataChildren;
226 loadFromDataSource( dataSource,
this, parseOptions );
230 explicit XmlTree(
const std::string &xmlString, ParseOptions parseOptions = ParseOptions() );
234 : mTag( tag ), mValue( value ), mParent( parent ), mNodeType(
type )
262 T
getValue()
const {
return boost::lexical_cast<T>( mValue ); }
265 T
getValue(
const T &defaultValue )
const {
try {
return boost::lexical_cast<T>( mValue ); }
catch( ... ) {
return defaultValue; } }
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;
330 else return defaultValue;
346 Iter begin(
const std::string &filterPath,
bool caseSensitive =
false,
char separator =
'/' ) {
return Iter( *
this, filterPath, caseSensitive, separator ); }
377 virtual const char*
what()
const throw() {
return mMessage; }
388 virtual const char*
what()
const throw() {
return mMessage; }
399 std::shared_ptr<rapidxml::xml_document<char> >
createRapidXmlDoc(
bool createDocument =
false )
const;
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;
405 static Container::const_iterator findNextChildNamed(
const Container &sequence, Container::const_iterator firstCandidate,
const std::string &searchTag,
bool caseSensitive );
413 std::list<Attr> mAttributes;
426 struct iterator_traits<cinder::XmlTree::Iter> {
428 typedef ptrdiff_t difference_type;
429 typedef forward_iterator_tag iterator_category;
435 struct iterator_traits<cinder::XmlTree::ConstIter> {
437 typedef ptrdiff_t difference_type;
438 typedef forward_iterator_tag iterator_category;
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
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
std::list< Attr > & getAttributes()
Returns a reference to the node's list of attributes.
Definition: Xml.h:297
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
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
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
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