Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 31, 2007, 12:06:33 AM (17 years ago)
Author:
landauf
Message:

updated to the newest tinyXML library and changed one line in the LevelLoader

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/FICN/src/tinyxml/tinyxml.h

    r471 r738  
    11/*
    22www.sourceforge.net/projects/tinyxml
    3 Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com)
     3Original code (2.0 and earlier )copyright (c) 2000-2006 Lee Thomason (www.grinninglizard.com)
    44
    55This software is provided 'as-is', without any express or implied
     
    2626#ifndef TINYXML_INCLUDED
    2727#define TINYXML_INCLUDED
    28 
    29 #define TIXML_USE_STL
    3028
    3129#ifdef _MSC_VER
     
    4644#endif
    4745
    48 #if defined( DEBUG ) && defined( _MSC_VER )
    49 #include <windows.h>
    50 #define TIXML_LOG OutputDebugString
    51 #else
    52 #define TIXML_LOG printf
    53 #endif
    54 
    5546#ifdef TIXML_USE_STL
    5647        #include <string>
    5748        #include <iostream>
    58         #define TIXML_STRING    std::string
    59         #define TIXML_ISTREAM   std::istream
    60         #define TIXML_OSTREAM   std::ostream
     49        #include <sstream>
     50        #define TIXML_STRING            std::string
    6151#else
    6252        #include "tinystr.h"
    63         #define TIXML_STRING    TiXmlString
    64         #define TIXML_OSTREAM   TiXmlOutStream
     53        #define TIXML_STRING            TiXmlString
    6554#endif
    6655
     
    6958// but it gets closer. There are too many compilers for me to fully
    7059// test. If you get compilation troubles, undefine TIXML_SAFE
    71 
    72 #define TIXML_SAFE              // TinyXml isn't fully buffer overrun protected, safe code. This is work in progress.
     60#define TIXML_SAFE
     61
    7362#ifdef TIXML_SAFE
    74         #if defined(_MSC_VER) && (_MSC_VER >= 1200 )
     63        #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
     64                // Microsoft visual studio, version 2005 and higher.
     65                #define TIXML_SNPRINTF _snprintf_s
     66                #define TIXML_SNSCANF  _snscanf_s
     67                #define TIXML_SSCANF   sscanf_s
     68        #elif defined(_MSC_VER) && (_MSC_VER >= 1200 )
    7569                // Microsoft visual studio, version 6 and higher.
    7670                //#pragma message( "Using _sn* functions." )
    7771                #define TIXML_SNPRINTF _snprintf
    7872                #define TIXML_SNSCANF  _snscanf
     73                #define TIXML_SSCANF   sscanf
    7974        #elif defined(__GNUC__) && (__GNUC__ >= 3 )
    8075                // GCC version 3 and higher.s
     
    8277                #define TIXML_SNPRINTF snprintf
    8378                #define TIXML_SNSCANF  snscanf
    84         #endif
    85 #endif
     79                #define TIXML_SSCANF   sscanf
     80        #else
     81                #define TIXML_SSCANF   sscanf
     82        #endif
     83#endif 
    8684
    8785class TiXmlDocument;
     
    9593
    9694const int TIXML_MAJOR_VERSION = 2;
    97 const int TIXML_MINOR_VERSION = 4;
    98 const int TIXML_PATCH_VERSION = 2;
    99 
    100 /*      Internal structure for tracking location of items
     95const int TIXML_MINOR_VERSION = 5;
     96const int TIXML_PATCH_VERSION = 3;
     97
     98/*      Internal structure for tracking location of items 
    10199        in the XML file.
    102100*/
     
    111109
    112110
     111/**
     112        If you call the Accept() method, it requires being passed a TiXmlVisitor
     113        class to handle callbacks. For nodes that contain other nodes (Document, Element)
     114        you will get called with a VisitEnter/VisitExit pair. Nodes that are always leaves
     115        are simple called with Visit().
     116
     117        If you return 'true' from a Visit method, recursive parsing will continue. If you return
     118        false, <b>no children of this node or its sibilings</b> will be Visited.
     119
     120        All flavors of Visit methods have a default implementation that returns 'true' (continue
     121        visiting). You need to only override methods that are interesting to you.
     122
     123        Generally Accept() is called on the TiXmlDocument, although all nodes suppert Visiting.
     124
     125        You should never change the document from a callback.
     126
     127        @sa TiXmlNode::Accept()
     128*/
     129class TiXmlVisitor
     130{
     131public:
     132        virtual ~TiXmlVisitor() {}
     133
     134        /// Visit a document.
     135        virtual bool VisitEnter( const TiXmlDocument& /*doc*/ )                 { return true; }
     136        /// Visit a document.
     137        virtual bool VisitExit( const TiXmlDocument& /*doc*/ )                  { return true; }
     138
     139        /// Visit an element.
     140        virtual bool VisitEnter( const TiXmlElement& /*element*/, const TiXmlAttribute* /*firstAttribute*/ )    { return true; }
     141        /// Visit an element.
     142        virtual bool VisitExit( const TiXmlElement& /*element*/ )               { return true; }
     143
     144        /// Visit a declaration
     145        virtual bool Visit( const TiXmlDeclaration& /*declaration*/ )   { return true; }
     146        /// Visit a text node
     147        virtual bool Visit( const TiXmlText& /*text*/ )                                 { return true; }
     148        /// Visit a comment node
     149        virtual bool Visit( const TiXmlComment& /*comment*/ )                   { return true; }
     150        /// Visit an unknow node
     151        virtual bool Visit( const TiXmlUnknown& /*unknown*/ )                   { return true; }
     152};
     153
    113154// Only used by Attribute::Query functions
    114 enum
    115 {
     155enum 
     156{ 
    116157        TIXML_SUCCESS,
    117158        TIXML_NO_ATTRIBUTE,
     
    159200
    160201public:
    161         TiXmlBase()     :       userData(0) {}
    162         virtual ~TiXmlBase()                                    {}
    163 
    164         /**     All TinyXml classes can print themselves to a filestream.
    165                 This is a formatted print, and will insert tabs and newlines.
    166 
     202        TiXmlBase()     :       userData(0)             {}
     203        virtual ~TiXmlBase()                    {}
     204
     205        /**     All TinyXml classes can print themselves to a filestream
     206                or the string class (TiXmlString in non-STL mode, std::string
     207                in STL mode.) Either or both cfile and str can be null.
     208               
     209                This is a formatted print, and will insert
     210                tabs and newlines.
     211               
    167212                (For an unformatted stream, use the << operator.)
    168213        */
     
    173218                are provided to set whether or not TinyXml will condense all white space
    174219                into a single space or not. The default is to condense. Note changing this
    175                 values is not thread safe.
     220                value is not thread safe.
    176221        */
    177222        static void SetCondenseWhiteSpace( bool condense )              { condenseWhiteSpace = condense; }
     
    201246        int Column() const              { return location.col + 1; }    ///< See Row()
    202247
    203         void  SetUserData( void* user )                 { userData = user; }
    204         void* GetUserData()                                             { return userData; }
     248        void  SetUserData( void* user )                 { userData = user; }    ///< Set a pointer to arbitrary user data.
     249        void* GetUserData()                                             { return userData; }    ///< Get a pointer to arbitrary user data.
     250        const void* GetUserData() const                 { return userData; }    ///< Get a pointer to arbitrary user data.
    205251
    206252        // Table that returs, for a given lead byte, the total number of bytes
     
    208254        static const int utf8ByteTable[256];
    209255
    210         virtual const char* Parse(      const char* p,
    211                                                                 TiXmlParsingData* data,
     256        virtual const char* Parse(      const char* p, 
     257                                                                TiXmlParsingData* data, 
    212258                                                                TiXmlEncoding encoding /*= TIXML_ENCODING_UNKNOWN */ ) = 0;
     259
     260        /** Expands entities in a string. Note this should not contian the tag's '<', '>', etc,
     261                or they will be transformed into entities!
     262        */
     263        static void EncodeString( const TIXML_STRING& str, TIXML_STRING* out );
    213264
    214265        enum
     
    230281                TIXML_ERROR_EMBEDDED_NULL,
    231282                TIXML_ERROR_PARSING_CDATA,
     283                TIXML_ERROR_DOCUMENT_TOP_ONLY,
    232284
    233285                TIXML_ERROR_STRING_COUNT
     
    236288protected:
    237289
    238         // See STL_STRING_BUG
    239         // Utility class to overcome a bug.
    240         class StringToBuffer
    241         {
    242           public:
    243                 StringToBuffer( const TIXML_STRING& str );
    244                 ~StringToBuffer();
    245                 char* buffer;
    246         };
    247 
    248         static const char*      SkipWhiteSpace( const char*, TiXmlEncoding encoding );
    249         inline static bool      IsWhiteSpace( char c )
    250         {
    251                 return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' );
    252         }
    253 
    254         virtual void StreamOut (TIXML_OSTREAM *) const = 0;
     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        }
    255301
    256302        #ifdef TIXML_USE_STL
    257             static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag );
    258             static bool StreamTo( TIXML_ISTREAM * in, int character, TIXML_STRING * tag );
     303        static bool     StreamWhiteSpace( std::istream * in, TIXML_STRING * tag );
     304        static bool StreamTo( std::istream * in, int character, TIXML_STRING * tag );
    259305        #endif
    260306
     
    285331                if ( encoding == TIXML_ENCODING_UTF8 )
    286332                {
    287                         *length = utf8ByteTable[ *((unsigned char*)p) ];
     333                        *length = utf8ByteTable[ *((const unsigned char*)p) ];
    288334                        assert( *length >= 0 && *length < 5 );
    289335                }
     
    316362        }
    317363
    318         // Puts a string to a stream, expanding entities as it goes.
    319         // Note this should not contian the '<', '>', etc, or they will be transformed into entities!
    320         static void PutString( const TIXML_STRING& str, TIXML_OSTREAM* out );
    321 
    322         static void PutString( const TIXML_STRING& str, TIXML_STRING* out );
    323 
    324364        // Return true if the next characters in the stream are any of the endTag sequences.
    325365        // Ignore case only works for english, and should only be relied on when comparing
     
    336376    /// Field containing a generic user pointer
    337377        void*                   userData;
    338 
     378       
    339379        // None of these methods are reliable for any language except English.
    340380        // Good for approximation, not great for accuracy.
     
    388428
    389429public:
    390         #ifdef TIXML_USE_STL
     430        #ifdef TIXML_USE_STL   
    391431
    392432            /** An input stream operator, for every class. Tolerant of newlines and
     
    402442                    a node to a stream is very well defined. You'll get a nice stream
    403443                    of output, without any extra whitespace or newlines.
    404 
     444                   
    405445                    But reading is not as well defined. (As it always is.) If you create
    406446                    a TiXmlElement (for example) and read that from an input stream,
     
    410450                    A TiXmlDocument will read nodes until it reads a root element, and
    411451                        all the children of that root element.
    412             */
     452            */ 
    413453            friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
    414454
     
    416456                friend std::string& operator<< (std::string& out, const TiXmlNode& base );
    417457
    418         #else
    419             // Used internally, not part of the public API.
    420             friend TIXML_OSTREAM& operator<< (TIXML_OSTREAM& out, const TiXmlNode& base);
    421458        #endif
    422459
     
    459496        #endif
    460497
     498        const TIXML_STRING& ValueTStr() const { return value; }
     499
    461500        /** Changes the value of the node. Defined as:
    462501                @verbatim
     
    472511    #ifdef TIXML_USE_STL
    473512        /// STL std::string form.
    474         void SetValue( const std::string& _value )
    475         {
    476                 StringToBuffer buf( _value );
    477                 SetValue( buf.buffer ? buf.buffer : "" );
    478         }
     513        void SetValue( const std::string& _value )      { value = _value; }
    479514        #endif
    480515
     
    486521        const TiXmlNode* Parent() const                         { return parent; }
    487522
    488         const TiXmlNode* FirstChild()   const   { return firstChild; }          ///< The first child of this node. Will be null if there are no children.
    489         TiXmlNode* FirstChild()                                 { return firstChild; }
     523        const TiXmlNode* FirstChild()   const           { return firstChild; }  ///< The first child of this node. Will be null if there are no children.
     524        TiXmlNode* FirstChild()                                         { return firstChild; }
    490525        const TiXmlNode* FirstChild( const char * value ) const;                        ///< The first child of this node with the matching 'value'. Will be null if none found.
    491         TiXmlNode* FirstChild( const char * value );                                            ///< The first child of this node with the matching 'value'. Will be null if none found.
    492 
     526        /// The first child of this node with the matching 'value'. Will be null if none found.
     527        TiXmlNode* FirstChild( const char * _value ) {
     528                // Call through to the const version - safe since nothing is changed. Exiting syntax: cast this to a const (always safe)
     529                // call the method, cast the return back to non-const.
     530                return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->FirstChild( _value ));
     531        }
    493532        const TiXmlNode* LastChild() const      { return lastChild; }           /// The last child of this node. Will be null if there are no children.
    494533        TiXmlNode* LastChild()  { return lastChild; }
     534       
    495535        const TiXmlNode* LastChild( const char * value ) const;                 /// The last child of this node matching 'value'. Will be null if there are no children.
    496         TiXmlNode* LastChild( const char * value );
     536        TiXmlNode* LastChild( const char * _value ) {
     537                return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->LastChild( _value ));
     538        }
    497539
    498540    #ifdef TIXML_USE_STL
     
    520562        */
    521563        const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const;
    522         TiXmlNode* IterateChildren( TiXmlNode* previous );
     564        TiXmlNode* IterateChildren( const TiXmlNode* previous ) {
     565                return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( previous ) );
     566        }
    523567
    524568        /// This flavor of IterateChildren searches for children with a particular 'value'
    525569        const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const;
    526         TiXmlNode* IterateChildren( const char * value, TiXmlNode* previous );
     570        TiXmlNode* IterateChildren( const char * _value, const TiXmlNode* previous ) {
     571                return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( _value, previous ) );
     572        }
    527573
    528574    #ifdef TIXML_USE_STL
    529575        const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const  {       return IterateChildren (_value.c_str (), previous);     }       ///< STL std::string form.
    530         TiXmlNode* IterateChildren( const std::string& _value, TiXmlNode* previous ) {  return IterateChildren (_value.c_str (), previous);     }       ///< STL std::string form.
     576        TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) {    return IterateChildren (_value.c_str (), previous);     }       ///< STL std::string form.
    531577        #endif
    532578
     
    572618        /// Navigate to a sibling node.
    573619        const TiXmlNode* PreviousSibling( const char * ) const;
    574         TiXmlNode* PreviousSibling( const char * );
     620        TiXmlNode* PreviousSibling( const char *_prev ) {
     621                return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->PreviousSibling( _prev ) );
     622        }
    575623
    576624    #ifdef TIXML_USE_STL
     
    587635        /// Navigate to a sibling node with the given 'value'.
    588636        const TiXmlNode* NextSibling( const char * ) const;
    589         TiXmlNode* NextSibling( const char * );
     637        TiXmlNode* NextSibling( const char* _next ) {
     638                return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->NextSibling( _next ) );
     639        }
    590640
    591641        /** Convenience function to get through elements.
     
    594644        */
    595645        const TiXmlElement* NextSiblingElement() const;
    596         TiXmlElement* NextSiblingElement();
     646        TiXmlElement* NextSiblingElement() {
     647                return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement() );
     648        }
    597649
    598650        /** Convenience function to get through elements.
     
    601653        */
    602654        const TiXmlElement* NextSiblingElement( const char * ) const;
    603         TiXmlElement* NextSiblingElement( const char * );
     655        TiXmlElement* NextSiblingElement( const char *_next ) {
     656                return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement( _next ) );
     657        }
    604658
    605659    #ifdef TIXML_USE_STL
     
    610664        /// Convenience function to get through elements.
    611665        const TiXmlElement* FirstChildElement() const;
    612         TiXmlElement* FirstChildElement();
     666        TiXmlElement* FirstChildElement() {
     667                return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement() );
     668        }
    613669
    614670        /// Convenience function to get through elements.
    615         const TiXmlElement* FirstChildElement( const char * value ) const;
    616         TiXmlElement* FirstChildElement( const char * value );
     671        const TiXmlElement* FirstChildElement( const char * _value ) const;
     672        TiXmlElement* FirstChildElement( const char * _value ) {
     673                return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement( _value ) );
     674        }
    617675
    618676    #ifdef TIXML_USE_STL
     
    631689        */
    632690        const TiXmlDocument* GetDocument() const;
    633         TiXmlDocument* GetDocument();
     691        TiXmlDocument* GetDocument() {
     692                return const_cast< TiXmlDocument* >( (const_cast< const TiXmlNode* >(this))->GetDocument() );
     693        }
    634694
    635695        /// Returns true if this node has no children.
    636696        bool NoChildren() const                                         { return !firstChild; }
    637697
    638         const TiXmlDocument* ToDocument()       const           { return ( this && type == DOCUMENT ) ? (const TiXmlDocument*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type.
    639         const TiXmlElement*  ToElement() const                  { return ( this && type == ELEMENT  ) ? (const TiXmlElement*)  this : 0; } ///< Cast to a more defined type. Will return null not of the requested type.
    640         const TiXmlComment*  ToComment() const                  { return ( this && type == COMMENT  ) ? (const TiXmlComment*)  this : 0; } ///< Cast to a more defined type. Will return null not of the requested type.
    641         const TiXmlUnknown*  ToUnknown() const                  { return ( this && type == UNKNOWN  ) ? (const TiXmlUnknown*)  this : 0; } ///< Cast to a more defined type. Will return null not of the requested type.
    642         const TiXmlText*           ToText()    const            { return ( this && type == TEXT     ) ? (const TiXmlText*)     this : 0; } ///< Cast to a more defined type. Will return null not of the requested type.
    643         const TiXmlDeclaration* ToDeclaration() const   { return ( this && type == DECLARATION ) ? (const TiXmlDeclaration*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type.
    644 
    645         TiXmlDocument* ToDocument()                     { return ( this && type == DOCUMENT ) ? (TiXmlDocument*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type.
    646         TiXmlElement*  ToElement()                      { return ( this && type == ELEMENT  ) ? (TiXmlElement*)  this : 0; } ///< Cast to a more defined type. Will return null not of the requested type.
    647         TiXmlComment*  ToComment()                      { return ( this && type == COMMENT  ) ? (TiXmlComment*)  this : 0; } ///< Cast to a more defined type. Will return null not of the requested type.
    648         TiXmlUnknown*  ToUnknown()                      { return ( this && type == UNKNOWN  ) ? (TiXmlUnknown*)  this : 0; } ///< Cast to a more defined type. Will return null not of the requested type.
    649         TiXmlText*         ToText()                     { return ( this && type == TEXT     ) ? (TiXmlText*)     this : 0; } ///< Cast to a more defined type. Will return null not of the requested type.
    650         TiXmlDeclaration* ToDeclaration()       { return ( this && type == DECLARATION ) ? (TiXmlDeclaration*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type.
     698        virtual const TiXmlDocument*    ToDocument()    const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
     699        virtual const TiXmlElement*     ToElement()     const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
     700        virtual const TiXmlComment*     ToComment()     const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
     701        virtual const TiXmlUnknown*     ToUnknown()     const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
     702        virtual const TiXmlText*        ToText()        const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
     703        virtual const TiXmlDeclaration* ToDeclaration() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
     704
     705        virtual TiXmlDocument*          ToDocument()    { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
     706        virtual TiXmlElement*           ToElement()         { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
     707        virtual TiXmlComment*           ToComment()     { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
     708        virtual TiXmlUnknown*           ToUnknown()         { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
     709        virtual TiXmlText*                  ToText()        { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
     710        virtual TiXmlDeclaration*       ToDeclaration() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
    651711
    652712        /** Create an exact duplicate of this node and return it. The memory must be deleted
    653                 by the caller.
     713                by the caller. 
    654714        */
    655715        virtual TiXmlNode* Clone() const = 0;
     716
     717        /** Accept a hierchical visit the nodes in the TinyXML DOM. Every node in the
     718                XML tree will be conditionally visited and the host will be called back
     719                via the TiXmlVisitor interface.
     720
     721                This is essentially a SAX interface for TinyXML. (Note however it doesn't re-parse
     722                the XML for the callbacks, so the performance of TinyXML is unchanged by using this
     723                interface versus any other.)
     724
     725                The interface has been based on ideas from:
     726
     727                - http://www.saxproject.org/
     728                - http://c2.com/cgi/wiki?HierarchicalVisitorPattern
     729
     730                Which are both good references for "visiting".
     731
     732                An example of using Accept():
     733                @verbatim
     734                TiXmlPrinter printer;
     735                tinyxmlDoc.Accept( &printer );
     736                const char* xmlcstr = printer.CStr();
     737                @endverbatim
     738        */
     739        virtual bool Accept( TiXmlVisitor* visitor ) const = 0;
    656740
    657741protected:
     
    664748        #ifdef TIXML_USE_STL
    665749            // The real work of the input operator.
    666             virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) = 0;
     750        virtual void StreamIn( std::istream* in, TIXML_STRING* tag ) = 0;
    667751        #endif
    668752
     
    726810        }
    727811
    728         const char*             Name()  const           { return name.c_str (); }               ///< Return the name of this attribute.
    729         const char*             Value() const           { return value.c_str (); }              ///< Return the value of this attribute.
     812        const char*             Name()  const           { return name.c_str(); }                ///< Return the name of this attribute.
     813        const char*             Value() const           { return value.c_str(); }               ///< Return the value of this attribute.
     814        #ifdef TIXML_USE_STL
     815        const std::string& ValueStr() const     { return value; }                               ///< Return the value of this attribute.
     816        #endif
    730817        int                             IntValue() const;                                                                       ///< Return the value of this attribute, converted to an integer.
    731818        double                  DoubleValue() const;                                                            ///< Return the value of this attribute, converted to a double.
    732819
     820        // Get the tinyxml string representation
     821        const TIXML_STRING& NameTStr() const { return name; }
     822
    733823        /** QueryIntValue examines the value string. It is an alternative to the
    734824                IntValue() method with richer error checking.
    735                 If the value is an integer, it is stored in 'value' and
     825                If the value is an integer, it is stored in 'value' and 
    736826                the call returns TIXML_SUCCESS. If it is not
    737827                an integer, it returns TIXML_WRONG_TYPE.
     
    752842    #ifdef TIXML_USE_STL
    753843        /// STL std::string form.
    754         void SetName( const std::string& _name )
    755         {
    756                 StringToBuffer buf( _name );
    757                 SetName ( buf.buffer ? buf.buffer : "error" );
    758         }
    759         /// STL std::string form.
    760         void SetValue( const std::string& _value )
    761         {
    762                 StringToBuffer buf( _value );
    763                 SetValue( buf.buffer ? buf.buffer : "error" );
    764         }
     844        void SetName( const std::string& _name )        { name = _name; }       
     845        /// STL std::string form.       
     846        void SetValue( const std::string& _value )      { value = _value; }
    765847        #endif
    766848
    767849        /// Get the next sibling attribute in the DOM. Returns null at end.
    768850        const TiXmlAttribute* Next() const;
    769         TiXmlAttribute* Next();
     851        TiXmlAttribute* Next() {
     852                return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Next() );
     853        }
     854
    770855        /// Get the previous sibling attribute in the DOM. Returns null at beginning.
    771856        const TiXmlAttribute* Previous() const;
    772         TiXmlAttribute* Previous();
     857        TiXmlAttribute* Previous() {
     858                return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Previous() );
     859        }
    773860
    774861        bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
     
    782869
    783870        // Prints this Attribute to a FILE stream.
    784         virtual void Print( FILE* cfile, int depth ) const;
    785 
    786         virtual void StreamOut( TIXML_OSTREAM * out ) const;
     871        virtual void Print( FILE* cfile, int depth ) const {
     872                Print( cfile, depth, 0 );
     873        }
     874        void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
     875
    787876        // [internal use]
    788877        // Set the document pointer so the attribute can report errors.
     
    803892/*      A class used to manage a group of attributes.
    804893        It is only used internally, both by the ELEMENT and the DECLARATION.
    805 
     894       
    806895        The set can be changed transparent to the Element and Declaration
    807896        classes that use it, but NOT transparent to the Attribute
     
    827916        TiXmlAttribute* Last()                                  { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
    828917
    829         const TiXmlAttribute*   Find( const char * name ) const;
    830         TiXmlAttribute* Find( const char * name );
     918        const TiXmlAttribute*   Find( const char* _name ) const;
     919        TiXmlAttribute* Find( const char* _name ) {
     920                return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttributeSet* >(this))->Find( _name ) );
     921        }
     922        #ifdef TIXML_USE_STL
     923        const TiXmlAttribute*   Find( const std::string& _name ) const;
     924        TiXmlAttribute* Find( const std::string& _name ) {
     925                return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttributeSet* >(this))->Find( _name ) );
     926        }
     927
     928        #endif
    831929
    832930private:
     
    884982        /** QueryIntAttribute examines the attribute - it is an alternative to the
    885983                Attribute() method with richer error checking.
    886                 If the attribute is an integer, it is stored in 'value' and
     984                If the attribute is an integer, it is stored in 'value' and 
    887985                the call returns TIXML_SUCCESS. If it is not
    888986                an integer, it returns TIXML_WRONG_TYPE. If the attribute
    889987                does not exist, then TIXML_NO_ATTRIBUTE is returned.
    890         */
     988        */     
    891989        int QueryIntAttribute( const char* name, int* _value ) const;
    892990        /// QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
     
    9021000        }
    9031001
     1002    #ifdef TIXML_USE_STL
     1003        /** Template form of the attribute query which will try to read the
     1004                attribute into the specified type. Very easy, very powerful, but
     1005                be careful to make sure to call this with the correct type.
     1006               
     1007                NOTE: This method doesn't work correctly for 'string' types.
     1008
     1009                @return TIXML_SUCCESS, TIXML_WRONG_TYPE, or TIXML_NO_ATTRIBUTE
     1010        */
     1011        template< typename T > int QueryValueAttribute( const std::string& name, T* outValue ) const
     1012        {
     1013                const TiXmlAttribute* node = attributeSet.Find( name );
     1014                if ( !node )
     1015                        return TIXML_NO_ATTRIBUTE;
     1016
     1017                std::stringstream sstream( node->ValueStr() );
     1018                sstream >> *outValue;
     1019                if ( !sstream.fail() )
     1020                        return TIXML_SUCCESS;
     1021                return TIXML_WRONG_TYPE;
     1022        }
     1023        /*
     1024         This is - in theory - a bug fix for "QueryValueAtribute returns truncated std::string"
     1025         but template specialization is hard to get working cross-compiler. Leaving the bug for now.
     1026         
     1027        // The above will fail for std::string because the space character is used as a seperator.
     1028        // Specialize for strings. Bug [ 1695429 ] QueryValueAtribute returns truncated std::string
     1029        template<> int QueryValueAttribute( const std::string& name, std::string* outValue ) const
     1030        {
     1031                const TiXmlAttribute* node = attributeSet.Find( name );
     1032                if ( !node )
     1033                        return TIXML_NO_ATTRIBUTE;
     1034                *outValue = node->ValueStr();
     1035                return TIXML_SUCCESS;
     1036        }
     1037        */
     1038        #endif
     1039
    9041040        /** Sets an attribute of name to a given value. The attribute
    9051041                will be created if it does not exist, or changed if it does.
     
    9081044
    9091045    #ifdef TIXML_USE_STL
    910         const char* Attribute( const std::string& name ) const                          { return Attribute( name.c_str() ); }
    911         const char* Attribute( const std::string& name, int* i ) const          { return Attribute( name.c_str(), i ); }
    912         const char* Attribute( const std::string& name, double* d ) const       { return Attribute( name.c_str(), d ); }
    913         int QueryIntAttribute( const std::string& name, int* _value ) const     { return QueryIntAttribute( name.c_str(), _value ); }
    914         int QueryDoubleAttribute( const std::string& name, double* _value ) const { return QueryDoubleAttribute( name.c_str(), _value ); }
     1046        const std::string* Attribute( const std::string& name ) const;
     1047        const std::string* Attribute( const std::string& name, int* i ) const;
     1048        const std::string* Attribute( const std::string& name, double* d ) const;
     1049        int QueryIntAttribute( const std::string& name, int* _value ) const;
     1050        int QueryDoubleAttribute( const std::string& name, double* _value ) const;
    9151051
    9161052        /// STL std::string form.
    917         void SetAttribute( const std::string& name, const std::string& _value )
    918         {
    919                 StringToBuffer n( name );
    920                 StringToBuffer v( _value );
    921                 if ( n.buffer && v.buffer )
    922                         SetAttribute (n.buffer, v.buffer );
    923         }
     1053        void SetAttribute( const std::string& name, const std::string& _value );
    9241054        ///< STL std::string form.
    925         void SetAttribute( const std::string& name, int _value )
    926         {
    927                 StringToBuffer n( name );
    928                 if ( n.buffer )
    929                         SetAttribute (n.buffer, _value);
    930         }
     1055        void SetAttribute( const std::string& name, int _value );
    9311056        #endif
    9321057
     
    9561081                and concise, GetText() is limited compared to getting the TiXmlText child
    9571082                and accessing it directly.
    958 
     1083       
    9591084                If the first child of 'this' is a TiXmlText, the GetText()
    9601085                returns the character string of the Text node, else null is returned.
     
    9661091                @endverbatim
    9671092
    968                 'str' will be a pointer to "This is text".
    969 
     1093                'str' will be a pointer to "This is text". 
     1094               
    9701095                Note that this function can be misleading. If the element foo was created from
    9711096                this XML:
    9721097                @verbatim
    973                 <foo><b>This is text</b></foo>
     1098                <foo><b>This is text</b></foo> 
    9741099                @endverbatim
    9751100
     
    9771102                another element. From this XML:
    9781103                @verbatim
    979                 <foo>This is <b>text</b></foo>
     1104                <foo>This is <b>text</b></foo> 
    9801105                @endverbatim
    9811106                GetText() will return "This is ".
    9821107
    983                 WARNING: GetText() accesses a child node - don't become confused with the
    984                                  similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are
     1108                WARNING: GetText() accesses a child node - don't become confused with the 
     1109                                 similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are 
    9851110                                 safe type casts on the referenced node.
    9861111        */
     
    9971122        virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
    9981123
     1124        virtual const TiXmlElement*     ToElement()     const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
     1125        virtual TiXmlElement*           ToElement()               { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
     1126
     1127        /** Walk the XML tree visiting this node and all of its children.
     1128        */
     1129        virtual bool Accept( TiXmlVisitor* visitor ) const;
     1130
    9991131protected:
    10001132
     
    10041136        // Used to be public [internal use]
    10051137        #ifdef TIXML_USE_STL
    1006             virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
    1007         #endif
    1008         virtual void StreamOut( TIXML_OSTREAM * out ) const;
    1009 
     1138        virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
     1139        #endif
    10101140        /*      [internal use]
    10111141                Reads the "value" of the element -- another element, or text.
     
    10271157        /// Constructs an empty comment.
    10281158        TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
     1159        /// Construct a comment from text.
     1160        TiXmlComment( const char* _value ) : TiXmlNode( TiXmlNode::COMMENT ) {
     1161                SetValue( _value );
     1162        }
    10291163        TiXmlComment( const TiXmlComment& );
    10301164        void operator=( const TiXmlComment& base );
     
    10341168        /// Returns a copy of this Comment.
    10351169        virtual TiXmlNode* Clone() const;
    1036         /// Write this Comment to a FILE stream.
     1170        // Write this Comment to a FILE stream.
    10371171        virtual void Print( FILE* cfile, int depth ) const;
    10381172
     
    10421176        virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
    10431177
     1178        virtual const TiXmlComment*  ToComment() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
     1179        virtual TiXmlComment*  ToComment() { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
     1180
     1181        /** Walk the XML tree visiting this node and all of its children.
     1182        */
     1183        virtual bool Accept( TiXmlVisitor* visitor ) const;
     1184
    10441185protected:
    10451186        void CopyTo( TiXmlComment* target ) const;
     
    10471188        // used to be public
    10481189        #ifdef TIXML_USE_STL
    1049             virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
    1050         #endif
    1051         virtual void StreamOut( TIXML_OSTREAM * out ) const;
     1190        virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
     1191        #endif
     1192//      virtual void StreamOut( TIXML_OSTREAM * out ) const;
    10521193
    10531194private:
     
    10561197
    10571198
    1058 /** XML text. A text node can have 2 ways to output the next. "normal" output
     1199/** XML text. A text node can have 2 ways to output the next. "normal" output 
    10591200        and CDATA. It will default to the mode it was parsed from the XML file and
    1060         you generally want to leave it alone, but you can change the output mode with
     1201        you generally want to leave it alone, but you can change the output mode with 
    10611202        SetCDATA() and query it with CDATA().
    10621203*/
     
    10651206        friend class TiXmlElement;
    10661207public:
    1067         /** Constructor for text element. By default, it is treated as
     1208        /** Constructor for text element. By default, it is treated as 
    10681209                normal, encoded text. If you want it be output as a CDATA text
    10691210                element, set the parameter _cdata to 'true'
     
    10881229        void operator=( const TiXmlText& base )                                                         { base.CopyTo( this ); }
    10891230
    1090         /// Write this text object to a FILE stream.
     1231        // Write this text object to a FILE stream.
    10911232        virtual void Print( FILE* cfile, int depth ) const;
    10921233
    10931234        /// Queries whether this represents text using a CDATA section.
    1094         bool CDATA()                                    { return cdata; }
     1235        bool CDATA() const                              { return cdata; }
    10951236        /// Turns on or off a CDATA representation of text.
    10961237        void SetCDATA( bool _cdata )    { cdata = _cdata; }
    10971238
    10981239        virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
     1240
     1241        virtual const TiXmlText* ToText() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
     1242        virtual TiXmlText*       ToText()       { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
     1243
     1244        /** Walk the XML tree visiting this node and all of its children.
     1245        */
     1246        virtual bool Accept( TiXmlVisitor* content ) const;
    10991247
    11001248protected :
     
    11031251        void CopyTo( TiXmlText* target ) const;
    11041252
    1105         virtual void StreamOut ( TIXML_OSTREAM * out ) const;
    11061253        bool Blank() const;     // returns true if all white space and new lines
    11071254        // [internal use]
    11081255        #ifdef TIXML_USE_STL
    1109             virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
     1256        virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
    11101257        #endif
    11111258
     
    11601307        /// Creates a copy of this Declaration and returns it.
    11611308        virtual TiXmlNode* Clone() const;
    1162         /// Print this declaration to a FILE stream.
    1163         virtual void Print( FILE* cfile, int depth ) const;
     1309        // Print this declaration to a FILE stream.
     1310        virtual void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
     1311        virtual void Print( FILE* cfile, int depth ) const {
     1312                Print( cfile, depth, 0 );
     1313        }
    11641314
    11651315        virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
     1316
     1317        virtual const TiXmlDeclaration* ToDeclaration() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
     1318        virtual TiXmlDeclaration*       ToDeclaration()       { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
     1319
     1320        /** Walk the XML tree visiting this node and all of its children.
     1321        */
     1322        virtual bool Accept( TiXmlVisitor* visitor ) const;
    11661323
    11671324protected:
     
    11691326        // used to be public
    11701327        #ifdef TIXML_USE_STL
    1171             virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
    1172         #endif
    1173         virtual void StreamOut ( TIXML_OSTREAM * out) const;
     1328        virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
     1329        #endif
    11741330
    11751331private:
     
    11991355        /// Creates a copy of this Unknown and returns it.
    12001356        virtual TiXmlNode* Clone() const;
    1201         /// Print this Unknown to a FILE stream.
     1357        // Print this Unknown to a FILE stream.
    12021358        virtual void Print( FILE* cfile, int depth ) const;
    12031359
    12041360        virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
     1361
     1362        virtual const TiXmlUnknown*     ToUnknown()     const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
     1363        virtual TiXmlUnknown*           ToUnknown()         { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
     1364
     1365        /** Walk the XML tree visiting this node and all of its children.
     1366        */
     1367        virtual bool Accept( TiXmlVisitor* content ) const;
    12051368
    12061369protected:
     
    12081371
    12091372        #ifdef TIXML_USE_STL
    1210             virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
    1211         #endif
    1212         virtual void StreamOut ( TIXML_OSTREAM * out ) const;
     1373        virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
     1374        #endif
    12131375
    12141376private:
     
    12501412        /// Save a file using the given filename. Returns true if successful.
    12511413        bool SaveFile( const char * filename ) const;
     1414        /** Load a file using the given FILE*. Returns true if successful. Note that this method
     1415                doesn't stream - the entire object pointed at by the FILE*
     1416                will be interpreted as an XML file. TinyXML doesn't stream in XML from the current
     1417                file location. Streaming may be added in the future.
     1418        */
     1419        bool LoadFile( FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING );
     1420        /// Save a file using the given FILE*. Returns true if successful.
     1421        bool SaveFile( FILE* ) const;
    12521422
    12531423        #ifdef TIXML_USE_STL
    12541424        bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING )                   ///< STL std::string version.
    12551425        {
    1256                 StringToBuffer f( filename );
    1257                 return ( f.buffer && LoadFile( f.buffer, encoding ));
     1426//              StringToBuffer f( filename );
     1427//              return ( f.buffer && LoadFile( f.buffer, encoding ));
     1428                return LoadFile( filename.c_str(), encoding );
    12581429        }
    12591430        bool SaveFile( const std::string& filename ) const              ///< STL std::string version.
    12601431        {
    1261                 StringToBuffer f( filename );
    1262                 return ( f.buffer && SaveFile( f.buffer ));
     1432//              StringToBuffer f( filename );
     1433//              return ( f.buffer && SaveFile( f.buffer ));
     1434                return SaveFile( filename.c_str() );
    12631435        }
    12641436        #endif
     
    12811453                - The ErrorDesc() method will return the name of the error. (very useful)
    12821454                - The ErrorRow() and ErrorCol() will return the location of the error (if known)
    1283         */
     1455        */     
    12841456        bool Error() const                                              { return error; }
    12851457
     
    12921464        int ErrorId()   const                           { return errorId; }
    12931465
    1294         /** Returns the location (if known) of the error. The first column is column 1,
     1466        /** Returns the location (if known) of the error. The first column is column 1, 
    12951467                and the first row is row 1. A value of 0 means the row and column wasn't applicable
    12961468                (memory errors, for example, have no row/column) or the parser lost the error. (An
     
    12991471                @sa SetTabSize, Row, Column
    13001472        */
    1301         int ErrorRow()  { return errorLocation.row+1; }
    1302         int ErrorCol()  { return errorLocation.col+1; } ///< The column where the error occured. See ErrorRow()
     1473        int ErrorRow() const    { return errorLocation.row+1; }
     1474        int ErrorCol() const    { return errorLocation.col+1; } ///< The column where the error occured. See ErrorRow()
    13031475
    13041476        /** SetTabSize() allows the error reporting functions (ErrorRow() and ErrorCol())
    13051477                to report the correct values for row and column. It does not change the output
    13061478                or input in any way.
    1307 
     1479               
    13081480                By calling this method, with a tab size
    13091481                greater than 0, the row and column of each node and attribute is stored
     
    13331505                state is automatically cleared if you Parse a new XML block.
    13341506        */
    1335         void ClearError()                                               {       error = false;
    1336                                                                                                 errorId = 0;
    1337                                                                                                 errorDesc = "";
    1338                                                                                                 errorLocation.row = errorLocation.col = 0;
    1339                                                                                                 //errorLocation.last = 0;
     1507        void ClearError()                                               {       error = false; 
     1508                                                                                                errorId = 0; 
     1509                                                                                                errorDesc = ""; 
     1510                                                                                                errorLocation.row = errorLocation.col = 0; 
     1511                                                                                                //errorLocation.last = 0; 
    13401512                                                                                        }
    13411513
    1342         /** Dump the document to standard out. */
     1514        /** Write the document to standard out using formatted printing ("pretty print"). */
    13431515        void Print() const                                              { Print( stdout, 0 ); }
     1516
     1517        /* Write the document to a string using formatted printing ("pretty print"). This
     1518                will allocate a character array (new char[]) and return it as a pointer. The
     1519                calling code pust call delete[] on the return char* to avoid a memory leak.
     1520        */
     1521        //char* PrintToMemory() const;
    13441522
    13451523        /// Print this Document to a FILE stream.
     
    13481526        void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );
    13491527
     1528        virtual const TiXmlDocument*    ToDocument()    const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
     1529        virtual TiXmlDocument*          ToDocument()          { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
     1530
     1531        /** Walk the XML tree visiting this node and all of its children.
     1532        */
     1533        virtual bool Accept( TiXmlVisitor* content ) const;
     1534
    13501535protected :
    1351         virtual void StreamOut ( TIXML_OSTREAM * out) const;
    13521536        // [internal use]
    13531537        virtual TiXmlNode* Clone() const;
    13541538        #ifdef TIXML_USE_STL
    1355             virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag );
     1539        virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
    13561540        #endif
    13571541
     
    13831567        @endverbatim
    13841568
    1385         Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very
     1569        Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very 
    13861570        easy to write a *lot* of code that looks like:
    13871571
     
    14031587
    14041588        And that doesn't even cover "else" cases. TiXmlHandle addresses the verbosity
    1405         of such code. A TiXmlHandle checks for null     pointers so it is perfectly safe
     1589        of such code. A TiXmlHandle checks for null     pointers so it is perfectly safe 
    14061590        and correct to use:
    14071591
    14081592        @verbatim
    14091593        TiXmlHandle docHandle( &document );
    1410         TiXmlElement* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", 1 ).Element();
     1594        TiXmlElement* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", 1 ).ToElement();
    14111595        if ( child2 )
    14121596        {
     
    14241608
    14251609        @verbatim
    1426         int i=0;
     1610        int i=0; 
    14271611        while ( true )
    14281612        {
    1429                 TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", i ).Element();
     1613                TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", i ).ToElement();
    14301614                if ( !child )
    14311615                        break;
     
    14351619        @endverbatim
    14361620
    1437         It seems reasonable, but it is in fact two embedded while loops. The Child method is
    1438         a linear walk to find the element, so this code would iterate much more than it needs
     1621        It seems reasonable, but it is in fact two embedded while loops. The Child method is 
     1622        a linear walk to find the element, so this code would iterate much more than it needs 
    14391623        to. Instead, prefer:
    14401624
    14411625        @verbatim
    1442         TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild( "Child" ).Element();
     1626        TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild( "Child" ).ToElement();
    14431627
    14441628        for( child; child; child=child->NextSiblingElement() )
     
    14661650        TiXmlHandle FirstChildElement( const char * value ) const;
    14671651
    1468         /** Return a handle to the "index" child with the given name.
     1652        /** Return a handle to the "index" child with the given name. 
    14691653                The first child is 0, the second 1, etc.
    14701654        */
    14711655        TiXmlHandle Child( const char* value, int index ) const;
    1472         /** Return a handle to the "index" child.
     1656        /** Return a handle to the "index" child. 
    14731657                The first child is 0, the second 1, etc.
    14741658        */
    14751659        TiXmlHandle Child( int index ) const;
    1476         /** Return a handle to the "index" child element with the given name.
     1660        /** Return a handle to the "index" child element with the given name. 
    14771661                The first child element is 0, the second 1, etc. Note that only TiXmlElements
    14781662                are indexed: other types are not counted.
    14791663        */
    14801664        TiXmlHandle ChildElement( const char* value, int index ) const;
    1481         /** Return a handle to the "index" child element.
     1665        /** Return a handle to the "index" child element. 
    14821666                The first child element is 0, the second 1, etc. Note that only TiXmlElements
    14831667                are indexed: other types are not counted.
     
    14931677        #endif
    14941678
    1495         /// Return the handle as a TiXmlNode. This may return null.
    1496         TiXmlNode* Node() const                 { return node; }
    1497         /// Return the handle as a TiXmlElement. This may return null.
    1498         TiXmlElement* Element() const   { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
    1499         /// Return the handle as a TiXmlText. This may return null.
    1500         TiXmlText* Text() const                 { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
    1501         /// Return the handle as a TiXmlUnknown. This may return null;
    1502         TiXmlUnknown* Unknown() const                   { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
     1679        /** Return the handle as a TiXmlNode. This may return null.
     1680        */
     1681        TiXmlNode* ToNode() const                       { return node; }
     1682        /** Return the handle as a TiXmlElement. This may return null.
     1683        */
     1684        TiXmlElement* ToElement() const         { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }
     1685        /**     Return the handle as a TiXmlText. This may return null.
     1686        */
     1687        TiXmlText* ToText() const                       { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }
     1688        /** Return the handle as a TiXmlUnknown. This may return null.
     1689        */
     1690        TiXmlUnknown* ToUnknown() const         { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }
     1691
     1692        /** @deprecated use ToNode.
     1693                Return the handle as a TiXmlNode. This may return null.
     1694        */
     1695        TiXmlNode* Node() const                 { return ToNode(); }
     1696        /** @deprecated use ToElement.
     1697                Return the handle as a TiXmlElement. This may return null.
     1698        */
     1699        TiXmlElement* Element() const   { return ToElement(); }
     1700        /**     @deprecated use ToText()
     1701                Return the handle as a TiXmlText. This may return null.
     1702        */
     1703        TiXmlText* Text() const                 { return ToText(); }
     1704        /** @deprecated use ToUnknown()
     1705                Return the handle as a TiXmlUnknown. This may return null.
     1706        */
     1707        TiXmlUnknown* Unknown() const   { return ToUnknown(); }
    15031708
    15041709private:
     
    15061711};
    15071712
     1713
     1714/** Print to memory functionality. The TiXmlPrinter is useful when you need to:
     1715
     1716        -# Print to memory (especially in non-STL mode)
     1717        -# Control formatting (line endings, etc.)
     1718
     1719        When constructed, the TiXmlPrinter is in its default "pretty printing" mode.
     1720        Before calling Accept() you can call methods to control the printing
     1721        of the XML document. After TiXmlNode::Accept() is called, the printed document can
     1722        be accessed via the CStr(), Str(), and Size() methods.
     1723
     1724        TiXmlPrinter uses the Visitor API.
     1725        @verbatim
     1726        TiXmlPrinter printer;
     1727        printer.SetIndent( "\t" );
     1728
     1729        doc.Accept( &printer );
     1730        fprintf( stdout, "%s", printer.CStr() );
     1731        @endverbatim
     1732*/
     1733class TiXmlPrinter : public TiXmlVisitor
     1734{
     1735public:
     1736        TiXmlPrinter() : depth( 0 ), simpleTextPrint( false ),
     1737                                         buffer(), indent( "    " ), lineBreak( "\n" ) {}
     1738
     1739        virtual bool VisitEnter( const TiXmlDocument& doc );
     1740        virtual bool VisitExit( const TiXmlDocument& doc );
     1741
     1742        virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute );
     1743        virtual bool VisitExit( const TiXmlElement& element );
     1744
     1745        virtual bool Visit( const TiXmlDeclaration& declaration );
     1746        virtual bool Visit( const TiXmlText& text );
     1747        virtual bool Visit( const TiXmlComment& comment );
     1748        virtual bool Visit( const TiXmlUnknown& unknown );
     1749
     1750        /** Set the indent characters for printing. By default 4 spaces
     1751                but tab (\t) is also useful, or null/empty string for no indentation.
     1752        */
     1753        void SetIndent( const char* _indent )                   { indent = _indent ? _indent : "" ; }
     1754        /// Query the indention string.
     1755        const char* Indent()                                                    { return indent.c_str(); }
     1756        /** Set the line breaking string. By default set to newline (\n).
     1757                Some operating systems prefer other characters, or can be
     1758                set to the null/empty string for no indenation.
     1759        */
     1760        void SetLineBreak( const char* _lineBreak )             { lineBreak = _lineBreak ? _lineBreak : ""; }
     1761        /// Query the current line breaking string.
     1762        const char* LineBreak()                                                 { return lineBreak.c_str(); }
     1763
     1764        /** Switch over to "stream printing" which is the most dense formatting without
     1765                linebreaks. Common when the XML is needed for network transmission.
     1766        */
     1767        void SetStreamPrinting()                                                { indent = "";
     1768                                                                                                          lineBreak = "";
     1769                                                                                                        }       
     1770        /// Return the result.
     1771        const char* CStr()                                                              { return buffer.c_str(); }
     1772        /// Return the length of the result string.
     1773        size_t Size()                                                                   { return buffer.size(); }
     1774
     1775        #ifdef TIXML_USE_STL
     1776        /// Return the result.
     1777        const std::string& Str()                                                { return buffer; }
     1778        #endif
     1779
     1780private:
     1781        void DoIndent() {
     1782                for( int i=0; i<depth; ++i )
     1783                        buffer += indent;
     1784        }
     1785        void DoLineBreak() {
     1786                buffer += lineBreak;
     1787        }
     1788
     1789        int depth;
     1790        bool simpleTextPrint;
     1791        TIXML_STRING buffer;
     1792        TIXML_STRING indent;
     1793        TIXML_STRING lineBreak;
     1794};
     1795
     1796
    15081797#ifdef _MSC_VER
    15091798#pragma warning( pop )
Note: See TracChangeset for help on using the changeset viewer.