- Cal3D 0.11 API Reference -

tinyxml.h
1/*
2www.sourceforge.net/projects/tinyxml
3Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com)
4
5This software is provided 'as-is', without any express or implied
6warranty. In no event will the authors be held liable for any
7damages arising from the use of this software.
8
9Permission is granted to anyone to use this software for any
10purpose, including commercial applications, and to alter it and
11redistribute it freely, subject to the following restrictions:
12
131. The origin of this software must not be misrepresented; you must
14not claim that you wrote the original software. If you use this
15software in a product, an acknowledgment in the product documentation
16would be appreciated but is not required.
17
182. Altered source versions must be plainly marked as such, and
19must not be misrepresented as being the original software.
20
213. This notice may not be removed or altered from any source
22distribution.
23*/
24
25
26#ifndef TINYXML_INCLUDED
27#define TINYXML_INCLUDED
28
29#ifdef _MSC_VER
30#pragma warning( disable : 4530 )
31#pragma warning( disable : 4786 )
32#endif
33
34#include <ctype.h>
35#include <stdio.h>
36#include <stdlib.h>
37#include <string.h>
38#include <assert.h>
39
40#include "cal3d/platform.h"
41
42// Help out windows:
43#if defined( _DEBUG ) && !defined( DEBUG )
44#define DEBUG
45#endif
46
47#if defined( DEBUG ) && defined( _MSC_VER )
48#include <windows.h>
49#define TIXML_LOG OutputDebugString
50#else
51#define TIXML_LOG printf
52#endif
53
54#define TIXML_USE_STL
55
56#ifdef TIXML_USE_STL
57 #include <string>
58 #include <iostream>
59 #define TIXML_STRING std::string
60 #define TIXML_ISTREAM std::istream
61 #define TIXML_OSTREAM std::ostream
62#else
63 #include "tinystr.h"
64 #define TIXML_STRING TiXmlString
65 #define TIXML_OSTREAM TiXmlOutStream
66#endif
67
68namespace cal3d
69{
70
71 class TiXmlDocument;
72 class TiXmlElement;
73 class TiXmlComment;
74 class TiXmlUnknown;
75 class TiXmlAttribute;
76 class TiXmlAttributeSet;
77 class TiXmlText;
78 class TiXmlDeclaration;
79
80 class TiXmlParsingData;
81
82 /* Internal structure for tracking location of items
83 in the XML file.
84 */
85 struct CAL3D_API TiXmlCursor
86 {
87 TiXmlCursor() { Clear(); }
88 void Clear() { row = col = -1; }
89
90 int row; // 0 based.
91 int col; // 0 based.
92 };
93
94
95 // Only used by Attribute::Query functions
96 enum
97 {
98 TIXML_SUCCESS,
99 TIXML_NO_ATTRIBUTE,
100 TIXML_WRONG_TYPE
101 };
102
125 class CAL3D_API TiXmlBase
126 {
127 friend class TiXmlNode;
128 friend class TiXmlElement;
129 friend class TiXmlDocument;
130
131 public:
132 TiXmlBase() {}
133 virtual ~TiXmlBase() {}
134
140 virtual void Print( FILE* cfile, int depth ) const = 0;
141
148 static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; }
149
151 static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; }
152
171 int Row() const { return location.row + 1; }
172 int Column() const { return location.col + 1; }
173
174 protected:
175 // See STL_STRING_BUG
176 // Utility class to overcome a bug.
178 {
179 public:
180 StringToBuffer( const TIXML_STRING& str );
182 char* buffer;
183 };
184
185 static const char* SkipWhiteSpace( const char* );
186 inline static bool IsWhiteSpace( int c ) { return ( isspace( c ) || c == '\n' || c == '\r' ); }
187
188 virtual void StreamOut (TIXML_OSTREAM *) const = 0;
189
190 #ifdef TIXML_USE_STL
191 static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag );
192 static bool StreamTo( TIXML_ISTREAM * in, int character, TIXML_STRING * tag );
193 #endif
194
195 /* Reads an XML name into the string provided. Returns
196 a pointer just past the last character of the name,
197 or 0 if the function has an error.
198 */
199 static const char* ReadName( const char* p, TIXML_STRING* name );
200
201 /* Reads text. Returns a pointer past the given end tag.
202 Wickedly complex options, but it keeps the (sensitive) code in one place.
203 */
204 static const char* ReadText( const char* in, // where to start
205 TIXML_STRING* text, // the string read
206 bool ignoreWhiteSpace, // whether to keep the white space
207 const char* endTag, // what ends this text
208 bool ignoreCase ); // whether to ignore case in the end tag
209
210 virtual const char* Parse( const char* p, TiXmlParsingData* data ) = 0;
211
212 // If an entity has been found, transform it into a character.
213 static const char* GetEntity( const char* in, char* value );
214
215 // Get a character, while interpreting entities.
216 inline static const char* GetChar( const char* p, char* _value )
217 {
218 assert( p );
219 if ( *p == '&' )
220 {
221 return GetEntity( p, _value );
222 }
223 else
224 {
225 *_value = *p;
226 return p+1;
227 }
228 }
229
230 // Puts a string to a stream, expanding entities as it goes.
231 // Note this should not contian the '<', '>', etc, or they will be transformed into entities!
232 static void PutString( const TIXML_STRING& str, TIXML_OSTREAM* out );
233
234 static void PutString( const TIXML_STRING& str, TIXML_STRING* out );
235
236 // Return true if the next characters in the stream are any of the endTag sequences.
237 static bool StringEqual( const char* p,
238 const char* endTag,
239 bool ignoreCase );
240
241
242 enum
243 {
244 TIXML_NO_ERROR = 0,
245 TIXML_ERROR,
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,
258
259 TIXML_ERROR_STRING_COUNT
260 };
261 static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
262
263 TiXmlCursor location;
264
265 private:
266 struct Entity
267 {
268 const char* str;
269 unsigned int strLength;
270 char chr;
271 };
272 enum
273 {
274 NUM_ENTITY = 5,
275 MAX_ENTITY_LENGTH = 6
276
277 };
278 static Entity entity[ NUM_ENTITY ];
279 static bool condenseWhiteSpace;
280 };
281
282
289 class CAL3D_API TiXmlNode : public TiXmlBase
290 {
291 friend class TiXmlDocument;
292 friend class TiXmlElement;
293
294 public:
295 #ifdef TIXML_USE_STL
296
300 friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
301
318 friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
319
321 friend std::string& operator<< (std::string& out, const TiXmlNode& base );
322
323 #else
324 // Used internally, not part of the public API.
325 friend TIXML_OSTREAM& operator<< (TIXML_OSTREAM& out, const TiXmlNode& base);
326 #endif
327
332 {
333 DOCUMENT,
334 ELEMENT,
335 COMMENT,
336 UNKNOWN,
337 TEXT,
338 DECLARATION,
339 TYPECOUNT
340 };
341
342 virtual ~TiXmlNode();
343
356 const char * Value() const { return value.c_str (); }
357
367 void SetValue(const char * _value) { value = _value;}
368
369 #ifdef TIXML_USE_STL
371 void SetValue( const std::string& _value )
372 {
374 SetValue( buf.buffer ? buf.buffer : "" );
375 }
376 #endif
377
379 void Clear();
380
382 TiXmlNode* Parent() const { return parent; }
383
384 TiXmlNode* FirstChild() const { return firstChild; }
385 TiXmlNode* FirstChild( const char * value ) const;
386
387 TiXmlNode* LastChild() const { return lastChild; }
388 TiXmlNode* LastChild( const char * value ) const;
389
390 #ifdef TIXML_USE_STL
391 TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); }
392 TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); }
393 #endif
394
411 TiXmlNode* IterateChildren( TiXmlNode* previous ) const;
412
414 TiXmlNode* IterateChildren( const char * value, TiXmlNode* previous ) const;
415
416 #ifdef TIXML_USE_STL
417 TiXmlNode* IterateChildren( const std::string& _value, TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); }
418 #endif
419
423 TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
424
425
435 TiXmlNode* LinkEndChild( TiXmlNode* addThis );
436
440 TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
441
445 TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis );
446
450 TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
451
453 bool RemoveChild( TiXmlNode* removeThis );
454
456 TiXmlNode* PreviousSibling() const { return prev; }
457
459 TiXmlNode* PreviousSibling( const char * ) const;
460
461 #ifdef TIXML_USE_STL
462 TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); }
463 TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); }
464 #endif
465
467 TiXmlNode* NextSibling() const { return next; }
468
470 TiXmlNode* NextSibling( const char * ) const;
471
476 TiXmlElement* NextSiblingElement() const;
477
482 TiXmlElement* NextSiblingElement( const char * ) const;
483
484 #ifdef TIXML_USE_STL
485 TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); }
486 #endif
487
489 TiXmlElement* FirstChildElement() const;
490
492 TiXmlElement* FirstChildElement( const char * value ) const;
493
494 #ifdef TIXML_USE_STL
495 TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); }
496 #endif
497
502 virtual int Type() const { return type; }
503
507 TiXmlDocument* GetDocument() const;
508
510 bool NoChildren() const { return !firstChild; }
511
512 TiXmlDocument* ToDocument() const { return ( this && type == DOCUMENT ) ? (TiXmlDocument*) this : 0; }
513 TiXmlElement* ToElement() const { return ( this && type == ELEMENT ) ? (TiXmlElement*) this : 0; }
514 TiXmlComment* ToComment() const { return ( this && type == COMMENT ) ? (TiXmlComment*) this : 0; }
515 TiXmlUnknown* ToUnknown() const { return ( this && type == UNKNOWN ) ? (TiXmlUnknown*) this : 0; }
516 TiXmlText* ToText() const { return ( this && type == TEXT ) ? (TiXmlText*) this : 0; }
517 TiXmlDeclaration* ToDeclaration() const { return ( this && type == DECLARATION ) ? (TiXmlDeclaration*) this : 0; }
518
519 virtual TiXmlNode* Clone() const = 0;
520
521 void SetUserData( void* user ) { userData = user; }
522 void* GetUserData() { return userData; }
523
524 protected:
525 TiXmlNode( NodeType type );
526
527 #ifdef TIXML_USE_STL
528 // The real work of the input operator.
529 virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) = 0;
530 #endif
531
532 // Figure out what is at *p, and parse it. Returns null if it is not an xml node.
533 TiXmlNode* Identify( const char* start );
534 void CopyToClone( TiXmlNode* target ) const { target->SetValue (value.c_str() );
535 target->userData = userData; }
536
537 // Internal Value function returning a TIXML_STRING
538 TIXML_STRING SValue() const { return value ; }
539
540 TiXmlNode* parent;
541 NodeType type;
542
543 TiXmlNode* firstChild;
544 TiXmlNode* lastChild;
545
546 TIXML_STRING value;
547
548 TiXmlNode* prev;
549 TiXmlNode* next;
550 void* userData;
551 };
552
553
561 class CAL3D_API TiXmlAttribute : public TiXmlBase
562 {
563 friend class TiXmlAttributeSet;
564
565 public:
568 {
569 document = 0;
570 prev = next = 0;
571 }
572
573 #ifdef TIXML_USE_STL
575 TiXmlAttribute( const std::string& _name, const std::string& _value )
576 {
577 name = _name;
578 value = _value;
579 document = 0;
580 prev = next = 0;
581 }
582 #endif
583
585 TiXmlAttribute( const char * _name, const char * _value )
586 {
587 name = _name;
588 value = _value;
589 document = 0;
590 prev = next = 0;
591 }
592
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;
597
607 int QueryIntValue( int* value ) const;
609 int QueryDoubleValue( double* value ) const;
610
611 void SetName( const char* _name ) { name = _name; }
612 void SetValue( const char* _value ) { value = _value; }
613
614 void SetIntValue( int value );
615 void SetDoubleValue( double value );
616
617 #ifdef TIXML_USE_STL
619 void SetName( const std::string& _name )
620 {
621 StringToBuffer buf( _name );
622 SetName ( buf.buffer ? buf.buffer : "error" );
623 }
625 void SetValue( const std::string& _value )
626 {
628 SetValue( buf.buffer ? buf.buffer : "error" );
629 }
630 #endif
631
633 TiXmlAttribute* Next() const;
635 TiXmlAttribute* Previous() const;
636
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; }
640
641 /* [internal use]
642 Attribtue parsing starts: first letter of the name
643 returns: the next char after the value end quote
644 */
645 virtual const char* Parse( const char* p, TiXmlParsingData* data );
646
647 // [internal use]
648 virtual void Print( FILE* cfile, int depth ) const;
649
650 virtual void StreamOut( TIXML_OSTREAM * out ) const;
651 // [internal use]
652 // Set the document pointer so the attribute can report errors.
653 void SetDocument( TiXmlDocument* doc ) { document = doc; }
654
655 private:
656 TiXmlDocument* document; // A pointer back to a document, for error reporting.
657 TIXML_STRING name;
658 TIXML_STRING value;
659 TiXmlAttribute* prev;
660 TiXmlAttribute* next;
661 };
662
663
664 /* A class used to manage a group of attributes.
665 It is only used internally, both by the ELEMENT and the DECLARATION.
666
667 The set can be changed transparent to the Element and Declaration
668 classes that use it, but NOT transparent to the Attribute
669 which has to implement a next() and previous() method. Which makes
670 it a bit problematic and prevents the use of STL.
671
672 This version is implemented with circular lists because:
673 - I like circular lists
674 - it demonstrates some independence from the (typical) doubly linked list.
675 */
676 class CAL3D_API TiXmlAttributeSet
677 {
678 public:
681
682 void Add( TiXmlAttribute* attribute );
683 void Remove( TiXmlAttribute* attribute );
684
685 TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
686 TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
687 TiXmlAttribute* Find( const char * name ) const;
688
689 private:
690 TiXmlAttribute sentinel;
691 };
692
693
698 class CAL3D_API TiXmlElement : public TiXmlNode
699 {
700 public:
702 TiXmlElement (const char * in_value);
703
704 #ifdef TIXML_USE_STL
706 TiXmlElement( const std::string& _value ) : TiXmlNode( TiXmlNode::ELEMENT )
707 {
708 firstChild = lastChild = 0;
709 value = _value;
710 }
711 #endif
712
713 virtual ~TiXmlElement();
714
718 const char* Attribute( const char* name ) const;
719
726 const char* Attribute( const char* name, int* i ) const;
727
734 const char* Attribute( const char* name, double* d ) const;
735
743 int QueryIntAttribute( const char* name, int* value ) const;
745 int QueryDoubleAttribute( const char* name, double* value ) const;
746
750 void SetAttribute( const char* name, const char * value );
751
752 #ifdef TIXML_USE_STL
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 ); }
755
757 void SetAttribute( const std::string& name, const std::string& _value )
758 {
759 StringToBuffer n( name );
761 if ( n.buffer && v.buffer )
762 SetAttribute (n.buffer, v.buffer );
763 }
765 void SetAttribute( const std::string& name, int _value )
766 {
767 StringToBuffer n( name );
768 if ( n.buffer )
769 SetAttribute (n.buffer, _value);
770 }
771 #endif
772
776 void SetAttribute( const char * name, int value );
777
780 void RemoveAttribute( const char * name );
781 #ifdef TIXML_USE_STL
782 void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); }
783 #endif
784
785 TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); }
786 TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); }
787
788 // [internal use] Creates a new Element and returs it.
789 virtual TiXmlNode* Clone() const;
790 // [internal use]
791
792 virtual void Print( FILE* cfile, int depth ) const;
793
794 protected:
795
796 // Used to be public [internal use]
797 #ifdef TIXML_USE_STL
798 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
799 #endif
800 virtual void StreamOut( TIXML_OSTREAM * out ) const;
801
802 /* [internal use]
803 Attribtue parsing starts: next char past '<'
804 returns: next char past '>'
805 */
806 virtual const char* Parse( const char* p, TiXmlParsingData* data );
807
808 /* [internal use]
809 Reads the "value" of the element -- another element, or text.
810 This should terminate with the current end tag.
811 */
812 const char* ReadValue( const char* in, TiXmlParsingData* prevData );
813
814 private:
815 TiXmlAttributeSet attributeSet;
816 };
817
818
821 class CAL3D_API TiXmlComment : public TiXmlNode
822 {
823 public:
826 virtual ~TiXmlComment() {}
827
828 // [internal use] Creates a new Element and returs it.
829 virtual TiXmlNode* Clone() const;
830 // [internal use]
831 virtual void Print( FILE* cfile, int depth ) const;
832 protected:
833 // used to be public
834 #ifdef TIXML_USE_STL
835 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
836 #endif
837 virtual void StreamOut( TIXML_OSTREAM * out ) const;
838 /* [internal use]
839 Attribtue parsing starts: at the ! of the !--
840 returns: next char past '>'
841 */
842 virtual const char* Parse( const char* p, TiXmlParsingData* data );
843 };
844
845
848 class CAL3D_API TiXmlText : public TiXmlNode
849 {
850 friend class TiXmlElement;
851 public:
853 TiXmlText (const char * initValue) : TiXmlNode (TiXmlNode::TEXT)
854 {
855 SetValue( initValue );
856 }
857 virtual ~TiXmlText() {}
858
859 #ifdef TIXML_USE_STL
861 TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
862 {
863 SetValue( initValue );
864 }
865 #endif
866
867 // [internal use]
868 virtual void Print( FILE* cfile, int depth ) const;
869
870 protected :
871 // [internal use] Creates a new Element and returns it.
872 virtual TiXmlNode* Clone() const;
873 virtual void StreamOut ( TIXML_OSTREAM * out ) const;
874 // [internal use]
875 bool Blank() const; // returns true if all white space and new lines
876 /* [internal use]
877 Attribtue parsing starts: First char of the text
878 returns: next char past '>'
879 */
880 virtual const char* Parse( const char* p, TiXmlParsingData* data );
881 // [internal use]
882 #ifdef TIXML_USE_STL
883 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
884 #endif
885 };
886
887
901 class CAL3D_API TiXmlDeclaration : public TiXmlNode
902 {
903 public:
905 TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {}
906
907 #ifdef TIXML_USE_STL
909 TiXmlDeclaration( const std::string& _version,
910 const std::string& _encoding,
911 const std::string& _standalone )
912 : TiXmlNode( TiXmlNode::DECLARATION )
913 {
914 version = _version;
915 encoding = _encoding;
916 standalone = _standalone;
917 }
918 #endif
919
921 TiXmlDeclaration( const char* _version,
922 const char* _encoding,
923 const char* _standalone );
924
925 virtual ~TiXmlDeclaration() {}
926
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 (); }
933
934 // [internal use] Creates a new Element and returs it.
935 virtual TiXmlNode* Clone() const;
936 // [internal use]
937 virtual void Print( FILE* cfile, int depth ) const;
938
939 protected:
940 // used to be public
941 #ifdef TIXML_USE_STL
942 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
943 #endif
944 virtual void StreamOut ( TIXML_OSTREAM * out) const;
945 // [internal use]
946 // Attribtue parsing starts: next char past '<'
947 // returns: next char past '>'
948
949 virtual const char* Parse( const char* p, TiXmlParsingData* data );
950
951 private:
952 TIXML_STRING version;
953 TIXML_STRING encoding;
954 TIXML_STRING standalone;
955 };
956
957
963 class CAL3D_API TiXmlUnknown : public TiXmlNode
964 {
965 public:
966 TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
967 virtual ~TiXmlUnknown() {}
968
969 // [internal use]
970 virtual TiXmlNode* Clone() const;
971 // [internal use]
972 virtual void Print( FILE* cfile, int depth ) const;
973 protected:
974 #ifdef TIXML_USE_STL
975 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
976 #endif
977 virtual void StreamOut ( TIXML_OSTREAM * out ) const;
978 /* [internal use]
979 Attribute parsing starts: First char of the text
980 returns: next char past '>'
981 */
982 virtual const char* Parse( const char* p, TiXmlParsingData* data );
983 };
984
985
990 class CAL3D_API TiXmlDocument : public TiXmlNode
991 {
992 public:
996 TiXmlDocument( const char * documentName );
997
998 #ifdef TIXML_USE_STL
1000 TiXmlDocument( const std::string& documentName ) :
1001 TiXmlNode( TiXmlNode::DOCUMENT )
1002 {
1003 tabsize = 4;
1004 value = documentName;
1005 error = false;
1006 }
1007 #endif
1008
1009 virtual ~TiXmlDocument() {}
1010
1015 bool LoadFile();
1017 bool SaveFile() const;
1019 bool LoadFile( const char * filename );
1021 bool SaveFile( const char * filename ) const;
1022
1023 #ifdef TIXML_USE_STL
1024 bool LoadFile( const std::string& filename )
1025 {
1027 return ( f.buffer && LoadFile( f.buffer ));
1028 }
1029 bool SaveFile( const std::string& filename ) const
1030 {
1032 return ( f.buffer && SaveFile( f.buffer ));
1033 }
1034 #endif
1035
1038 virtual const char* Parse( const char* p, TiXmlParsingData* data = 0 );
1039
1044 TiXmlElement* RootElement() const { return FirstChildElement(); }
1045
1051 bool Error() const { return error; }
1052
1054 const char * ErrorDesc() const { return errorDesc.c_str (); }
1055
1059 const int ErrorId() const { return errorId; }
1060
1068 int ErrorRow() { return errorLocation.row+1; }
1069 int ErrorCol() { return errorLocation.col+1; }
1070
1091 void SetTabSize( int _tabsize ) { tabsize = _tabsize; }
1092
1093 int TabSize() const { return tabsize; }
1094
1098 void ClearError() { error = false;
1099 errorId = 0;
1100 errorDesc = "";
1101 errorLocation.row = errorLocation.col = 0;
1102 //errorLocation.last = 0;
1103 }
1104
1106 void Print() const { Print( stdout, 0 ); }
1107
1108 // [internal use]
1109 virtual void Print( FILE* cfile, int depth = 0 ) const;
1110 // [internal use]
1111 void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData );
1112
1113 protected :
1114 virtual void StreamOut ( TIXML_OSTREAM * out) const;
1115 // [internal use]
1116 virtual TiXmlNode* Clone() const;
1117 #ifdef TIXML_USE_STL
1118 virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
1119 #endif
1120
1121 private:
1122 bool error;
1123 int errorId;
1124 TIXML_STRING errorDesc;
1125 int tabsize;
1126 TiXmlCursor errorLocation;
1127 };
1128
1129
1210 class CAL3D_API TiXmlHandle
1211 {
1212 public:
1214 TiXmlHandle( TiXmlNode* node ) { this->node = node; }
1216 TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; }
1217
1219 TiXmlHandle FirstChild() const;
1221 TiXmlHandle FirstChild( const char * value ) const;
1223 TiXmlHandle FirstChildElement() const;
1225 TiXmlHandle FirstChildElement( const char * value ) const;
1226
1230 TiXmlHandle Child( const char* value, int index ) const;
1234 TiXmlHandle Child( int index ) const;
1239 TiXmlHandle ChildElement( const char* value, int index ) const;
1244 TiXmlHandle ChildElement( int index ) const;
1245
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() ); }
1249
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 ); }
1252 #endif
1253
1255 TiXmlNode* Node() const { return node; }
1257 TiXmlElement* Element() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
1259 TiXmlText* Text() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
1260
1261 private:
1262 TiXmlNode* node;
1263 };
1264
1265}
1266
1267#endif
1268
1269
A container-safe smart pointer used for refcounted classes.
Definition refptr.h:11
Definition tinyxml.h:677
An attribute is a name-value pair.
Definition tinyxml.h:562
TiXmlAttribute(const char *_name, const char *_value)
Construct an attribute with a name and value.
Definition tinyxml.h:585
void SetValue(const std::string &_value)
STL std::string form.
Definition tinyxml.h:625
TiXmlAttribute(const std::string &_name, const std::string &_value)
std::string constructor.
Definition tinyxml.h:575
const char * Name() const
Return the name of this attribute.
Definition tinyxml.h:593
void SetName(const char *_name)
Set the name of this attribute.
Definition tinyxml.h:611
const char * Value() const
Return the value of this attribute.
Definition tinyxml.h:594
void SetValue(const char *_value)
Set the value.
Definition tinyxml.h:612
TiXmlAttribute()
Construct an empty attribute.
Definition tinyxml.h:567
void SetName(const std::string &_name)
STL std::string form.
Definition tinyxml.h:619
Definition tinyxml.h:178
TiXmlBase is a base class for every class in TinyXml.
Definition tinyxml.h:126
static void SetCondenseWhiteSpace(bool condense)
The world does not agree on whether white space should be kept or not.
Definition tinyxml.h:148
int Column() const
See Row()
Definition tinyxml.h:172
int Row() const
Return the position, in the original source file, of this node or attribute.
Definition tinyxml.h:171
static bool IsWhiteSpaceCondensed()
Return the current white space setting.
Definition tinyxml.h:151
virtual void Print(FILE *cfile, int depth) const =0
All TinyXml classes can print themselves to a filestream.
An XML comment.
Definition tinyxml.h:822
TiXmlComment()
Constructs an empty comment.
Definition tinyxml.h:825
In correct XML the declaration is the first entry in the file.
Definition tinyxml.h:902
const char * Standalone() const
Is this a standalone document?
Definition tinyxml.h:932
TiXmlDeclaration()
Construct an empty declaration.
Definition tinyxml.h:905
const char * Encoding() const
Encoding. Will return empty if none was found.
Definition tinyxml.h:930
const char * Version() const
Version. Will return empty if none was found.
Definition tinyxml.h:928
TiXmlDeclaration(const std::string &_version, const std::string &_encoding, const std::string &_standalone)
Constructor.
Definition tinyxml.h:909
Always the top level node.
Definition tinyxml.h:991
bool SaveFile(const std::string &filename) const
< STL std::string version.
Definition tinyxml.h:1029
bool LoadFile(const std::string &filename)
Definition tinyxml.h:1024
int ErrorCol()
The column where the error occurred. See ErrorRow()
Definition tinyxml.h:1069
bool Error() const
If an error occurs, Error will be set to true.
Definition tinyxml.h:1051
int ErrorRow()
Returns the location (if known) of the error.
Definition tinyxml.h:1068
const char * ErrorDesc() const
Contains a textual (english) description of the error if one occurs.
Definition tinyxml.h:1054
TiXmlDocument(const std::string &documentName)
Constructor.
Definition tinyxml.h:1000
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
void Print() const
Dump the document to standard out.
Definition tinyxml.h:1106
const int ErrorId() const
Generally, you probably want the error string ( ErrorDesc() ).
Definition tinyxml.h:1059
void ClearError()
If you have handled the error, it can be reset with this call.
Definition tinyxml.h:1098
TiXmlElement * RootElement() const
Get the root element – the only top level element – of the document.
Definition tinyxml.h:1044
The element is a container class.
Definition tinyxml.h:699
TiXmlAttribute * FirstAttribute() const
Access the first attribute in this element.
Definition tinyxml.h:785
void SetAttribute(const std::string &name, const std::string &_value)
STL std::string form.
Definition tinyxml.h:757
TiXmlAttribute * LastAttribute() const
Access the last attribute in this element.
Definition tinyxml.h:786
TiXmlElement(const std::string &_value)
std::string constructor.
Definition tinyxml.h:706
void RemoveAttribute(const std::string &name)
STL std::string form.
Definition tinyxml.h:782
A TiXmlHandle is a class that wraps a node pointer with null checks; this is an incredibly useful thi...
Definition tinyxml.h:1211
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
TiXmlHandle(const TiXmlHandle &ref)
Copy constructor.
Definition tinyxml.h:1216
TiXmlNode * Node() const
Return the handle as a TiXmlNode. This may return null.
Definition tinyxml.h:1255
TiXmlElement * Element() const
Return the handle as a TiXmlElement. This may return null.
Definition tinyxml.h:1257
TiXmlText * Text() const
Return the handle as a TiXmlText. This may return null.
Definition tinyxml.h:1259
The parent class for everything in the Document Object Model.
Definition tinyxml.h:290
TiXmlText * ToText() const
Cast to a more defined type. Will return null not of the requested type.
Definition tinyxml.h:516
TiXmlNode * IterateChildren(const std::string &_value, TiXmlNode *previous) const
STL std::string form.
Definition tinyxml.h:417
TiXmlDocument * ToDocument() const
Cast to a more defined type. Will return null not of the requested type.
Definition tinyxml.h:512
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
TiXmlNode * PreviousSibling(const std::string &_value) const
STL std::string form.
Definition tinyxml.h:462
TiXmlComment * ToComment() const
Cast to a more defined type. Will return null not of the requested type.
Definition tinyxml.h:514
virtual int Type() const
Query the type (as an enumerated value, above) of this node.
Definition tinyxml.h:502
TiXmlNode * NextSibling(const std::string &_value) const
STL std::string form.
Definition tinyxml.h:463
TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
Definition tinyxml.h:384
TiXmlElement * NextSiblingElement(const std::string &_value) const
STL std::string form.
Definition tinyxml.h:485
bool NoChildren() const
Returns true if this node has no children.
Definition tinyxml.h:510
TiXmlElement * FirstChildElement(const std::string &_value) const
STL std::string form.
Definition tinyxml.h:495
void SetValue(const std::string &_value)
STL std::string form.
Definition tinyxml.h:371
TiXmlDeclaration * ToDeclaration() const
Cast to a more defined type. Will return null not of the requested type.
Definition tinyxml.h:517
TiXmlElement * ToElement() const
Cast to a more defined type. Will return null not of the requested type.
Definition tinyxml.h:513
const char * Value() const
The meaning of 'value' changes for the specific type of TiXmlNode.
Definition tinyxml.h:356
TiXmlNode * PreviousSibling() const
Navigate to a sibling node.
Definition tinyxml.h:456
TiXmlNode * LastChild(const std::string &_value) const
STL std::string form.
Definition tinyxml.h:392
TiXmlNode * NextSibling() const
Navigate to a sibling node.
Definition tinyxml.h:467
void SetValue(const char *_value)
Changes the value of the node.
Definition tinyxml.h:367
NodeType
The types of XML nodes supported by TinyXml.
Definition tinyxml.h:332
TiXmlUnknown * ToUnknown() const
Cast to a more defined type. Will return null not of the requested type.
Definition tinyxml.h:515
TiXmlNode * Parent() const
One step up the DOM.
Definition tinyxml.h:382
Definition tinyxmlparser.cpp:47
XML text.
Definition tinyxml.h:849
TiXmlText(const std::string &initValue)
Constructor.
Definition tinyxml.h:861
TiXmlText(const char *initValue)
Constructor.
Definition tinyxml.h:853
Any tag that tinyXml doesn't recognize is saved as an unknown.
Definition tinyxml.h:964
Definition tinyxml.h:86

Generated by The Cal3D Team with Doxygen 1.10.0