tinyxml.h
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: Peter Soetens  do nov 2 13:06:00 CET 2006  tinyxml.h
00003 
00004                         tinyxml.h -  description
00005                            -------------------
00006     begin                : do november 02 2006
00007     copyright            : (C) 2006 Peter Soetens
00008     email                : peter.soetens@gmail.com
00009 
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU General Public                   *
00013  *   License as published by the Free Software Foundation;                 *
00014  *   version 2 of the License.                                             *
00015  *                                                                         *
00016  *   As a special exception, you may use this file as part of a free       *
00017  *   software library without restriction.  Specifically, if other files   *
00018  *   instantiate templates or use macros or inline functions from this     *
00019  *   file, or you compile this file and link it with other files to        *
00020  *   produce an executable, this file does not by itself cause the         *
00021  *   resulting executable to be covered by the GNU General Public          *
00022  *   License.  This exception does not however invalidate any other        *
00023  *   reasons why the executable file might be covered by the GNU General   *
00024  *   Public License.                                                       *
00025  *                                                                         *
00026  *   This library is distributed in the hope that it will be useful,       *
00027  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00028  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00029  *   Lesser General Public License for more details.                       *
00030  *                                                                         *
00031  *   You should have received a copy of the GNU General Public             *
00032  *   License along with this library; if not, write to the Free Software   *
00033  *   Foundation, Inc., 59 Temple Place,                                    *
00034  *   Suite 330, Boston, MA  02111-1307  USA                                *
00035  *                                                                         *
00036  ***************************************************************************/
00037 
00038 
00039 /*
00040 www.sourceforge.net/projects/tinyxml
00041 Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com)
00042 
00043 This software is provided 'as-is', without any express or implied
00044 warranty. In no event will the authors be held liable for any
00045 damages arising from the use of this software.
00046 
00047 Permission is granted to anyone to use this software for any
00048 purpose, including commercial applications, and to alter it and
00049 redistribute it freely, subject to the following restrictions:
00050 
00051 1. The origin of this software must not be misrepresented; you must
00052 not claim that you wrote the original software. If you use this
00053 software in a product, an acknowledgment in the product documentation
00054 would be appreciated but is not required.
00055 
00056 2. Altered source versions must be plainly marked as such, and
00057 must not be misrepresented as being the original software.
00058 
00059 3. This notice may not be removed or altered from any source
00060 distribution.
00061 */
00062 
00063 
00064 #ifndef TINYXML_INCLUDED
00065 #define TINYXML_INCLUDED
00066 
00067 #ifdef _MSC_VER
00068 #pragma warning( push )
00069 #pragma warning( disable : 4530 )
00070 #pragma warning( disable : 4786 )
00071 #endif
00072 
00073 #include <ctype.h>
00074 #include <stdio.h>
00075 #include <stdlib.h>
00076 #include <string.h>
00077 #include <assert.h>
00078 
00079 // Help out windows:
00080 #if defined( _DEBUG ) && !defined( DEBUG )
00081 #define DEBUG
00082 #endif
00083 
00084 #ifdef TIXML_USE_STL
00085         #include <string>
00086         #include <iostream>
00087         #define TIXML_STRING    std::string
00088         #define TIXML_ISTREAM   std::istream
00089         #define TIXML_OSTREAM   std::ostream
00090 #else
00091         #include "tinystr.h"
00092         #define TIXML_STRING    TiXmlString
00093         #define TIXML_OSTREAM   TiXmlOutStream
00094 #endif
00095 
00096 // Deprecated library function hell. Compilers want to use the
00097 // new safe versions. This probably doesn't fully address the problem,
00098 // but it gets closer. There are too many compilers for me to fully
00099 // test. If you get compilation troubles, undefine TIXML_SAFE
00100 
00101 #define TIXML_SAFE              // TinyXml isn't fully buffer overrun protected, safe code. This is work in progress.
00102 #ifdef TIXML_SAFE
00103         #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
00104                 // Microsoft visual studio, version 2005 and higher.
00105                 #define TIXML_SNPRINTF _snprintf_s
00106                 #define TIXML_SNSCANF  _snscanf_s
00107         #elif defined(_MSC_VER) && (_MSC_VER >= 1200 )
00108                 // Microsoft visual studio, version 6 and higher.
00109                 //#pragma message( "Using _sn* functions." )
00110                 #define TIXML_SNPRINTF _snprintf
00111                 #define TIXML_SNSCANF  _snscanf
00112         #elif defined(__GNUC__) && (__GNUC__ >= 3 )
00113                 // GCC version 3 and higher.s
00114                 //#warning( "Using sn* functions." )
00115                 #define TIXML_SNPRINTF snprintf
00116                 #define TIXML_SNSCANF  snscanf
00117         #endif
00118 #endif
00119 
00120 namespace RTT { namespace marsh {
00121 
00122 class TiXmlDocument;
00123 class TiXmlElement;
00124 class TiXmlComment;
00125 class TiXmlUnknown;
00126 class TiXmlAttribute;
00127 class TiXmlText;
00128 class TiXmlDeclaration;
00129 class TiXmlParsingData;
00130 
00131 const int TIXML_MAJOR_VERSION = 2;
00132 const int TIXML_MINOR_VERSION = 4;
00133 const int TIXML_PATCH_VERSION = 3;
00134 
00135 /*      Internal structure for tracking location of items
00136         in the XML file.
00137 */
00138 struct TiXmlCursor
00139 {
00140         TiXmlCursor()           { Clear(); }
00141         void Clear()            { row = col = -1; }
00142 
00143         int row;        // 0 based.
00144         int col;        // 0 based.
00145 };
00146 
00147 
00148 // Only used by Attribute::Query functions
00149 enum
00150 {
00151         TIXML_SUCCESS,
00152         TIXML_NO_ATTRIBUTE,
00153         TIXML_WRONG_TYPE
00154 };
00155 
00156 
00157 // Used by the parsing routines.
00158 enum TiXmlEncoding
00159 {
00160         TIXML_ENCODING_UNKNOWN,
00161         TIXML_ENCODING_UTF8,
00162         TIXML_ENCODING_LEGACY
00163 };
00164 
00165 const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
00166 
00189 class TiXmlBase
00190 {
00191         friend class TiXmlNode;
00192         friend class TiXmlElement;
00193         friend class TiXmlDocument;
00194 
00195 public:
00196         TiXmlBase()     :       userData(0) {}
00197         virtual ~TiXmlBase()                                    {}
00198 
00204         virtual void Print( FILE* cfile, int depth ) const = 0;
00205 
00212         static void SetCondenseWhiteSpace( bool condense )              { condenseWhiteSpace = condense; }
00213 
00215         static bool IsWhiteSpaceCondensed()                                             { return condenseWhiteSpace; }
00216 
00235         int Row() const                 { return location.row + 1; }
00236         int Column() const              { return location.col + 1; }    
00237 
00238         void  SetUserData( void* user )                 { userData = user; }
00239         void* GetUserData()                                             { return userData; }
00240 
00241         // Table that returs, for a given lead byte, the total number of bytes
00242         // in the UTF-8 sequence.
00243         static const int utf8ByteTable[256];
00244 
00245         virtual const char* Parse(      const char* p,
00246                                                                 TiXmlParsingData* data,
00247                                                                 TiXmlEncoding encoding /*= TIXML_ENCODING_UNKNOWN */ ) = 0;
00248 
00249         enum
00250         {
00251                 TIXML_NO_ERROR = 0,
00252                 TIXML_ERROR,
00253                 TIXML_ERROR_OPENING_FILE,
00254                 TIXML_ERROR_OUT_OF_MEMORY,
00255                 TIXML_ERROR_PARSING_ELEMENT,
00256                 TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
00257                 TIXML_ERROR_READING_ELEMENT_VALUE,
00258                 TIXML_ERROR_READING_ATTRIBUTES,
00259                 TIXML_ERROR_PARSING_EMPTY,
00260                 TIXML_ERROR_READING_END_TAG,
00261                 TIXML_ERROR_PARSING_UNKNOWN,
00262                 TIXML_ERROR_PARSING_COMMENT,
00263                 TIXML_ERROR_PARSING_DECLARATION,
00264                 TIXML_ERROR_DOCUMENT_EMPTY,
00265                 TIXML_ERROR_EMBEDDED_NULL,
00266                 TIXML_ERROR_PARSING_CDATA,
00267 
00268                 TIXML_ERROR_STRING_COUNT
00269         };
00270 
00271 protected:
00272 
00273         // See STL_STRING_BUG
00274         // Utility class to overcome a bug.
00275         class StringToBuffer
00276         {
00277           public:
00278                 StringToBuffer( const TIXML_STRING& str );
00279                 ~StringToBuffer();
00280                 char* buffer;
00281         };
00282 
00283         static const char*      SkipWhiteSpace( const char*, TiXmlEncoding encoding );
00284         inline static bool      IsWhiteSpace( char c )
00285         {
00286                 return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' );
00287         }
00288         inline static bool      IsWhiteSpace( int c )
00289         {
00290                 if ( c < 256 )
00291                         return IsWhiteSpace( (char) c );
00292                 return false;   // Again, only truly correct for English/Latin...but usually works.
00293         }
00294 
00295         virtual void StreamOut (TIXML_OSTREAM *) const = 0;
00296 
00297         #ifdef TIXML_USE_STL
00298             static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag );
00299             static bool StreamTo( TIXML_ISTREAM * in, int character, TIXML_STRING * tag );
00300         #endif
00301 
00302         /*      Reads an XML name into the string provided. Returns
00303                 a pointer just past the last character of the name,
00304                 or 0 if the function has an error.
00305         */
00306         static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding );
00307 
00308         /*      Reads text. Returns a pointer past the given end tag.
00309                 Wickedly complex options, but it keeps the (sensitive) code in one place.
00310         */
00311         static const char* ReadText(    const char* in,                         // where to start
00312                                                                         TIXML_STRING* text,                     // the string read
00313                                                                         bool ignoreWhiteSpace,          // whether to keep the white space
00314                                                                         const char* endTag,                     // what ends this text
00315                                                                         bool ignoreCase,                        // whether to ignore case in the end tag
00316                                                                         TiXmlEncoding encoding );       // the current encoding
00317 
00318         // If an entity has been found, transform it into a character.
00319         static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding );
00320 
00321         // Get a character, while interpreting entities.
00322         // The length can be from 0 to 4 bytes.
00323         inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding )
00324         {
00325                 assert( p );
00326                 if ( encoding == TIXML_ENCODING_UTF8 )
00327                 {
00328                         *length = utf8ByteTable[ *((unsigned char*)p) ];
00329                         assert( *length >= 0 && *length < 5 );
00330                 }
00331                 else
00332                 {
00333                         *length = 1;
00334                 }
00335 
00336                 if ( *length == 1 )
00337                 {
00338                         if ( *p == '&' )
00339                                 return GetEntity( p, _value, length, encoding );
00340                         *_value = *p;
00341                         return p+1;
00342                 }
00343                 else if ( *length )
00344                 {
00345                         //strncpy( _value, p, *length );        // lots of compilers don't like this function (unsafe),
00346                                                                                                 // and the null terminator isn't needed
00347                         for( int i=0; p[i] && i<*length; ++i ) {
00348                                 _value[i] = p[i];
00349                         }
00350                         return p + (*length);
00351                 }
00352                 else
00353                 {
00354                         // Not valid text.
00355                         return 0;
00356                 }
00357         }
00358 
00359         // Puts a string to a stream, expanding entities as it goes.
00360         // Note this should not contian the '<', '>', etc, or they will be transformed into entities!
00361         static void PutString( const TIXML_STRING& str, TIXML_OSTREAM* out );
00362 
00363         static void PutString( const TIXML_STRING& str, TIXML_STRING* out );
00364 
00365         // Return true if the next characters in the stream are any of the endTag sequences.
00366         // Ignore case only works for english, and should only be relied on when comparing
00367         // to English words: StringEqual( p, "version", true ) is fine.
00368         static bool StringEqual(        const char* p,
00369                                                                 const char* endTag,
00370                                                                 bool ignoreCase,
00371                                                                 TiXmlEncoding encoding );
00372 
00373         static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
00374 
00375         TiXmlCursor location;
00376 
00378         void*                   userData;
00379 
00380         // None of these methods are reliable for any language except English.
00381         // Good for approximation, not great for accuracy.
00382         static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding );
00383         static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding );
00384         inline static int ToLower( int v, TiXmlEncoding encoding )
00385         {
00386                 if ( encoding == TIXML_ENCODING_UTF8 )
00387                 {
00388                         if ( v < 128 ) return tolower( v );
00389                         return v;
00390                 }
00391                 else
00392                 {
00393                         return tolower( v );
00394                 }
00395         }
00396         static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
00397 
00398 private:
00399         TiXmlBase( const TiXmlBase& );                          // not implemented.
00400         void operator=( const TiXmlBase& base );        // not allowed.
00401 
00402         struct Entity
00403         {
00404                 const char*     str;
00405                 unsigned int    strLength;
00406                 char                chr;
00407         };
00408         enum
00409         {
00410                 NUM_ENTITY = 5,
00411                 MAX_ENTITY_LENGTH = 6
00412 
00413         };
00414         static Entity entity[ NUM_ENTITY ];
00415         static bool condenseWhiteSpace;
00416 };
00417 
00418 
00425 class TiXmlNode : public TiXmlBase
00426 {
00427         friend class TiXmlDocument;
00428         friend class TiXmlElement;
00429 
00430 public:
00431         #ifdef TIXML_USE_STL
00432 
00436             friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
00437 
00454             friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
00455 
00457                 friend std::string& operator<< (std::string& out, const TiXmlNode& base );
00458 
00459         #else
00460             // Used internally, not part of the public API.
00461             friend TIXML_OSTREAM& operator<< (TIXML_OSTREAM& out, const TiXmlNode& base);
00462         #endif
00463 
00467         enum NodeType
00468         {
00469                 DOCUMENT,
00470                 ELEMENT,
00471                 COMMENT,
00472                 UNKNOWN,
00473                 TEXT,
00474                 DECLARATION,
00475                 TYPECOUNT
00476         };
00477 
00478         virtual ~TiXmlNode();
00479 
00492         const char *Value() const { return value.c_str (); }
00493 
00494     #ifdef TIXML_USE_STL
00495 
00499         const std::string& ValueStr() const { return value; }
00500         #endif
00501 
00511         void SetValue(const char * _value) { value = _value;}
00512 
00513     #ifdef TIXML_USE_STL
00514 
00515         void SetValue( const std::string& _value )      { value = _value; }
00516         #endif
00517 
00519         void Clear();
00520 
00522         TiXmlNode* Parent()                                                     { return parent; }
00523         const TiXmlNode* Parent() const                         { return parent; }
00524 
00525         const TiXmlNode* FirstChild()   const   { return firstChild; }          
00526         TiXmlNode* FirstChild()                                 { return firstChild; }
00527         const TiXmlNode* FirstChild( const char * value ) const;                        
00528         TiXmlNode* FirstChild( const char * value );                                            
00529 
00530         const TiXmlNode* LastChild() const      { return lastChild; }           
00531         TiXmlNode* LastChild()  { return lastChild; }
00532         const TiXmlNode* LastChild( const char * value ) const;                 
00533         TiXmlNode* LastChild( const char * value );
00534 
00535     #ifdef TIXML_USE_STL
00536         const TiXmlNode* FirstChild( const std::string& _value ) const  {       return FirstChild (_value.c_str ());    }       
00537         TiXmlNode* FirstChild( const std::string& _value )                              {       return FirstChild (_value.c_str ());    }       
00538         const TiXmlNode* LastChild( const std::string& _value ) const   {       return LastChild (_value.c_str ());     }       
00539         TiXmlNode* LastChild( const std::string& _value )                               {       return LastChild (_value.c_str ());     }       
00540         #endif
00541 
00558         const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const;
00559         TiXmlNode* IterateChildren( TiXmlNode* previous );
00560 
00562         const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const;
00563         TiXmlNode* IterateChildren( const char * value, TiXmlNode* previous );
00564 
00565     #ifdef TIXML_USE_STL
00566         const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const  {       return IterateChildren (_value.c_str (), previous);     }       
00567         TiXmlNode* IterateChildren( const std::string& _value, TiXmlNode* previous ) {  return IterateChildren (_value.c_str (), previous);     }       
00568         #endif
00569 
00573         TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
00574 
00575 
00585         TiXmlNode* LinkEndChild( TiXmlNode* addThis );
00586 
00590         TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
00591 
00595         TiXmlNode* InsertAfterChild(  TiXmlNode* afterThis, const TiXmlNode& addThis );
00596 
00600         TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
00601 
00603         bool RemoveChild( TiXmlNode* removeThis );
00604 
00606         const TiXmlNode* PreviousSibling() const                        { return prev; }
00607         TiXmlNode* PreviousSibling()                                            { return prev; }
00608 
00610         const TiXmlNode* PreviousSibling( const char * ) const;
00611         TiXmlNode* PreviousSibling( const char * );
00612 
00613     #ifdef TIXML_USE_STL
00614         const TiXmlNode* PreviousSibling( const std::string& _value ) const     {       return PreviousSibling (_value.c_str ());       }       
00615         TiXmlNode* PreviousSibling( const std::string& _value )                         {       return PreviousSibling (_value.c_str ());       }       
00616         const TiXmlNode* NextSibling( const std::string& _value) const          {       return NextSibling (_value.c_str ());   }       
00617         TiXmlNode* NextSibling( const std::string& _value)                                      {       return NextSibling (_value.c_str ());   }       
00618         #endif
00619 
00621         const TiXmlNode* NextSibling() const                            { return next; }
00622         TiXmlNode* NextSibling()                                                        { return next; }
00623 
00625         const TiXmlNode* NextSibling( const char * ) const;
00626         TiXmlNode* NextSibling( const char * );
00627 
00632         const TiXmlElement* NextSiblingElement() const;
00633         TiXmlElement* NextSiblingElement();
00634 
00639         const TiXmlElement* NextSiblingElement( const char * ) const;
00640         TiXmlElement* NextSiblingElement( const char * );
00641 
00642     #ifdef TIXML_USE_STL
00643         const TiXmlElement* NextSiblingElement( const std::string& _value) const        {       return NextSiblingElement (_value.c_str ());    }       
00644         TiXmlElement* NextSiblingElement( const std::string& _value)                            {       return NextSiblingElement (_value.c_str ());    }       
00645         #endif
00646 
00648         const TiXmlElement* FirstChildElement() const;
00649         TiXmlElement* FirstChildElement();
00650 
00652         const TiXmlElement* FirstChildElement( const char * value ) const;
00653         TiXmlElement* FirstChildElement( const char * value );
00654 
00655     #ifdef TIXML_USE_STL
00656         const TiXmlElement* FirstChildElement( const std::string& _value ) const        {       return FirstChildElement (_value.c_str ());     }       
00657         TiXmlElement* FirstChildElement( const std::string& _value )                            {       return FirstChildElement (_value.c_str ());     }       
00658         #endif
00659 
00664         int Type() const        { return type; }
00665 
00669         const TiXmlDocument* GetDocument() const;
00670         TiXmlDocument* GetDocument();
00671 
00673         bool NoChildren() const                                         { return !firstChild; }
00674 
00675         virtual const TiXmlDocument*    ToDocument()    const { return 0; } 
00676         virtual const TiXmlElement*     ToElement()     const { return 0; } 
00677         virtual const TiXmlComment*     ToComment()     const { return 0; } 
00678         virtual const TiXmlUnknown*     ToUnknown()     const { return 0; } 
00679         virtual const TiXmlText*        ToText()        const { return 0; } 
00680         virtual const TiXmlDeclaration* ToDeclaration() const { return 0; } 
00681 
00682         virtual TiXmlDocument*          ToDocument()    { return 0; } 
00683         virtual TiXmlElement*           ToElement()         { return 0; } 
00684         virtual TiXmlComment*           ToComment()     { return 0; } 
00685         virtual TiXmlUnknown*           ToUnknown()         { return 0; } 
00686         virtual TiXmlText*                  ToText()        { return 0; } 
00687         virtual TiXmlDeclaration*       ToDeclaration() { return 0; } 
00688 
00692         virtual TiXmlNode* Clone() const = 0;
00693 
00694 protected:
00695         TiXmlNode( NodeType _type );
00696 
00697         // Copy to the allocated object. Shared functionality between Clone, Copy constructor,
00698         // and the assignment operator.
00699         void CopyTo( TiXmlNode* target ) const;
00700 
00701         #ifdef TIXML_USE_STL
00702             // The real work of the input operator.
00703             virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) = 0;
00704         #endif
00705 
00706         // Figure out what is at *p, and parse it. Returns null if it is not an xml node.
00707         TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
00708 
00709         TiXmlNode*              parent;
00710         NodeType                type;
00711 
00712         TiXmlNode*              firstChild;
00713         TiXmlNode*              lastChild;
00714 
00715         TIXML_STRING    value;
00716 
00717         TiXmlNode*              prev;
00718         TiXmlNode*              next;
00719 
00720 private:
00721         TiXmlNode( const TiXmlNode& );                          // not implemented.
00722         void operator=( const TiXmlNode& base );        // not allowed.
00723 };
00724 
00725 
00733 class TiXmlAttribute : public TiXmlBase
00734 {
00735         friend class TiXmlAttributeSet;
00736 
00737 public:
00739         TiXmlAttribute() : TiXmlBase()
00740         {
00741                 document = 0;
00742                 prev = next = 0;
00743         }
00744 
00745         #ifdef TIXML_USE_STL
00746 
00747         TiXmlAttribute( const std::string& _name, const std::string& _value )
00748         {
00749                 name = _name;
00750                 value = _value;
00751                 document = 0;
00752                 prev = next = 0;
00753         }
00754         #endif
00755 
00757         TiXmlAttribute( const char * _name, const char * _value )
00758         {
00759                 name = _name;
00760                 value = _value;
00761                 document = 0;
00762                 prev = next = 0;
00763         }
00764 
00765         const char*             Name()  const           { return name.c_str (); }               
00766         const char*             Value() const           { return value.c_str (); }              
00767         int                             IntValue() const;                                                                       
00768         double                  DoubleValue() const;                                                            
00769 
00770         // Get the tinyxml string representation
00771         const TIXML_STRING& NameTStr() const { return name; }
00772 
00782         int QueryIntValue( int* _value ) const;
00784         int QueryDoubleValue( double* _value ) const;
00785 
00786         void SetName( const char* _name )       { name = _name; }                               
00787         void SetValue( const char* _value )     { value = _value; }                             
00788 
00789         void SetIntValue( int _value );                                                                         
00790         void SetDoubleValue( double _value );                                                           
00791 
00792     #ifdef TIXML_USE_STL
00793 
00794         void SetName( const std::string& _name )        { name = _name; }
00796         void SetValue( const std::string& _value )      { value = _value; }
00797         #endif
00798 
00800         const TiXmlAttribute* Next() const;
00801         TiXmlAttribute* Next();
00803         const TiXmlAttribute* Previous() const;
00804         TiXmlAttribute* Previous();
00805 
00806         bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
00807         bool operator<( const TiXmlAttribute& rhs )      const { return name < rhs.name; }
00808         bool operator>( const TiXmlAttribute& rhs )  const { return name > rhs.name; }
00809 
00810         /*      Attribute parsing starts: first letter of the name
00811                                                  returns: the next char after the value end quote
00812         */
00813         virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
00814 
00815         // Prints this Attribute to a FILE stream.
00816         virtual void Print( FILE* cfile, int depth ) const;
00817 
00818         virtual void StreamOut( TIXML_OSTREAM * out ) const;
00819         // [internal use]
00820         // Set the document pointer so the attribute can report errors.
00821         void SetDocument( TiXmlDocument* doc )  { document = doc; }
00822 
00823 private:
00824         TiXmlAttribute( const TiXmlAttribute& );                                // not implemented.
00825         void operator=( const TiXmlAttribute& base );   // not allowed.
00826 
00827         TiXmlDocument*  document;       // A pointer back to a document, for error reporting.
00828         TIXML_STRING name;
00829         TIXML_STRING value;
00830         TiXmlAttribute* prev;
00831         TiXmlAttribute* next;
00832 };
00833 
00834 
00835 /*      A class used to manage a group of attributes.
00836         It is only used internally, both by the ELEMENT and the DECLARATION.
00837 
00838         The set can be changed transparent to the Element and Declaration
00839         classes that use it, but NOT transparent to the Attribute
00840         which has to implement a next() and previous() method. Which makes
00841         it a bit problematic and prevents the use of STL.
00842 
00843         This version is implemented with circular lists because:
00844                 - I like circular lists
00845                 - it demonstrates some independence from the (typical) doubly linked list.
00846 */
00847 class TiXmlAttributeSet
00848 {
00849 public:
00850         TiXmlAttributeSet();
00851         ~TiXmlAttributeSet();
00852 
00853         void Add( TiXmlAttribute* attribute );
00854         void Remove( TiXmlAttribute* attribute );
00855 
00856         const TiXmlAttribute* First()   const   { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00857         TiXmlAttribute* First()                                 { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
00858         const TiXmlAttribute* Last() const              { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00859         TiXmlAttribute* Last()                                  { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
00860 
00861         const TiXmlAttribute*   Find( const TIXML_STRING& name ) const;
00862         TiXmlAttribute* Find( const TIXML_STRING& name );
00863 
00864 private:
00865         //*ME:  Because of hidden/disabled copy-construktor in TiXmlAttribute (sentinel-element),
00866         //*ME:  this class must be also use a hidden/disabled copy-constructor !!!
00867         TiXmlAttributeSet( const TiXmlAttributeSet& );  // not allowed
00868         void operator=( const TiXmlAttributeSet& );     // not allowed (as TiXmlAttribute)
00869 
00870         TiXmlAttribute sentinel;
00871 };
00872 
00873 
00878 class TiXmlElement : public TiXmlNode
00879 {
00880 public:
00882         TiXmlElement (const char * in_value);
00883 
00884         #ifdef TIXML_USE_STL
00885 
00886         TiXmlElement( const std::string& _value );
00887         #endif
00888 
00889         TiXmlElement( const TiXmlElement& );
00890 
00891         void operator=( const TiXmlElement& base );
00892 
00893         virtual ~TiXmlElement();
00894 
00898         const char* Attribute( const char* name ) const;
00899 
00906         const char* Attribute( const char* name, int* i ) const;
00907 
00914         const char* Attribute( const char* name, double* d ) const;
00915 
00923         int QueryIntAttribute( const char* name, int* _value ) const;
00925         int QueryDoubleAttribute( const char* name, double* _value ) const;
00927         int QueryFloatAttribute( const char* name, float* _value ) const {
00928                 double d;
00929                 int result = QueryDoubleAttribute( name, &d );
00930                 if ( result == TIXML_SUCCESS ) {
00931                         *_value = (float)d;
00932                 }
00933                 return result;
00934         }
00935 
00939         void SetAttribute( const char* name, const char * _value );
00940 
00941     #ifdef TIXML_USE_STL
00942         const char* Attribute( const std::string& name ) const                          { return Attribute( name.c_str() ); }
00943         const char* Attribute( const std::string& name, int* i ) const          { return Attribute( name.c_str(), i ); }
00944         const char* Attribute( const std::string& name, double* d ) const       { return Attribute( name.c_str(), d ); }
00945         int QueryIntAttribute( const std::string& name, int* _value ) const     { return QueryIntAttribute( name.c_str(), _value ); }
00946         int QueryDoubleAttribute( const std::string& name, double* _value ) const { return QueryDoubleAttribute( name.c_str(), _value ); }
00947 
00949         void SetAttribute( const std::string& name, const std::string& _value );
00951         void SetAttribute( const std::string& name, int _value );
00952         #endif
00953 
00957         void SetAttribute( const char * name, int value );
00958 
00962         void SetDoubleAttribute( const char * name, double value );
00963 
00966         void RemoveAttribute( const char * name );
00967     #ifdef TIXML_USE_STL
00968         void RemoveAttribute( const std::string& name ) {       RemoveAttribute (name.c_str ());        }       
00969         #endif
00970 
00971         const TiXmlAttribute* FirstAttribute() const    { return attributeSet.First(); }                
00972         TiXmlAttribute* FirstAttribute()                                { return attributeSet.First(); }
00973         const TiXmlAttribute* LastAttribute()   const   { return attributeSet.Last(); }         
00974         TiXmlAttribute* LastAttribute()                                 { return attributeSet.Last(); }
00975 
01008         const char* GetText() const;
01009 
01011         virtual TiXmlNode* Clone() const;
01012         // Print the Element to a FILE stream.
01013         virtual void Print( FILE* cfile, int depth ) const;
01014 
01015         /*      Attribtue parsing starts: next char past '<'
01016                                                  returns: next char past '>'
01017         */
01018         virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01019 
01020         virtual const TiXmlElement*     ToElement()     const { return this; } 
01021         virtual TiXmlElement*           ToElement()               { return this; } 
01022 
01023 protected:
01024 
01025         void CopyTo( TiXmlElement* target ) const;
01026         void ClearThis();       // like clear, but initializes 'this' object as well
01027 
01028         // Used to be public [internal use]
01029         #ifdef TIXML_USE_STL
01030             virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01031         #endif
01032         virtual void StreamOut( TIXML_OSTREAM * out ) const;
01033 
01034         /*      [internal use]
01035                 Reads the "value" of the element -- another element, or text.
01036                 This should terminate with the current end tag.
01037         */
01038         const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01039 
01040 private:
01041 
01042         TiXmlAttributeSet attributeSet;
01043 };
01044 
01045 
01048 class TiXmlComment : public TiXmlNode
01049 {
01050 public:
01052         TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
01053         TiXmlComment( const TiXmlComment& );
01054         void operator=( const TiXmlComment& base );
01055 
01056         virtual ~TiXmlComment() {}
01057 
01059         virtual TiXmlNode* Clone() const;
01061         virtual void Print( FILE* cfile, int depth ) const;
01062 
01063         /*      Attribtue parsing starts: at the ! of the !--
01064                                                  returns: next char past '>'
01065         */
01066         virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01067 
01068         virtual const TiXmlComment*  ToComment() const { return this; } 
01069         virtual TiXmlComment*  ToComment() { return this; } 
01070 
01071 protected:
01072         void CopyTo( TiXmlComment* target ) const;
01073 
01074         // used to be public
01075         #ifdef TIXML_USE_STL
01076             virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01077         #endif
01078         virtual void StreamOut( TIXML_OSTREAM * out ) const;
01079 
01080 private:
01081 
01082 };
01083 
01084 
01090 class TiXmlText : public TiXmlNode
01091 {
01092         friend class TiXmlElement;
01093 public:
01098         TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TEXT)
01099         {
01100                 SetValue( initValue );
01101                 cdata = false;
01102         }
01103         virtual ~TiXmlText() {}
01104 
01105         #ifdef TIXML_USE_STL
01106 
01107         TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT)
01108         {
01109                 SetValue( initValue );
01110                 cdata = false;
01111         }
01112         #endif
01113 
01114         TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT )       { copy.CopyTo( this ); }
01115         void operator=( const TiXmlText& base )                                                         { base.CopyTo( this ); }
01116 
01118         virtual void Print( FILE* cfile, int depth ) const;
01119 
01121         bool CDATA()                                    { return cdata; }
01123         void SetCDATA( bool _cdata )    { cdata = _cdata; }
01124 
01125         virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01126 
01127         virtual const TiXmlText* ToText() const { return this; } 
01128         virtual TiXmlText*       ToText()       { return this; } 
01129 
01130 protected :
01132         virtual TiXmlNode* Clone() const;
01133         void CopyTo( TiXmlText* target ) const;
01134 
01135         virtual void StreamOut ( TIXML_OSTREAM * out ) const;
01136         bool Blank() const;     // returns true if all white space and new lines
01137         // [internal use]
01138         #ifdef TIXML_USE_STL
01139             virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01140         #endif
01141 
01142 private:
01143         bool cdata;                     // true if this should be input and output as a CDATA style text element
01144 };
01145 
01146 
01160 class TiXmlDeclaration : public TiXmlNode
01161 {
01162 public:
01164         TiXmlDeclaration()   : TiXmlNode( TiXmlNode::DECLARATION ) {}
01165 
01166 #ifdef TIXML_USE_STL
01167 
01168         TiXmlDeclaration(       const std::string& _version,
01169                                                 const std::string& _encoding,
01170                                                 const std::string& _standalone );
01171 #endif
01172 
01174         TiXmlDeclaration(       const char* _version,
01175                                                 const char* _encoding,
01176                                                 const char* _standalone );
01177 
01178         TiXmlDeclaration( const TiXmlDeclaration& copy );
01179         void operator=( const TiXmlDeclaration& copy );
01180 
01181         virtual ~TiXmlDeclaration()     {}
01182 
01184         const char *Version() const                     { return version.c_str (); }
01186         const char *Encoding() const            { return encoding.c_str (); }
01188         const char *Standalone() const          { return standalone.c_str (); }
01189 
01191         virtual TiXmlNode* Clone() const;
01193         virtual void Print( FILE* cfile, int depth ) const;
01194 
01195         virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01196 
01197         virtual const TiXmlDeclaration* ToDeclaration() const { return this; } 
01198         virtual TiXmlDeclaration*       ToDeclaration()       { return this; } 
01199 
01200 protected:
01201         void CopyTo( TiXmlDeclaration* target ) const;
01202         // used to be public
01203         #ifdef TIXML_USE_STL
01204             virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01205         #endif
01206         virtual void StreamOut ( TIXML_OSTREAM * out) const;
01207 
01208 private:
01209 
01210         TIXML_STRING version;
01211         TIXML_STRING encoding;
01212         TIXML_STRING standalone;
01213 };
01214 
01215 
01223 class TiXmlUnknown : public TiXmlNode
01224 {
01225 public:
01226         TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN )        {}
01227         virtual ~TiXmlUnknown() {}
01228 
01229         TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNKNOWN )              { copy.CopyTo( this ); }
01230         void operator=( const TiXmlUnknown& copy )                                                                              { copy.CopyTo( this ); }
01231 
01233         virtual TiXmlNode* Clone() const;
01235         virtual void Print( FILE* cfile, int depth ) const;
01236 
01237         virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
01238 
01239         virtual const TiXmlUnknown*     ToUnknown()     const { return this; } 
01240         virtual TiXmlUnknown*           ToUnknown()         { return this; } 
01241 
01242 protected:
01243         void CopyTo( TiXmlUnknown* target ) const;
01244 
01245         #ifdef TIXML_USE_STL
01246             virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01247         #endif
01248         virtual void StreamOut ( TIXML_OSTREAM * out ) const;
01249 
01250 private:
01251 
01252 };
01253 
01254 
01259 class TiXmlDocument : public TiXmlNode
01260 {
01261 public:
01263         TiXmlDocument();
01265         TiXmlDocument( const char * documentName );
01266 
01267         #ifdef TIXML_USE_STL
01268 
01269         TiXmlDocument( const std::string& documentName );
01270         #endif
01271 
01272         TiXmlDocument( const TiXmlDocument& copy );
01273         void operator=( const TiXmlDocument& copy );
01274 
01275         virtual ~TiXmlDocument() {}
01276 
01281         bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01283         bool SaveFile() const;
01285         bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01287         bool SaveFile( const char * filename ) const;
01293         bool LoadFile( FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01295         bool SaveFile( FILE* ) const;
01296 
01297         #ifdef TIXML_USE_STL
01298         bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING )                   
01299         {
01300                 StringToBuffer f( filename );
01301                 return ( f.buffer && LoadFile( f.buffer, encoding ));
01302         }
01303         bool SaveFile( const std::string& filename ) const              
01304         {
01305                 StringToBuffer f( filename );
01306                 return ( f.buffer && SaveFile( f.buffer ));
01307         }
01308         #endif
01309 
01314         virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
01315 
01320         const TiXmlElement* RootElement() const         { return FirstChildElement(); }
01321         TiXmlElement* RootElement()                                     { return FirstChildElement(); }
01322 
01328         bool Error() const                                              { return error; }
01329 
01331         const char * ErrorDesc() const  { return errorDesc.c_str (); }
01332 
01336         int ErrorId()   const                           { return errorId; }
01337 
01345         int ErrorRow()  { return errorLocation.row+1; }
01346         int ErrorCol()  { return errorLocation.col+1; } 
01347 
01372         void SetTabSize( int _tabsize )         { tabsize = _tabsize; }
01373 
01374         int TabSize() const     { return tabsize; }
01375 
01379         void ClearError()                                               {       error = false;
01380                                                                                                 errorId = 0;
01381                                                                                                 errorDesc = "";
01382                                                                                                 errorLocation.row = errorLocation.col = 0;
01383                                                                                                 //errorLocation.last = 0;
01384                                                                                         }
01385 
01387         void Print() const                                              { Print( stdout, 0 ); }
01388 
01390         virtual void Print( FILE* cfile, int depth = 0 ) const;
01391         // [internal use]
01392         void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );
01393 
01394         virtual const TiXmlDocument*    ToDocument()    const { return this; } 
01395         virtual TiXmlDocument*          ToDocument()          { return this; } 
01396 
01397 protected :
01398         virtual void StreamOut ( TIXML_OSTREAM * out) const;
01399         // [internal use]
01400         virtual TiXmlNode* Clone() const;
01401         #ifdef TIXML_USE_STL
01402             virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
01403         #endif
01404 
01405 private:
01406         void CopyTo( TiXmlDocument* target ) const;
01407 
01408         bool error;
01409         int  errorId;
01410         TIXML_STRING errorDesc;
01411         int tabsize;
01412         TiXmlCursor errorLocation;
01413         bool useMicrosoftBOM;           // the UTF-8 BOM were found when read. Note this, and try to write.
01414 };
01415 
01416 
01497 class TiXmlHandle
01498 {
01499 public:
01501         TiXmlHandle( TiXmlNode* _node )                                 { this->node = _node; }
01503         TiXmlHandle( const TiXmlHandle& ref )                   { this->node = ref.node; }
01504         TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.node; return *this; }
01505 
01507         TiXmlHandle FirstChild() const;
01509         TiXmlHandle FirstChild( const char * value ) const;
01511         TiXmlHandle FirstChildElement() const;
01513         TiXmlHandle FirstChildElement( const char * value ) const;
01514 
01518         TiXmlHandle Child( const char* value, int index ) const;
01522         TiXmlHandle Child( int index ) const;
01527         TiXmlHandle ChildElement( const char* value, int index ) const;
01532         TiXmlHandle ChildElement( int index ) const;
01533 
01534         #ifdef TIXML_USE_STL
01535         TiXmlHandle FirstChild( const std::string& _value ) const                               { return FirstChild( _value.c_str() ); }
01536         TiXmlHandle FirstChildElement( const std::string& _value ) const                { return FirstChildElement( _value.c_str() ); }
01537 
01538         TiXmlHandle Child( const std::string& _value, int index ) const                 { return Child( _value.c_str(), index ); }
01539         TiXmlHandle ChildElement( const std::string& _value, int index ) const  { return ChildElement( _value.c_str(), index ); }
01540         #endif
01541 
01543         TiXmlNode* Node() const                 { return node; }
01545         TiXmlElement* Element() const   { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
01547         TiXmlText* Text() const                 { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
01549         TiXmlUnknown* Unknown() const                   { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
01550 
01551 private:
01552         TiXmlNode* node;
01553 };
01554 
01555 }}
01556 
01557 #ifdef _MSC_VER
01558 #pragma warning( pop )
01559 #endif
01560 
01561 #endif
01562 


rtt
Author(s): RTT Developers
autogenerated on Fri Sep 9 2016 04:02:16