33 #ifndef TINYXML_INCLUDED
34 #define TINYXML_INCLUDED
36 #ifndef _MADARA_NO_XML_
39 #pragma warning( push )
40 #pragma warning( disable : 4530 )
41 #pragma warning( disable : 4786 )
49 #include "madara/MADARA_export.h"
52 #if defined( _DEBUG ) && !defined( DEBUG )
65 #define TIXML_STRING std::string
75 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
77 #define TIXML_SNPRINTF _snprintf_s
78 #define TIXML_SSCANF sscanf_s
79 #elif defined(_MSC_VER) && (_MSC_VER >= 1200 )
82 #define TIXML_SNPRINTF _snprintf
83 #define TIXML_SSCANF sscanf
84 #elif defined(__GNUC__) && (__GNUC__ >= 3 )
87 #define TIXML_SNPRINTF snprintf
88 #define TIXML_SSCANF sscanf
90 #define TIXML_SNPRINTF snprintf
91 #define TIXML_SSCANF sscanf
233 virtual void Print( FILE* cfile,
int depth )
const = 0;
275 virtual const char*
Parse(
const char* p,
312 return ( isspace( (
unsigned char) c ) || c ==
'\n' || c ==
'\r' );
335 static const char*
ReadText(
const char* in,
337 bool ignoreWhiteSpace,
352 *length = utf8ByteTable[ *((
const unsigned char*)p) ];
353 assert( *length >= 0 && *length < 5 );
363 return GetEntity( p, _value, length, encoding );
371 for(
int i=0; p[i] && i<*length; ++i ) {
374 return p + (*length);
406 if ( v < 128 )
return tolower( v );
432 MAX_ENTITY_LENGTH = 6
534 void SetValue(
const std::string& _value ) {
value = _value; }
552 return const_cast< TiXmlNode*
> ((
const_cast< const TiXmlNode*
>(
this))->FirstChild( _value ));
559 return const_cast< TiXmlNode*
> ((
const_cast< const TiXmlNode*
>(
this))->LastChild( _value ));
587 return const_cast< TiXmlNode*
>( (
const_cast< const TiXmlNode*
>(
this))->IterateChildren( previous ) );
593 return const_cast< TiXmlNode*
>( (
const_cast< const TiXmlNode*
>(
this))->IterateChildren( _value, previous ) );
643 return const_cast< TiXmlNode*
>( (
const_cast< const TiXmlNode*
>(
this))->PreviousSibling( _prev ) );
660 return const_cast< TiXmlNode*
>( (
const_cast< const TiXmlNode*
>(
this))->NextSibling( _next ) );
678 return const_cast< TiXmlElement*
>( (
const_cast< const TiXmlNode*
>(
this))->NextSiblingElement( _next ) );
695 return const_cast< TiXmlElement*
>( (
const_cast< const TiXmlNode*
>(
this))->FirstChildElement( _value ) );
815 TiXmlAttribute(
const std::string& _name,
const std::string& _value )
834 const char*
Name()
const {
return name.c_str(); }
835 const char*
Value()
const {
return value.c_str(); }
837 const std::string&
ValueStr()
const {
return value; }
839 int IntValue()
const;
840 double DoubleValue()
const;
854 int QueryIntValue(
int* _value )
const;
856 int QueryDoubleValue(
double* _value )
const;
858 void SetName(
const char* _name ) { name = _name; }
859 void SetValue(
const char* _value ) { value = _value; }
861 void SetIntValue(
int _value );
862 void SetDoubleValue(
double _value );
865 void SetName(
const std::string& _name ) { name = _name; }
868 void SetValue(
const std::string& _value ) { value = _value; }
893 virtual void Print( FILE* cfile,
int depth )
const {
894 Print( cfile, depth, 0 );
944 # ifdef TIXML_USE_STL
984 const char* Attribute(
const char* name )
const;
992 const char* Attribute(
const char* name,
int* i )
const;
1000 const char* Attribute(
const char* name,
double* d )
const;
1009 int QueryIntAttribute(
const char* name,
int* _value )
const;
1011 int QueryDoubleAttribute(
const char* name,
double* _value )
const;
1015 int result = QueryDoubleAttribute( name, &d );
1022 #ifdef TIXML_USE_STL
1023 int QueryStringAttribute(
const char* name, std::string* _value )
const {
1025 const char* cstr = Attribute( name );
1027 *_value = std::string( cstr );
1047 std::stringstream sstream( node->
ValueStr() );
1048 sstream >> *outValue;
1049 if ( !sstream.fail() )
1067 void SetAttribute(
const char* name,
const char * _value );
1069 #ifdef TIXML_USE_STL
1070 const std::string* Attribute(
const std::string& name )
const;
1071 const std::string* Attribute(
const std::string& name,
int* i )
const;
1072 const std::string* Attribute(
const std::string& name,
double* d )
const;
1073 int QueryIntAttribute(
const std::string& name,
int* _value )
const;
1074 int QueryDoubleAttribute(
const std::string& name,
double* _value )
const;
1077 void SetAttribute(
const std::string& name,
const std::string& _value );
1079 void SetAttribute(
const std::string& name,
int _value );
1081 void SetDoubleAttribute(
const std::string& name,
double value );
1087 void SetAttribute(
const char * name,
int value );
1092 void SetDoubleAttribute(
const char * name,
double value );
1096 void RemoveAttribute(
const char * name );
1097 #ifdef TIXML_USE_STL
1138 const char* GetText()
const;
1143 virtual void Print( FILE* cfile,
int depth )
const;
1163 #ifdef TIXML_USE_STL
1197 virtual void Print( FILE* cfile,
int depth )
const;
1215 #ifdef TIXML_USE_STL
1245 #ifdef TIXML_USE_STL
1258 virtual void Print( FILE* cfile,
int depth )
const;
1281 #ifdef TIXML_USE_STL
1309 #ifdef TIXML_USE_STL
1312 const std::string& _encoding,
1313 const std::string& _standalone );
1318 const char* _encoding,
1319 const char* _standalone );
1327 const char *
Version()
const {
return version.c_str (); }
1329 const char *
Encoding()
const {
return encoding.c_str (); }
1337 virtual void Print( FILE* cfile,
int depth )
const {
1338 Print( cfile, depth, 0 );
1353 #ifdef TIXML_USE_STL
1384 virtual void Print( FILE* cfile,
int depth )
const;
1398 #ifdef TIXML_USE_STL
1419 #ifdef TIXML_USE_STL
1435 bool SaveFile()
const;
1439 bool SaveFile(
const char * filename )
const;
1447 bool SaveFile( FILE* )
const;
1449 #ifdef TIXML_USE_STL
1458 return LoadFile( filename.c_str(), encoding );
1468 return SaveFile( filename.c_str() );
1493 const char *
ErrorDesc()
const {
return errorDesc.c_str (); }
1544 errorLocation.row = errorLocation.col = 0;
1558 virtual void Print( FILE* cfile,
int depth = 0 )
const;
1572 #ifdef TIXML_USE_STL
1680 TiXmlHandle FirstChild(
const char * value )
const;
1684 TiXmlHandle FirstChildElement(
const char * value )
const;
1689 TiXmlHandle Child(
const char* value,
int index )
const;
1698 TiXmlHandle ChildElement(
const char* value,
int index )
const;
1705 #ifdef TIXML_USE_STL
1771 buffer(), indent(
" " ), lineBreak(
"\n" ) {}
1787 void SetIndent(
const char* _indent ) { indent = _indent ? _indent :
"" ; }
1789 const char*
Indent() {
return indent.c_str(); }
1794 void SetLineBreak(
const char* _lineBreak ) { lineBreak = _lineBreak ? _lineBreak :
""; }
1805 const char*
CStr() {
return buffer.c_str(); }
1807 size_t Size() {
return buffer.size(); }
1809 #ifdef TIXML_USE_STL
1810 const std::string& Str() {
return buffer; }
1816 for(
int i=0; i<depth; ++i )
1820 buffer += lineBreak;
1832 #pragma warning( pop )
1835 #endif // _MADARA_NO_XML_
virtual void StreamIn(std::istream *in, std::string *tag)
static const int utf8ByteTable[256]
TiXmlHandle Child(const std::string &_value, int index) const
const TiXmlAttribute * First() const
TiXmlNode * LastChild(const char *_value)
The last child of this node matching 'value'. Will be null if there are no children.
An attribute is a name-value pair.
TiXmlHandle(TiXmlNode *_node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
TiXmlUnknown * Unknown() const
TiXmlNode * FirstChild(const std::string &_value)
STL std::string form.
virtual bool Accept(TiXmlVisitor *visitor) const
Walk the XML tree visiting this node and all of its children.
void SetUserData(void *user)
Set a pointer to arbitrary user data.
Implements the interface to the "Visitor pattern" (see the Accept() method.) If you call the Accept()...
A class used to manage a group of attributes.
virtual const TiXmlDocument * ToDocument() const
Cast to a more defined type. Will return null not of the requested type.
const std::string & ValueTStr() const
TiXmlUnknown(const TiXmlUnknown ©)
const TiXmlNode * Parent() const
const std::string & ValueStr() const
Return Value() as a std::string.
const TiXmlElement * RootElement() const
Get the root element – the only top level element – of the document.
void SetLineBreak(const char *_lineBreak)
Set the line breaking string.
TiXmlElement * NextSiblingElement()
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null not of the requested type.
static bool StreamWhiteSpace(std::istream *in, std::string *tag)
TiXmlHandle(const TiXmlHandle &ref)
Copy constructor.
void operator=(const TiXmlNode &base)
TiXmlNode * PreviousSibling(const char *_prev)
TiXmlNode * LastChild()
The last child of this node. Will be null if there are no children.
const char * LineBreak()
Query the current line breaking string.
virtual TiXmlNode * Clone() const
Creates a new Element and returns it - the returned element is a copy.
bool Error() const
If an error occurs, Error will be set to true.
virtual TiXmlElement * ToElement()
Cast to a more defined type. Will return null if not of the requested type.
virtual bool Visit(const TiXmlUnknown &)
Visit an unknow node.
TiXmlAttribute(const char *_name, const char *_value)
Construct an attribute with a name and value.
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null not of the requested type.
void CopyTo(TiXmlUnknown *target) const
const void * GetUserData() const
Get a pointer to arbitrary user data.
int Type() const
Query the type (as an enumerated value, above) of this node.
static int ToLower(int v, TiXmlEncoding encoding)
TiXmlNode * IterateChildren(const std::string &_value, const TiXmlNode *previous)
STL std::string form.
const TiXmlElement * FirstChildElement(const std::string &_value) const
STL std::string form.
TiXmlNode * IterateChildren(const char *_value, const TiXmlNode *previous)
static int IsAlphaNum(unsigned char anyByte, TiXmlEncoding encoding)
Internal structure for tracking location of items in the XML file.
void operator=(const TiXmlUnknown ©)
static void EncodeString(const std::string &str, std::string *out)
Expands entities in a string.
int ErrorId() const
Generally, you probably want the error string ( ErrorDesc() ).
virtual void Print(FILE *cfile, int depth) const
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL ...
TiXmlElement * NextSiblingElement(const std::string &_value)
STL std::string form.
TiXmlAttribute * FirstAttribute()
TiXmlElement * FirstChildElement(const char *_value)
void operator=(const TiXmlDocument ©)
void SetValue(const std::string &_value)
STL std::string form.
TiXmlNode * ReplaceChild(TiXmlNode *replaceThis, const TiXmlNode &withThis)
Replace a child of this node.
bool SaveFile(const std::string &filename) const
Saves a XML structure to file.
const TiXmlAttribute * LastAttribute() const
Access the last attribute in this element.
virtual bool VisitExit(const TiXmlElement &)
Visit an element.
void SetName(const char *_name)
Set the name of this attribute.
TiXmlNode * NextSibling()
void SetTabSize(int _tabsize)
SetTabSize() allows the error reporting functions (ErrorRow() and ErrorCol()) to report the correct v...
TiXmlAttribute()
Construct an empty attribute.
const int TIXML_PATCH_VERSION
const char * Standalone() const
Is this a standalone document?
TiXmlElement * ToElement() const
Return the handle as a TiXmlElement.
TiXmlElement * NextSiblingElement(const char *_next)
TiXmlElement * FirstChildElement()
virtual TiXmlDocument * ToDocument()
Cast to a more defined type. Will return null if not of the requested type.
void ClearError()
If you have handled the error, it can be reset with this call.
const char * Value() const
Return the value of this attribute.
virtual const TiXmlComment * ToComment() const
Cast to a more defined type. Will return null if not of the requested type.
void Clear()
Sets row and column to -1.
static const char * errorString[TIXML_ERROR_STRING_COUNT]
void SetValue(const char *_value)
Changes the value of the node.
int ErrorCol() const
The column where the error occured. See ErrorRow()
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
Add a new node related to this.
static void ConvertUTF32ToUTF8(unsigned long input, char *output, int *length)
const std::string & NameTStr() const
virtual TiXmlElement * ToElement()
Cast to a more defined type. Will return null not of the requested type.
TiXmlNode * InsertBeforeChild(TiXmlNode *beforeThis, const TiXmlNode &addThis)
Add a new node related to this.
static bool condenseWhiteSpace
TiXmlNode * PreviousSibling()
NodeType
The types of XML nodes supported by TinyXml.
virtual const TiXmlDeclaration * ToDeclaration() const
Cast to a more defined type. Will return null if not of the requested type.
virtual bool VisitEnter(const TiXmlDocument &)
Visit a document.
TiXmlHandle ChildElement(const std::string &_value, int index) const
const char * Encoding() const
Encoding. Will return an empty string if none was found.
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
Add a new node related to this.
const TiXmlNode * LastChild() const
const char * Name() const
Return the name of this attribute.
void * userData
Field containing a generic user pointer.
virtual bool Accept(TiXmlVisitor *visitor) const =0
Accept a hierchical visit the nodes in the TinyXML DOM.
TiXmlDocument * GetDocument()
void Print() const
Write the document to standard out using formatted printing ("pretty print").
In correct XML the declaration is the first entry in the file.
const TiXmlAttribute * Last() const
static bool IsWhiteSpace(char c)
std::istream & operator>>(std::istream &in, TiXmlNode &base)
TiXmlCursor()
Constructor.
TiXmlAttributeSet attributeSet
Any tag that tinyXml doesn't recognize is saved as an unknown.
virtual bool Visit(const TiXmlText &)
Visit a text node.
const TiXmlEncoding TIXML_DEFAULT_ENCODING
Internal entity struct for holding string elements.
int ErrorRow() const
Returns the location (if known) of the error.
const char * Version() const
Version. Will return an empty string if none was found.
TiXmlNode * NextSibling(const char *_next)
int Column() const
See Row()
static bool IsWhiteSpaceCondensed()
Return the current white space setting.
TiXmlText(const TiXmlText ©)
const int TIXML_MAJOR_VERSION
static const char * ReadName(const char *p, std::string *name, TiXmlEncoding encoding)
void SetIndent(const char *_indent)
Set the indent characters for printing.
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
const char * ErrorDesc() const
Contains a textual (english) description of the error if one occurs.
bool LoadFile(const std::string &filename, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Loads a XML file.
virtual const TiXmlUnknown * ToUnknown() const
Cast to a more defined type. Will return null not of the requested type.
std::ostream & operator<<(std::ostream &stream, const madara::knowledge::KnowledgeRecord &rhs)
output stream buffering
virtual TiXmlDocument * ToDocument()
Cast to a more defined type. Will return null not of the requested type.
virtual void Print(FILE *cfile, int depth) const
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL ...
void SetCDATA(bool _cdata)
Turns on or off a CDATA representation of text.
const char * Indent()
Query the indention string.
TiXmlElement * FirstChildElement(const std::string &_value)
STL std::string form.
virtual void StreamIn(std::istream *in, std::string *tag)=0
virtual TiXmlDeclaration * ToDeclaration()
Cast to a more defined type. Will return null not of the requested type.
Always the top level node.
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
TiXmlEncoding
Used by the parsing routines.
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)=0
virtual const TiXmlDeclaration * ToDeclaration() const
Cast to a more defined type. Will return null not of the requested type.
const TiXmlNode * LastChild(const std::string &_value) const
STL std::string form.
int QueryFloatAttribute(const char *name, float *_value) const
QueryFloatAttribute examines the attribute - see QueryIntAttribute().
const TiXmlNode * PreviousSibling() const
Navigate to a sibling node.
const TiXmlNode * NextSibling(const std::string &_value) const
STL std::string form.
static const char * SkipWhiteSpace(const char *, TiXmlEncoding encoding)
friend class TiXmlElement
TiXmlNode * Identify(const char *start, TiXmlEncoding encoding)
TiXmlNode * InsertAfterChild(TiXmlNode *afterThis, const TiXmlNode &addThis)
Add a new node related to this.
virtual TiXmlDeclaration * ToDeclaration()
Cast to a more defined type. Will return null if not of the requested type.
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null if not of the requested type.
const std::string & ValueStr() const
Return the value of this attribute.
const TiXmlDocument * GetDocument() const
Return a pointer to the Document this node lives in.
bool CDATA() const
Queries whether this represents text using a CDATA section.
A TiXmlHandle is a class that wraps a node pointer with null checks; this is an incredibly useful thi...
static bool IsWhiteSpace(int c)
virtual TiXmlComment * ToComment()
Cast to a more defined type. Will return null if not of the requested type.
bool operator>(const TiXmlAttribute &rhs) const
const TiXmlNode * IterateChildren(const std::string &_value, const TiXmlNode *previous) const
STL std::string form.
static const char * GetEntity(const char *in, char *value, int *length, TiXmlEncoding encoding)
void operator=(const TiXmlBase &base)
TiXmlNode * ToNode() const
Return the handle as a TiXmlNode.
static void SetCondenseWhiteSpace(bool condense)
The world does not agree on whether white space should be kept or not.
bool operator<(const TiXmlAttribute &rhs) const
TiXmlBase is a base class for every class in TinyXml.
const TiXmlElement * NextSiblingElement() const
Convenience function to get through elements.
TiXmlNode * Parent()
One step up the DOM.
virtual TiXmlUnknown * ToUnknown()
Cast to a more defined type. Will return null if not of the requested type.
bool operator==(const TiXmlAttribute &rhs) const
virtual const TiXmlUnknown * ToUnknown() const
Cast to a more defined type. Will return null if not of the requested type.
static bool StringEqual(const char *p, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
static bool StreamTo(std::istream *in, int character, std::string *tag)
virtual const char * Parse(const char *p, TiXmlParsingData *data=0, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
Parse the given null terminated block of xml data.
TiXmlHandle operator=(const TiXmlHandle &ref)
TiXmlNode * IterateChildren(const TiXmlNode *previous)
int Row() const
Return the position, in the original source file, of this node or attribute.
TiXmlHandle FirstChild(const std::string &_value) const
TiXmlAttribute * Previous()
TiXmlElement * Element() const
TiXmlElement * RootElement()
int QueryValueAttribute(const std::string &name, T *outValue) const
Template form of the attribute query which will try to read the attribute into the specified type...
void * GetUserData()
Get a pointer to arbitrary user data.
The parent class for everything in the Document Object Model.
INTERNAL USE: holds parsing data for tabs, cursors, etc.
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null if not of the requested type.
void CopyTo(TiXmlNode *target) const
TiXmlNode * LastChild(const std::string &_value)
STL std::string form.
size_t Size()
Return the length of the result string.
Print to memory functionality.
TiXmlNode * PreviousSibling(const std::string &_value)
STL std::string form.
const TiXmlNode * FirstChild(const std::string &_value) const
STL std::string form.
friend class TiXmlDocument
virtual bool VisitExit(const TiXmlDocument &)
Visit a document.
virtual bool Visit(const TiXmlComment &)
Visit a comment node.
static const char * GetChar(const char *p, char *_value, int *length, TiXmlEncoding encoding)
void operator=(const TiXmlText &base)
TiXmlText(const char *initValue)
Constructor for text element.
const TiXmlNode * IterateChildren(const TiXmlNode *previous) const
An alternate way to walk the children of a node.
const char * Value() const
The meaning of 'value' changes for the specific type of TiXmlNode.
TiXmlNode * NextSibling(const std::string &_value)
STL std::string form.
int QueryValueAttribute(const std::string &name, std::string *outValue) const
void CopyTo(TiXmlText *target) const
bool NoChildren() const
Returns true if this node has no children.
void CopyTo(TiXmlElement *target) const
const TiXmlAttribute * FirstAttribute() const
Access the first attribute in this element.
bool RemoveChild(TiXmlNode *removeThis)
Delete a child of this node.
void RemoveAttribute(const std::string &name)
STL std::string form.
void SetDocument(TiXmlDocument *doc)
virtual TiXmlUnknown * ToUnknown()
Cast to a more defined type. Will return null not of the requested type.
virtual const TiXmlDocument * ToDocument() const
Cast to a more defined type. Will return null if not of the requested type.
void Clear()
Delete all the children of this node. Does not affect 'this'.
TiXmlHandle FirstChildElement(const std::string &_value) const
void SetValue(const char *_value)
Set the value.
virtual ~TiXmlDeclaration()
const TiXmlNode * NextSibling() const
Navigate to a sibling node.
virtual TiXmlText * ToText()
Cast to a more defined type. Will return null not of the requested type.
TiXmlAttribute * LastAttribute()
TiXmlText * ToText() const
Return the handle as a TiXmlText.
TiXmlDeclaration()
Construct an empty declaration.
void SetStreamPrinting()
Switch over to "stream printing" which is the most dense formatting without linebreaks.
static int IsAlpha(unsigned char anyByte, TiXmlEncoding encoding)
virtual void Print(FILE *cfile, int depth) const =0
All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL ...
static const char * ReadText(const char *in, std::string *text, bool ignoreWhiteSpace, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
virtual TiXmlNode * Clone() const =0
Create an exact duplicate of this node and return it.
const TiXmlElement * NextSiblingElement(const std::string &_value) const
STL std::string form.
TiXmlUnknown * ToUnknown() const
Return the handle as a TiXmlUnknown.
const TiXmlNode * PreviousSibling(const std::string &_value) const
STL std::string form.
const char * CStr()
Return the result.
virtual TiXmlText * ToText()
Cast to a more defined type. Will return null if not of the requested type.
const int TIXML_MINOR_VERSION
The element is a container class.
TiXmlCursor errorLocation
virtual bool VisitEnter(const TiXmlElement &, const TiXmlAttribute *)
Visit an element.
virtual bool Visit(const TiXmlDeclaration &)
Visit a declaration.