26 #ifndef TINYXML_INCLUDED
27 #define TINYXML_INCLUDED
30 #pragma warning( disable : 4530 )
31 #pragma warning( disable : 4786 )
40 #include "cal3d/platform.h"
43 #if defined( _DEBUG ) && !defined( DEBUG )
47 #if defined( DEBUG ) && defined( _MSC_VER )
49 #define TIXML_LOG OutputDebugString
51 #define TIXML_LOG printf
59 #define TIXML_STRING std::string
60 #define TIXML_ISTREAM std::istream
61 #define TIXML_OSTREAM std::ostream
64 #define TIXML_STRING TiXmlString
65 #define TIXML_OSTREAM TiXmlOutStream
77 class TiXmlDeclaration;
79 class TiXmlParsingData;
87 void Clear() { row = col = -1; }
139 virtual void Print( FILE* cfile,
int depth )
const = 0;
170 int Row()
const {
return location.row + 1; }
171 int Column()
const {
return location.col + 1; }
184 static const char* SkipWhiteSpace(
const char* );
185 inline static bool IsWhiteSpace(
int c ) {
return ( isspace( c ) || c ==
'\n' || c ==
'\r' ); }
187 virtual void StreamOut (TIXML_OSTREAM *)
const = 0;
190 static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag );
191 static bool StreamTo( TIXML_ISTREAM * in,
int character, TIXML_STRING * tag );
198 static const char* ReadName(
const char* p, TIXML_STRING* name );
203 static const char* ReadText(
const char* in,
205 bool ignoreWhiteSpace,
212 static const char* GetEntity(
const char* in,
char* value );
215 inline static const char* GetChar(
const char* p,
char* _value )
220 return GetEntity( p, _value );
231 static void PutString(
const TIXML_STRING& str, TIXML_OSTREAM* out );
233 static void PutString(
const TIXML_STRING& str, TIXML_STRING* out );
236 static bool StringEqual(
const char* p,
245 TIXML_ERROR_OPENING_FILE,
246 TIXML_ERROR_OUT_OF_MEMORY,
247 TIXML_ERROR_PARSING_ELEMENT,
248 TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
249 TIXML_ERROR_READING_ELEMENT_VALUE,
250 TIXML_ERROR_READING_ATTRIBUTES,
251 TIXML_ERROR_PARSING_EMPTY,
252 TIXML_ERROR_READING_END_TAG,
253 TIXML_ERROR_PARSING_UNKNOWN,
254 TIXML_ERROR_PARSING_COMMENT,
255 TIXML_ERROR_PARSING_DECLARATION,
256 TIXML_ERROR_DOCUMENT_EMPTY,
258 TIXML_ERROR_STRING_COUNT
260 static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
262 TiXmlCursor location;
268 unsigned int strLength;
274 MAX_ENTITY_LENGTH = 6
277 static Entity entity[ NUM_ENTITY ];
278 static bool condenseWhiteSpace;
299 friend std::istream& operator >> (std::istream& in,
TiXmlNode& base);
317 friend std::ostream& operator<< (std::ostream& out,
const TiXmlNode& base);
320 friend std::string& operator<< (std::string& out,
const TiXmlNode& base );
324 friend TIXML_OSTREAM& operator<< (TIXML_OSTREAM& out,
const TiXmlNode& base);
355 const char *
Value()
const {
return value.c_str (); }
366 void SetValue(
const char * _value) { value = _value;}
369 void SetValue(
const std::string& _value )
372 StringToBuffer buf( _value );
373 SetValue( buf.buffer ? buf.buffer :
"" );
383 TiXmlNode* FirstChild()
const {
return firstChild; }
384 TiXmlNode* FirstChild(
const char * value )
const;
386 TiXmlNode* LastChild()
const {
return lastChild; }
387 TiXmlNode* LastChild(
const char * value )
const;
390 TiXmlNode* FirstChild(
const std::string& _value )
const {
return FirstChild (_value.c_str ()); }
391 TiXmlNode* LastChild(
const std::string& _value )
const {
return LastChild (_value.c_str ()); }
410 TiXmlNode* IterateChildren( TiXmlNode* previous )
const;
413 TiXmlNode* IterateChildren(
const char * value, TiXmlNode* previous )
const;
416 TiXmlNode* IterateChildren(
const std::string& _value, TiXmlNode* previous )
const {
return IterateChildren (_value.c_str (), previous); }
422 TiXmlNode* InsertEndChild(
const TiXmlNode& addThis );
434 TiXmlNode* LinkEndChild( TiXmlNode* addThis );
439 TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis,
const TiXmlNode& addThis );
444 TiXmlNode* InsertAfterChild( TiXmlNode* afterThis,
const TiXmlNode& addThis );
449 TiXmlNode* ReplaceChild( TiXmlNode* replaceThis,
const TiXmlNode& withThis );
452 bool RemoveChild( TiXmlNode* removeThis );
458 TiXmlNode* PreviousSibling(
const char * )
const;
461 TiXmlNode* PreviousSibling(
const std::string& _value )
const {
return PreviousSibling (_value.c_str ()); }
462 TiXmlNode* NextSibling(
const std::string& _value)
const {
return NextSibling (_value.c_str ()); }
469 TiXmlNode* NextSibling(
const char * )
const;
484 TiXmlElement* NextSiblingElement(
const std::string& _value)
const {
return NextSiblingElement (_value.c_str ()); }
488 TiXmlElement* FirstChildElement()
const;
491 TiXmlElement* FirstChildElement(
const char * value )
const;
494 TiXmlElement* FirstChildElement(
const std::string& _value )
const {
return FirstChildElement (_value.c_str ()); }
501 virtual int Type()
const {
return type; }
512 TiXmlElement* ToElement()
const {
return (
this && type == ELEMENT ) ? (TiXmlElement*)
this : 0; }
513 TiXmlComment* ToComment()
const {
return (
this && type == COMMENT ) ? (TiXmlComment*)
this : 0; }
514 TiXmlUnknown* ToUnknown()
const {
return (
this && type == UNKNOWN ) ? (TiXmlUnknown*)
this : 0; }
515 TiXmlText* ToText()
const {
return (
this && type == TEXT ) ? (TiXmlText*)
this : 0; }
516 TiXmlDeclaration* ToDeclaration()
const {
return (
this && type == DECLARATION ) ? (TiXmlDeclaration*)
this : 0; }
518 virtual TiXmlNode* Clone()
const = 0;
520 void SetUserData(
void* user ) { userData = user; }
521 void* GetUserData() {
return userData; }
524 TiXmlNode( NodeType type );
528 virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) = 0;
532 TiXmlNode* Identify(
const char* start );
533 void CopyToClone( TiXmlNode* target )
const { target->SetValue (value.c_str() );
534 target->userData = userData; }
537 TIXML_STRING SValue()
const {
return value ; }
542 TiXmlNode* firstChild;
543 TiXmlNode* lastChild;
573 TiXmlAttribute(
const std::string& _name,
const std::string& _value )
592 const char* Name()
const {
return name.c_str (); }
593 const char* Value()
const {
return value.c_str (); }
594 const int IntValue()
const;
595 const double DoubleValue()
const;
606 int QueryIntValue(
int* value )
const;
608 int QueryDoubleValue(
double* value )
const;
610 void SetName(
const char* _name ) { name = _name; }
611 void SetValue(
const char* _value ) { value = _value; }
613 void SetIntValue(
int value );
614 void SetDoubleValue(
double value );
617 void SetName(
const std::string& _name )
620 StringToBuffer buf( _name );
621 SetName ( buf.buffer ? buf.buffer :
"error" );
627 SetValue( buf.buffer ? buf.buffer :
"error" );
636 bool operator==(
const TiXmlAttribute& rhs )
const {
return rhs.name == name; }
637 bool operator<(
const TiXmlAttribute& rhs )
const {
return name < rhs.name; }
638 bool operator>(
const TiXmlAttribute& rhs )
const {
return name > rhs.name; }
644 virtual const char* Parse(
const char* p, TiXmlParsingData* data );
647 virtual void Print( FILE* cfile,
int depth )
const;
649 virtual void StreamOut( TIXML_OSTREAM * out )
const;
652 void SetDocument( TiXmlDocument* doc ) { document = doc; }
655 TiXmlDocument* document;
658 TiXmlAttribute* prev;
659 TiXmlAttribute* next;
684 TiXmlAttribute* First()
const {
return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
685 TiXmlAttribute* Last()
const {
return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
707 firstChild = lastChild = 0;
717 const char* Attribute(
const char* name )
const;
725 const char* Attribute(
const char* name,
int* i )
const;
733 const char* Attribute(
const char* name,
double* d )
const;
742 int QueryIntAttribute(
const char* name,
int* value )
const;
744 int QueryDoubleAttribute(
const char* name,
double* value )
const;
749 void SetAttribute(
const char* name,
const char * value );
752 const char* Attribute(
const std::string& name )
const {
return Attribute( name.c_str() ); }
753 const char* Attribute(
const std::string& name,
int* i )
const {
return Attribute( name.c_str(), i ); }
756 void SetAttribute(
const std::string& name,
const std::string& _value )
760 if ( n.buffer && v.buffer )
761 SetAttribute (n.buffer, v.buffer );
764 void SetAttribute(
const std::string& name,
int _value )
768 SetAttribute (n.buffer, _value);
775 void SetAttribute(
const char * name,
int value );
779 void RemoveAttribute(
const char * name );
781 void RemoveAttribute(
const std::string& name ) { RemoveAttribute (name.c_str ()); }
784 TiXmlAttribute* FirstAttribute()
const {
return attributeSet.First(); }
785 TiXmlAttribute* LastAttribute()
const {
return attributeSet.Last(); }
791 virtual void Print( FILE* cfile,
int depth )
const;
797 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
799 virtual void StreamOut( TIXML_OSTREAM * out )
const;
828 virtual TiXmlNode* Clone()
const;
830 virtual void Print( FILE* cfile,
int depth )
const;
834 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
836 virtual void StreamOut( TIXML_OSTREAM * out )
const;
841 virtual const char* Parse(
const char* p, TiXmlParsingData* data );
854 SetValue( initValue );
859 TiXmlText(
const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
862 SetValue( initValue );
867 virtual void Print( FILE* cfile,
int depth )
const;
871 virtual TiXmlNode* Clone()
const;
872 virtual void StreamOut ( TIXML_OSTREAM * out )
const;
879 virtual const char* Parse(
const char* p, TiXmlParsingData* data );
882 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
909 const std::string& _encoding,
910 const std::string& _standalone )
914 encoding = _encoding;
915 standalone = _standalone;
920 TiXmlDeclaration(
const char* _version,
921 const char* _encoding,
922 const char* _standalone );
924 virtual ~TiXmlDeclaration() {}
927 const char *
Version()
const {
return version.c_str (); }
929 const char *
Encoding()
const {
return encoding.c_str (); }
931 const char *
Standalone()
const {
return standalone.c_str (); }
936 virtual void Print( FILE* cfile,
int depth )
const;
941 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
943 virtual void StreamOut ( TIXML_OSTREAM * out)
const;
951 TIXML_STRING version;
952 TIXML_STRING encoding;
953 TIXML_STRING standalone;
971 virtual void Print( FILE* cfile,
int depth )
const;
974 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
976 virtual void StreamOut ( TIXML_OSTREAM * out )
const;
1003 value = documentName;
1016 bool SaveFile()
const;
1018 bool LoadFile(
const char * filename );
1020 bool SaveFile(
const char * filename )
const;
1022 #ifdef TIXML_USE_STL
1026 return ( f.buffer && LoadFile( f.buffer ));
1031 return ( f.buffer && SaveFile( f.buffer ));
1053 const char *
ErrorDesc()
const {
return errorDesc.c_str (); }
1068 int ErrorCol() {
return errorLocation.col+1; }
1092 int TabSize()
const {
return tabsize; }
1100 errorLocation.row = errorLocation.col = 0;
1108 virtual void Print( FILE* cfile,
int depth = 0 )
const;
1110 void SetError(
int err,
const char* errorLocation,
TiXmlParsingData* prevData );
1113 virtual void StreamOut ( TIXML_OSTREAM * out)
const;
1116 #ifdef TIXML_USE_STL
1117 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
1123 TIXML_STRING errorDesc;
1220 TiXmlHandle FirstChild(
const char * value )
const;
1224 TiXmlHandle FirstChildElement(
const char * value )
const;
1229 TiXmlHandle Child(
const char* value,
int index )
const;
1238 TiXmlHandle ChildElement(
const char* value,
int index )
const;
1245 #ifdef TIXML_USE_STL
1246 TiXmlHandle FirstChild(
const std::string& _value )
const {
return FirstChild( _value.c_str() ); }
1247 TiXmlHandle FirstChildElement(
const std::string& _value )
const {
return FirstChildElement( _value.c_str() ); }
1249 TiXmlHandle Child(
const std::string& _value,
int index )
const {
return Child( _value.c_str(), index ); }
1250 TiXmlHandle ChildElement(
const std::string& _value,
int index )
const {
return ChildElement( _value.c_str(), index ); }
1258 TiXmlText*
Text()
const {
return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }