- Cal3D 0.11 API Reference -

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

Generated by The Cal3D Team with Doxygen 1.15.0