Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 29, 2005, 10:52:08 AM (19 years ago)
Author:
bensch
Message:

orxonox/branches/we: new tinyXML-version (version 2.4.2)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/world_entities/src/lib/tinyxml/tinyxml.h

    r4491 r5817  
    2828
    2929#ifdef _MSC_VER
     30#pragma warning( push )
    3031#pragma warning( disable : 4530 )
    3132#pragma warning( disable : 4786 )
     
    6263#endif
    6364
     65// Deprecated library function hell. Compilers want to use the
     66// new safe versions. This probably doesn't fully address the problem,
     67// but it gets closer. There are too many compilers for me to fully
     68// test. If you get compilation troubles, undefine TIXML_SAFE
     69
     70#define TIXML_SAFE              // TinyXml isn't fully buffer overrun protected, safe code. This is work in progress.
     71#ifdef TIXML_SAFE
     72        #if defined(_MSC_VER) && (_MSC_VER >= 1200 )
     73                // Microsoft visual studio, version 6 and higher.
     74                //#pragma message( "Using _sn* functions." )
     75                #define TIXML_SNPRINTF _snprintf
     76                #define TIXML_SNSCANF  _snscanf
     77        #elif defined(__GNUC__) && (__GNUC__ >= 3 )
     78                // GCC version 3 and higher.s
     79                //#warning( "Using sn* functions." )
     80                #define TIXML_SNPRINTF snprintf
     81                #define TIXML_SNSCANF  snscanf
     82        #endif
     83#endif 
     84
    6485class TiXmlDocument;
    6586class TiXmlElement;
     
    7293
    7394const int TIXML_MAJOR_VERSION = 2;
    74 const int TIXML_MINOR_VERSION = 3;
    75 const int TIXML_PATCH_VERSION = 4;
     95const int TIXML_MINOR_VERSION = 4;
     96const int TIXML_PATCH_VERSION = 2;
    7697
    7798/*      Internal structure for tracking location of items
     
    206227                TIXML_ERROR_DOCUMENT_EMPTY,
    207228                TIXML_ERROR_EMBEDDED_NULL,
     229                TIXML_ERROR_PARSING_CDATA,
    208230
    209231                TIXML_ERROR_STRING_COUNT
     
    278300                else if ( *length )
    279301                {
    280                         strncpy( _value, p, *length );
     302                        //strncpy( _value, p, *length );        // lots of compilers don't like this function (unsafe),
     303                                                                                                // and the null terminator isn't needed
     304                        for( int i=0; p[i] && i<*length; ++i ) {
     305                                _value[i] = p[i];
     306                        }
    281307                        return p + (*length);
    282308                }
     
    296322        // Return true if the next characters in the stream are any of the endTag sequences.
    297323        // Ignore case only works for english, and should only be relied on when comparing
    298         // to Engilish words: StringEqual( p, "version", true ) is fine.
     324        // to English words: StringEqual( p, "version", true ) is fine.
    299325        static bool StringEqual(        const char* p,
    300326                                                                const char* endTag,
     
    421447                The subclasses will wrap this function.
    422448        */
    423         const char * Value() const { return value.c_str (); }
     449        const char *Value() const { return value.c_str (); }
     450
     451    #ifdef TIXML_USE_STL
     452        /** Return Value() as a std::string. If you only use STL,
     453            this is more efficient than calling Value().
     454                Only available in STL mode.
     455        */
     456        const std::string& ValueStr() const { return value; }
     457        #endif
    424458
    425459        /** Changes the value of the node. Defined as:
     
    589623                                                                UNKNOWN, TEXT, and DECLARATION.
    590624        */
    591         virtual int Type() const        { return type; }
     625        int Type() const        { return type; }
    592626
    593627        /** Return a pointer to the Document this node lives in.
     
    633667        // Figure out what is at *p, and parse it. Returns null if it is not an xml node.
    634668        TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
    635 
    636         // Internal Value function returning a TIXML_STRING
    637         const TIXML_STRING& SValue() const      { return value ; }
    638669
    639670        TiXmlNode*              parent;
     
    695726        const char*             Name()  const           { return name.c_str (); }               ///< Return the name of this attribute.
    696727        const char*             Value() const           { return value.c_str (); }              ///< Return the value of this attribute.
    697         const int       IntValue() const;                                                                       ///< Return the value of this attribute, converted to an integer.
    698         const double    DoubleValue() const;                                                            ///< Return the value of this attribute, converted to a double.
     728        int                             IntValue() const;                                                                       ///< Return the value of this attribute, converted to an integer.
     729        double                  DoubleValue() const;                                                            ///< Return the value of this attribute, converted to a double.
    699730
    700731        /** QueryIntValue examines the value string. It is an alternative to the
     
    707738                which is the opposite of almost all other TinyXml calls.
    708739        */
    709         int QueryIntValue( int* value ) const;
     740        int QueryIntValue( int* _value ) const;
    710741        /// QueryDoubleValue examines the value string. See QueryIntValue().
    711         int QueryDoubleValue( double* value ) const;
     742        int QueryDoubleValue( double* _value ) const;
    712743
    713744        void SetName( const char* _name )       { name = _name; }                               ///< Set the name of this attribute.
    714745        void SetValue( const char* _value )     { value = _value; }                             ///< Set the value.
    715746
    716         void SetIntValue( int value );                                                                          ///< Set the value from an integer.
    717         void SetDoubleValue( double value );                                                            ///< Set the value from a double.
     747        void SetIntValue( int _value );                                                                         ///< Set the value from an integer.
     748        void SetDoubleValue( double _value );                                                           ///< Set the value from a double.
    718749
    719750    #ifdef TIXML_USE_STL
     
    856887                does not exist, then TIXML_NO_ATTRIBUTE is returned.
    857888        */     
    858         int QueryIntAttribute( const char* name, int* value ) const;
     889        int QueryIntAttribute( const char* name, int* _value ) const;
    859890        /// QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
    860         int QueryDoubleAttribute( const char* name, double* value ) const;
     891        int QueryDoubleAttribute( const char* name, double* _value ) const;
    861892        /// QueryFloatAttribute examines the attribute - see QueryIntAttribute().
    862         int QueryDoubleAttribute( const char* name, float* value ) const {
     893        int QueryFloatAttribute( const char* name, float* _value ) const {
    863894                double d;
    864895                int result = QueryDoubleAttribute( name, &d );
    865                 *value = (float)d;
     896                if ( result == TIXML_SUCCESS ) {
     897                        *_value = (float)d;
     898                }
    866899                return result;
    867900        }
     
    870903                will be created if it does not exist, or changed if it does.
    871904        */
    872         void SetAttribute( const char* name, const char * value );
     905        void SetAttribute( const char* name, const char * _value );
    873906
    874907    #ifdef TIXML_USE_STL
     
    876909        const char* Attribute( const std::string& name, int* i ) const          { return Attribute( name.c_str(), i ); }
    877910        const char* Attribute( const std::string& name, double* d ) const       { return Attribute( name.c_str(), d ); }
    878         int QueryIntAttribute( const std::string& name, int* value ) const      { return QueryIntAttribute( name.c_str(), value ); }
    879         int QueryDoubleAttribute( const std::string& name, double* value ) const { return QueryDoubleAttribute( name.c_str(), value ); }
     911        int QueryIntAttribute( const std::string& name, int* _value ) const     { return QueryIntAttribute( name.c_str(), _value ); }
     912        int QueryDoubleAttribute( const std::string& name, double* _value ) const { return QueryDoubleAttribute( name.c_str(), _value ); }
    880913
    881914        /// STL std::string form.
     
    918951        TiXmlAttribute* LastAttribute()                                 { return attributeSet.Last(); }
    919952
     953        /** Convenience function for easy access to the text inside an element. Although easy
     954                and concise, GetText() is limited compared to getting the TiXmlText child
     955                and accessing it directly.
     956       
     957                If the first child of 'this' is a TiXmlText, the GetText()
     958                returns the character string of the Text node, else null is returned.
     959
     960                This is a convenient method for getting the text of simple contained text:
     961                @verbatim
     962                <foo>This is text</foo>
     963                const char* str = fooElement->GetText();
     964                @endverbatim
     965
     966                'str' will be a pointer to "This is text".
     967               
     968                Note that this function can be misleading. If the element foo was created from
     969                this XML:
     970                @verbatim
     971                <foo><b>This is text</b></foo>
     972                @endverbatim
     973
     974                then the value of str would be null. The first child node isn't a text node, it is
     975                another element. From this XML:
     976                @verbatim
     977                <foo>This is <b>text</b></foo>
     978                @endverbatim
     979                GetText() will return "This is ".
     980
     981                WARNING: GetText() accesses a child node - don't become confused with the
     982                                 similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are
     983                                 safe type casts on the referenced node.
     984        */
     985        const char* GetText() const;
     986
    920987        /// Creates a new Element and returns it - the returned element is a copy.
    921988        virtual TiXmlNode* Clone() const;
     
    9871054
    9881055
    989 /** XML text. Contained in an element.
     1056/** XML text. A text node can have 2 ways to output the next. "normal" output
     1057        and CDATA. It will default to the mode it was parsed from the XML file and
     1058        you generally want to leave it alone, but you can change the output mode with
     1059        SetCDATA() and query it with CDATA().
    9901060*/
    9911061class TiXmlText : public TiXmlNode
     
    9931063        friend class TiXmlElement;
    9941064public:
    995         /// Constructor.
    996         TiXmlText (const char * initValue) : TiXmlNode (TiXmlNode::TEXT)
     1065        /** Constructor for text element. By default, it is treated as
     1066                normal, encoded text. If you want it be output as a CDATA text
     1067                element, set the parameter _cdata to 'true'
     1068        */
     1069        TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TEXT)
    9971070        {
    9981071                SetValue( initValue );
     1072                cdata = false;
    9991073        }
    10001074        virtual ~TiXmlText() {}
     
    10051079        {
    10061080                SetValue( initValue );
     1081                cdata = false;
    10071082        }
    10081083        #endif
     
    10131088        /// Write this text object to a FILE stream.
    10141089        virtual void Print( FILE* cfile, int depth ) const;
     1090
     1091        /// Queries whether this represents text using a CDATA section.
     1092        bool CDATA()                                    { return cdata; }
     1093        /// Turns on or off a CDATA representation of text.
     1094        void SetCDATA( bool _cdata )    { cdata = _cdata; }
    10151095
    10161096        virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
     
    10291109
    10301110private:
     1111        bool cdata;                     // true if this should be input and output as a CDATA style text element
    10311112};
    10321113
     
    12071288                prefer the ErrorId, this function will fetch it.
    12081289        */
    1209         const int ErrorId()     const                           { return errorId; }
     1290        int ErrorId()   const                           { return errorId; }
    12101291
    12111292        /** Returns the location (if known) of the error. The first column is column 1,
     
    12191300        int ErrorCol()  { return errorLocation.col+1; } ///< The column where the error occured. See ErrorRow()
    12201301
    1221         /** By calling this method, with a tab size
     1302        /** SetTabSize() allows the error reporting functions (ErrorRow() and ErrorCol())
     1303                to report the correct values for row and column. It does not change the output
     1304                or input in any way.
     1305               
     1306                By calling this method, with a tab size
    12221307                greater than 0, the row and column of each node and attribute is stored
    12231308                when the file is loaded. Very useful for tracking the DOM back in to
     
    12771362        int tabsize;
    12781363        TiXmlCursor errorLocation;
     1364        bool useMicrosoftBOM;           // the UTF-8 BOM were found when read. Note this, and try to write.
    12791365};
    12801366
     
    13641450public:
    13651451        /// Create a handle from any node (at any depth of the tree.) This can be a null pointer.
    1366         TiXmlHandle( TiXmlNode* node )                                  { this->node = node; }
     1452        TiXmlHandle( TiXmlNode* _node )                                 { this->node = _node; }
    13671453        /// Copy constructor
    13681454        TiXmlHandle( const TiXmlHandle& ref )                   { this->node = ref.node; }
     
    14191505
    14201506#ifdef _MSC_VER
    1421 #pragma warning( default : 4530 )
    1422 #pragma warning( default : 4786 )
     1507#pragma warning( pop )
    14231508#endif
    14241509
Note: See TracChangeset for help on using the changeset viewer.