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 76 class TiXmlAttributeSet;
78 class TiXmlDeclaration;
80 class TiXmlParsingData;
88 void Clear() { row = col = -1; }
140 virtual void Print( FILE* cfile,
int depth )
const = 0;
171 int Row()
const {
return location.row + 1; }
172 int Column()
const {
return location.col + 1; }
185 static const char* SkipWhiteSpace(
const char* );
186 inline static bool IsWhiteSpace(
int c ) {
return ( isspace( c ) || c ==
'\n' || c ==
'\r' ); }
188 virtual void StreamOut (TIXML_OSTREAM *)
const = 0;
191 static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag );
192 static bool StreamTo( TIXML_ISTREAM * in,
int character, TIXML_STRING * tag );
199 static const char* ReadName(
const char* p, TIXML_STRING* name );
204 static const char* ReadText(
const char* in,
206 bool ignoreWhiteSpace,
213 static const char* GetEntity(
const char* in,
char* value );
216 inline static const char* GetChar(
const char* p,
char* _value )
221 return GetEntity( p, _value );
232 static void PutString(
const TIXML_STRING& str, TIXML_OSTREAM* out );
234 static void PutString(
const TIXML_STRING& str, TIXML_STRING* out );
237 static bool StringEqual(
const char* p,
246 TIXML_ERROR_OPENING_FILE,
247 TIXML_ERROR_OUT_OF_MEMORY,
248 TIXML_ERROR_PARSING_ELEMENT,
249 TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
250 TIXML_ERROR_READING_ELEMENT_VALUE,
251 TIXML_ERROR_READING_ATTRIBUTES,
252 TIXML_ERROR_PARSING_EMPTY,
253 TIXML_ERROR_READING_END_TAG,
254 TIXML_ERROR_PARSING_UNKNOWN,
255 TIXML_ERROR_PARSING_COMMENT,
256 TIXML_ERROR_PARSING_DECLARATION,
257 TIXML_ERROR_DOCUMENT_EMPTY,
259 TIXML_ERROR_STRING_COUNT
261 static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
263 TiXmlCursor location;
269 unsigned int strLength;
275 MAX_ENTITY_LENGTH = 6
278 static Entity entity[ NUM_ENTITY ];
279 static bool condenseWhiteSpace;
300 friend std::istream& operator >> (std::istream& in,
TiXmlNode& base);
318 friend std::ostream& operator<< (std::ostream& out,
const TiXmlNode& base);
321 friend std::string& operator<< (std::string& out,
const TiXmlNode& base );
325 friend TIXML_OSTREAM& operator<< (TIXML_OSTREAM& out,
const TiXmlNode& base);
356 const char *
Value()
const {
return value.c_str (); }
367 void SetValue(
const char * _value) { value = _value;}
370 void SetValue(
const std::string& _value )
373 StringToBuffer buf( _value );
374 SetValue( buf.buffer ? buf.buffer :
"" );
385 TiXmlNode* FirstChild(
const char * value )
const;
387 TiXmlNode* LastChild()
const {
return lastChild; }
388 TiXmlNode* LastChild(
const char * value )
const;
453 bool RemoveChild(
TiXmlNode* removeThis );
459 TiXmlNode* PreviousSibling(
const char * )
const;
470 TiXmlNode* NextSibling(
const char * )
const;
492 TiXmlElement* FirstChildElement(
const char * value )
const;
502 virtual int Type()
const {
return type; }
521 void SetUserData(
void* user ) { userData = user; }
522 void* GetUserData() {
return userData; }
525 TiXmlNode( NodeType type );
529 virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) = 0;
533 TiXmlNode* Identify(
const char* start );
534 void CopyToClone( TiXmlNode* target )
const { target->SetValue (value.c_str() );
535 target->userData = userData; }
538 TIXML_STRING SValue()
const {
return value ; }
543 TiXmlNode* firstChild;
544 TiXmlNode* lastChild;
574 TiXmlAttribute(
const std::string& _name,
const std::string& _value )
593 const char*
Name()
const {
return name.c_str (); }
594 const char*
Value()
const {
return value.c_str (); }
595 const int IntValue()
const;
596 const double DoubleValue()
const;
607 int QueryIntValue(
int* value )
const;
609 int QueryDoubleValue(
double* value )
const;
611 void SetName(
const char* _name ) { name = _name; }
612 void SetValue(
const char* _value ) { value = _value; }
614 void SetIntValue(
int value );
615 void SetDoubleValue(
double value );
618 void SetName(
const std::string& _name )
621 StringToBuffer buf( _name );
622 SetName ( buf.buffer ? buf.buffer :
"error" );
628 SetValue( buf.buffer ? buf.buffer :
"error" );
637 bool operator==(
const TiXmlAttribute& rhs )
const {
return rhs.name == name; }
638 bool operator<(
const TiXmlAttribute& rhs )
const {
return name < rhs.name; }
639 bool operator>(
const TiXmlAttribute& rhs )
const {
return name > rhs.name; }
645 virtual const char* Parse(
const char* p, TiXmlParsingData* data );
648 virtual void Print( FILE* cfile,
int depth )
const;
650 virtual void StreamOut( TIXML_OSTREAM * out )
const;
653 void SetDocument( TiXmlDocument* doc ) { document = doc; }
656 TiXmlDocument* document;
659 TiXmlAttribute* prev;
660 TiXmlAttribute* next;
685 TiXmlAttribute* First()
const {
return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
686 TiXmlAttribute* Last()
const {
return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
708 firstChild = lastChild = 0;
718 const char* Attribute(
const char* name )
const;
726 const char* Attribute(
const char* name,
int* i )
const;
734 const char* Attribute(
const char* name,
double* d )
const;
743 int QueryIntAttribute(
const char* name,
int* value )
const;
745 int QueryDoubleAttribute(
const char* name,
double* value )
const;
750 void SetAttribute(
const char* name,
const char * value );
753 const char* Attribute(
const std::string& name )
const {
return Attribute( name.c_str() ); }
754 const char* Attribute(
const std::string& name,
int* i )
const {
return Attribute( name.c_str(), i ); }
757 void SetAttribute(
const std::string& name,
const std::string& _value )
761 if ( n.buffer && v.buffer )
762 SetAttribute (n.buffer, v.buffer );
765 void SetAttribute(
const std::string& name,
int _value )
767 StringToBuffer n( name );
769 SetAttribute (n.buffer, _value);
776 void SetAttribute(
const char * name,
int value );
780 void RemoveAttribute(
const char * name );
792 virtual void Print( FILE* cfile,
int depth )
const;
798 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
800 virtual void StreamOut( TIXML_OSTREAM * out )
const;
829 virtual TiXmlNode* Clone()
const;
831 virtual void Print( FILE* cfile,
int depth )
const;
835 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
837 virtual void StreamOut( TIXML_OSTREAM * out )
const;
842 virtual const char* Parse(
const char* p, TiXmlParsingData* data );
855 SetValue( initValue );
860 TiXmlText(
const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
863 SetValue( initValue );
868 virtual void Print( FILE* cfile,
int depth )
const;
872 virtual TiXmlNode* Clone()
const;
873 virtual void StreamOut ( TIXML_OSTREAM * out )
const;
880 virtual const char* Parse(
const char* p, TiXmlParsingData* data );
883 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
910 const std::string& _encoding,
911 const std::string& _standalone )
915 encoding = _encoding;
916 standalone = _standalone;
921 TiXmlDeclaration(
const char* _version,
922 const char* _encoding,
923 const char* _standalone );
925 virtual ~TiXmlDeclaration() {}
928 const char *
Version()
const {
return version.c_str (); }
930 const char *
Encoding()
const {
return encoding.c_str (); }
932 const char *
Standalone()
const {
return standalone.c_str (); }
937 virtual void Print( FILE* cfile,
int depth )
const;
942 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
944 virtual void StreamOut ( TIXML_OSTREAM * out)
const;
952 TIXML_STRING version;
953 TIXML_STRING encoding;
954 TIXML_STRING standalone;
972 virtual void Print( FILE* cfile,
int depth )
const;
975 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
977 virtual void StreamOut ( TIXML_OSTREAM * out )
const;
1004 value = documentName;
1017 bool SaveFile()
const;
1019 bool LoadFile(
const char * filename );
1021 bool SaveFile(
const char * filename )
const;
1023 #ifdef TIXML_USE_STL 1027 return ( f.buffer && LoadFile( f.buffer ));
1032 return ( f.buffer && SaveFile( f.buffer ));
1054 const char *
ErrorDesc()
const {
return errorDesc.c_str (); }
1093 int TabSize()
const {
return tabsize; }
1101 errorLocation.row = errorLocation.col = 0;
1109 virtual void Print( FILE* cfile,
int depth = 0 )
const;
1111 void SetError(
int err,
const char* errorLocation,
TiXmlParsingData* prevData );
1114 virtual void StreamOut ( TIXML_OSTREAM * out)
const;
1117 #ifdef TIXML_USE_STL 1118 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
1124 TIXML_STRING errorDesc;
1221 TiXmlHandle FirstChild(
const char * value )
const;
1225 TiXmlHandle FirstChildElement(
const char * value )
const;
1230 TiXmlHandle Child(
const char* value,
int index )
const;
1239 TiXmlHandle ChildElement(
const char* value,
int index )
const;
1246 #ifdef TIXML_USE_STL 1247 TiXmlHandle FirstChild(
const std::string& _value )
const {
return FirstChild( _value.c_str() ); }
1248 TiXmlHandle FirstChildElement(
const std::string& _value )
const {
return FirstChildElement( _value.c_str() ); }
1250 TiXmlHandle Child(
const std::string& _value,
int index )
const {
return Child( _value.c_str(), index ); }
1251 TiXmlHandle ChildElement(
const std::string& _value,
int index )
const {
return ChildElement( _value.c_str(), index ); }
1259 TiXmlText*
Text()
const {
return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
int ErrorCol()
The column where the error occurred. See ErrorRow()
Definition: tinyxml.h:1069
void ClearError()
If you have handled the error, it can be reset with this call.
Definition: tinyxml.h:1098
bool NoChildren() const
Returns true if this node has no children.
Definition: tinyxml.h:510
Any tag that tinyXml doesn't recognize is saved as an unknown.
Definition: tinyxml.h:963
const int ErrorId() const
Generally, you probably want the error string ( ErrorDesc() ).
Definition: tinyxml.h:1059
TiXmlNode * Parent() const
One step up the DOM.
Definition: tinyxml.h:382
A TiXmlHandle is a class that wraps a node pointer with null checks; this is an incredibly useful thi...
Definition: tinyxml.h:1210
Definition: tinyxml.h:676
void SetValue(const char *_value)
Set the value.
Definition: tinyxml.h:612
TiXmlAttribute(const char *_name, const char *_value)
Construct an attribute with a name and value.
Definition: tinyxml.h:585
TiXmlText * ToText() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:516
const char * Encoding() const
Encoding. Will return empty if none was found.
Definition: tinyxml.h:930
NodeType
The types of XML nodes supported by TinyXml.
Definition: tinyxml.h:331
TiXmlNode * NextSibling() const
Navigate to a sibling node.
Definition: tinyxml.h:467
XML text.
Definition: tinyxml.h:848
TiXmlElement * Element() const
Return the handle as a TiXmlElement. This may return null.
Definition: tinyxml.h:1257
TiXmlUnknown * ToUnknown() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:515
int ErrorRow()
Returns the location (if known) of the error.
Definition: tinyxml.h:1068
const char * Version() const
Version. Will return empty if none was found.
Definition: tinyxml.h:928
Definition: tinyxml.h:177
TiXmlText * Text() const
Return the handle as a TiXmlText. This may return null.
Definition: tinyxml.h:1259
In correct XML the declaration is the first entry in the file.
Definition: tinyxml.h:901
TiXmlHandle(const TiXmlHandle &ref)
Copy constructor.
Definition: tinyxml.h:1216
TiXmlNode * PreviousSibling(const std::string &_value) const
STL std::string form.
Definition: tinyxml.h:462
TiXmlBase is a base class for every class in TinyXml.
Definition: tinyxml.h:125
const char * Value() const
The meaning of 'value' changes for the specific type of TiXmlNode.
Definition: tinyxml.h:356
An attribute is a name-value pair.
Definition: tinyxml.h:561
Always the top level node.
Definition: tinyxml.h:990
void SetTabSize(int _tabsize)
By calling this method, with a tab size greater than 0, the row and column of each node and attribute...
Definition: tinyxml.h:1091
virtual int Type() const
Query the type (as an enumerated value, above) of this node.
Definition: tinyxml.h:502
TiXmlDocument * ToDocument() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:512
TiXmlElement * NextSiblingElement(const std::string &_value) const
STL std::string form.
Definition: tinyxml.h:485
bool SaveFile(const std::string &filename) const
< STL std::string version.
Definition: tinyxml.h:1029
TiXmlText(const char *initValue)
Constructor.
Definition: tinyxml.h:853
TiXmlNode * Node() const
Return the handle as a TiXmlNode. This may return null.
Definition: tinyxml.h:1255
void SetAttribute(const std::string &name, const std::string &_value)
STL std::string form.
Definition: tinyxml.h:757
TiXmlNode * NextSibling(const std::string &_value) const
STL std::string form.
Definition: tinyxml.h:463
TiXmlDeclaration()
Construct an empty declaration.
Definition: tinyxml.h:905
Definition: tinyxmlparser.cpp:46
TiXmlAttribute * FirstAttribute() const
Access the first attribute in this element.
Definition: tinyxml.h:785
static void SetCondenseWhiteSpace(bool condense)
The world does not agree on whether white space should be kept or not.
Definition: tinyxml.h:148
void Print() const
Dump the document to standard out.
Definition: tinyxml.h:1106
TiXmlHandle(TiXmlNode *node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
Definition: tinyxml.h:1214
TiXmlElement * FirstChildElement(const std::string &_value) const
STL std::string form.
Definition: tinyxml.h:495
TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
Definition: tinyxml.h:384
TiXmlNode * PreviousSibling() const
Navigate to a sibling node.
Definition: tinyxml.h:456
TiXmlDeclaration * ToDeclaration() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:517
void SetValue(const std::string &_value)
STL std::string form.
Definition: tinyxml.h:625
int Column() const
See Row()
Definition: tinyxml.h:172
bool Error() const
If an error occurs, Error will be set to true.
Definition: tinyxml.h:1051
const char * Standalone() const
Is this a standalone document?
Definition: tinyxml.h:932
const char * Name() const
Return the name of this attribute.
Definition: tinyxml.h:593
const char * Value() const
Return the value of this attribute.
Definition: tinyxml.h:594
The element is a container class.
Definition: tinyxml.h:698
TiXmlNode * FirstChild(const std::string &_value) const
The last child of this node matching 'value'. Will be null if there are no children.
Definition: tinyxml.h:391
TiXmlAttribute()
Construct an empty attribute.
Definition: tinyxml.h:567
TiXmlAttribute * LastAttribute() const
Access the last attribute in this element.
Definition: tinyxml.h:786
const char * ErrorDesc() const
Contains a textual (english) description of the error if one occurs.
Definition: tinyxml.h:1054
The parent class for everything in the Document Object Model.
Definition: tinyxml.h:289
static bool IsWhiteSpaceCondensed()
Return the current white space setting.
Definition: tinyxml.h:151
TiXmlElement * RootElement() const
Get the root element – the only top level element – of the document.
Definition: tinyxml.h:1044
bool LoadFile(const std::string &filename)
Definition: tinyxml.h:1024
void SetName(const char *_name)
Set the name of this attribute.
Definition: tinyxml.h:611
int Row() const
Return the position, in the original source file, of this node or attribute.
Definition: tinyxml.h:171
TiXmlNode * LastChild(const std::string &_value) const
STL std::string form.
Definition: tinyxml.h:392
TiXmlElement * ToElement() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:513
void RemoveAttribute(const std::string &name)
STL std::string form.
Definition: tinyxml.h:782
void SetValue(const char *_value)
Changes the value of the node.
Definition: tinyxml.h:367
TiXmlNode * IterateChildren(const std::string &_value, TiXmlNode *previous) const
STL std::string form.
Definition: tinyxml.h:417
TiXmlComment * ToComment() const
Cast to a more defined type. Will return null not of the requested type.
Definition: tinyxml.h:514