| tinyxml.h | | tinyxml.h | |
| | | | |
| skipping to change at line 29 | | skipping to change at line 29 | |
| must not be misrepresented as being the original software. | | must not be misrepresented as being the original software. | |
| | | | |
| 3. This notice may not be removed or altered from any source | | 3. This notice may not be removed or altered from any source | |
| distribution. | | distribution. | |
| */ | | */ | |
| | | | |
| #ifndef TINYXML_INCLUDED | | #ifndef TINYXML_INCLUDED | |
| #define TINYXML_INCLUDED | | #define TINYXML_INCLUDED | |
| | | | |
| #ifdef _MSC_VER | | #ifdef _MSC_VER | |
|
| | | #pragma warning( push ) | |
| #pragma warning( disable : 4530 ) | | #pragma warning( disable : 4530 ) | |
| #pragma warning( disable : 4786 ) | | #pragma warning( disable : 4786 ) | |
| #endif | | #endif | |
| | | | |
| #include <ctype.h> | | #include <ctype.h> | |
| #include <stdio.h> | | #include <stdio.h> | |
| #include <stdlib.h> | | #include <stdlib.h> | |
| #include <string.h> | | #include <string.h> | |
| #include <assert.h> | | #include <assert.h> | |
| | | | |
| | | | |
| skipping to change at line 63 | | skipping to change at line 64 | |
| #include <iostream> | | #include <iostream> | |
| #define TIXML_STRING std::string | | #define TIXML_STRING std::string | |
| #define TIXML_ISTREAM std::istream | | #define TIXML_ISTREAM std::istream | |
| #define TIXML_OSTREAM std::ostream | | #define TIXML_OSTREAM std::ostream | |
| #else | | #else | |
| #include "tinystr.h" | | #include "tinystr.h" | |
| #define TIXML_STRING TiXmlString | | #define TIXML_STRING TiXmlString | |
| #define TIXML_OSTREAM TiXmlOutStream | | #define TIXML_OSTREAM TiXmlOutStream | |
| #endif | | #endif | |
| | | | |
|
| | | // Deprecated library function hell. Compilers want to use the | |
| | | // new safe versions. This probably doesn't fully address the problem, | |
| | | // but it gets closer. There are too many compilers for me to fully | |
| | | // test. If you get compilation troubles, undefine TIXML_SAFE | |
| | | | |
| | | #define TIXML_SAFE // TinyXml isn't fully buffer overrun protec | |
| | | ted, safe code. This is work in progress. | |
| | | #ifdef TIXML_SAFE | |
| | | #if defined(_MSC_VER) && (_MSC_VER >= 1200 ) | |
| | | // Microsoft visual studio, version 6 and higher. | |
| | | //#pragma message( "Using _sn* functions." ) | |
| | | #define TIXML_SNPRINTF _snprintf | |
| | | #define TIXML_SNSCANF _snscanf | |
| | | #elif defined(__GNUC__) && (__GNUC__ >= 3 ) | |
| | | // GCC version 3 and higher.s | |
| | | //#warning( "Using sn* functions." ) | |
| | | #define TIXML_SNPRINTF snprintf | |
| | | #define TIXML_SNSCANF snscanf | |
| | | #endif | |
| | | #endif | |
| | | | |
| class TiXmlDocument; | | class TiXmlDocument; | |
| class TiXmlElement; | | class TiXmlElement; | |
| class TiXmlComment; | | class TiXmlComment; | |
| class TiXmlUnknown; | | class TiXmlUnknown; | |
| class TiXmlAttribute; | | class TiXmlAttribute; | |
| class TiXmlText; | | class TiXmlText; | |
| class TiXmlDeclaration; | | class TiXmlDeclaration; | |
| class TiXmlParsingData; | | class TiXmlParsingData; | |
| | | | |
| const int TIXML_MAJOR_VERSION = 2; | | const int TIXML_MAJOR_VERSION = 2; | |
|
| const int TIXML_MINOR_VERSION = 3; | | const int TIXML_MINOR_VERSION = 4; | |
| const int TIXML_PATCH_VERSION = 4; | | const int TIXML_PATCH_VERSION = 0; | |
| | | | |
| /* Internal structure for tracking location of items | | /* Internal structure for tracking location of items | |
| in the XML file. | | in the XML file. | |
| */ | | */ | |
| struct TiXmlCursor | | struct TiXmlCursor | |
| { | | { | |
| TiXmlCursor() { Clear(); } | | TiXmlCursor() { Clear(); } | |
| void Clear() { row = col = -1; } | | void Clear() { row = col = -1; } | |
| | | | |
| int row; // 0 based. | | int row; // 0 based. | |
| | | | |
| skipping to change at line 205 | | skipping to change at line 226 | |
| TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, | | TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, | |
| TIXML_ERROR_READING_ELEMENT_VALUE, | | TIXML_ERROR_READING_ELEMENT_VALUE, | |
| TIXML_ERROR_READING_ATTRIBUTES, | | TIXML_ERROR_READING_ATTRIBUTES, | |
| TIXML_ERROR_PARSING_EMPTY, | | TIXML_ERROR_PARSING_EMPTY, | |
| TIXML_ERROR_READING_END_TAG, | | TIXML_ERROR_READING_END_TAG, | |
| TIXML_ERROR_PARSING_UNKNOWN, | | TIXML_ERROR_PARSING_UNKNOWN, | |
| TIXML_ERROR_PARSING_COMMENT, | | TIXML_ERROR_PARSING_COMMENT, | |
| TIXML_ERROR_PARSING_DECLARATION, | | TIXML_ERROR_PARSING_DECLARATION, | |
| TIXML_ERROR_DOCUMENT_EMPTY, | | TIXML_ERROR_DOCUMENT_EMPTY, | |
| TIXML_ERROR_EMBEDDED_NULL, | | TIXML_ERROR_EMBEDDED_NULL, | |
|
| | | TIXML_ERROR_PARSING_CDATA, | |
| | | | |
| TIXML_ERROR_STRING_COUNT | | TIXML_ERROR_STRING_COUNT | |
| }; | | }; | |
| | | | |
| protected: | | protected: | |
| | | | |
| // See STL_STRING_BUG | | // See STL_STRING_BUG | |
| // Utility class to overcome a bug. | | // Utility class to overcome a bug. | |
| class StringToBuffer | | class StringToBuffer | |
| { | | { | |
| | | | |
| skipping to change at line 277 | | skipping to change at line 299 | |
| | | | |
| if ( *length == 1 ) | | if ( *length == 1 ) | |
| { | | { | |
| if ( *p == '&' ) | | if ( *p == '&' ) | |
| return GetEntity( p, _value, length, encodin
g ); | | return GetEntity( p, _value, length, encodin
g ); | |
| *_value = *p; | | *_value = *p; | |
| return p+1; | | return p+1; | |
| } | | } | |
| else if ( *length ) | | else if ( *length ) | |
| { | | { | |
|
| strncpy( _value, p, *length ); | | //strncpy( _value, p, *length ); // lots of c | |
| | | ompilers don't like this function (unsafe), | |
| | | | |
| | | // and the null terminator isn't needed | |
| | | for( int i=0; p[i] && i<*length; ++i ) { | |
| | | _value[i] = p[i]; | |
| | | } | |
| return p + (*length); | | return p + (*length); | |
| } | | } | |
| else | | else | |
| { | | { | |
| // Not valid text. | | // Not valid text. | |
| return 0; | | return 0; | |
| } | | } | |
| } | | } | |
| | | | |
| // Puts a string to a stream, expanding entities as it goes. | | // Puts a string to a stream, expanding entities as it goes. | |
| // Note this should not contian the '<', '>', etc, or they will be t
ransformed into entities! | | // Note this should not contian the '<', '>', etc, or they will be t
ransformed into entities! | |
| static void PutString( const TIXML_STRING& str, TIXML_OSTREAM* out )
; | | static void PutString( const TIXML_STRING& str, TIXML_OSTREAM* out )
; | |
| | | | |
| static void PutString( const TIXML_STRING& str, TIXML_STRING* out ); | | static void PutString( const TIXML_STRING& str, TIXML_STRING* out ); | |
| | | | |
| // Return true if the next characters in the stream are any of the e
ndTag sequences. | | // Return true if the next characters in the stream are any of the e
ndTag sequences. | |
| // Ignore case only works for english, and should only be relied on
when comparing | | // Ignore case only works for english, and should only be relied on
when comparing | |
|
| // to Engilish words: StringEqual( p, "version", true ) is fine. | | // to English words: StringEqual( p, "version", true ) is fine. | |
| static bool StringEqual( const char* p, | | static bool StringEqual( const char* p, | |
| const char*
endTag, | | const char*
endTag, | |
| bool ignoreC
ase, | | bool ignoreC
ase, | |
| TiXmlEncodin
g encoding ); | | TiXmlEncodin
g encoding ); | |
| | | | |
| static const char* errorString[ TIXML_ERROR_STRING_COUNT ]; | | static const char* errorString[ TIXML_ERROR_STRING_COUNT ]; | |
| | | | |
| TiXmlCursor location; | | TiXmlCursor location; | |
| | | | |
| /// Field containing a generic user pointer | | /// Field containing a generic user pointer | |
| | | | |
| skipping to change at line 419 | | skipping to change at line 445 | |
| @verbatim | | @verbatim | |
| Document: filename of the xml file | | Document: filename of the xml file | |
| Element: name of the element | | Element: name of the element | |
| Comment: the comment text | | Comment: the comment text | |
| Unknown: the tag contents | | Unknown: the tag contents | |
| Text: the text string | | Text: the text string | |
| @endverbatim | | @endverbatim | |
| | | | |
| The subclasses will wrap this function. | | The subclasses will wrap this function. | |
| */ | | */ | |
|
| const char * Value() const { return value.c_str (); } | | const char *Value() const { return value.c_str (); } | |
| | | | |
| | | #ifdef TIXML_USE_STL | |
| | | /** Return Value() as a std::string. If you only use STL, | |
| | | this is more efficient than calling Value(). | |
| | | Only available in STL mode. | |
| | | */ | |
| | | const std::string& ValueStr() const { return value; } | |
| | | #endif | |
| | | | |
| /** Changes the value of the node. Defined as: | | /** Changes the value of the node. Defined as: | |
| @verbatim | | @verbatim | |
| Document: filename of the xml file | | Document: filename of the xml file | |
| Element: name of the element | | Element: name of the element | |
| Comment: the comment text | | Comment: the comment text | |
| Unknown: the tag contents | | Unknown: the tag contents | |
| Text: the text string | | Text: the text string | |
| @endverbatim | | @endverbatim | |
| */ | | */ | |
| | | | |
| skipping to change at line 631 | | skipping to change at line 665 | |
| void CopyTo( TiXmlNode* target ) const; | | void CopyTo( TiXmlNode* target ) const; | |
| | | | |
| #ifdef TIXML_USE_STL | | #ifdef TIXML_USE_STL | |
| // The real work of the input operator. | | // The real work of the input operator. | |
| virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) =
0; | | virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) =
0; | |
| #endif | | #endif | |
| | | | |
| // Figure out what is at *p, and parse it. Returns null if it is not
an xml node. | | // Figure out what is at *p, and parse it. Returns null if it is not
an xml node. | |
| TiXmlNode* Identify( const char* start, TiXmlEncoding encoding ); | | TiXmlNode* Identify( const char* start, TiXmlEncoding encoding ); | |
| | | | |
|
| // Internal Value function returning a TIXML_STRING | | | |
| const TIXML_STRING& SValue() const { return value ; } | | | |
| | | | |
| TiXmlNode* parent; | | TiXmlNode* parent; | |
| NodeType type; | | NodeType type; | |
| | | | |
| TiXmlNode* firstChild; | | TiXmlNode* firstChild; | |
| TiXmlNode* lastChild; | | TiXmlNode* lastChild; | |
| | | | |
| TIXML_STRING value; | | TIXML_STRING value; | |
| | | | |
| TiXmlNode* prev; | | TiXmlNode* prev; | |
| TiXmlNode* next; | | TiXmlNode* next; | |
| | | | |
| skipping to change at line 691 | | skipping to change at line 722 | |
| TiXmlAttribute( const char * _name, const char * _value ) | | TiXmlAttribute( const char * _name, const char * _value ) | |
| { | | { | |
| name = _name; | | name = _name; | |
| value = _value; | | value = _value; | |
| document = 0; | | document = 0; | |
| prev = next = 0; | | prev = next = 0; | |
| } | | } | |
| | | | |
| const char* Name() const { return name.c_str
(); } ///< Return the name of this attribute. | | const char* Name() const { return name.c_str
(); } ///< Return the name of this attribute. | |
| const char* Value() const { return value.c_str
(); } ///< Return the value of this attribute. | | const char* Value() const { return value.c_str
(); } ///< Return the value of this attribute. | |
|
| const int IntValue() const; | | int IntValue() const; | |
| ///< Return the value of this attribute | | ///< Return the value o | |
| , converted to an integer. | | f this attribute, converted to an integer. | |
| const double DoubleValue() const; | | double DoubleValue() const; | |
| ///< Return the value of this attribute, conver | | ///< Return the value of this attribute | |
| ted to a double. | | , converted to a double. | |
| | | | |
| /** QueryIntValue examines the value string. It is an alternative to
the | | /** QueryIntValue examines the value string. It is an alternative to
the | |
| IntValue() method with richer error checking. | | IntValue() method with richer error checking. | |
| If the value is an integer, it is stored in 'value' and | | If the value is an integer, it is stored in 'value' and | |
| the call returns TIXML_SUCCESS. If it is not | | the call returns TIXML_SUCCESS. If it is not | |
| an integer, it returns TIXML_WRONG_TYPE. | | an integer, it returns TIXML_WRONG_TYPE. | |
| | | | |
| A specialized but useful call. Note that for success it retu
rns 0, | | A specialized but useful call. Note that for success it retu
rns 0, | |
| which is the opposite of almost all other TinyXml calls. | | which is the opposite of almost all other TinyXml calls. | |
| */ | | */ | |
|
| int QueryIntValue( int* value ) const; | | int QueryIntValue( int* _value ) const; | |
| /// QueryDoubleValue examines the value string. See QueryIntValue(). | | /// QueryDoubleValue examines the value string. See QueryIntValue(). | |
|
| int QueryDoubleValue( double* value ) const; | | int QueryDoubleValue( double* _value ) const; | |
| | | | |
| void SetName( const char* _name ) { name = _name; }
///< Set the name of this attribute. | | void SetName( const char* _name ) { name = _name; }
///< Set the name of this attribute. | |
| void SetValue( const char* _value ) { value = _value; }
///< Set the value. | | void SetValue( const char* _value ) { value = _value; }
///< Set the value. | |
| | | | |
|
| void SetIntValue( int value ); | | void SetIntValue( int _value ); | |
| ///< Set the value from an integer. | | ///< Set the value from an integer. | |
| void SetDoubleValue( double value ); | | void SetDoubleValue( double _value ); | |
| ///< Set the value from a double. | | ///< Set the value from a double. | |
| | | | |
| #ifdef TIXML_USE_STL | | #ifdef TIXML_USE_STL | |
| /// STL std::string form. | | /// STL std::string form. | |
| void SetName( const std::string& _name ) | | void SetName( const std::string& _name ) | |
| { | | { | |
| StringToBuffer buf( _name ); | | StringToBuffer buf( _name ); | |
| SetName ( buf.buffer ? buf.buffer : "error" ); | | SetName ( buf.buffer ? buf.buffer : "error" ); | |
| } | | } | |
| /// STL std::string form. | | /// STL std::string form. | |
| void SetValue( const std::string& _value ) | | void SetValue( const std::string& _value ) | |
| | | | |
| skipping to change at line 850 | | skipping to change at line 881 | |
| */ | | */ | |
| const char* Attribute( const char* name, double* d ) const; | | const char* Attribute( const char* name, double* d ) const; | |
| | | | |
| /** QueryIntAttribute examines the attribute - it is an alternative
to the | | /** QueryIntAttribute examines the attribute - it is an alternative
to the | |
| Attribute() method with richer error checking. | | Attribute() method with richer error checking. | |
| If the attribute is an integer, it is stored in 'value' and | | If the attribute is an integer, it is stored in 'value' and | |
| the call returns TIXML_SUCCESS. If it is not | | the call returns TIXML_SUCCESS. If it is not | |
| an integer, it returns TIXML_WRONG_TYPE. If the attribute | | an integer, it returns TIXML_WRONG_TYPE. If the attribute | |
| does not exist, then TIXML_NO_ATTRIBUTE is returned. | | does not exist, then TIXML_NO_ATTRIBUTE is returned. | |
| */ | | */ | |
|
| int QueryIntAttribute( const char* name, int* value ) const; | | int QueryIntAttribute( const char* name, int* _value ) const; | |
| /// QueryDoubleAttribute examines the attribute - see QueryIntAttrib
ute(). | | /// QueryDoubleAttribute examines the attribute - see QueryIntAttrib
ute(). | |
|
| int QueryDoubleAttribute( const char* name, double* value ) const; | | int QueryDoubleAttribute( const char* name, double* _value ) const; | |
| /// QueryFloatAttribute examines the attribute - see QueryIntAttribu
te(). | | /// QueryFloatAttribute examines the attribute - see QueryIntAttribu
te(). | |
|
| int QueryDoubleAttribute( const char* name, float* value ) const { | | int QueryFloatAttribute( const char* name, float* _value ) const { | |
| double d; | | double d; | |
| int result = QueryDoubleAttribute( name, &d ); | | int result = QueryDoubleAttribute( name, &d ); | |
|
| *value = (float)d; | | if ( result == TIXML_SUCCESS ) { | |
| | | *_value = (float)d; | |
| | | } | |
| return result; | | return result; | |
| } | | } | |
| | | | |
| /** Sets an attribute of name to a given value. The attribute | | /** Sets an attribute of name to a given value. The attribute | |
| will be created if it does not exist, or changed if it does. | | will be created if it does not exist, or changed if it does. | |
| */ | | */ | |
|
| void SetAttribute( const char* name, const char * value ); | | void SetAttribute( const char* name, const char * _value ); | |
| | | | |
| #ifdef TIXML_USE_STL | | #ifdef TIXML_USE_STL | |
| const char* Attribute( const std::string& name ) const
{ return Attribute( name.c_str() ); } | | const char* Attribute( const std::string& name ) const
{ return Attribute( name.c_str() ); } | |
| const char* Attribute( const std::string& name, int* i ) const
{ return Attribute( name.c_str(), i ); } | | const char* Attribute( const std::string& name, int* i ) const
{ return Attribute( name.c_str(), i ); } | |
| const char* Attribute( const std::string& name, double* d ) const
{ return Attribute( name.c_str(), d ); } | | const char* Attribute( const std::string& name, double* d ) const
{ return Attribute( name.c_str(), d ); } | |
|
| int QueryIntAttribute( const std::string& name, int* value ) const | | int QueryIntAttribute( const std::string& name, int* _value ) const | |
| { return QueryIntAttribute( name.c_str(), value ); } | | { return QueryIntAttribute( name.c_str(), _value ); } | |
| int QueryDoubleAttribute( const std::string& name, double* value ) c | | int QueryDoubleAttribute( const std::string& name, double* _value ) | |
| onst { return QueryDoubleAttribute( name.c_str(), value ); } | | const { return QueryDoubleAttribute( name.c_str(), _value ); } | |
| | | | |
| /// STL std::string form. | | /// STL std::string form. | |
| void SetAttribute( const std::string& name, const std::string& _valu
e ) | | void SetAttribute( const std::string& name, const std::string& _valu
e ) | |
| { | | { | |
| StringToBuffer n( name ); | | StringToBuffer n( name ); | |
| StringToBuffer v( _value ); | | StringToBuffer v( _value ); | |
| if ( n.buffer && v.buffer ) | | if ( n.buffer && v.buffer ) | |
| SetAttribute (n.buffer, v.buffer ); | | SetAttribute (n.buffer, v.buffer ); | |
| } | | } | |
| ///< STL std::string form. | | ///< STL std::string form. | |
| | | | |
| skipping to change at line 912 | | skipping to change at line 945 | |
| void RemoveAttribute( const char * name ); | | void RemoveAttribute( const char * name ); | |
| #ifdef TIXML_USE_STL | | #ifdef TIXML_USE_STL | |
| void RemoveAttribute( const std::string& name ) { RemoveAttrib
ute (name.c_str ()); } ///< STL std::string form. | | void RemoveAttribute( const std::string& name ) { RemoveAttrib
ute (name.c_str ()); } ///< STL std::string form. | |
| #endif | | #endif | |
| | | | |
| const TiXmlAttribute* FirstAttribute() const { return attributeSe
t.First(); } ///< Access the first attribute in this element
. | | const TiXmlAttribute* FirstAttribute() const { return attributeSe
t.First(); } ///< Access the first attribute in this element
. | |
| TiXmlAttribute* FirstAttribute() { re
turn attributeSet.First(); } | | TiXmlAttribute* FirstAttribute() { re
turn attributeSet.First(); } | |
| const TiXmlAttribute* LastAttribute() const { return attributeSe
t.Last(); } ///< Access the last attribute in this element. | | const TiXmlAttribute* LastAttribute() const { return attributeSe
t.Last(); } ///< Access the last attribute in this element. | |
| TiXmlAttribute* LastAttribute() { re
turn attributeSet.Last(); } | | TiXmlAttribute* LastAttribute() { re
turn attributeSet.Last(); } | |
| | | | |
|
| | | /** Convenience function for easy access to the text inside an eleme | |
| | | nt. Although easy | |
| | | and concise, GetText() is limited compared to getting the Ti | |
| | | XmlText child | |
| | | and accessing it directly. | |
| | | | |
| | | If the first child of 'this' is a TiXmlText, the GetText() | |
| | | returs the character string of the Text node, else null is r | |
| | | eturned. | |
| | | | |
| | | This is a convenient method for getting the text of simple c | |
| | | ontained text: | |
| | | @verbatim | |
| | | <foo>This is text</foo> | |
| | | const char* str = fooElement->GetText(); | |
| | | @endverbatim | |
| | | | |
| | | 'str' will be a pointer to "This is text". | |
| | | | |
| | | Note that this function can be misleading. If the element fo | |
| | | o was created from | |
| | | this XML: | |
| | | @verbatim | |
| | | <foo><b>This is text</b></foo> | |
| | | @endverbatim | |
| | | | |
| | | then the value of str would be null. The first child node is | |
| | | n't a text node, it is | |
| | | another element. From this XML: | |
| | | @verbatim | |
| | | <foo>This is <b>text</b></foo> | |
| | | @endverbatim | |
| | | GetText() will return "This is ". | |
| | | | |
| | | WARNING: GetText() accesses a child node - don't become conf | |
| | | used with the | |
| | | similarly named TiXmlHandle::Text() and TiX | |
| | | mlNode::ToText() which are | |
| | | safe type casts on the referenced node. | |
| | | */ | |
| | | const char* GetText() const; | |
| | | | |
| /// Creates a new Element and returns it - the returned element is a
copy. | | /// Creates a new Element and returns it - the returned element is a
copy. | |
| virtual TiXmlNode* Clone() const; | | virtual TiXmlNode* Clone() const; | |
| // Print the Element to a FILE stream. | | // Print the Element to a FILE stream. | |
| virtual void Print( FILE* cfile, int depth ) const; | | virtual void Print( FILE* cfile, int depth ) const; | |
| | | | |
| /* Attribtue parsing starts: next char past '<' | | /* Attribtue parsing starts: next char past '<' | |
| returns: next char past '>' | | returns: next char past '>' | |
| */ | | */ | |
| virtual const char* Parse( const char* p, TiXmlParsingData* data, Ti
XmlEncoding encoding ); | | virtual const char* Parse( const char* p, TiXmlParsingData* data, Ti
XmlEncoding encoding ); | |
| | | | |
| | | | |
| skipping to change at line 979 | | skipping to change at line 1046 | |
| // used to be public | | // used to be public | |
| #ifdef TIXML_USE_STL | | #ifdef TIXML_USE_STL | |
| virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ); | | virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ); | |
| #endif | | #endif | |
| virtual void StreamOut( TIXML_OSTREAM * out ) const; | | virtual void StreamOut( TIXML_OSTREAM * out ) const; | |
| | | | |
| private: | | private: | |
| | | | |
| }; | | }; | |
| | | | |
|
| /** XML text. Contained in an element. | | /** XML text. A text node can have 2 ways to output the next. "normal" outp | |
| | | ut | |
| | | and CDATA. It will default to the mode it was parsed from the XML fi | |
| | | le and | |
| | | you generally want to leave it alone, but you can change the output | |
| | | mode with | |
| | | SetCDATA() and query it with CDATA(). | |
| */ | | */ | |
| class TiXmlText : public TiXmlNode | | class TiXmlText : public TiXmlNode | |
| { | | { | |
| friend class TiXmlElement; | | friend class TiXmlElement; | |
| public: | | public: | |
|
| /// Constructor. | | /** Constructor for text element. By default, it is treated as | |
| TiXmlText (const char * initValue) : TiXmlNode (TiXmlNode::TEXT) | | normal, encoded text. If you want it be output as a CDATA te | |
| | | xt | |
| | | element, set the parameter _cdata to 'true' | |
| | | */ | |
| | | TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TEXT) | |
| { | | { | |
| SetValue( initValue ); | | SetValue( initValue ); | |
|
| | | cdata = false; | |
| } | | } | |
| virtual ~TiXmlText() {} | | virtual ~TiXmlText() {} | |
| | | | |
| #ifdef TIXML_USE_STL | | #ifdef TIXML_USE_STL | |
| /// Constructor. | | /// Constructor. | |
| TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TE
XT) | | TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TE
XT) | |
| { | | { | |
| SetValue( initValue ); | | SetValue( initValue ); | |
|
| | | cdata = false; | |
| } | | } | |
| #endif | | #endif | |
| | | | |
| TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT )
{ copy.CopyTo( this ); } | | TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT )
{ copy.CopyTo( this ); } | |
| void operator=( const TiXmlText& base )
{ base.CopyTo( this ); } | | void operator=( const TiXmlText& base )
{ base.CopyTo( this ); } | |
| | | | |
| /// Write this text object to a FILE stream. | | /// Write this text object to a FILE stream. | |
| virtual void Print( FILE* cfile, int depth ) const; | | virtual void Print( FILE* cfile, int depth ) const; | |
| | | | |
|
| | | /// Queries whether this represents text using a CDATA section. | |
| | | bool CDATA() { return cdata; } | |
| | | /// Turns on or off a CDATA representation of text. | |
| | | void SetCDATA( bool _cdata ) { cdata = _cdata; } | |
| | | | |
| virtual const char* Parse( const char* p, TiXmlParsingData* data, Ti
XmlEncoding encoding ); | | virtual const char* Parse( const char* p, TiXmlParsingData* data, Ti
XmlEncoding encoding ); | |
| | | | |
| protected : | | protected : | |
| /// [internal use] Creates a new Element and returns it. | | /// [internal use] Creates a new Element and returns it. | |
| virtual TiXmlNode* Clone() const; | | virtual TiXmlNode* Clone() const; | |
| void CopyTo( TiXmlText* target ) const; | | void CopyTo( TiXmlText* target ) const; | |
| | | | |
| virtual void StreamOut ( TIXML_OSTREAM * out ) const; | | virtual void StreamOut ( TIXML_OSTREAM * out ) const; | |
| bool Blank() const; // returns true if all white space and new l
ines | | bool Blank() const; // returns true if all white space and new l
ines | |
| // [internal use] | | // [internal use] | |
| #ifdef TIXML_USE_STL | | #ifdef TIXML_USE_STL | |
| virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ); | | virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ); | |
| #endif | | #endif | |
| | | | |
| private: | | private: | |
|
| | | bool cdata; // true if this should be input and
output as a CDATA style text element | |
| }; | | }; | |
| | | | |
| /** In correct XML the declaration is the first entry in the file. | | /** In correct XML the declaration is the first entry in the file. | |
| @verbatim | | @verbatim | |
| <?xml version="1.0" standalone="yes"?> | | <?xml version="1.0" standalone="yes"?> | |
| @endverbatim | | @endverbatim | |
| | | | |
| TinyXml will happily read or write files without a declaration, | | TinyXml will happily read or write files without a declaration, | |
| however. There are 3 possible attributes to the declaration: | | however. There are 3 possible attributes to the declaration: | |
| version, encoding, and standalone. | | version, encoding, and standalone. | |
| | | | |
| skipping to change at line 1196 | | skipping to change at line 1277 | |
| - The ErrorRow() and ErrorCol() will return the location of
the error (if known) | | - The ErrorRow() and ErrorCol() will return the location of
the error (if known) | |
| */ | | */ | |
| bool Error() const { re
turn error; } | | bool Error() const { re
turn error; } | |
| | | | |
| /// Contains a textual (english) description of the error if one occ
urs. | | /// Contains a textual (english) description of the error if one occ
urs. | |
| const char * ErrorDesc() const { return errorDesc.c_str (); } | | const char * ErrorDesc() const { return errorDesc.c_str (); } | |
| | | | |
| /** Generally, you probably want the error string ( ErrorDesc() ). B
ut if you | | /** Generally, you probably want the error string ( ErrorDesc() ). B
ut if you | |
| prefer the ErrorId, this function will fetch it. | | prefer the ErrorId, this function will fetch it. | |
| */ | | */ | |
|
| const int ErrorId() const { return err
orId; } | | int ErrorId() const { return errorId; } | |
| | | | |
| /** Returns the location (if known) of the error. The first column i
s column 1, | | /** Returns the location (if known) of the error. The first column i
s column 1, | |
| and the first row is row 1. A value of 0 means the row and c
olumn wasn't applicable | | and the first row is row 1. A value of 0 means the row and c
olumn wasn't applicable | |
| (memory errors, for example, have no row/column) or the pars
er lost the error. (An | | (memory errors, for example, have no row/column) or the pars
er lost the error. (An | |
| error in the error reporting, in that case.) | | error in the error reporting, in that case.) | |
| | | | |
| @sa SetTabSize, Row, Column | | @sa SetTabSize, Row, Column | |
| */ | | */ | |
| int ErrorRow() { return errorLocation.row+1; } | | int ErrorRow() { return errorLocation.row+1; } | |
| int ErrorCol() { return errorLocation.col+1; } ///< The column wher
e the error occured. See ErrorRow() | | int ErrorCol() { return errorLocation.col+1; } ///< The column wher
e the error occured. See ErrorRow() | |
| | | | |
|
| /** By calling this method, with a tab size | | /** SetTabSize() allows the error reporting functions (ErrorRow() an | |
| | | d ErrorCol()) | |
| | | to report the correct values for row and column. It does not | |
| | | change the output | |
| | | or input in any way. | |
| | | | |
| | | By calling this method, with a tab size | |
| greater than 0, the row and column of each node and attribut
e is stored | | greater than 0, the row and column of each node and attribut
e is stored | |
| when the file is loaded. Very useful for tracking the DOM ba
ck in to | | when the file is loaded. Very useful for tracking the DOM ba
ck in to | |
| the source file. | | the source file. | |
| | | | |
| The tab size is required for calculating the location of nod
es. If not | | The tab size is required for calculating the location of nod
es. If not | |
| set, the default of 4 is used. The tabsize is set per docume
nt. Setting | | set, the default of 4 is used. The tabsize is set per docume
nt. Setting | |
| the tabsize to 0 disables row/column tracking. | | the tabsize to 0 disables row/column tracking. | |
| | | | |
| Note that row and column tracking is not supported when usin
g operator>>. | | Note that row and column tracking is not supported when usin
g operator>>. | |
| | | | |
| | | | |
| skipping to change at line 1266 | | skipping to change at line 1351 | |
| #endif | | #endif | |
| | | | |
| private: | | private: | |
| void CopyTo( TiXmlDocument* target ) const; | | void CopyTo( TiXmlDocument* target ) const; | |
| | | | |
| bool error; | | bool error; | |
| int errorId; | | int errorId; | |
| TIXML_STRING errorDesc; | | TIXML_STRING errorDesc; | |
| int tabsize; | | int tabsize; | |
| TiXmlCursor errorLocation; | | TiXmlCursor errorLocation; | |
|
| | | bool useMicrosoftBOM; // the UTF-8 BOM were found when rea
d. Note this, and try to write. | |
| }; | | }; | |
| | | | |
| /** | | /** | |
| A TiXmlHandle is a class that wraps a node pointer with null checks;
this is | | A TiXmlHandle is a class that wraps a node pointer with null checks;
this is | |
| an incredibly useful thing. Note that TiXmlHandle is not part of the
TinyXml | | an incredibly useful thing. Note that TiXmlHandle is not part of the
TinyXml | |
| DOM structure. It is a separate utility class. | | DOM structure. It is a separate utility class. | |
| | | | |
| Take an example: | | Take an example: | |
| @verbatim | | @verbatim | |
| <Document> | | <Document> | |
| | | | |
| skipping to change at line 1352 | | skipping to change at line 1438 | |
| for( child; child; child=child->NextSiblingElement() ) | | for( child; child; child=child->NextSiblingElement() ) | |
| { | | { | |
| // do something | | // do something | |
| } | | } | |
| @endverbatim | | @endverbatim | |
| */ | | */ | |
| class TiXmlHandle | | class TiXmlHandle | |
| { | | { | |
| public: | | public: | |
| /// Create a handle from any node (at any depth of the tree.) This c
an be a null pointer. | | /// Create a handle from any node (at any depth of the tree.) This c
an be a null pointer. | |
|
| TiXmlHandle( TiXmlNode* node ) { th
is->node = node; } | | TiXmlHandle( TiXmlNode* _node ) { th
is->node = _node; } | |
| /// Copy constructor | | /// Copy constructor | |
| TiXmlHandle( const TiXmlHandle& ref ) { this->node
= ref.node; } | | TiXmlHandle( const TiXmlHandle& ref ) { this->node
= ref.node; } | |
| TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.n
ode; return *this; } | | TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.n
ode; return *this; } | |
| | | | |
| /// Return a handle to the first child node. | | /// Return a handle to the first child node. | |
| TiXmlHandle FirstChild() const; | | TiXmlHandle FirstChild() const; | |
| /// Return a handle to the first child node with the given name. | | /// Return a handle to the first child node with the given name. | |
| TiXmlHandle FirstChild( const char * value ) const; | | TiXmlHandle FirstChild( const char * value ) const; | |
| /// Return a handle to the first child element. | | /// Return a handle to the first child element. | |
| TiXmlHandle FirstChildElement() const; | | TiXmlHandle FirstChildElement() const; | |
| | | | |
| skipping to change at line 1407 | | skipping to change at line 1493 | |
| /// Return the handle as a TiXmlText. This may return null. | | /// Return the handle as a TiXmlText. This may return null. | |
| TiXmlText* Text() const { return ( ( node && node->T
oText() ) ? node->ToText() : 0 ); } | | TiXmlText* Text() const { return ( ( node && node->T
oText() ) ? node->ToText() : 0 ); } | |
| /// Return the handle as a TiXmlUnknown. This may return null; | | /// Return the handle as a TiXmlUnknown. This may return null; | |
| TiXmlUnknown* Unknown() const { return ( ( node &&
node->ToUnknown() ) ? node->ToUnknown() : 0 ); } | | TiXmlUnknown* Unknown() const { return ( ( node &&
node->ToUnknown() ) ? node->ToUnknown() : 0 ); } | |
| | | | |
| private: | | private: | |
| TiXmlNode* node; | | TiXmlNode* node; | |
| }; | | }; | |
| | | | |
| #ifdef _MSC_VER | | #ifdef _MSC_VER | |
|
| #pragma warning( default : 4530 ) | | #pragma warning( pop ) | |
| #pragma warning( default : 4786 ) | | | |
| #endif | | #endif | |
| | | | |
| #endif | | #endif | |
| | | | |
End of changes. 30 change blocks. |
| 37 lines changed or deleted | | 139 lines changed or added | |
|