26 #ifndef TINYXML_INCLUDED
27 #define TINYXML_INCLUDED
30 #pragma warning( push )
31 #pragma warning( disable : 4530 )
32 #pragma warning( disable : 4786 )
42 #if defined( _DEBUG ) && !defined( DEBUG )
50 #define TIXML_STRING std::string
53 #define TIXML_STRING TiXmlString
63 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
65 #define TIXML_SNPRINTF _snprintf_s
66 #define TIXML_SSCANF sscanf_s
67 #elif defined(_MSC_VER) && (_MSC_VER >= 1200 )
70 #define TIXML_SNPRINTF _snprintf
71 #define TIXML_SSCANF sscanf
72 #elif defined(__GNUC__) && (__GNUC__ >= 3 )
75 #define TIXML_SNPRINTF snprintf
76 #define TIXML_SSCANF sscanf
78 #define TIXML_SNPRINTF snprintf
79 #define TIXML_SSCANF sscanf
213 virtual void Print( FILE* cfile,
int depth )
const = 0;
255 virtual const char*
Parse(
const char* p,
292 return ( isspace( (
unsigned char) c ) || c ==
'\n' || c ==
'\r' );
302 static bool StreamWhiteSpace( std::istream * in,
TIXML_STRING * tag );
303 static bool StreamTo( std::istream * in,
int character,
TIXML_STRING * tag );
315 static const char*
ReadText(
const char* in,
317 bool ignoreWhiteSpace,
332 *length = utf8ByteTable[ *((
const unsigned char*)p) ];
333 assert( *length >= 0 && *length < 5 );
343 return GetEntity( p, _value, length, encoding );
351 for(
int i=0; p[i] && i<*length; ++i ) {
354 return p + (*length);
386 if ( v < 128 )
return tolower( v );
403 unsigned int strLength;
409 MAX_ENTITY_LENGTH = 6
412 static Entity entity[ NUM_ENTITY ];
413 static bool condenseWhiteSpace;
494 const std::string& ValueStr()
const {
return value; }
511 void SetValue(
const std::string& _value ) {
value = _value; }
529 return const_cast< TiXmlNode*
> ((
const_cast< const TiXmlNode*
>(
this))->FirstChild( _value ));
536 return const_cast< TiXmlNode*
> ((
const_cast< const TiXmlNode*
>(
this))->LastChild( _value ));
564 return const_cast< TiXmlNode*
>( (
const_cast< const TiXmlNode*
>(
this))->IterateChildren( previous ) );
570 return const_cast< TiXmlNode*
>( (
const_cast< const TiXmlNode*
>(
this))->IterateChildren( _value, previous ) );
620 return const_cast< TiXmlNode*
>( (
const_cast< const TiXmlNode*
>(
this))->PreviousSibling( _prev ) );
637 return const_cast< TiXmlNode*
>( (
const_cast< const TiXmlNode*
>(
this))->NextSibling( _next ) );
655 return const_cast< TiXmlElement*
>( (
const_cast< const TiXmlNode*
>(
this))->NextSiblingElement( _next ) );
672 return const_cast< TiXmlElement*
>( (
const_cast< const TiXmlNode*
>(
this))->FirstChildElement( _value ) );
749 virtual void StreamIn( std::istream* in,
TIXML_STRING* tag ) = 0;
792 TiXmlAttribute(
const std::string& _name,
const std::string& _value )
811 const char*
Name()
const {
return name.c_str(); }
812 const char*
Value()
const {
return value.c_str(); }
814 const std::string& ValueStr()
const {
return value; }
835 void SetName(
const char* _name ) { name = _name; }
836 void SetValue(
const char* _value ) { value = _value; }
842 void SetName(
const std::string& _name ) { name = _name; }
845 void SetValue(
const std::string& _value ) { value = _value; }
870 virtual void Print( FILE* cfile,
int depth )
const {
871 Print( cfile, depth, 0 );
920 # ifdef TIXML_USE_STL
960 const char*
Attribute(
const char* name )
const;
968 const char*
Attribute(
const char* name,
int* i )
const;
976 const char*
Attribute(
const char* name,
double* d )
const;
1005 #ifdef TIXML_USE_STL
1006 int QueryStringAttribute(
const char* name, std::string* _value )
const {
1010 *_value = std::string( cstr );
1024 template<
typename T >
int QueryValueAttribute(
const std::string& name, T* outValue )
const
1030 std::stringstream sstream( node->ValueStr() );
1031 sstream >> *outValue;
1032 if ( !sstream.fail() )
1037 int QueryValueAttribute(
const std::string& name, std::string* outValue )
const
1042 *outValue = node->ValueStr();
1050 void SetAttribute(
const char* name,
const char * _value );
1052 #ifdef TIXML_USE_STL
1053 const std::string*
Attribute(
const std::string& name )
const;
1054 const std::string*
Attribute(
const std::string& name,
int* i )
const;
1055 const std::string*
Attribute(
const std::string& name,
double* d )
const;
1060 void SetAttribute(
const std::string& name,
const std::string& _value );
1062 void SetAttribute(
const std::string& name,
int _value );
1080 #ifdef TIXML_USE_STL
1126 virtual void Print( FILE* cfile,
int depth )
const;
1146 #ifdef TIXML_USE_STL
1147 virtual void StreamIn( std::istream * in,
TIXML_STRING * tag );
1179 virtual void Print( FILE* cfile,
int depth )
const;
1197 #ifdef TIXML_USE_STL
1198 virtual void StreamIn( std::istream * in,
TIXML_STRING * tag );
1227 #ifdef TIXML_USE_STL
1240 virtual void Print( FILE* cfile,
int depth )
const;
1263 #ifdef TIXML_USE_STL
1264 virtual void StreamIn( std::istream * in,
TIXML_STRING * tag );
1291 #ifdef TIXML_USE_STL
1294 const std::string& _encoding,
1295 const std::string& _standalone );
1300 const char* _encoding,
1301 const char* _standalone );
1309 const char *
Version()
const {
return version.c_str (); }
1311 const char *
Encoding()
const {
return encoding.c_str (); }
1319 virtual void Print( FILE* cfile,
int depth )
const {
1320 Print( cfile, depth, 0 );
1335 #ifdef TIXML_USE_STL
1336 virtual void StreamIn( std::istream * in,
TIXML_STRING * tag );
1366 virtual void Print( FILE* cfile,
int depth )
const;
1380 #ifdef TIXML_USE_STL
1381 virtual void StreamIn( std::istream * in,
TIXML_STRING * tag );
1401 #ifdef TIXML_USE_STL
1421 bool SaveFile(
const char * filename )
const;
1431 #ifdef TIXML_USE_STL
1434 return LoadFile( filename.c_str(), encoding );
1436 bool SaveFile(
const std::string& filename )
const
1438 return SaveFile( filename.c_str() );
1463 const char *
ErrorDesc()
const {
return errorDesc.c_str (); }
1514 errorLocation.
row = errorLocation.
col = 0;
1528 virtual void Print( FILE* cfile,
int depth = 0 )
const;
1542 #ifdef TIXML_USE_STL
1543 virtual void StreamIn( std::istream * in,
TIXML_STRING * tag );
1554 bool useMicrosoftBOM;
1675 #ifdef TIXML_USE_STL
1679 TiXmlHandle Child(
const std::string& _value,
int index )
const {
return Child( _value.c_str(), index ); }
1741 buffer(), indent(
" " ), lineBreak(
"\n" ) {}
1757 void SetIndent(
const char* _indent ) { indent = _indent ? _indent :
"" ; }
1759 const char*
Indent() {
return indent.c_str(); }
1764 void SetLineBreak(
const char* _lineBreak ) { lineBreak = _lineBreak ? _lineBreak :
""; }
1775 const char*
CStr() {
return buffer.c_str(); }
1777 size_t Size() {
return buffer.size(); }
1779 #ifdef TIXML_USE_STL
1780 const std::string& Str() {
return buffer; }
1786 for(
int i=0; i<depth; ++i )
1789 void DoLineBreak() {
1790 buffer += lineBreak;
1794 bool simpleTextPrint;
1802 #pragma warning( pop )
TiXmlAttribute * LastAttribute()
virtual TiXmlUnknown * ToUnknown()
Cast to a more defined type. Will return null not of the requested type.
TiXmlNode * Parent()
One step up the DOM.
TiXmlHandle FirstChildElement() const
Return a handle to the first child element.
void SetDoubleAttribute(const char *name, double value)
void SetTabSize(int _tabsize)
virtual TiXmlNode * Clone() const
Creates a copy of this Declaration and returns it.
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
static const char * ReadName(const char *p, TIXML_STRING *name, TiXmlEncoding encoding)
TiXmlAttribute * Find(const char *_name) const
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
TiXmlHandle operator=(const TiXmlHandle &ref)
const TIXML_STRING & NameTStr() const
static const char * GetChar(const char *p, char *_value, int *length, TiXmlEncoding encoding)
void SetCDATA(bool _cdata)
Turns on or off a CDATA representation of text.
static const char * SkipWhiteSpace(const char *, TiXmlEncoding encoding)
const char * Version() const
Version. Will return an empty string if none was found.
void CopyTo(TiXmlElement *target) const
virtual ~TiXmlDeclaration()
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
int QueryDoubleAttribute(const char *name, double *_value) const
QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
const TiXmlNode * LastChild() const
int Column() const
See Row()
virtual TiXmlNode * Clone() const =0
TiXmlElement & operator=(const TiXmlElement &base)
const TiXmlAttribute * First() const
const char * Standalone() const
Is this a standalone document?
static void SetCondenseWhiteSpace(bool condense)
bool SaveFile() const
Save a file using the current document value. Returns true if successful.
static bool IsWhiteSpace(char c)
void SetDoubleValue(double _value)
Set the value from a double.
size_t Size()
Return the length of the result string.
void RemoveAttribute(const char *name)
bool RemoveChild(TiXmlNode *removeThis)
Delete a child of this node.
TiXmlHandle(TiXmlNode *_node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
virtual bool Accept(TiXmlVisitor *visitor) const
static void ConvertUTF32ToUTF8(unsigned long input, char *output, int *length)
virtual bool VisitEnter(const TiXmlElement &, const TiXmlAttribute *)
Visit an element.
QDataStream & operator<<(QDataStream &ds, const CObject &obj)
TiXmlElement * FirstChildElement(const char *_value)
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null not of the requested type.
void SetIntValue(int _value)
Set the value from an integer.
void CopyTo(TiXmlDeclaration *target) const
static int IsAlpha(unsigned char anyByte, TiXmlEncoding encoding)
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)=0
const int TIXML_PATCH_VERSION
TiXmlDocument()
Create an empty document, that has no name.
void SetIndent(const char *_indent)
virtual TiXmlText * ToText()
Cast to a more defined type. Will return null not of the requested type.
virtual TiXmlUnknown * ToUnknown()
Cast to a more defined type. Will return null if not of the requested type.
virtual TiXmlNode * Clone() const
Creates a copy of this Unknown and returns it.
static int IsAlphaNum(unsigned char anyByte, TiXmlEncoding encoding)
const char * ReadValue(const char *in, TiXmlParsingData *prevData, TiXmlEncoding encoding)
const char * Value() const
const void * GetUserData() const
Get a pointer to arbitrary user data.
TiXmlElement * Element() const
TiXmlDocument * GetDocument()
TiXmlElement * ToElement() const
TiXmlAttribute * FindOrCreate(const char *_name)
int IntValue() const
Return the value of this attribute, converted to an integer.
static bool IsWhiteSpace(int c)
int QueryIntAttribute(const char *name, int *_value) const
const char * Name() const
Return the name of this attribute.
const TiXmlAttribute * Previous() const
Get the previous sibling attribute in the DOM. Returns null at beginning.
virtual void Print(FILE *cfile, int depth) const
virtual TiXmlDocument * ToDocument()
Cast to a more defined type. Will return null if not of the requested type.
virtual TiXmlNode * Clone() const
Creates a new Element and returns it - the returned element is a copy.
void CopyTo(TiXmlText *target) const
const TiXmlAttribute * LastAttribute() const
Access the last attribute in this element.
const TiXmlNode * Parent() const
static const char * GetEntity(const char *in, char *value, int *length, TiXmlEncoding encoding)
bool operator>(const TiXmlAttribute &rhs) const
virtual const TiXmlDocument * ToDocument() const
Cast to a more defined type. Will return null not of the requested type.
int QueryFloatAttribute(const char *name, float *_value) const
QueryFloatAttribute examines the attribute - see QueryIntAttribute().
void Add(TiXmlAttribute *attribute)
int ErrorCol() const
The column where the error occured. See ErrorRow()
TiXmlDeclaration & operator=(const TiXmlDeclaration ©)
QDataStream & operator>>(QDataStream &ds, CObject &obj)
TiXmlUnknown * ToUnknown() const
const TiXmlNode * PreviousSibling() const
Navigate to a sibling node.
virtual bool Accept(TiXmlVisitor *visitor) const
TiXmlNode * ReplaceChild(TiXmlNode *replaceThis, const TiXmlNode &withThis)
TiXmlText(const char *initValue)
int QueryIntValue(int *_value) const
virtual bool VisitExit(const TiXmlElement &)
Visit an element.
virtual bool Visit(const TiXmlComment &)
Visit a comment node.
void SetName(const char *_name)
Set the name of this attribute.
const TiXmlEncoding TIXML_DEFAULT_ENCODING
TiXmlAttribute()
Construct an empty attribute.
int QueryBoolAttribute(const char *name, bool *_value) const
TiXmlText(const TiXmlText ©)
virtual const char * Parse(const char *p, TiXmlParsingData *data=0, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
virtual TiXmlDeclaration * ToDeclaration()
Cast to a more defined type. Will return null not of the requested type.
TiXmlNode(NodeType _type)
virtual TiXmlDeclaration * ToDeclaration()
Cast to a more defined type. Will return null if not of the requested type.
const int TIXML_MAJOR_VERSION
bool operator==(const TiXmlAttribute &rhs) const
virtual bool Visit(const TiXmlText &)
Visit a text node.
bool operator<(const TiXmlAttribute &rhs) const
const TiXmlAttribute * FirstAttribute() const
Access the first attribute in this element.
void Clear()
Delete all the children of this node. Does not affect 'this'.
virtual bool Accept(TiXmlVisitor *content) const
virtual void Print(FILE *cfile, int depth, TIXML_STRING *str) const
TiXmlElement * NextSiblingElement(const char *_next)
virtual bool VisitEnter(const TiXmlDocument &)
Visit a document.
const TiXmlElement * NextSiblingElement() const
static const int utf8ByteTable[256]
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
TiXmlElement(const char *in_value)
Construct an element.
virtual bool Visit(const TiXmlUnknown &)
Visit an unknown node.
TiXmlDeclaration()
Construct an empty declaration.
bool NoChildren() const
Returns true if this node has no children.
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
virtual TiXmlNode * Clone() const
[internal use] Creates a new Element and returns it.
static const char * ReadText(const char *in, TIXML_STRING *text, bool ignoreWhiteSpace, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
TiXmlElement * NextSiblingElement()
static void EncodeString(const TIXML_STRING &str, TIXML_STRING *out)
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null not of the requested type.
virtual TiXmlNode * Clone() const
virtual bool Accept(TiXmlVisitor *visitor) const =0
void * userData
Field containing a generic user pointer.
TiXmlDocument & operator=(const TiXmlDocument ©)
const char * Attribute(const char *name) const
void SetValue(const char *_value)
Set the value.
void SetError(int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding)
virtual void Print(FILE *cfile, int depth) const
virtual bool Accept(TiXmlVisitor *content) const
TiXmlNode * InsertAfterChild(TiXmlNode *afterThis, const TiXmlNode &addThis)
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null if not of the requested type.
static int ToLower(int v, TiXmlEncoding encoding)
void * GetUserData()
Get a pointer to arbitrary user data.
const TIXML_STRING & ValueTStr() const
virtual TiXmlDocument * ToDocument()
Cast to a more defined type. Will return null not of the requested type.
const char * CStr()
Return the result.
TiXmlNode * NextSibling(const char *_next)
TiXmlElement * RootElement()
const TiXmlNode * NextSibling() const
Navigate to a sibling node.
virtual bool Visit(const TiXmlDeclaration &)
Visit a declaration.
void CopyTo(TiXmlUnknown *target) const
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null if not of the requested type.
void SetAttribute(const char *name, const char *_value)
const char * Indent()
Query the indention string.
virtual const TiXmlDeclaration * ToDeclaration() const
Cast to a more defined type. Will return null not of the requested type.
void SetValue(const char *_value)
const TiXmlNode * IterateChildren(const TiXmlNode *previous) const
const char * Encoding() const
Encoding. Will return an empty string if none was found.
static bool IsWhiteSpaceCondensed()
Return the current white space setting.
TiXmlText & operator=(const TiXmlText &base)
virtual const TiXmlUnknown * ToUnknown() const
Cast to a more defined type. Will return null not of the requested type.
static bool StringEqual(const char *p, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
const char * GetText() const
TiXmlAttribute * FirstAttribute()
virtual void Print(FILE *cfile, int depth) const
int QueryUnsignedAttribute(const char *name, unsigned *_value) const
QueryUnsignedAttribute examines the attribute - see QueryIntAttribute().
virtual void Print(FILE *cfile, int depth) const =0
TiXmlNode * InsertBeforeChild(TiXmlNode *beforeThis, const TiXmlNode &addThis)
virtual TiXmlComment * ToComment()
Cast to a more defined type. Will return null if 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 SetDocument(TiXmlDocument *doc)
virtual const TiXmlDeclaration * ToDeclaration() const
Cast to a more defined type. Will return null if not of the requested type.
virtual bool Accept(TiXmlVisitor *content) const
int QueryDoubleValue(double *_value) const
QueryDoubleValue examines the value string. See QueryIntValue().
TiXmlElement * FirstChildElement()
bool LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
const char * ErrorDesc() const
Contains a textual (english) description of the error if one occurs.
TiXmlNode * PreviousSibling(const char *_prev)
TiXmlNode * Identify(const char *start, TiXmlEncoding encoding)
void SetLineBreak(const char *_lineBreak)
TiXmlHandle FirstChild() const
Return a handle to the first child node.
TiXmlNode * LastChild(const char *_value)
The last child of this node matching 'value'. Will be null if there are no children.
static const char * errorString[TIXML_ERROR_STRING_COUNT]
virtual bool VisitExit(const TiXmlDocument &doc)
Visit a document.
virtual const TiXmlComment * ToComment() const
Cast to a more defined type. Will return null if not of the requested type.
TiXmlHandle Child(const char *value, int index) const
TiXmlUnknown(const TiXmlUnknown ©)
virtual bool VisitExit(const TiXmlDocument &)
Visit a document.
virtual TiXmlText * ToText()
Cast to a more defined type. Will return null if not of the requested type.
TiXmlNode * PreviousSibling()
void Remove(TiXmlAttribute *attribute)
const char * Value() const
Return the value of this attribute.
const char * LineBreak()
Query the current line breaking string.
TiXmlUnknown & operator=(const TiXmlUnknown ©)
const TiXmlAttribute * Next() const
Get the next sibling attribute in the DOM. Returns null at end.
TiXmlNode * LastChild()
The last child of this node. Will be null if there are no children.
const TiXmlDocument * GetDocument() const
virtual void Print(FILE *cfile, int depth) const
TiXmlNode * IterateChildren(const TiXmlNode *previous)
virtual const TiXmlUnknown * ToUnknown() const
Cast to a more defined type. Will return null if not of the requested type.
const TiXmlAttribute * Last() const
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
TiXmlNode * IterateChildren(const char *_value, const TiXmlNode *previous)
TiXmlUnknown * Unknown() const
void SetUserData(void *user)
Set a pointer to arbitrary user data.
virtual TiXmlElement * ToElement()
Cast to a more defined type. Will return null if not of the requested type.
TiXmlHandle(const TiXmlHandle &ref)
Copy constructor.
virtual bool VisitEnter(const TiXmlDocument &doc)
Visit a document.
virtual void Print(FILE *cfile, int depth) const
double DoubleValue() const
Return the value of this attribute, converted to a double.
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
bool CDATA() const
Queries whether this represents text using a CDATA section.
const TiXmlElement * RootElement() const
TiXmlNode * ToNode() const
TiXmlHandle ChildElement(const char *value, int index) const
TiXmlNode * NextSibling()
const int TIXML_MINOR_VERSION
virtual TiXmlElement * ToElement()
Cast to a more defined type. Will return null not of the requested type.
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
TiXmlText * ToText() const
void CopyTo(TiXmlNode *target) const
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
virtual bool Visit(const TiXmlDeclaration &declaration)
Visit a declaration.
TiXmlAttribute * Previous()
TiXmlAttribute(const char *_name, const char *_value)
Construct an attribute with a name and value.