edelib 1.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List

TiXml.h
1 /*
2 www.sourceforge.net/projects/tinyxml
3 Original code (2.0 and earlier )copyright (c) 2000-2006 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 __EDELIB_TIXML_H__
27 #define __EDELIB_TIXML_H__
28
29 #include <ctype.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <assert.h>
34
35 // Help out windows:
36 #if defined( _DEBUG ) && !defined( DEBUG )
37 #define DEBUG
38 #endif
39
40 #ifdef TIXML_USE_STL
41 #include <string>
42 #include <iostream>
43 #include <sstream>
44 #define TIXML_STRING std::string
45 #else
46 #include "String.h"
47 #define TIXML_STRING EDELIB_NS_PREPEND(String)
48 #endif
49
50 // Deprecated library function hell. Compilers want to use the
51 // new safe versions. This probably doesn't fully address the problem,
52 // but it gets closer. There are too many compilers for me to fully
53 // test. If you get compilation troubles, undefine TIXML_SAFE
54 #define TIXML_SAFE
55
56 #ifdef TIXML_SAFE
57 #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
58 // Microsoft visual studio, version 2005 and higher.
59 #define TIXML_SNPRINTF _snprintf_s
60 #define TIXML_SNSCANF _snscanf_s
61 #elif defined(_MSC_VER) && (_MSC_VER >= 1200 )
62 // Microsoft visual studio, version 6 and higher.
63 //#pragma message( "Using _sn* functions." )
64 #define TIXML_SNPRINTF _snprintf
65 #define TIXML_SNSCANF _snscanf
66 #elif defined(__GNUC__) && (__GNUC__ >= 3 )
67 // GCC version 3 and higher.s
68 //#warning( "Using sn* functions." )
69 #define TIXML_SNPRINTF snprintf
70 #define TIXML_SNSCANF snscanf
71 #endif
72 #endif
73
74 class TiXmlDocument;
75 class TiXmlElement;
76 class TiXmlComment;
77 class TiXmlUnknown;
78 class TiXmlAttribute;
79 class TiXmlText;
80 class TiXmlDeclaration;
81 class TiXmlParsingData;
82
83 const int TIXML_MAJOR_VERSION = 2;
84 const int TIXML_MINOR_VERSION = 5;
85 const int TIXML_PATCH_VERSION = 2;
86
87 #ifndef SKIP_DOCS
88 /*
89 * Internal structure for tracking location of items
90 * in the XML file.
91 */
92 struct TiXmlCursor
93 {
94 TiXmlCursor() { Clear(); }
95 void Clear() { row = col = -1; }
96
97 int row; // 0 based.
98 int col; // 0 based.
99 };
100 #endif
101
123 class TiXmlVisitor
124 {
125 public:
127 virtual ~TiXmlVisitor() {}
128
130 virtual bool VisitEnter( const TiXmlDocument& doc ) { return true; }
132 virtual bool VisitExit( const TiXmlDocument& doc ) { return true; }
134 virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute ) { return true; }
136 virtual bool VisitExit( const TiXmlElement& element ) { return true; }
138 virtual bool Visit( const TiXmlDeclaration& declaration ) { return true; }
140 virtual bool Visit( const TiXmlText& text ) { return true; }
142 virtual bool Visit( const TiXmlComment& comment ) { return true; }
144 virtual bool Visit( const TiXmlUnknown& unknown ) { return true; }
145 };
146
147 // Only used by Attribute::Query functions
148 enum
149 {
150 TIXML_SUCCESS,
151 TIXML_NO_ATTRIBUTE,
152 TIXML_WRONG_TYPE
153 };
154
155 // Used by the parsing routines.
156 enum TiXmlEncoding
157 {
158 TIXML_ENCODING_UNKNOWN,
159 TIXML_ENCODING_UTF8,
160 TIXML_ENCODING_LEGACY
161 };
162
163 const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
164
194 class TiXmlBase
195 {
196 friend class TiXmlNode;
197 friend class TiXmlElement;
198 friend class TiXmlDocument;
199
200 public:
201 TiXmlBase() : userData(0) {}
202 virtual ~TiXmlBase() {}
203
214 virtual void Print( FILE* cfile, int depth ) const = 0;
215
223 static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; }
224
226 static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; }
227
246 int Row() const { return location.row + 1; }
248 int Column() const { return location.col + 1; }
250 void SetUserData( void* user ) { userData = user; }
252 void* GetUserData() { return userData; }
254 const void* GetUserData() const { return userData; }
255 #ifndef SKIP_DOCS
256 // Table that returs, for a given lead byte, the total number of bytes
257 // in the UTF-8 sequence.
258 static const int utf8ByteTable[256];
259
260 virtual const char* Parse( const char* p,
261 TiXmlParsingData* data,
262 TiXmlEncoding encoding /*= TIXML_ENCODING_UNKNOWN */ ) = 0;
263 #endif
264
265 enum
266 {
267 TIXML_NO_ERROR = 0,
268 TIXML_ERROR,
269 TIXML_ERROR_OPENING_FILE,
270 TIXML_ERROR_OUT_OF_MEMORY,
271 TIXML_ERROR_PARSING_ELEMENT,
272 TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
273 TIXML_ERROR_READING_ELEMENT_VALUE,
274 TIXML_ERROR_READING_ATTRIBUTES,
275 TIXML_ERROR_PARSING_EMPTY,
276 TIXML_ERROR_READING_END_TAG,
277 TIXML_ERROR_PARSING_UNKNOWN,
278 TIXML_ERROR_PARSING_COMMENT,
279 TIXML_ERROR_PARSING_DECLARATION,
280 TIXML_ERROR_DOCUMENT_EMPTY,
281 TIXML_ERROR_EMBEDDED_NULL,
282 TIXML_ERROR_PARSING_CDATA,
283 TIXML_ERROR_DOCUMENT_TOP_ONLY,
284
285 TIXML_ERROR_STRING_COUNT
286 };
287
288 protected:
289 #ifndef SKIP_DOCS
290 static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding );
291 inline static bool IsWhiteSpace( char c )
292 {
293 return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' );
294 }
295 inline static bool IsWhiteSpace( int c )
296 {
297 if ( c < 256 )
298 return IsWhiteSpace( (char) c );
299 return false; // Again, only truly correct for English/Latin...but usually works.
300 }
301
302 #ifdef TIXML_USE_STL
303 static bool StreamWhiteSpace( std::istream * in, TIXML_STRING * tag );
304 static bool StreamTo( std::istream * in, int character, TIXML_STRING * tag );
305 #endif
306
307 #endif
308
314 static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding );
315
320 static const char* ReadText( const char* in, // where to start
321 TIXML_STRING* text, // the string read
322 bool ignoreWhiteSpace, // whether to keep the white space
323 const char* endTag, // what ends this text
324 bool ignoreCase, // whether to ignore case in the end tag
325 TiXmlEncoding encoding ); // the current encoding
326
328 static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding );
329
334 inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding )
335 {
336 assert( p );
337 if ( encoding == TIXML_ENCODING_UTF8 )
338 {
339 *length = utf8ByteTable[ *((const unsigned char*)p) ];
340 assert( *length >= 0 && *length < 5 );
341 }
342 else
343 {
344 *length = 1;
345 }
346
347 if ( *length == 1 )
348 {
349 if ( *p == '&' )
350 return GetEntity( p, _value, length, encoding );
351 *_value = *p;
352 return p+1;
353 }
354 else if ( *length )
355 {
356 //strncpy( _value, p, *length ); // lots of compilers don't like this function (unsafe),
357 // and the null terminator isn't needed
358 for( int i=0; p[i] && i<*length; ++i ) {
359 _value[i] = p[i];
360 }
361 return p + (*length);
362 }
363 else
364 {
365 // Not valid text.
366 return 0;
367 }
368 }
369
374 static void PutString( const TIXML_STRING& str, TIXML_STRING* out );
375
381 static bool StringEqual( const char* p,
382 const char* endTag,
383 bool ignoreCase,
384 TiXmlEncoding encoding );
385
387 static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
388
390 TiXmlCursor location;
391
393 void* userData;
394
399 static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding );
401 static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding );
403 inline static int ToLower( int v, TiXmlEncoding encoding )
404 {
405 if ( encoding == TIXML_ENCODING_UTF8 )
406 {
407 if ( v < 128 ) return tolower( v );
408 return v;
409 }
410 else
411 {
412 return tolower( v );
413 }
414 }
416 static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
417
418 private:
419 TiXmlBase( const TiXmlBase& ); // not implemented.
420 void operator=( const TiXmlBase& base ); // not allowed.
421 #ifndef SKIP_DOCS
422 struct Entity
423 {
424 const char* str;
425 unsigned int strLength;
426 char chr;
427 };
428 #endif
429 enum
430 {
431 NUM_ENTITY = 5,
432 MAX_ENTITY_LENGTH = 6
433
434 };
435 static Entity entity[ NUM_ENTITY ];
436 static bool condenseWhiteSpace;
437 };
438
439
450 class EDELIB_API TiXmlNode : public TiXmlBase
451 {
452 friend class TiXmlDocument;
453 friend class TiXmlElement;
454
455 public:
456 #ifdef TIXML_USE_STL
457
462 friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
463
481 friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
482
484 friend std::string& operator<< (std::string& out, const TiXmlNode& base );
485
486 #endif
487
492 enum NodeType
493 {
494 DOCUMENT,
495 ELEMENT,
496 COMMENT,
497 UNKNOWN,
498 TEXT,
499 DECLARATION,
500 TYPECOUNT
501 };
502
503 virtual ~TiXmlNode();
504
517 const char *Value() const { return value.c_str (); }
518
519 #ifdef TIXML_USE_STL
520
525 const std::string& ValueStr() const { return value; }
526 #endif
527
538 void SetValue(const char * _value) { value = _value;}
539
540 #ifdef TIXML_USE_STL
541
542 void SetValue( const std::string& _value ) { value = _value; }
543 #endif
544
546 void Clear();
547
549 TiXmlNode* Parent() { return parent; }
551 const TiXmlNode* Parent() const { return parent; }
552
554 const TiXmlNode* FirstChild() const { return firstChild; }
556 TiXmlNode* FirstChild() { return firstChild; }
557
559 const TiXmlNode* FirstChild( const char * value ) const;
561 TiXmlNode* FirstChild( const char * _value ) {
562 // Call through to the const version - safe since nothing is changed.
563 // Exiting syntax: cast this to a const (always safe)
564 // call the method, cast the return back to non-const.
565 return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->FirstChild( _value ));
566 }
567
569 const TiXmlNode* LastChild() const { return lastChild; }
570
572 TiXmlNode* LastChild() { return lastChild; }
573
575 const TiXmlNode* LastChild( const char * value ) const;
576
578 TiXmlNode* LastChild( const char * _value ) {
579 return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->LastChild( _value ));
580 }
581
582 #ifdef TIXML_USE_STL
583
584 const TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); }
586 TiXmlNode* FirstChild( const std::string& _value ) { return FirstChild (_value.c_str ()); }
588 const TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); }
590 TiXmlNode* LastChild( const std::string& _value ) { return LastChild (_value.c_str ()); }
591 #endif
592
610 const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const;
611
613 TiXmlNode* IterateChildren( const TiXmlNode* previous ) {
614 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( previous ) );
615 }
616
618 const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const;
620 TiXmlNode* IterateChildren( const char * _value, const TiXmlNode* previous ) {
621 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( _value, previous ) );
622 }
623
624 #ifdef TIXML_USE_STL
625
626 const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const {
627 return IterateChildren (_value.c_str (), previous);
628 }
629
631 TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) {
632 return IterateChildren (_value.c_str (), previous);
633 }
634 #endif
635
640 TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
641
652 TiXmlNode* LinkEndChild( TiXmlNode* addThis );
653
658 TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
659
664 TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis );
665
670 TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
671
675 bool RemoveChild( TiXmlNode* removeThis );
676
680 const TiXmlNode* PreviousSibling() const { return prev; }
681
685 TiXmlNode* PreviousSibling() { return prev; }
686
688 const TiXmlNode* PreviousSibling( const char * ) const;
690 TiXmlNode* PreviousSibling( const char *_prev ) {
691 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->PreviousSibling( _prev ) );
692 }
693
694 #ifdef TIXML_USE_STL
695
696 const TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); }
698 TiXmlNode* PreviousSibling( const std::string& _value ) { return PreviousSibling (_value.c_str ()); }
700 const TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); }
702 TiXmlNode* NextSibling( const std::string& _value) { return NextSibling (_value.c_str ()); }
703 #endif
704
706 const TiXmlNode* NextSibling() const { return next; }
708 TiXmlNode* NextSibling() { return next; }
709
711 const TiXmlNode* NextSibling( const char * ) const;
713 TiXmlNode* NextSibling( const char* _next ) {
714 return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->NextSibling( _next ) );
715 }
716
723 const TiXmlElement* NextSiblingElement() const;
724
726 TiXmlElement* NextSiblingElement() {
727 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement() );
728 }
729
736 const TiXmlElement* NextSiblingElement( const char * ) const;
737
739 TiXmlElement* NextSiblingElement( const char *_next ) {
740 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement( _next ) );
741 }
742
743 #ifdef TIXML_USE_STL
744
745 const TiXmlElement* NextSiblingElement( const std::string& _value) const {
746 return NextSiblingElement (_value.c_str ());
747 }
749 TiXmlElement* NextSiblingElement( const std::string& _value) {
750 return NextSiblingElement (_value.c_str ());
751 }
752 #endif
753
755 const TiXmlElement* FirstChildElement() const;
757 TiXmlElement* FirstChildElement() {
758 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement() );
759 }
761 const TiXmlElement* FirstChildElement( const char * _value ) const;
763 TiXmlElement* FirstChildElement( const char * _value ) {
764 return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement( _value ) );
765 }
766
767 #ifdef TIXML_USE_STL
768
769 const TiXmlElement* FirstChildElement( const std::string& _value ) const {
770 return FirstChildElement (_value.c_str ());
771 }
772
774 TiXmlElement* FirstChildElement( const std::string& _value ) {
775 return FirstChildElement (_value.c_str ());
776 }
777 #endif
778
784 int Type() const { return type; }
785
790 const TiXmlDocument* GetDocument() const;
791
793 TiXmlDocument* GetDocument() {
794 return const_cast< TiXmlDocument* >( (const_cast< const TiXmlNode* >(this))->GetDocument() );
795 }
796
798 bool NoChildren() const { return !firstChild; }
800 virtual const TiXmlDocument* ToDocument() const { return 0; }
802 virtual const TiXmlElement* ToElement() const { return 0; }
804 virtual const TiXmlComment* ToComment() const { return 0; }
806 virtual const TiXmlUnknown* ToUnknown() const { return 0; }
808 virtual const TiXmlText* ToText() const { return 0; }
810 virtual const TiXmlDeclaration* ToDeclaration() const { return 0; }
811
813 virtual TiXmlDocument* ToDocument() { return 0; }
815 virtual TiXmlElement* ToElement() { return 0; }
817 virtual TiXmlComment* ToComment() { return 0; }
819 virtual TiXmlUnknown* ToUnknown() { return 0; }
821 virtual TiXmlText* ToText() { return 0; }
823 virtual TiXmlDeclaration* ToDeclaration() { return 0; }
824
829 virtual TiXmlNode* Clone() const = 0;
830
854 virtual bool Accept( TiXmlVisitor* visitor ) const = 0;
855
856 protected:
858 TiXmlNode( NodeType _type );
859
864 void CopyTo( TiXmlNode* target ) const;
865
866 #ifdef TIXML_USE_STL
867
868 virtual void StreamIn( std::istream* in, TIXML_STRING* tag ) = 0;
869 #endif
870
872 TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
873 #ifndef SKIP_DOCS
874 TiXmlNode* parent;
875 NodeType type;
876
877 TiXmlNode* firstChild;
878 TiXmlNode* lastChild;
879
880 TIXML_STRING value;
881
882 TiXmlNode* prev;
883 TiXmlNode* next;
884 #endif
885
886 private:
887 TiXmlNode( const TiXmlNode& ); // not implemented.
888 void operator=( const TiXmlNode& base ); // not allowed.
889 };
890
891
903 class EDELIB_API TiXmlAttribute : public TiXmlBase
904 {
905 friend class TiXmlAttributeSet;
906
907 public:
909 TiXmlAttribute() : TiXmlBase()
910 {
911 document = 0;
912 prev = next = 0;
913 }
914
915 #ifdef TIXML_USE_STL
916
917 TiXmlAttribute( const std::string& _name, const std::string& _value )
918 {
919 name = _name;
920 value = _value;
921 document = 0;
922 prev = next = 0;
923 }
924 #endif
925
927 TiXmlAttribute( const char * _name, const char * _value )
928 {
929 name = _name;
930 value = _value;
931 document = 0;
932 prev = next = 0;
933 }
934
936 const char* Name() const { return name.c_str(); }
938 const char* Value() const { return value.c_str(); }
939 #ifdef TIXML_USE_STL
940
941 const std::string& ValueStr() const { return value; }
942 #endif
943
944 int IntValue() const;
946 double DoubleValue() const;
947
949 const TIXML_STRING& NameTStr() const { return name; }
950
961 int QueryIntValue( int* _value ) const;
963 int QueryDoubleValue( double* _value ) const;
964
966 void SetName( const char* _name ) { name = _name; }
968 void SetValue( const char* _value ) { value = _value; }
969
971 void SetIntValue( int _value );
973 void SetDoubleValue( double _value );
974
975 #ifdef TIXML_USE_STL
976
977 void SetName( const std::string& _name ) { name = _name; }
979 void SetValue( const std::string& _value ) { value = _value; }
980 #endif
981
983 const TiXmlAttribute* Next() const;
985 TiXmlAttribute* Next() {
986 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Next() );
987 }
988
990 const TiXmlAttribute* Previous() const;
992 TiXmlAttribute* Previous() {
993 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Previous() );
994 }
995
997 bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
999 bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; }
1001 bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; }
1002
1007 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1008
1010 virtual void Print( FILE* cfile, int depth ) const {
1011 Print( cfile, depth, 0 );
1012 }
1014 void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
1015
1016 #ifndef SKIP_DOCS
1017 // [internal use]
1018 // Set the document pointer so the attribute can report errors.
1019 void SetDocument( TiXmlDocument* doc ) { document = doc; }
1020 #endif
1021
1022 private:
1023 TiXmlAttribute( const TiXmlAttribute& ); // not implemented.
1024 void operator=( const TiXmlAttribute& base ); // not allowed.
1025
1026 TiXmlDocument* document; // A pointer back to a document, for error reporting.
1027 TIXML_STRING name;
1028 TIXML_STRING value;
1029 TiXmlAttribute* prev;
1030 TiXmlAttribute* next;
1031 };
1032
1033 #ifndef SKIP_DOCS
1034
1047 class TiXmlAttributeSet
1048 {
1049 public:
1050 TiXmlAttributeSet();
1051 ~TiXmlAttributeSet();
1052
1053 void Add( TiXmlAttribute* attribute );
1054 void Remove( TiXmlAttribute* attribute );
1055
1056 const TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
1057 TiXmlAttribute* First() { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
1058 const TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
1059 TiXmlAttribute* Last() { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
1060
1061 const TiXmlAttribute* Find( const char* _name ) const;
1062 TiXmlAttribute* Find( const char* _name ) {
1063 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttributeSet* >(this))->Find( _name ) );
1064 }
1065 #ifdef TIXML_USE_STL
1066 const TiXmlAttribute* Find( const std::string& _name ) const;
1067 TiXmlAttribute* Find( const std::string& _name ) {
1068 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttributeSet* >(this))->Find( _name ) );
1069 }
1070 #endif
1071
1072 private:
1073 //*ME: Because of hidden/disabled copy-construktor in TiXmlAttribute (sentinel-element),
1074 //*ME: this class must be also use a hidden/disabled copy-constructor !!!
1075 TiXmlAttributeSet( const TiXmlAttributeSet& ); // not allowed
1076 void operator=( const TiXmlAttributeSet& ); // not allowed (as TiXmlAttribute)
1077
1078 TiXmlAttribute sentinel;
1079 };
1080
1081 #endif // SKIP_DOCS
1082
1083
1092 class EDELIB_API TiXmlElement : public TiXmlNode
1093 {
1094 public:
1096 TiXmlElement (const char * in_value);
1097
1098 #ifdef TIXML_USE_STL
1099
1100 TiXmlElement( const std::string& _value );
1101 #endif
1102
1104 TiXmlElement( const TiXmlElement& );
1105
1107 void operator=( const TiXmlElement& base );
1108
1110 virtual ~TiXmlElement();
1111
1116 const char* Attribute( const char* name ) const;
1117
1125 const char* Attribute( const char* name, int* i ) const;
1126
1134 const char* Attribute( const char* name, double* d ) const;
1135
1144 int QueryIntAttribute( const char* name, int* _value ) const;
1146 int QueryDoubleAttribute( const char* name, double* _value ) const;
1148 int QueryFloatAttribute( const char* name, float* _value ) const {
1149 double d;
1150 int result = QueryDoubleAttribute( name, &d );
1151 if ( result == TIXML_SUCCESS ) {
1152 *_value = (float)d;
1153 }
1154 return result;
1155 }
1156 #ifdef TIXML_USE_STL
1157
1164 template< typename T > int QueryValueAttribute( const std::string& name, T* outValue ) const
1165 {
1166 const TiXmlAttribute* node = attributeSet.Find( name );
1167 if ( !node )
1168 return TIXML_NO_ATTRIBUTE;
1169
1170 std::stringstream sstream( node->ValueStr() );
1171 sstream >> *outValue;
1172 if ( !sstream.fail() )
1173 return TIXML_SUCCESS;
1174 return TIXML_WRONG_TYPE;
1175 }
1176 #endif
1177
1182 void SetAttribute( const char* name, const char * _value );
1183
1184 #ifdef TIXML_USE_STL
1185
1186 const std::string* Attribute( const std::string& name ) const;
1188 const std::string* Attribute( const std::string& name, int* i ) const;
1190 const std::string* Attribute( const std::string& name, double* d ) const;
1192 int QueryIntAttribute( const std::string& name, int* _value ) const;
1194 int QueryDoubleAttribute( const std::string& name, double* _value ) const;
1195
1197 void SetAttribute( const std::string& name, const std::string& _value );
1199 void SetAttribute( const std::string& name, int _value );
1200 #endif
1201
1206 void SetAttribute( const char * name, int value );
1207
1212 void SetDoubleAttribute( const char * name, double value );
1213
1215 void RemoveAttribute( const char * name );
1216 #ifdef TIXML_USE_STL
1217
1218 void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); }
1219 #endif
1220
1222 const TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); }
1224 TiXmlAttribute* FirstAttribute() { return attributeSet.First(); }
1225
1227 const TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); }
1229 TiXmlAttribute* LastAttribute() { return attributeSet.Last(); }
1230
1264 const char* GetText() const;
1265
1267 virtual TiXmlNode* Clone() const;
1269 virtual void Print( FILE* cfile, int depth ) const;
1270
1275 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1276
1278 virtual const TiXmlElement* ToElement() const { return this; }
1280 virtual TiXmlElement* ToElement() { return this; }
1281
1283 virtual bool Accept( TiXmlVisitor* visitor ) const;
1284
1285 protected:
1286 #ifndef SKIP_DOCS
1287 void CopyTo( TiXmlElement* target ) const;
1288 void ClearThis(); // like clear, but initializes 'this' object as well
1289
1290 // Used to be public [internal use]
1291 #ifdef TIXML_USE_STL
1292 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1293 #endif
1294
1299 const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding );
1300 #endif
1301
1302 private:
1303
1304 TiXmlAttributeSet attributeSet;
1305 };
1306
1307
1312 class EDELIB_API TiXmlComment : public TiXmlNode
1313 {
1314 public:
1316 TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
1318 TiXmlComment( const char* _value ) : TiXmlNode( TiXmlNode::COMMENT ) {
1319 SetValue( _value );
1320 }
1322 TiXmlComment( const TiXmlComment& );
1324 void operator=( const TiXmlComment& base );
1325
1327 virtual ~TiXmlComment() {}
1328
1330 virtual TiXmlNode* Clone() const;
1332 virtual void Print( FILE* cfile, int depth ) const;
1333
1338 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1339
1341 virtual const TiXmlComment* ToComment() const { return this; }
1343 virtual TiXmlComment* ToComment() { return this; }
1344
1346 virtual bool Accept( TiXmlVisitor* visitor ) const;
1347
1348 protected:
1349 #ifndef SKIP_DOCS
1350 void CopyTo( TiXmlComment* target ) const;
1351
1352 // used to be public
1353 #ifdef TIXML_USE_STL
1354 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1355 #endif
1356 // virtual void StreamOut( TIXML_OSTREAM * out ) const;
1357 #endif
1358
1359 };
1360
1361
1371 class EDELIB_API TiXmlText : public TiXmlNode
1372 {
1373 friend class TiXmlElement;
1374 public:
1380 TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TEXT)
1381 {
1382 SetValue( initValue );
1383 cdata = false;
1384 }
1385 virtual ~TiXmlText() {}
1386
1387 #ifdef TIXML_USE_STL
1388
1389 TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
1390 {
1391 SetValue( initValue );
1392 cdata = false;
1393 }
1394 #endif
1395
1396 TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT ) { copy.CopyTo( this ); }
1398 void operator=( const TiXmlText& base ) { base.CopyTo( this ); }
1399
1401 virtual void Print( FILE* cfile, int depth ) const;
1402
1404 bool CDATA() const { return cdata; }
1406 void SetCDATA( bool _cdata ) { cdata = _cdata; }
1407
1408 #ifndef SKIP_DOCS
1409 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1410 #endif
1411
1412 virtual const TiXmlText* ToText() const { return this; }
1414 virtual TiXmlText* ToText() { return this; }
1415
1417 virtual bool Accept( TiXmlVisitor* content ) const;
1418
1419 protected :
1420 #ifndef SKIP_DOCS
1421
1422 virtual TiXmlNode* Clone() const;
1423 void CopyTo( TiXmlText* target ) const;
1424
1425 bool Blank() const; // returns true if all white space and new lines
1426 // [internal use]
1427 #ifdef TIXML_USE_STL
1428 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1429 #endif
1430
1431 #endif
1432
1433 private:
1434 bool cdata; // true if this should be input and output as a CDATA style text element
1435 };
1436
1437
1455 class EDELIB_API TiXmlDeclaration : public TiXmlNode
1456 {
1457 public:
1459 TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {}
1460
1461 #ifdef TIXML_USE_STL
1462
1463 TiXmlDeclaration( const std::string& _version,
1464 const std::string& _encoding,
1465 const std::string& _standalone );
1466 #endif
1467
1469 TiXmlDeclaration( const char* _version,
1470 const char* _encoding,
1471 const char* _standalone );
1472
1474 TiXmlDeclaration( const TiXmlDeclaration& copy );
1476 void operator=( const TiXmlDeclaration& copy );
1477
1478 #ifndef SKIP_DOCS
1479 virtual ~TiXmlDeclaration() {}
1480 #endif
1481
1483 const char *Version() const { return version.c_str (); }
1485 const char *Encoding() const { return encoding.c_str (); }
1487 const char *Standalone() const { return standalone.c_str (); }
1488
1490 virtual TiXmlNode* Clone() const;
1491
1493 virtual void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
1495 virtual void Print( FILE* cfile, int depth ) const {
1496 Print( cfile, depth, 0 );
1497 }
1498 #ifndef SKIP_DOCS
1499 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1500 #endif
1501
1502 virtual const TiXmlDeclaration* ToDeclaration() const { return this; }
1504 virtual TiXmlDeclaration* ToDeclaration() { return this; }
1505
1507 virtual bool Accept( TiXmlVisitor* visitor ) const;
1508
1509 protected:
1510 #ifndef SKIP_DOCS
1511 void CopyTo( TiXmlDeclaration* target ) const;
1512 // used to be public
1513 #ifdef TIXML_USE_STL
1514 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1515 #endif
1516
1517 #endif
1518
1519 private:
1520
1521 TIXML_STRING version;
1522 TIXML_STRING encoding;
1523 TIXML_STRING standalone;
1524 };
1525
1526
1538 class TiXmlUnknown : public TiXmlNode
1539 {
1540 public:
1542 TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
1543 #ifndef SKIP_DOCS
1544 virtual ~TiXmlUnknown() {}
1545 #endif
1546
1548 TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNKNOWN ) { copy.CopyTo( this ); }
1550 void operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); }
1551
1553 virtual TiXmlNode* Clone() const;
1555 virtual void Print( FILE* cfile, int depth ) const;
1556 #ifndef SKIP_DOCS
1557 virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1558 #endif
1559
1560 virtual const TiXmlUnknown* ToUnknown() const { return this; }
1562 virtual TiXmlUnknown* ToUnknown() { return this; }
1563
1565 virtual bool Accept( TiXmlVisitor* content ) const;
1566
1567 protected:
1568 #ifndef SKIP_DOCS
1569 void CopyTo( TiXmlUnknown* target ) const;
1570
1571 #ifdef TIXML_USE_STL
1572 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1573 #endif
1574
1575 #endif
1576
1577 private:
1578
1579 };
1580
1581
1590 class EDELIB_API TiXmlDocument : public TiXmlNode
1591 {
1592 public:
1594 TiXmlDocument();
1596 TiXmlDocument( const char * documentName );
1597
1598 #ifdef TIXML_USE_STL
1599
1600 TiXmlDocument( const std::string& documentName );
1601 #endif
1602
1604 TiXmlDocument( const TiXmlDocument& copy );
1606 void operator=( const TiXmlDocument& copy );
1607
1608 #ifndef SKIP_DOCS
1609 virtual ~TiXmlDocument() {}
1610 #endif
1611
1617 bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1619 bool SaveFile() const;
1621 bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1623 bool SaveFile( const char * filename ) const;
1630 bool LoadFile( FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1632 bool SaveFile( FILE* ) const;
1633
1634 #ifdef TIXML_USE_STL
1635
1636 bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING )
1637 {
1638 return LoadFile( filename.c_str(), encoding );
1639 }
1640
1642 bool SaveFile( const std::string& filename ) const
1643 {
1644 return SaveFile( filename.c_str() );
1645 }
1646 #endif
1647
1653 virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
1654
1660 const TiXmlElement* RootElement() const { return FirstChildElement(); }
1662 TiXmlElement* RootElement() { return FirstChildElement(); }
1663
1670 bool Error() const { return error; }
1671
1673 const char * ErrorDesc() const { return errorDesc.c_str (); }
1674
1679 int ErrorId() const { return errorId; }
1680
1689 int ErrorRow() const { return errorLocation.row+1; }
1690
1692 int ErrorCol() const { return errorLocation.col+1; }
1693
1719 void SetTabSize( int _tabsize ) { tabsize = _tabsize; }
1720
1722 int TabSize() const { return tabsize; }
1723
1728 void ClearError() { error = false;
1729 errorId = 0;
1730 errorDesc = "";
1731 errorLocation.row = errorLocation.col = 0;
1732 //errorLocation.last = 0;
1733 }
1734
1736 void Print() const { Print( stdout, 0 ); }
1737
1743 //char* PrintToMemory() const;
1744
1746 virtual void Print( FILE* cfile, int depth = 0 ) const;
1747 #ifndef SKIP_DOCS
1748 // [internal use]
1749 void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );
1750 #endif
1751
1752 virtual const TiXmlDocument* ToDocument() const { return this; }
1754 virtual TiXmlDocument* ToDocument() { return this; }
1755
1757 virtual bool Accept( TiXmlVisitor* content ) const;
1758
1759 protected :
1760 #ifndef SKIP_DOCS
1761 // [internal use]
1762 virtual TiXmlNode* Clone() const;
1763 #ifdef TIXML_USE_STL
1764 virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1765 #endif
1766
1767 #endif
1768
1769 private:
1770 void CopyTo( TiXmlDocument* target ) const;
1771
1772 bool error;
1773 int errorId;
1774 TIXML_STRING errorDesc;
1775 int tabsize;
1776 TiXmlCursor errorLocation;
1777 bool useMicrosoftBOM; // the UTF-8 BOM were found when read. Note this, and try to write.
1778 };
1779
1780
1866 class EDELIB_API TiXmlHandle
1867 {
1868 public:
1870 TiXmlHandle( TiXmlNode* _node ) { this->node = _node; }
1872 TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; }
1874 TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.node; return *this; }
1875
1877 TiXmlHandle FirstChild() const;
1879 TiXmlHandle FirstChild( const char * value ) const;
1881 TiXmlHandle FirstChildElement() const;
1883 TiXmlHandle FirstChildElement( const char * value ) const;
1884
1889 TiXmlHandle Child( const char* value, int index ) const;
1894 TiXmlHandle Child( int index ) const;
1900 TiXmlHandle ChildElement( const char* value, int index ) const;
1906 TiXmlHandle ChildElement( int index ) const;
1907
1908 #ifdef TIXML_USE_STL
1909
1910 TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); }
1912 TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); }
1913
1915 TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); }
1917 TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); }
1918 #endif
1919
1921 TiXmlNode* ToNode() const { return node; }
1923 TiXmlElement* ToElement() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
1925 TiXmlText* ToText() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
1927 TiXmlUnknown* ToUnknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
1928
1933 TiXmlNode* Node() const { return ToNode(); }
1938 TiXmlElement* Element() const { return ToElement(); }
1943 TiXmlText* Text() const { return ToText(); }
1948 TiXmlUnknown* Unknown() const { return ToUnknown(); }
1949
1950 private:
1951 TiXmlNode* node;
1952 };
1953
1954
1978 class TiXmlPrinter : public TiXmlVisitor
1979 {
1980 public:
1982 TiXmlPrinter() : depth( 0 ), simpleTextPrint( false ),
1983 buffer(), indent( " " ), lineBreak( "\n" ) {}
1984 #ifndef SKIP_DOCS
1985 virtual bool VisitEnter( const TiXmlDocument& doc );
1986 virtual bool VisitExit( const TiXmlDocument& doc );
1987
1988 virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute );
1989 virtual bool VisitExit( const TiXmlElement& element );
1990
1991 virtual bool Visit( const TiXmlDeclaration& declaration );
1992 virtual bool Visit( const TiXmlText& text );
1993 virtual bool Visit( const TiXmlComment& comment );
1994 virtual bool Visit( const TiXmlUnknown& unknown );
1995 #endif
1996
2001 void SetIndent( const char* _indent ) { indent = _indent ? _indent : "" ; }
2003 const char* Indent() { return indent.c_str(); }
2004
2010 void SetLineBreak( const char* _lineBreak ) { lineBreak = _lineBreak ? _lineBreak : ""; }
2011
2013 const char* LineBreak() { return lineBreak.c_str(); }
2014
2019 void SetStreamPrinting() { indent = ""; lineBreak = ""; }
2021 const char* CStr() { return buffer.c_str(); }
2023 size_t Size() { return buffer.length(); }
2024
2025 #ifdef TIXML_USE_STL
2026
2027 const std::string& Str() { return buffer; }
2028 #endif
2029
2030 private:
2031 void DoIndent() {
2032 for( int i=0; i<depth; ++i )
2033 buffer += indent;
2034 }
2035 void DoLineBreak() {
2036 buffer += lineBreak;
2037 }
2038
2039 int depth;
2040 bool simpleTextPrint;
2041 TIXML_STRING buffer;
2042 TIXML_STRING indent;
2043 TIXML_STRING lineBreak;
2044 };
2045
2046
2047 #ifdef _MSC_VER
2048 #pragma warning( pop )
2049 #endif
2050
2051 #endif