123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776 |
- #ifndef TINYXML_INCLUDED
- #define TINYXML_INCLUDED
- #ifdef _MSC_VER
- #pragma warning( push )
- #pragma warning( disable : 4530 )
- #pragma warning( disable : 4786 )
- #endif
- #include <ctype.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <assert.h>
- #if defined( _DEBUG ) && !defined( DEBUG )
- #define DEBUG
- #endif
- #ifdef TIXML_USE_STL
- #include <string>
- #include <iostream>
- #include <sstream>
- #define TIXML_STRING std::string
- #else
- #include "tinystr.h"
- #define TIXML_STRING TiXmlString
- #endif
- #define TIXML_SAFE
- #ifdef TIXML_SAFE
- #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
-
- #define TIXML_SNPRINTF _snprintf_s
- #define TIXML_SNSCANF _snscanf_s
- #elif defined(_MSC_VER) && (_MSC_VER >= 1200 )
-
-
- #define TIXML_SNPRINTF _snprintf
- #define TIXML_SNSCANF _snscanf
- #elif defined(__GNUC__) && (__GNUC__ >= 3 )
-
-
- #define TIXML_SNPRINTF snprintf
- #define TIXML_SNSCANF snscanf
- #endif
- #endif
- class TiXmlDocument;
- class TiXmlElement;
- class TiXmlComment;
- class TiXmlUnknown;
- class TiXmlAttribute;
- class TiXmlText;
- class TiXmlDeclaration;
- class TiXmlParsingData;
- const int TIXML_MAJOR_VERSION = 2;
- const int TIXML_MINOR_VERSION = 5;
- const int TIXML_PATCH_VERSION = 1;
- struct TiXmlCursor
- {
- TiXmlCursor() { Clear(); }
- void Clear() { row = col = -1; }
- int row;
- int col;
- };
- class TiXmlVisitor
- {
- public:
- virtual ~TiXmlVisitor() {}
-
- virtual bool VisitEnter( const TiXmlDocument& doc ) { return true; }
-
- virtual bool VisitExit( const TiXmlDocument& doc ) { return true; }
-
- virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute ) { return true; }
-
- virtual bool VisitExit( const TiXmlElement& element ) { return true; }
-
- virtual bool Visit( const TiXmlDeclaration& declaration ) { return true; }
-
- virtual bool Visit( const TiXmlText& text ) { return true; }
-
- virtual bool Visit( const TiXmlComment& comment ) { return true; }
-
- virtual bool Visit( const TiXmlUnknown& unknown ) { return true; }
- };
- enum
- {
- TIXML_SUCCESS,
- TIXML_NO_ATTRIBUTE,
- TIXML_WRONG_TYPE
- };
- enum TiXmlEncoding
- {
- TIXML_ENCODING_UNKNOWN,
- TIXML_ENCODING_UTF8,
- TIXML_ENCODING_LEGACY
- };
- const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
- class TiXmlBase
- {
- friend class TiXmlNode;
- friend class TiXmlElement;
- friend class TiXmlDocument;
- public:
- TiXmlBase() : userData(0) {}
- virtual ~TiXmlBase() {}
-
- virtual void Print( FILE* cfile, int depth ) const = 0;
-
- static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; }
-
- static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; }
-
- int Row() const { return location.row + 1; }
- int Column() const { return location.col + 1; }
- void SetUserData( void* user ) { userData = user; }
- void* GetUserData() { return userData; }
- const void* GetUserData() const { return userData; }
-
-
- static const int utf8ByteTable[256];
- virtual const char* Parse( const char* p,
- TiXmlParsingData* data,
- TiXmlEncoding encoding ) = 0;
- enum
- {
- TIXML_NO_ERROR = 0,
- TIXML_ERROR,
- TIXML_ERROR_OPENING_FILE,
- TIXML_ERROR_OUT_OF_MEMORY,
- TIXML_ERROR_PARSING_ELEMENT,
- TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
- TIXML_ERROR_READING_ELEMENT_VALUE,
- TIXML_ERROR_READING_ATTRIBUTES,
- TIXML_ERROR_PARSING_EMPTY,
- TIXML_ERROR_READING_END_TAG,
- TIXML_ERROR_PARSING_UNKNOWN,
- TIXML_ERROR_PARSING_COMMENT,
- TIXML_ERROR_PARSING_DECLARATION,
- TIXML_ERROR_DOCUMENT_EMPTY,
- TIXML_ERROR_EMBEDDED_NULL,
- TIXML_ERROR_PARSING_CDATA,
- TIXML_ERROR_DOCUMENT_TOP_ONLY,
- TIXML_ERROR_STRING_COUNT
- };
- protected:
- static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding );
- inline static bool IsWhiteSpace( char c )
- {
- return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' );
- }
- inline static bool IsWhiteSpace( int c )
- {
- if ( c < 256 )
- return IsWhiteSpace( (char) c );
- return false;
- }
- #ifdef TIXML_USE_STL
- static bool StreamWhiteSpace( std::istream * in, TIXML_STRING * tag );
- static bool StreamTo( std::istream * in, int character, TIXML_STRING * tag );
- #endif
-
- static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding );
-
- static const char* ReadText( const char* in,
- TIXML_STRING* text,
- bool ignoreWhiteSpace,
- const char* endTag,
- bool ignoreCase,
- TiXmlEncoding encoding );
-
- static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding );
-
-
- inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding )
- {
- assert( p );
- if ( encoding == TIXML_ENCODING_UTF8 )
- {
- *length = utf8ByteTable[ *((const unsigned char*)p) ];
- assert( *length >= 0 && *length < 5 );
- }
- else
- {
- *length = 1;
- }
- if ( *length == 1 )
- {
- if ( *p == '&' )
- return GetEntity( p, _value, length, encoding );
- *_value = *p;
- return p+1;
- }
- else if ( *length )
- {
-
-
- for( int i=0; p[i] && i<*length; ++i ) {
- _value[i] = p[i];
- }
- return p + (*length);
- }
- else
- {
-
- return 0;
- }
- }
-
-
- static void PutString( const TIXML_STRING& str, TIXML_STRING* out );
-
-
-
- static bool StringEqual( const char* p,
- const char* endTag,
- bool ignoreCase,
- TiXmlEncoding encoding );
- static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
- TiXmlCursor location;
-
- void* userData;
-
-
-
- static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding );
- static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding );
- inline static int ToLower( int v, TiXmlEncoding encoding )
- {
- if ( encoding == TIXML_ENCODING_UTF8 )
- {
- if ( v < 128 ) return tolower( v );
- return v;
- }
- else
- {
- return tolower( v );
- }
- }
- static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
- private:
- TiXmlBase( const TiXmlBase& );
- void operator=( const TiXmlBase& base );
- struct Entity
- {
- const char* str;
- unsigned int strLength;
- char chr;
- };
- enum
- {
- NUM_ENTITY = 5,
- MAX_ENTITY_LENGTH = 6
- };
- static Entity entity[ NUM_ENTITY ];
- static bool condenseWhiteSpace;
- };
- class TiXmlNode : public TiXmlBase
- {
- friend class TiXmlDocument;
- friend class TiXmlElement;
- public:
- #ifdef TIXML_USE_STL
-
- friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
-
-
- friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
-
- friend std::string& operator<< (std::string& out, const TiXmlNode& base );
- #endif
-
- enum NodeType
- {
- DOCUMENT,
- ELEMENT,
- COMMENT,
- UNKNOWN,
- TEXT,
- DECLARATION,
- TYPECOUNT
- };
- virtual ~TiXmlNode();
-
- const char *Value() const { return value.c_str (); }
- #ifdef TIXML_USE_STL
-
- const std::string& ValueStr() const { return value; }
- #endif
-
- void SetValue(const char * _value) { value = _value;}
- #ifdef TIXML_USE_STL
-
- void SetValue( const std::string& _value ) { value = _value; }
- #endif
-
- void Clear();
-
- TiXmlNode* Parent() { return parent; }
- const TiXmlNode* Parent() const { return parent; }
- const TiXmlNode* FirstChild() const { return firstChild; }
- TiXmlNode* FirstChild() { return firstChild; }
- const TiXmlNode* FirstChild( const char * value ) const;
-
- TiXmlNode* FirstChild( const char * _value ) {
-
-
- return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->FirstChild( _value ));
- }
- const TiXmlNode* LastChild() const { return lastChild; }
- TiXmlNode* LastChild() { return lastChild; }
-
- const TiXmlNode* LastChild( const char * value ) const;
- TiXmlNode* LastChild( const char * _value ) {
- return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->LastChild( _value ));
- }
- #ifdef TIXML_USE_STL
- const TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); }
- TiXmlNode* FirstChild( const std::string& _value ) { return FirstChild (_value.c_str ()); }
- const TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); }
- TiXmlNode* LastChild( const std::string& _value ) { return LastChild (_value.c_str ()); }
- #endif
-
- const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const;
- TiXmlNode* IterateChildren( TiXmlNode* previous ) {
- return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( previous ) );
- }
-
- const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const;
- TiXmlNode* IterateChildren( const char * _value, TiXmlNode* previous ) {
- return const_cast< TiXmlNode* >( const_cast< const TiXmlNode* >(this)->IterateChildren( _value, previous ) );
- }
- #ifdef TIXML_USE_STL
- const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); }
- TiXmlNode* IterateChildren( const std::string& _value, TiXmlNode* previous ) { return IterateChildren (_value.c_str (), previous); }
- #endif
-
- TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
-
- TiXmlNode* LinkEndChild( TiXmlNode* addThis );
-
- TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
-
- TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis );
-
- TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
-
- bool RemoveChild( TiXmlNode* removeThis );
-
- const TiXmlNode* PreviousSibling() const { return prev; }
- TiXmlNode* PreviousSibling() { return prev; }
-
- const TiXmlNode* PreviousSibling( const char * ) const;
- TiXmlNode* PreviousSibling( const char *_prev ) {
- return const_cast< TiXmlNode* >( const_cast< const TiXmlNode* >(this)->PreviousSibling( _prev ) );
- }
- #ifdef TIXML_USE_STL
- const TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); }
- TiXmlNode* PreviousSibling( const std::string& _value ) { return PreviousSibling (_value.c_str ()); }
- const TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); }
- TiXmlNode* NextSibling( const std::string& _value) { return NextSibling (_value.c_str ()); }
- #endif
-
- const TiXmlNode* NextSibling() const { return next; }
- TiXmlNode* NextSibling() { return next; }
-
- const TiXmlNode* NextSibling( const char * ) const;
- TiXmlNode* NextSibling( const char* _next ) {
- return const_cast< TiXmlNode* >( const_cast< const TiXmlNode* >(this)->NextSibling( _next ) );
- }
-
- const TiXmlElement* NextSiblingElement() const;
- TiXmlElement* NextSiblingElement() {
- return const_cast< TiXmlElement* >( const_cast< const TiXmlNode* >(this)->NextSiblingElement() );
- }
-
- const TiXmlElement* NextSiblingElement( const char * ) const;
- TiXmlElement* NextSiblingElement( const char *_next ) {
- return const_cast< TiXmlElement* >( const_cast< const TiXmlNode* >(this)->NextSiblingElement( _next ) );
- }
- #ifdef TIXML_USE_STL
- const TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); }
- TiXmlElement* NextSiblingElement( const std::string& _value) { return NextSiblingElement (_value.c_str ()); }
- #endif
-
- const TiXmlElement* FirstChildElement() const;
- TiXmlElement* FirstChildElement() {
- return const_cast< TiXmlElement* >( const_cast< const TiXmlNode* >(this)->FirstChildElement() );
- }
-
- const TiXmlElement* FirstChildElement( const char * _value ) const;
- TiXmlElement* FirstChildElement( const char * _value ) {
- return const_cast< TiXmlElement* >( const_cast< const TiXmlNode* >(this)->FirstChildElement( _value ) );
- }
- #ifdef TIXML_USE_STL
- const TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); }
- TiXmlElement* FirstChildElement( const std::string& _value ) { return FirstChildElement (_value.c_str ()); }
- #endif
-
- int Type() const { return type; }
-
- const TiXmlDocument* GetDocument() const;
- TiXmlDocument* GetDocument() {
- return const_cast< TiXmlDocument* >( const_cast< const TiXmlNode* >(this)->GetDocument() );
- }
-
- bool NoChildren() const { return !firstChild; }
- virtual const TiXmlDocument* ToDocument() const { return 0; }
- virtual const TiXmlElement* ToElement() const { return 0; }
- virtual const TiXmlComment* ToComment() const { return 0; }
- virtual const TiXmlUnknown* ToUnknown() const { return 0; }
- virtual const TiXmlText* ToText() const { return 0; }
- virtual const TiXmlDeclaration* ToDeclaration() const { return 0; }
- virtual TiXmlDocument* ToDocument() { return 0; }
- virtual TiXmlElement* ToElement() { return 0; }
- virtual TiXmlComment* ToComment() { return 0; }
- virtual TiXmlUnknown* ToUnknown() { return 0; }
- virtual TiXmlText* ToText() { return 0; }
- virtual TiXmlDeclaration* ToDeclaration() { return 0; }
-
- virtual TiXmlNode* Clone() const = 0;
-
- virtual bool Accept( TiXmlVisitor* visitor ) const = 0;
- protected:
- TiXmlNode( NodeType _type );
-
-
- void CopyTo( TiXmlNode* target ) const;
- #ifdef TIXML_USE_STL
-
- virtual void StreamIn( std::istream* in, TIXML_STRING* tag ) = 0;
- #endif
-
- TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
- TiXmlNode* parent;
- NodeType type;
- TiXmlNode* firstChild;
- TiXmlNode* lastChild;
- TIXML_STRING value;
- TiXmlNode* prev;
- TiXmlNode* next;
- private:
- TiXmlNode( const TiXmlNode& );
- void operator=( const TiXmlNode& base );
- };
- class TiXmlAttribute : public TiXmlBase
- {
- friend class TiXmlAttributeSet;
- public:
-
- TiXmlAttribute() : TiXmlBase()
- {
- document = 0;
- prev = next = 0;
- }
- #ifdef TIXML_USE_STL
-
- TiXmlAttribute( const std::string& _name, const std::string& _value )
- {
- name = _name;
- value = _value;
- document = 0;
- prev = next = 0;
- }
- #endif
-
- TiXmlAttribute( const char * _name, const char * _value )
- {
- name = _name;
- value = _value;
- document = 0;
- prev = next = 0;
- }
- const char* Name() const { return name.c_str(); }
- const char* Value() const { return value.c_str(); }
- #ifdef TIXML_USE_STL
- const std::string& ValueStr() const { return value; }
- #endif
- int IntValue() const;
- double DoubleValue() const;
-
- const TIXML_STRING& NameTStr() const { return name; }
-
- int QueryIntValue( int* _value ) const;
-
- int QueryDoubleValue( double* _value ) const;
- void SetName( const char* _name ) { name = _name; }
- void SetValue( const char* _value ) { value = _value; }
- void SetIntValue( int _value );
- void SetDoubleValue( double _value );
- #ifdef TIXML_USE_STL
-
- void SetName( const std::string& _name ) { name = _name; }
-
- void SetValue( const std::string& _value ) { value = _value; }
- #endif
-
- const TiXmlAttribute* Next() const;
- TiXmlAttribute* Next() {
- return const_cast< TiXmlAttribute* >( const_cast< const TiXmlAttribute* >(this)->Next() );
- }
-
- const TiXmlAttribute* Previous() const;
- TiXmlAttribute* Previous() {
- return const_cast< TiXmlAttribute* >( const_cast< const TiXmlAttribute* >(this)->Previous() );
- }
- bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
- bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; }
- bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; }
-
- virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
-
- virtual void Print( FILE* cfile, int depth ) const {
- Print( cfile, depth, 0 );
- }
- void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
-
-
- void SetDocument( TiXmlDocument* doc ) { document = doc; }
- private:
- TiXmlAttribute( const TiXmlAttribute& );
- void operator=( const TiXmlAttribute& base );
- TiXmlDocument* document;
- TIXML_STRING name;
- TIXML_STRING value;
- TiXmlAttribute* prev;
- TiXmlAttribute* next;
- };
- class TiXmlAttributeSet
- {
- public:
- TiXmlAttributeSet();
- ~TiXmlAttributeSet();
- void Add( TiXmlAttribute* attribute );
- void Remove( TiXmlAttribute* attribute );
- const TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
- TiXmlAttribute* First() { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
- const TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
- TiXmlAttribute* Last() { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
- const TiXmlAttribute* Find( const char* _name ) const;
- TiXmlAttribute* Find( const char* _name ) {
- return const_cast< TiXmlAttribute* >( const_cast< const TiXmlAttributeSet* >(this)->Find( _name ) );
- }
- #ifdef TIXML_USE_STL
- const TiXmlAttribute* Find( const std::string& _name ) const;
- TiXmlAttribute* Find( const std::string& _name ) {
- return const_cast< TiXmlAttribute* >( const_cast< const TiXmlAttributeSet* >(this)->Find( _name ) );
- }
- #endif
- private:
-
-
- TiXmlAttributeSet( const TiXmlAttributeSet& );
- void operator=( const TiXmlAttributeSet& );
- TiXmlAttribute sentinel;
- };
- class TiXmlElement : public TiXmlNode
- {
- public:
-
- TiXmlElement (const char * in_value);
- #ifdef TIXML_USE_STL
-
- TiXmlElement( const std::string& _value );
- #endif
- TiXmlElement( const TiXmlElement& );
- void operator=( const TiXmlElement& base );
- virtual ~TiXmlElement();
-
- const char* Attribute( const char* name ) const;
-
- const char* Attribute( const char* name, int* i ) const;
-
- const char* Attribute( const char* name, double* d ) const;
-
-
- int QueryIntAttribute( const char* name, int* _value ) const;
-
- int QueryDoubleAttribute( const char* name, double* _value ) const;
-
- int QueryFloatAttribute( const char* name, float* _value ) const {
- double d;
- int result = QueryDoubleAttribute( name, &d );
- if ( result == TIXML_SUCCESS ) {
- *_value = (float)d;
- }
- return result;
- }
- #ifdef TIXML_USE_STL
-
- template< typename T > int QueryValueAttribute( const std::string& name, T* outValue ) const
- {
- const TiXmlAttribute* node = attributeSet.Find( name );
- if ( !node )
- return TIXML_NO_ATTRIBUTE;
- std::stringstream sstream( node->ValueStr() );
- sstream >> *outValue;
- if ( !sstream.fail() )
- return TIXML_SUCCESS;
- return TIXML_WRONG_TYPE;
- }
- #endif
-
- void SetAttribute( const char* name, const char * _value );
- #ifdef TIXML_USE_STL
- const std::string* Attribute( const std::string& name ) const;
- const std::string* Attribute( const std::string& name, int* i ) const;
- const std::string* Attribute( const std::string& name, double* d ) const;
- int QueryIntAttribute( const std::string& name, int* _value ) const;
- int QueryDoubleAttribute( const std::string& name, double* _value ) const;
-
- void SetAttribute( const std::string& name, const std::string& _value );
-
- void SetAttribute( const std::string& name, int _value );
- #endif
-
- void SetAttribute( const char * name, int value );
-
- void SetDoubleAttribute( const char * name, double value );
-
- void RemoveAttribute( const char * name );
- #ifdef TIXML_USE_STL
- void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); }
- #endif
- const TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); }
- TiXmlAttribute* FirstAttribute() { return attributeSet.First(); }
- const TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); }
- TiXmlAttribute* LastAttribute() { return attributeSet.Last(); }
-
- const char* GetText() const;
-
- virtual TiXmlNode* Clone() const;
-
- virtual void Print( FILE* cfile, int depth ) const;
-
- virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
- virtual const TiXmlElement* ToElement() const { return this; }
- virtual TiXmlElement* ToElement() { return this; }
-
- virtual bool Accept( TiXmlVisitor* visitor ) const;
- protected:
- void CopyTo( TiXmlElement* target ) const;
- void ClearThis();
-
- #ifdef TIXML_USE_STL
- virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
- #endif
-
- const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding );
- private:
- TiXmlAttributeSet attributeSet;
- };
- class TiXmlComment : public TiXmlNode
- {
- public:
-
- TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
-
- TiXmlComment( const char* _value ) : TiXmlNode( TiXmlNode::COMMENT ) {
- SetValue( _value );
- }
- TiXmlComment( const TiXmlComment& );
- void operator=( const TiXmlComment& base );
- virtual ~TiXmlComment() {}
-
- virtual TiXmlNode* Clone() const;
-
- virtual void Print( FILE* cfile, int depth ) const;
-
- virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
- virtual const TiXmlComment* ToComment() const { return this; }
- virtual TiXmlComment* ToComment() { return this; }
-
- virtual bool Accept( TiXmlVisitor* visitor ) const;
- protected:
- void CopyTo( TiXmlComment* target ) const;
-
- #ifdef TIXML_USE_STL
- virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
- #endif
- private:
- };
- class TiXmlText : public TiXmlNode
- {
- friend class TiXmlElement;
- public:
-
- TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TEXT)
- {
- SetValue( initValue );
- cdata = false;
- }
- virtual ~TiXmlText() {}
- #ifdef TIXML_USE_STL
-
- TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
- {
- SetValue( initValue );
- cdata = false;
- }
- #endif
- TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT ) { copy.CopyTo( this ); }
- void operator=( const TiXmlText& base ) { base.CopyTo( this ); }
-
- virtual void Print( FILE* cfile, int depth ) const;
-
- bool CDATA() const { return cdata; }
-
- void SetCDATA( bool _cdata ) { cdata = _cdata; }
- virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
- virtual const TiXmlText* ToText() const { return this; }
- virtual TiXmlText* ToText() { return this; }
-
- virtual bool Accept( TiXmlVisitor* content ) const;
- protected :
-
- virtual TiXmlNode* Clone() const;
- void CopyTo( TiXmlText* target ) const;
- bool Blank() const;
-
- #ifdef TIXML_USE_STL
- virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
- #endif
- private:
- bool cdata;
- };
- class TiXmlDeclaration : public TiXmlNode
- {
- public:
-
- TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {}
- #ifdef TIXML_USE_STL
-
- TiXmlDeclaration( const std::string& _version,
- const std::string& _encoding,
- const std::string& _standalone );
- #endif
-
- TiXmlDeclaration( const char* _version,
- const char* _encoding,
- const char* _standalone );
- TiXmlDeclaration( const TiXmlDeclaration& copy );
- void operator=( const TiXmlDeclaration& copy );
- virtual ~TiXmlDeclaration() {}
-
- const char *Version() const { return version.c_str (); }
-
- const char *Encoding() const { return encoding.c_str (); }
-
- const char *Standalone() const { return standalone.c_str (); }
-
- virtual TiXmlNode* Clone() const;
-
- virtual void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
- virtual void Print( FILE* cfile, int depth ) const {
- Print( cfile, depth, 0 );
- }
- virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
- virtual const TiXmlDeclaration* ToDeclaration() const { return this; }
- virtual TiXmlDeclaration* ToDeclaration() { return this; }
-
- virtual bool Accept( TiXmlVisitor* visitor ) const;
- protected:
- void CopyTo( TiXmlDeclaration* target ) const;
-
- #ifdef TIXML_USE_STL
- virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
- #endif
- private:
- TIXML_STRING version;
- TIXML_STRING encoding;
- TIXML_STRING standalone;
- };
- class TiXmlUnknown : public TiXmlNode
- {
- public:
- TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
- virtual ~TiXmlUnknown() {}
- TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNKNOWN ) { copy.CopyTo( this ); }
- void operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); }
-
- virtual TiXmlNode* Clone() const;
-
- virtual void Print( FILE* cfile, int depth ) const;
- virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
- virtual const TiXmlUnknown* ToUnknown() const { return this; }
- virtual TiXmlUnknown* ToUnknown() { return this; }
-
- virtual bool Accept( TiXmlVisitor* content ) const;
- protected:
- void CopyTo( TiXmlUnknown* target ) const;
- #ifdef TIXML_USE_STL
- virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
- #endif
- private:
- };
- class TiXmlDocument : public TiXmlNode
- {
- public:
-
- TiXmlDocument();
-
- TiXmlDocument( const char * documentName );
- #ifdef TIXML_USE_STL
-
- TiXmlDocument( const std::string& documentName );
- #endif
- TiXmlDocument( const TiXmlDocument& copy );
- void operator=( const TiXmlDocument& copy );
- virtual ~TiXmlDocument() {}
-
- bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
-
- bool SaveFile() const;
-
- bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
-
- bool SaveFile( const char * filename ) const;
-
- bool LoadFile( FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
-
- bool SaveFile( FILE* ) const;
- #ifdef TIXML_USE_STL
- bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING )
- {
- return LoadFile( filename.c_str(), encoding );
- }
- bool SaveFile( const std::string& filename ) const
- {
- return SaveFile( filename.c_str() );
- }
- #endif
-
- virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
-
- const TiXmlElement* RootElement() const { return FirstChildElement(); }
- TiXmlElement* RootElement() { return FirstChildElement(); }
-
-
- bool Error() const { return error; }
-
- const char * ErrorDesc() const { return errorDesc.c_str (); }
-
- int ErrorId() const { return errorId; }
-
- int ErrorRow() { return errorLocation.row+1; }
- int ErrorCol() { return errorLocation.col+1; }
-
- void SetTabSize( int _tabsize ) { tabsize = _tabsize; }
- int TabSize() const { return tabsize; }
-
- void ClearError() { error = false;
- errorId = 0;
- errorDesc = "";
- errorLocation.row = errorLocation.col = 0;
-
- }
-
- void Print() const { Print( stdout, 0 ); }
-
-
-
- virtual void Print( FILE* cfile, int depth = 0 ) const;
-
- void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );
- virtual const TiXmlDocument* ToDocument() const { return this; }
- virtual TiXmlDocument* ToDocument() { return this; }
-
- virtual bool Accept( TiXmlVisitor* content ) const;
- protected :
-
- virtual TiXmlNode* Clone() const;
- #ifdef TIXML_USE_STL
- virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
- #endif
- private:
- void CopyTo( TiXmlDocument* target ) const;
- bool error;
- int errorId;
- TIXML_STRING errorDesc;
- int tabsize;
- TiXmlCursor errorLocation;
- bool useMicrosoftBOM;
- };
- class TiXmlHandle
- {
- public:
-
- TiXmlHandle( TiXmlNode* _node ) { this->node = _node; }
-
- TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; }
- TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.node; return *this; }
-
- TiXmlHandle FirstChild() const;
-
- TiXmlHandle FirstChild( const char * value ) const;
-
- TiXmlHandle FirstChildElement() const;
-
- TiXmlHandle FirstChildElement( const char * value ) const;
-
- TiXmlHandle Child( const char* value, int index ) const;
-
- TiXmlHandle Child( int index ) const;
-
- TiXmlHandle ChildElement( const char* value, int index ) const;
-
- TiXmlHandle ChildElement( int index ) const;
- #ifdef TIXML_USE_STL
- TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); }
- TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); }
- TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); }
- TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); }
- #endif
-
- TiXmlNode* ToNode() const { return node; }
-
- TiXmlElement* ToElement() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
-
- TiXmlText* ToText() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
-
- TiXmlUnknown* ToUnknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
-
- TiXmlNode* Node() const { return ToNode(); }
-
- TiXmlElement* Element() const { return ToElement(); }
-
- TiXmlText* Text() const { return ToText(); }
-
- TiXmlUnknown* Unknown() const { return ToUnknown(); }
- private:
- TiXmlNode* node;
- };
- class TiXmlPrinter : public TiXmlVisitor
- {
- public:
- TiXmlPrinter() : depth( 0 ), simpleTextPrint( false ),
- buffer(), indent( " " ), lineBreak( "\n" ) {}
- virtual bool VisitEnter( const TiXmlDocument& doc );
- virtual bool VisitExit( const TiXmlDocument& doc );
- virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute );
- virtual bool VisitExit( const TiXmlElement& element );
- virtual bool Visit( const TiXmlDeclaration& declaration );
- virtual bool Visit( const TiXmlText& text );
- virtual bool Visit( const TiXmlComment& comment );
- virtual bool Visit( const TiXmlUnknown& unknown );
-
- void SetIndent( const char* _indent ) { indent = _indent ? _indent : "" ; }
-
- const char* Indent() { return indent.c_str(); }
-
- void SetLineBreak( const char* _lineBreak ) { lineBreak = _lineBreak ? _lineBreak : ""; }
-
- const char* LineBreak() { return lineBreak.c_str(); }
-
- void SetStreamPrinting() { indent = "";
- lineBreak = "";
- }
-
- const char* CStr() { return buffer.c_str(); }
-
- size_t Size() { return buffer.size(); }
- #ifdef TIXML_USE_STL
-
- const std::string& Str() { return buffer; }
- #endif
- private:
- void DoIndent() {
- for( int i=0; i<depth; ++i )
- buffer += indent;
- }
- void DoLineBreak() {
- buffer += lineBreak;
- }
- int depth;
- bool simpleTextPrint;
- TIXML_STRING buffer;
- TIXML_STRING indent;
- TIXML_STRING lineBreak;
- };
- #ifdef _MSC_VER
- #pragma warning( pop )
- #endif
- #endif
|