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 92 const int TIXML_MAJOR_VERSION = 2;
93 const int TIXML_MINOR_VERSION = 6;
94 const int TIXML_PATCH_VERSION = 2;
102 void Clear() { row = col = -1; }
165 TIXML_ENCODING_UNKNOWN,
167 TIXML_ENCODING_LEGACY
170 const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
213 virtual void Print( FILE* cfile,
int depth )
const = 0;
244 int Row()
const {
return location.row + 1; }
245 int Column()
const {
return location.col + 1; }
253 static const int utf8ByteTable[256];
255 virtual const char*
Parse(
const char* p,
257 TiXmlEncoding encoding ) = 0;
262 static void EncodeString(
const TIXML_STRING& str, TIXML_STRING* out );
268 TIXML_ERROR_OPENING_FILE,
269 TIXML_ERROR_PARSING_ELEMENT,
270 TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
271 TIXML_ERROR_READING_ELEMENT_VALUE,
272 TIXML_ERROR_READING_ATTRIBUTES,
273 TIXML_ERROR_PARSING_EMPTY,
274 TIXML_ERROR_READING_END_TAG,
275 TIXML_ERROR_PARSING_UNKNOWN,
276 TIXML_ERROR_PARSING_COMMENT,
277 TIXML_ERROR_PARSING_DECLARATION,
278 TIXML_ERROR_DOCUMENT_EMPTY,
279 TIXML_ERROR_EMBEDDED_NULL,
280 TIXML_ERROR_PARSING_CDATA,
281 TIXML_ERROR_DOCUMENT_TOP_ONLY,
283 TIXML_ERROR_STRING_COUNT
288 static const char* SkipWhiteSpace(
const char*, TiXmlEncoding encoding );
290 inline static bool IsWhiteSpace(
char c )
292 return ( isspace( (
unsigned char) c ) || c ==
'\n' || c ==
'\r' );
294 inline static bool IsWhiteSpace(
int c )
297 return IsWhiteSpace( (
char) c );
302 static bool StreamWhiteSpace( std::istream * in, TIXML_STRING * tag );
303 static bool StreamTo( std::istream * in,
int character, TIXML_STRING * tag );
310 static const char* ReadName(
const char* p, TIXML_STRING* name, TiXmlEncoding encoding );
315 static const char* ReadText(
const char* in,
317 bool ignoreWhiteSpace,
320 TiXmlEncoding encoding );
323 static const char* GetEntity(
const char* in,
char* value,
int* length, TiXmlEncoding encoding );
327 inline static const char* GetChar(
const char* p,
char* _value,
int* length, TiXmlEncoding encoding )
330 if ( encoding == TIXML_ENCODING_UTF8 )
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);
366 static bool StringEqual(
const char* p,
369 TiXmlEncoding encoding );
371 static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
380 static int IsAlpha(
unsigned char anyByte, TiXmlEncoding encoding );
381 static int IsAlphaNum(
unsigned char anyByte, TiXmlEncoding encoding );
382 inline static int ToLower(
int v, TiXmlEncoding encoding )
384 if ( encoding == TIXML_ENCODING_UTF8 )
386 if ( v < 128 )
return tolower( v );
394 static void ConvertUTF32ToUTF8(
unsigned long input,
char* output,
int* length );
403 unsigned int strLength;
409 MAX_ENTITY_LENGTH = 6
412 static Entity entity[ NUM_ENTITY ];
413 static bool condenseWhiteSpace;
434 friend std::istream& operator >> (std::istream& in,
TiXmlNode& base);
452 friend std::ostream& operator<< (std::ostream& out,
const TiXmlNode& base);
455 friend std::string& operator<< (std::string& out,
const TiXmlNode& base );
487 const char *
Value()
const {
return value.c_str (); }
494 const std::string& ValueStr()
const {
return value; }
497 const TIXML_STRING& ValueTStr()
const {
return value; }
508 void SetValue(
const char * _value) { value = _value;}
511 void SetValue(
const std::string& _value ) { value = _value; }
529 return const_cast< TiXmlNode*
> ((
const_cast< const TiXmlNode*
>(
this))->FirstChild( _value ));
531 const TiXmlNode* LastChild()
const {
return lastChild; }
534 const TiXmlNode* LastChild(
const char * value )
const;
536 return const_cast< TiXmlNode*
> ((
const_cast< const TiXmlNode*
>(
this))->LastChild( _value ));
542 const TiXmlNode* LastChild(
const std::string& _value )
const {
return LastChild (_value.c_str ()); }
543 TiXmlNode* LastChild(
const std::string& _value ) {
return LastChild (_value.c_str ()); }
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 ) );
684 int Type()
const {
return type; }
749 virtual void StreamIn( std::istream* in, TIXML_STRING* tag ) = 0;
753 TiXmlNode* Identify(
const char* start, TiXmlEncoding encoding );
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; }
816 int IntValue()
const;
817 double DoubleValue()
const;
820 const TIXML_STRING& NameTStr()
const {
return name; }
831 int QueryIntValue(
int* _value )
const;
833 int QueryDoubleValue(
double* _value )
const;
835 void SetName(
const char* _name ) { name = _name; }
836 void SetValue(
const char* _value ) { value = _value; }
838 void SetIntValue(
int _value );
839 void SetDoubleValue(
double _value );
842 void SetName(
const std::string& _name ) { name = _name; }
845 void SetValue(
const std::string& _value ) { value = _value; }
860 bool operator==(
const TiXmlAttribute& rhs )
const {
return rhs.name == name; }
861 bool operator<(
const TiXmlAttribute& rhs )
const {
return name < rhs.name; }
862 bool operator>(
const TiXmlAttribute& rhs )
const {
return name > rhs.name; }
867 virtual const char* Parse(
const char* p,
TiXmlParsingData* data, TiXmlEncoding encoding );
870 virtual void Print( FILE* cfile,
int depth )
const {
871 Print( cfile, depth, 0 );
873 void Print( FILE* cfile,
int depth, TIXML_STRING* str )
const;
912 const TiXmlAttribute* First()
const {
return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
913 TiXmlAttribute* First() {
return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
914 const TiXmlAttribute* Last()
const {
return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
915 TiXmlAttribute* Last() {
return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
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;
985 int QueryIntAttribute(
const char* name,
int* _value )
const;
987 int QueryUnsignedAttribute(
const char* name,
unsigned* _value )
const;
992 int QueryBoolAttribute(
const char* name,
bool* _value )
const;
994 int QueryDoubleAttribute(
const char* name,
double* _value )
const;
998 int result = QueryDoubleAttribute( name, &d );
999 if ( result == TIXML_SUCCESS ) {
1005 #ifdef TIXML_USE_STL 1006 int QueryStringAttribute(
const char* name, std::string* _value )
const {
1008 const char* cstr = Attribute( name );
1010 *_value = std::string( cstr );
1011 return TIXML_SUCCESS;
1013 return TIXML_NO_ATTRIBUTE;
1024 template<
typename T >
int QueryValueAttribute(
const std::string& name, T* outValue )
const 1028 return TIXML_NO_ATTRIBUTE;
1030 std::stringstream sstream( node->ValueStr() );
1031 sstream >> *outValue;
1032 if ( !sstream.fail() )
1033 return TIXML_SUCCESS;
1034 return TIXML_WRONG_TYPE;
1037 int QueryValueAttribute(
const std::string& name, std::string* outValue )
const 1041 return TIXML_NO_ATTRIBUTE;
1042 *outValue = node->ValueStr();
1043 return TIXML_SUCCESS;
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;
1056 int QueryIntAttribute(
const std::string& name,
int* _value )
const;
1057 int QueryDoubleAttribute(
const std::string& name,
double* _value )
const;
1060 void SetAttribute(
const std::string& name,
const std::string& _value );
1062 void SetAttribute(
const std::string& name,
int _value );
1064 void SetDoubleAttribute(
const std::string& name,
double value );
1070 void SetAttribute(
const char * name,
int value );
1075 void SetDoubleAttribute(
const char * name,
double value );
1079 void RemoveAttribute(
const char * name );
1080 #ifdef TIXML_USE_STL 1081 void RemoveAttribute(
const std::string& name ) { RemoveAttribute (name.c_str ()); }
1085 TiXmlAttribute* FirstAttribute() {
return attributeSet.First(); }
1121 const char* GetText()
const;
1126 virtual void Print( FILE* cfile,
int depth )
const;
1131 virtual const char* Parse(
const char* p,
TiXmlParsingData* data, TiXmlEncoding encoding );
1146 #ifdef TIXML_USE_STL 1147 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1153 const char* ReadValue(
const char* in,
TiXmlParsingData* prevData, TiXmlEncoding encoding );
1179 virtual void Print( FILE* cfile,
int depth )
const;
1184 virtual const char* Parse(
const char* p,
TiXmlParsingData* data, TiXmlEncoding encoding );
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;
1247 virtual const char* Parse(
const char* p,
TiXmlParsingData* data, TiXmlEncoding encoding );
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 (); }
1318 virtual void Print( FILE* cfile,
int depth, TIXML_STRING* str )
const;
1319 virtual void Print( FILE* cfile,
int depth )
const {
1320 Print( cfile, depth, 0 );
1323 virtual const char* Parse(
const char* p,
TiXmlParsingData* data, TiXmlEncoding encoding );
1335 #ifdef TIXML_USE_STL 1336 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1341 TIXML_STRING version;
1342 TIXML_STRING encoding;
1343 TIXML_STRING standalone;
1366 virtual void Print( FILE* cfile,
int depth )
const;
1368 virtual const char* Parse(
const char* p,
TiXmlParsingData* data, TiXmlEncoding encoding );
1380 #ifdef TIXML_USE_STL 1381 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1401 #ifdef TIXML_USE_STL 1415 bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1417 bool SaveFile()
const;
1419 bool LoadFile(
const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1421 bool SaveFile(
const char * filename )
const;
1427 bool LoadFile( FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1429 bool SaveFile( FILE* )
const;
1431 #ifdef TIXML_USE_STL 1432 bool LoadFile(
const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING )
1434 return LoadFile( filename.c_str(), encoding );
1436 bool SaveFile(
const std::string& filename )
const 1438 return SaveFile( filename.c_str() );
1446 virtual const char* Parse(
const char* p,
TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1453 TiXmlElement* RootElement() {
return FirstChildElement(); }
1463 const char *
ErrorDesc()
const {
return errorDesc.c_str (); }
1506 int TabSize()
const {
return tabsize; }
1514 errorLocation.row = errorLocation.col = 0;
1528 virtual void Print( FILE* cfile,
int depth = 0 )
const;
1530 void SetError(
int err,
const char* errorLocation,
TiXmlParsingData* prevData, TiXmlEncoding encoding );
1542 #ifdef TIXML_USE_STL 1543 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1551 TIXML_STRING errorDesc;
1554 bool useMicrosoftBOM;
1645 TiXmlHandle operator=(
const TiXmlHandle& ref ) {
if ( &ref !=
this ) this->node = ref.node;
return *
this; }
1650 TiXmlHandle FirstChild(
const char * value )
const;
1654 TiXmlHandle FirstChildElement(
const char * value )
const;
1659 TiXmlHandle Child(
const char* value,
int index )
const;
1668 TiXmlHandle ChildElement(
const char* value,
int index )
const;
1675 #ifdef TIXML_USE_STL 1676 TiXmlHandle FirstChild(
const std::string& _value )
const {
return FirstChild( _value.c_str() ); }
1677 TiXmlHandle FirstChildElement(
const std::string& _value )
const {
return FirstChildElement( _value.c_str() ); }
1679 TiXmlHandle Child(
const std::string& _value,
int index )
const {
return Child( _value.c_str(), index ); }
1680 TiXmlHandle ChildElement(
const std::string& _value,
int index )
const {
return ChildElement( _value.c_str(), index ); }
1741 buffer(), indent(
" " ), lineBreak(
"\n" ) {}
1750 virtual bool Visit(
const TiXmlText& text );
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;
1795 TIXML_STRING buffer;
1796 TIXML_STRING indent;
1797 TIXML_STRING lineBreak;
1802 #pragma warning( pop )
virtual TiXmlUnknown * ToUnknown()
Cast to a more defined type. Will return null not of the requested type.
TiXmlNode * Parent()
One step up the DOM.
void SetTabSize(int _tabsize)
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
void SetCDATA(bool _cdata)
Turns on or off a CDATA representation of text.
const char * Version() const
Version. Will return an empty string if none was found.
int Column() const
See Row()
const char * Standalone() const
Is this a standalone document?
static void SetCondenseWhiteSpace(bool condense)
size_t Size()
Return the length of the result string.
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
virtual bool VisitEnter(const TiXmlElement &, const TiXmlAttribute *)
Visit an element.
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null not of the requested type.
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.
const char * Value() const
const void * GetUserData() const
Get a pointer to arbitrary user data.
TiXmlElement * Element() const
TiXmlElement * ToElement() const
const char * Name() const
Return the name of this attribute.
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.
const TiXmlAttribute * LastAttribute() const
Access the last attribute in this element.
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().
int ErrorCol() const
The column where the error occured. See ErrorRow()
TiXmlUnknown * ToUnknown() const
const TiXmlNode * PreviousSibling() const
Navigate to a sibling node.
TiXmlNode * ReplaceChild(TiXmlNode *replaceThis, const TiXmlNode &withThis)
TiXmlText(const char *initValue)
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.
TiXmlAttribute()
Construct an empty attribute.
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.
virtual TiXmlDeclaration * ToDeclaration()
Cast to a more defined type. Will return null if not of the requested type.
virtual bool Visit(const TiXmlText &)
Visit a text node.
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 VisitEnter(const TiXmlDocument &)
Visit a document.
const TiXmlElement * NextSiblingElement() const
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.
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.
void * userData
Field containing a generic user pointer.
void SetValue(const char *_value)
Set the value.
virtual void Print(FILE *cfile, int depth) 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.
void * GetUserData()
Get a pointer to arbitrary user data.
virtual TiXmlDocument * ToDocument()
Cast to a more defined type. Will return null not of the requested type.
const char * CStr()
Return the result.
const TiXmlNode * NextSibling() const
Navigate to a sibling node.
virtual bool Visit(const TiXmlDeclaration &)
Visit a declaration.
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null if not of the requested type.
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.
virtual const TiXmlUnknown * ToUnknown() const
Cast to a more defined type. Will return null not of the requested type.
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.
virtual const TiXmlDeclaration * ToDeclaration() const
Cast to a more defined type. Will return null if not of the requested type.
const char * ErrorDesc() const
Contains a textual (english) description of the error if one occurs.
void SetLineBreak(const char *_lineBreak)
TiXmlNode * LastChild(const char *_value)
The last child of this node matching 'value'. Will be null if there are no children.
virtual const TiXmlComment * ToComment() const
Cast to a more defined type. Will return null if not of the requested type.
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.
const char * Value() const
Return the value of this attribute.
const char * LineBreak()
Query the current line breaking string.
TiXmlNode * LastChild()
The last child of this node. Will be null if there are no children.
const TiXmlDocument * GetDocument() const
virtual const TiXmlUnknown * ToUnknown() const
Cast to a more defined type. Will return null if not of the requested type.
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
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 void Print(FILE *cfile, int depth) const
bool CDATA() const
Queries whether this represents text using a CDATA section.
const TiXmlElement * RootElement() const
TiXmlNode * ToNode() const
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
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
TiXmlAttribute(const char *_name, const char *_value)
Construct an attribute with a name and value.