tinyxml.h | tinyxml.h | |||
---|---|---|---|---|
skipping to change at line 54 | skipping to change at line 54 | |||
#if defined( DEBUG ) && defined( _MSC_VER ) | #if defined( DEBUG ) && defined( _MSC_VER ) | |||
#include <windows.h> | #include <windows.h> | |||
#define TIXML_LOG OutputDebugString | #define TIXML_LOG OutputDebugString | |||
#else | #else | |||
#define TIXML_LOG printf | #define TIXML_LOG printf | |||
#endif | #endif | |||
#ifdef TIXML_USE_STL | #ifdef TIXML_USE_STL | |||
#include <string> | #include <string> | |||
#include <iostream> | #include <iostream> | |||
//#include <ostream> | ||||
#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 | |||
class TiXmlDocument; | class TiXmlDocument; | |||
skipping to change at line 71 | skipping to change at line 70 | |||
#define TIXML_OSTREAM TiXmlOutStream | #define TIXML_OSTREAM TiXmlOutStream | |||
#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_MINOR_VERSION = 3; | ||||
const int TIXML_PATCH_VERSION = 1; | ||||
/* 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. | |||
int col; // 0 based. | int col; // 0 based. | |||
}; | }; | |||
// Only used by Attribute::Query functions | // Only used by Attribute::Query functions | |||
enum | enum | |||
{ | { | |||
TIXML_SUCCESS, | TIXML_SUCCESS, | |||
TIXML_NO_ATTRIBUTE, | TIXML_NO_ATTRIBUTE, | |||
TIXML_WRONG_TYPE | TIXML_WRONG_TYPE | |||
}; | }; | |||
// Used by the parsing routines. | ||||
enum TiXmlEncoding | ||||
{ | ||||
TIXML_ENCODING_UNKNOWN, | ||||
TIXML_ENCODING_UTF8, | ||||
TIXML_ENCODING_LEGACY | ||||
}; | ||||
const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN; | ||||
/** TiXmlBase is a base class for every class in TinyXml. | /** TiXmlBase is a base class for every class in TinyXml. | |||
It does little except to establish that TinyXml classes | It does little except to establish that TinyXml classes | |||
can be printed and provide some utility functions. | can be printed and provide some utility functions. | |||
In XML, the document and elements can contain | In XML, the document and elements can contain | |||
other elements and other types of nodes. | other elements and other types of nodes. | |||
@verbatim | @verbatim | |||
A Document can contain: Element (container or leaf) | A Document can contain: Element (container or leaf) | |||
Comment (leaf) | Comment (leaf) | |||
skipping to change at line 123 | skipping to change at line 135 | |||
A Decleration contains: Attributes (not on tree) | A Decleration contains: Attributes (not on tree) | |||
@endverbatim | @endverbatim | |||
*/ | */ | |||
class TiXmlBase | class TiXmlBase | |||
{ | { | |||
friend class TiXmlNode; | friend class TiXmlNode; | |||
friend class TiXmlElement; | friend class TiXmlElement; | |||
friend class TiXmlDocument; | friend class TiXmlDocument; | |||
public: | public: | |||
TiXmlBase() {userData = 0;} | TiXmlBase() : userData(0) {} | |||
virtual ~TiXmlBase() {} | virtual ~TiXmlBase() {} | |||
/** All TinyXml classes can print themselves to a filestream. | /** All TinyXml classes can print themselves to a filestream. | |||
This is a formatted print, and will insert tabs and newlines . | This is a formatted print, and will insert tabs and newlines . | |||
(For an unformatted stream, use the << operator.) | (For an unformatted stream, use the << operator.) | |||
*/ | */ | |||
virtual void Print( FILE* cfile, int depth ) const = 0; | virtual void Print( FILE* cfile, int depth ) const = 0; | |||
/** The world does not agree on whether white space should be ke pt or | /** The world does not agree on whether white space should be ke pt or | |||
skipping to change at line 172 | skipping to change at line 184 | |||
int Row() const { return location.row + 1; } | int Row() const { return location.row + 1; } | |||
int Column() const { return location.col + 1; } ///< See Row() | int Column() const { return location.col + 1; } ///< See Row() | |||
void SetUserData( void* user ) { userData = user; } | void SetUserData( void* user ) { userData = user; } | |||
void* GetUserData() { re turn userData; } | void* GetUserData() { re turn userData; } | |||
// Table that returs, for a given lead byte, the total number of byt es | // Table that returs, for a given lead byte, the total number of byt es | |||
// in the UTF-8 sequence. | // in the UTF-8 sequence. | |||
static const int utf8ByteTable[256]; | static const int utf8ByteTable[256]; | |||
virtual const char* Parse( const char* p, | ||||
TiXmlParsing | ||||
Data* data, | ||||
TiXmlEncodin | ||||
g encoding /*= TIXML_ENCODING_UNKNOWN */ ) = 0; | ||||
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 | |||
{ | { | |||
public: | public: | |||
StringToBuffer( const TIXML_STRING& str ); | StringToBuffer( const TIXML_STRING& str ); | |||
~StringToBuffer(); | ~StringToBuffer(); | |||
char* buffer; | char* buffer; | |||
}; | }; | |||
static const char* SkipWhiteSpace( const char* ); | static const char* SkipWhiteSpace( const char*, TiXmlEncoding e ncoding ); | |||
inline static bool IsWhiteSpace( char c ) | inline static bool IsWhiteSpace( char c ) | |||
{ | { | |||
return ( isspace( (unsigned char) c ) || c == '\n' || c == ' \r' ); | return ( isspace( (unsigned char) c ) || c == '\n' || c == ' \r' ); | |||
} | } | |||
virtual void StreamOut (TIXML_OSTREAM *) const = 0; | virtual void StreamOut (TIXML_OSTREAM *) const = 0; | |||
#ifdef TIXML_USE_STL | #ifdef TIXML_USE_STL | |||
static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag ); | static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag ); | |||
static bool StreamTo( TIXML_ISTREAM * in, int character, TIXML_S TRING * tag ); | static bool StreamTo( TIXML_ISTREAM * in, int character, TIXML_S TRING * tag ); | |||
#endif | #endif | |||
/* Reads an XML name into the string provided. Returns | /* Reads an XML name into the string provided. Returns | |||
a pointer just past the last character of the name, | a pointer just past the last character of the name, | |||
or 0 if the function has an error. | or 0 if the function has an error. | |||
*/ | */ | |||
static const char* ReadName( const char* p, TIXML_STRING* name ); | static const char* ReadName( const char* p, TIXML_STRING* name, TiXm lEncoding encoding ); | |||
/* Reads text. Returns a pointer past the given end tag. | /* Reads text. Returns a pointer past the given end tag. | |||
Wickedly complex options, but it keeps the (sensitive) code in one place. | Wickedly complex options, but it keeps the (sensitive) code in one place. | |||
*/ | */ | |||
static const char* ReadText( const char* in, // where to start | static const char* ReadText( const char* in, // where to start | |||
TIXM L_STRING* text, // the string read | TIXM L_STRING* text, // the string read | |||
bool ignoreWhiteSpace, // whether to keep the white space | bool ignoreWhiteSpace, // whether to keep the white space | |||
cons t char* endTag, // what ends this text | cons t char* endTag, // what ends this text | |||
bool | bool | |||
ignoreCase ); // whether to ignore case in the end ta | ignoreCase, // whether to ignore case in the end ta | |||
g | g | |||
TiXm | ||||
virtual const char* Parse( const char* p, TiXmlParsingData* data ) = | lEncoding encoding ); // the current encoding | |||
0; | ||||
// If an entity has been found, transform it into a character. | // If an entity has been found, transform it into a character. | |||
static const char* GetEntity( const char* in, char* value, int* leng th ); | static const char* GetEntity( const char* in, char* value, int* leng th, TiXmlEncoding encoding ); | |||
// Get a character, while interpreting entities. | // Get a character, while interpreting entities. | |||
// The length can be from 0 to 4 bytes. | // The length can be from 0 to 4 bytes. | |||
inline static const char* GetCharUTF8( const char* p, char* _value, int* length ) | inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding ) | |||
{ | { | |||
assert( p ); | assert( p ); | |||
*length = utf8ByteTable[ *((unsigned char*)p) ]; | if ( encoding == TIXML_ENCODING_UTF8 ) | |||
assert( *length >= 0 && *length < 5 ); | { | |||
*length = utf8ByteTable[ *((unsigned char*)p) ]; | ||||
assert( *length >= 0 && *length < 5 ); | ||||
} | ||||
else | ||||
{ | ||||
*length = 1; | ||||
} | ||||
if ( *length == 1 ) | if ( *length == 1 ) | |||
{ | { | |||
if ( *p == '&' ) | if ( *p == '&' ) | |||
return GetEntity( p, _value, length ); | 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 ); | |||
return p + (*length); | return p + (*length); | |||
} | } | |||
else | else | |||
{ | { | |||
skipping to change at line 255 | skipping to change at line 277 | |||
// 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 Engilish 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 | bool ignoreC | |||
ase ); | ase, | |||
TiXmlEncodin | ||||
g encoding ); | ||||
enum | enum | |||
{ | { | |||
TIXML_NO_ERROR = 0, | TIXML_NO_ERROR = 0, | |||
TIXML_ERROR, | TIXML_ERROR, | |||
TIXML_ERROR_OPENING_FILE, | TIXML_ERROR_OPENING_FILE, | |||
TIXML_ERROR_OUT_OF_MEMORY, | TIXML_ERROR_OUT_OF_MEMORY, | |||
TIXML_ERROR_PARSING_ELEMENT, | TIXML_ERROR_PARSING_ELEMENT, | |||
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_STRING_COUNT | TIXML_ERROR_STRING_COUNT | |||
}; | }; | |||
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 | |||
void* userData; | void* userData; | |||
// None of these methods are reliable for any language except Englis h. | // None of these methods are reliable for any language except Englis h. | |||
// Good for approximation, not great for accuracy. | // Good for approximation, not great for accuracy. | |||
static int IsAlphaUTF8( unsigned char anyByte ); | static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding ); | |||
static int IsAlphaNumUTF8( unsigned char anyByte ); | static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding | |||
inline static int ToLowerUTF8( int v ) | ); | |||
inline static int ToLower( int v, TiXmlEncoding encoding ) | ||||
{ | { | |||
if ( v < 128 ) return tolower( v ); | if ( encoding == TIXML_ENCODING_UTF8 ) | |||
return v; | { | |||
if ( v < 128 ) return tolower( v ); | ||||
return v; | ||||
} | ||||
else | ||||
{ | ||||
return tolower( v ); | ||||
} | ||||
} | } | |||
static void ConvertUTF32ToUTF8( unsigned long input, char* output, i nt* length ); | static void ConvertUTF32ToUTF8( unsigned long input, char* output, i nt* length ); | |||
private: | private: | |||
TiXmlBase( const TiXmlBase& ); // not imple mented. | TiXmlBase( const TiXmlBase& ); // not imple mented. | |||
void operator=( const TiXmlBase& base ); // not allowed. | void operator=( const TiXmlBase& base ); // not allowed. | |||
struct Entity | struct Entity | |||
{ | { | |||
const char* str; | const char* str; | |||
skipping to change at line 549 | skipping to change at line 580 | |||
/// Returns true if this node has no children. | /// Returns true if this node has no children. | |||
bool NoChildren() const { re turn !firstChild; } | bool NoChildren() const { re turn !firstChild; } | |||
TiXmlDocument* ToDocument() const { return ( this && t ype == DOCUMENT ) ? (TiXmlDocument*) this : 0; } ///< Cast to a more define d type. Will return null not of the requested type. | TiXmlDocument* ToDocument() const { return ( this && t ype == DOCUMENT ) ? (TiXmlDocument*) this : 0; } ///< Cast to a more define d type. Will return null not of the requested type. | |||
TiXmlElement* ToElement() const { return ( this && t ype == ELEMENT ) ? (TiXmlElement*) this : 0; } ///< Cast to a more define d type. Will return null not of the requested type. | TiXmlElement* ToElement() const { return ( this && t ype == ELEMENT ) ? (TiXmlElement*) this : 0; } ///< Cast to a more define d type. Will return null not of the requested type. | |||
TiXmlComment* ToComment() const { return ( this && t ype == COMMENT ) ? (TiXmlComment*) this : 0; } ///< Cast to a more define d type. Will return null not of the requested type. | TiXmlComment* ToComment() const { return ( this && t ype == COMMENT ) ? (TiXmlComment*) this : 0; } ///< Cast to a more define d type. Will return null not of the requested type. | |||
TiXmlUnknown* ToUnknown() const { return ( this && t ype == UNKNOWN ) ? (TiXmlUnknown*) this : 0; } ///< Cast to a more define d type. Will return null not of the requested type. | TiXmlUnknown* ToUnknown() const { return ( this && t ype == UNKNOWN ) ? (TiXmlUnknown*) this : 0; } ///< Cast to a more define d type. Will return null not of the requested type. | |||
TiXmlText* ToText() const { return ( this && t ype == TEXT ) ? (TiXmlText*) this : 0; } ///< Cast to a more define d type. Will return null not of the requested type. | TiXmlText* ToText() const { return ( this && t ype == TEXT ) ? (TiXmlText*) this : 0; } ///< Cast to a more define d type. Will return null not of the requested type. | |||
TiXmlDeclaration* ToDeclaration() const { return ( this && type == D ECLARATION ) ? (TiXmlDeclaration*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. | TiXmlDeclaration* ToDeclaration() const { return ( this && type == D ECLARATION ) ? (TiXmlDeclaration*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. | |||
/** Create an exact duplicate of this node and return it. The memory | ||||
must be deleted | ||||
by the caller. | ||||
*/ | ||||
virtual TiXmlNode* Clone() const = 0; | virtual TiXmlNode* Clone() const = 0; | |||
protected: | protected: | |||
TiXmlNode( NodeType _type ); | TiXmlNode( NodeType _type ); | |||
// Copy to the allocated object. Shared functionality between Clone, | ||||
Copy constructor, | ||||
// and the assignment operator. | ||||
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 ); | TiXmlNode* Identify( const char* start, TiXmlEncoding encoding ); | |||
void CopyToClone( TiXmlNode* target ) const { target->SetValue ( | ||||
value.c_str() ); | ||||
target->userData = userData; } | ||||
// Internal Value function returning a TIXML_STRING | // Internal Value function returning a TIXML_STRING | |||
const TIXML_STRING& SValue() const { return value ; } | const TIXML_STRING& SValue() const { return value ; } | |||
TiXmlNode* parent; | TiXmlNode* parent; | |||
NodeType type; | NodeType type; | |||
TiXmlNode* firstChild; | TiXmlNode* firstChild; | |||
TiXmlNode* lastChild; | TiXmlNode* lastChild; | |||
skipping to change at line 670 | skipping to change at line 706 | |||
/// Get the next sibling attribute in the DOM. Returns null at end. | /// Get the next sibling attribute in the DOM. Returns null at end. | |||
TiXmlAttribute* Next() const; | TiXmlAttribute* Next() const; | |||
/// Get the previous sibling attribute in the DOM. Returns null at b eginning. | /// Get the previous sibling attribute in the DOM. Returns null at b eginning. | |||
TiXmlAttribute* Previous() const; | TiXmlAttribute* Previous() const; | |||
bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; } | bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; } | |||
bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; } | bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; } | |||
bool operator>( const TiXmlAttribute& rhs ) const { return name > r hs.name; } | bool operator>( const TiXmlAttribute& rhs ) const { return name > r hs.name; } | |||
/* [internal use] | /* Attribute parsing starts: first letter of the name | |||
Attribtue parsing starts: first letter of the name | ||||
returns: the next char afte r the value end quote | returns: the next char afte r the value end quote | |||
*/ | */ | |||
virtual const char* Parse( const char* p, TiXmlParsingData* data ); | virtual const char* Parse( const char* p, TiXmlParsingData* data, Ti XmlEncoding encoding ); | |||
// [internal use] | // Prints this Attribute to a FILE stream. | |||
virtual void Print( FILE* cfile, int depth ) const; | virtual void Print( FILE* cfile, int depth ) const; | |||
virtual void StreamOut( TIXML_OSTREAM * out ) const; | virtual void StreamOut( TIXML_OSTREAM * out ) const; | |||
// [internal use] | // [internal use] | |||
// Set the document pointer so the attribute can report errors. | // Set the document pointer so the attribute can report errors. | |||
void SetDocument( TiXmlDocument* doc ) { document = doc; } | void SetDocument( TiXmlDocument* doc ) { document = doc; } | |||
private: | private: | |||
TiXmlAttribute( const TiXmlAttribute& ); // not implemented. | TiXmlAttribute( const TiXmlAttribute& ); // not implemented. | |||
void operator=( const TiXmlAttribute& base ); // not allowed. | void operator=( const TiXmlAttribute& base ); // not allowed. | |||
skipping to change at line 736 | skipping to change at line 771 | |||
Elements also contain an arbitrary number of attributes. | Elements also contain an arbitrary number of attributes. | |||
*/ | */ | |||
class TiXmlElement : public TiXmlNode | class TiXmlElement : public TiXmlNode | |||
{ | { | |||
public: | public: | |||
/// Construct an element. | /// Construct an element. | |||
TiXmlElement (const char * in_value); | TiXmlElement (const char * in_value); | |||
#ifdef TIXML_USE_STL | #ifdef TIXML_USE_STL | |||
/// std::string constructor. | /// std::string constructor. | |||
TiXmlElement( const std::string& _value ) : TiXmlNode( TiXmlNode | TiXmlElement( const std::string& _value ); | |||
::ELEMENT ) | ||||
{ | ||||
firstChild = lastChild = 0; | ||||
value = _value; | ||||
} | ||||
#endif | #endif | |||
TiXmlElement( const TiXmlElement& ); | ||||
void operator=( const TiXmlElement& base ); | ||||
virtual ~TiXmlElement(); | virtual ~TiXmlElement(); | |||
/** Given an attribute name, Attribute() returns the value | /** Given an attribute name, Attribute() returns the value | |||
for the attribute of that name, or null if none exists. | for the attribute of that name, or null if none exists. | |||
*/ | */ | |||
const char* Attribute( const char* name ) const; | const char* Attribute( const char* name ) const; | |||
/** Given an attribute name, Attribute() returns the value | /** Given an attribute name, Attribute() returns the value | |||
for the attribute of that name, or null if none exists. | for the attribute of that name, or null if none exists. | |||
If the attribute exists and can be converted to an integer, | If the attribute exists and can be converted to an integer, | |||
skipping to change at line 785 | skipping to change at line 820 | |||
int QueryDoubleAttribute( const char* name, double* value ) const; | int QueryDoubleAttribute( const char* name, double* value ) const; | |||
/** 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 ); } | ||||
int QueryIntAttribute( const std::string& name, int* value ) const | ||||
{ return QueryIntAttribute( name.c_str(), value ); } | ||||
int QueryDoubleAttribute( const std::string& name, double* value ) c | ||||
onst { 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 823 | skipping to change at line 861 | |||
/** Deletes an attribute with the given name. | /** Deletes an attribute with the given name. | |||
*/ | */ | |||
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 | |||
TiXmlAttribute* FirstAttribute() const { return attributeSet.First( ); } ///< Access the first attribute in this element. | TiXmlAttribute* FirstAttribute() const { return attributeSet.First( ); } ///< Access the first attribute in this element. | |||
TiXmlAttribute* LastAttribute() const { return attributeSet.Last() ; } ///< Access the last attribute in this element. | TiXmlAttribute* LastAttribute() const { return attributeSet.Last() ; } ///< Access the last attribute in this element. | |||
// [internal use] Creates a new Element and returs it. | /// Creates a new Element and returns it - the returned element is a copy. | |||
virtual TiXmlNode* Clone() const; | virtual TiXmlNode* Clone() const; | |||
// [internal use] | // 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 '<' | ||||
returns: next char past '>' | ||||
*/ | ||||
virtual const char* Parse( const char* p, TiXmlParsingData* data, Ti | ||||
XmlEncoding encoding ); | ||||
protected: | protected: | |||
void CopyTo( TiXmlElement* target ) const; | ||||
void ClearThis(); // like clear, but initializes 'this' object | ||||
as well | ||||
// Used to be public [internal use] | // Used to be public [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 | |||
virtual void StreamOut( TIXML_OSTREAM * out ) const; | virtual void StreamOut( TIXML_OSTREAM * out ) const; | |||
/* [internal use] | /* [internal use] | |||
Attribtue parsing starts: next char past '<' | ||||
returns: next char past '>' | ||||
*/ | ||||
virtual const char* Parse( const char* p, TiXmlParsingData* data ); | ||||
/* [internal use] | ||||
Reads the "value" of the element -- another element, or text . | Reads the "value" of the element -- another element, or text . | |||
This should terminate with the current end tag. | This should terminate with the current end tag. | |||
*/ | */ | |||
const char* ReadValue( const char* in, TiXmlParsingData* prevData ); | const char* ReadValue( const char* in, TiXmlParsingData* prevData, T iXmlEncoding encoding ); | |||
private: | private: | |||
TiXmlElement( const TiXmlElement& ); // n | ||||
ot implemented. | ||||
void operator=( const TiXmlElement& base ); // not allowed. | ||||
TiXmlAttributeSet attributeSet; | TiXmlAttributeSet attributeSet; | |||
}; | }; | |||
/** An XML comment. | /** An XML comment. | |||
*/ | */ | |||
class TiXmlComment : public TiXmlNode | class TiXmlComment : public TiXmlNode | |||
{ | { | |||
public: | public: | |||
/// Constructs an empty comment. | /// Constructs an empty comment. | |||
TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {} | TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {} | |||
TiXmlComment( const TiXmlComment& ); | ||||
void operator=( const TiXmlComment& base ); | ||||
virtual ~TiXmlComment() {} | virtual ~TiXmlComment() {} | |||
// [internal use] Creates a new Element and returs it. | /// Returns a copy of this Comment. | |||
virtual TiXmlNode* Clone() const; | virtual TiXmlNode* Clone() const; | |||
// [internal use] | /// Write this Comment to a FILE stream. | |||
virtual void Print( FILE* cfile, int depth ) const; | virtual void Print( FILE* cfile, int depth ) const; | |||
/* Attribtue parsing starts: at the ! of the !-- | ||||
returns: next char past '>' | ||||
*/ | ||||
virtual const char* Parse( const char* p, TiXmlParsingData* data, Ti | ||||
XmlEncoding encoding ); | ||||
protected: | protected: | |||
void CopyTo( TiXmlComment* target ) const; | ||||
// 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; | |||
/* [internal use] | ||||
Attribtue parsing starts: at the ! of the !-- | ||||
returns: next char past '>' | ||||
*/ | ||||
virtual const char* Parse( const char* p, TiXmlParsingData* data ); | ||||
private: | private: | |||
TiXmlComment( const TiXmlComment& ); // n | ||||
ot implemented. | ||||
void operator=( const TiXmlComment& base ); // not allowed. | ||||
}; | }; | |||
/** XML text. Contained in an element. | /** XML text. Contained in an element. | |||
*/ | */ | |||
class TiXmlText : public TiXmlNode | class TiXmlText : public TiXmlNode | |||
{ | { | |||
friend class TiXmlElement; | friend class TiXmlElement; | |||
public: | public: | |||
/// Constructor. | /// Constructor. | |||
skipping to change at line 909 | skipping to change at line 949 | |||
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 ); | |||
} | } | |||
#endif | #endif | |||
// [internal use] | TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT ) | |||
{ copy.CopyTo( this ); } | ||||
void operator=( const TiXmlText& base ) | ||||
{ base.CopyTo( this ); } | ||||
/// Write this text object to a FILE stream. | ||||
virtual void Print( FILE* cfile, int depth ) const; | virtual void Print( FILE* cfile, int depth ) const; | |||
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; | ||||
virtual void StreamOut ( TIXML_OSTREAM * out ) const; | virtual void StreamOut ( TIXML_OSTREAM * out ) const; | |||
// [internal use] | ||||
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] | ||||
Attribtue parsing starts: First char of the text | ||||
returns: next char | ||||
past '>' | ||||
*/ | ||||
virtual const char* Parse( const char* p, TiXmlParsingData* data ); | ||||
// [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: | |||
TiXmlText( const TiXmlText& ); // not imple | ||||
mented. | ||||
void operator=( const TiXmlText& base ); // not allowed. | ||||
}; | }; | |||
/** 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 956 | skipping to change at line 995 | |||
class TiXmlDeclaration : public TiXmlNode | class TiXmlDeclaration : public TiXmlNode | |||
{ | { | |||
public: | public: | |||
/// Construct an empty declaration. | /// Construct an empty declaration. | |||
TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {} | TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {} | |||
#ifdef TIXML_USE_STL | #ifdef TIXML_USE_STL | |||
/// Constructor. | /// Constructor. | |||
TiXmlDeclaration( const std::string& _version, | TiXmlDeclaration( const std::string& _version, | |||
const std::string& _encoding , | const std::string& _encoding , | |||
const std::string& _standalo | const std::string& _standalo | |||
ne ) | ne ); | |||
: TiXmlNode( TiXmlNode::DECLARATION ) | ||||
{ | ||||
version = _version; | ||||
encoding = _encoding; | ||||
standalone = _standalone; | ||||
} | ||||
#endif | #endif | |||
/// Construct. | /// Construct. | |||
TiXmlDeclaration( const char* _version, | TiXmlDeclaration( const char* _version, | |||
const char* _encoding, | const char* _encoding, | |||
const char* _standalone ); | const char* _standalone ); | |||
TiXmlDeclaration( const TiXmlDeclaration& copy ); | ||||
void operator=( const TiXmlDeclaration& copy ); | ||||
virtual ~TiXmlDeclaration() {} | virtual ~TiXmlDeclaration() {} | |||
/// Version. Will return empty if none was found. | /// Version. Will return an empty string if none was found. | |||
const char * Version() const { return version.c_str (); } | const char *Version() const { return version.c_s | |||
/// Encoding. Will return empty if none was found. | tr (); } | |||
const char * Encoding() const { return encoding.c_str (); | /// Encoding. Will return an empty string if none was found. | |||
} | const char *Encoding() const { return encoding.c_str (); | |||
} | ||||
/// Is this a standalone document? | /// Is this a standalone document? | |||
const char * Standalone() const { return standalone.c_str () ; } | const char *Standalone() const { return standalone.c_str () ; } | |||
// [internal use] Creates a new Element and returs it. | /// Creates a copy of this Declaration and returns it. | |||
virtual TiXmlNode* Clone() const; | virtual TiXmlNode* Clone() const; | |||
// [internal use] | /// Print this declaration to a FILE stream. | |||
virtual void Print( FILE* cfile, int depth ) const; | virtual void Print( FILE* cfile, int depth ) const; | |||
virtual const char* Parse( const char* p, TiXmlParsingData* data, Ti | ||||
XmlEncoding encoding ); | ||||
protected: | protected: | |||
void CopyTo( TiXmlDeclaration* target ) const; | ||||
// 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; | |||
// [internal use] | ||||
// Attribtue parsing starts: next char past '<' | ||||
// returns: next char past '>' | ||||
virtual const char* Parse( const char* p, TiXmlParsingData* data ); | ||||
private: | private: | |||
TiXmlDeclaration( const TiXmlDeclaration& copy ); | ||||
void operator=( const TiXmlDeclaration& copy ); | ||||
TIXML_STRING version; | TIXML_STRING version; | |||
TIXML_STRING encoding; | TIXML_STRING encoding; | |||
TIXML_STRING standalone; | TIXML_STRING standalone; | |||
}; | }; | |||
/** Any tag that tinyXml doesn't recognize is saved as an | /** Any tag that tinyXml doesn't recognize is saved as an | |||
unknown. It is a tag of text, but should not be modified. | unknown. It is a tag of text, but should not be modified. | |||
It will be written back to the XML, unchanged, when the file | It will be written back to the XML, unchanged, when the file | |||
is saved. | is saved. | |||
DTD tags get thrown into TiXmlUnknowns. | DTD tags get thrown into TiXmlUnknowns. | |||
*/ | */ | |||
class TiXmlUnknown : public TiXmlNode | class TiXmlUnknown : public TiXmlNode | |||
{ | { | |||
public: | public: | |||
TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {} | TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {} | |||
virtual ~TiXmlUnknown() {} | virtual ~TiXmlUnknown() {} | |||
// [internal use] | TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNK | |||
NOWN ) { copy.CopyTo( this ); } | ||||
void operator=( const TiXmlUnknown& copy ) | ||||
{ copy.CopyTo( this ); | ||||
} | ||||
/// Creates a copy of this Unknown and returns it. | ||||
virtual TiXmlNode* Clone() const; | virtual TiXmlNode* Clone() const; | |||
// [internal use] | /// Print this Unknown to a FILE stream. | |||
virtual void Print( FILE* cfile, int depth ) const; | virtual void Print( FILE* cfile, int depth ) const; | |||
virtual const char* Parse( const char* p, TiXmlParsingData* data, Ti | ||||
XmlEncoding encoding ); | ||||
protected: | protected: | |||
void CopyTo( TiXmlUnknown* target ) const; | ||||
#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; | |||
/* [internal use] | ||||
Attribute parsing starts: First char of the text | ||||
returns: next char past '>' | ||||
*/ | ||||
virtual const char* Parse( const char* p, TiXmlParsingData* data ); | ||||
private: | private: | |||
TiXmlUnknown( const TiXmlUnknown& copy ); | ||||
void operator=( const TiXmlUnknown& copy ); | ||||
}; | }; | |||
/** Always the top level node. A document binds together all the | /** Always the top level node. A document binds together all the | |||
XML pieces. It can be saved, loaded, and printed to the screen. | XML pieces. It can be saved, loaded, and printed to the screen. | |||
The 'value' of a document node is the xml file name. | The 'value' of a document node is the xml file name. | |||
*/ | */ | |||
class TiXmlDocument : public TiXmlNode | class TiXmlDocument : public TiXmlNode | |||
{ | { | |||
public: | public: | |||
/// Create an empty document, that has no name. | /// Create an empty document, that has no name. | |||
TiXmlDocument(); | TiXmlDocument(); | |||
/// Create a document with a name. The name of the document is also the filename of the xml. | /// Create a document with a name. The name of the document is also the filename of the xml. | |||
TiXmlDocument( const char * documentName ); | TiXmlDocument( const char * documentName ); | |||
#ifdef TIXML_USE_STL | #ifdef TIXML_USE_STL | |||
/// Constructor. | /// Constructor. | |||
TiXmlDocument( const std::string& documentName ) : | TiXmlDocument( const std::string& documentName ); | |||
TiXmlNode( TiXmlNode::DOCUMENT ) | ||||
{ | ||||
value = documentName; | ||||
error = false; | ||||
} | ||||
#endif | #endif | |||
TiXmlDocument( const TiXmlDocument& copy ); | ||||
void operator=( const TiXmlDocument& copy ); | ||||
virtual ~TiXmlDocument() {} | virtual ~TiXmlDocument() {} | |||
/** Load a file using the current document value. | /** Load a file using the current document value. | |||
Returns true if successful. Will delete any existing | Returns true if successful. Will delete any existing | |||
document data before loading. | document data before loading. | |||
*/ | */ | |||
bool LoadFile(); | bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); | |||
/// Save a file using the current document value. Returns true if su ccessful. | /// Save a file using the current document value. Returns true if su ccessful. | |||
bool SaveFile() const; | bool SaveFile() const; | |||
/// Load a file using the given filename. Returns true if successful . | /// Load a file using the given filename. Returns true if successful . | |||
bool LoadFile( const char * filename ); | bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML _DEFAULT_ENCODING ); | |||
/// Save a file using the given filename. Returns true if successful . | /// Save a file using the given filename. Returns true if successful . | |||
bool SaveFile( const char * filename ) const; | bool SaveFile( const char * filename ) const; | |||
#ifdef TIXML_USE_STL | #ifdef TIXML_USE_STL | |||
bool LoadFile( const std::string& filename ) ///< STL std::string version. | bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ) ///< STL std::string version. | |||
{ | { | |||
StringToBuffer f( filename ); | StringToBuffer f( filename ); | |||
return ( f.buffer && LoadFile( f.buffer )); | return ( f.buffer && LoadFile( f.buffer, encoding )); | |||
} | } | |||
bool SaveFile( const std::string& filename ) const ///< STL std::string version. | bool SaveFile( const std::string& filename ) const ///< STL std::string version. | |||
{ | { | |||
StringToBuffer f( filename ); | StringToBuffer f( filename ); | |||
return ( f.buffer && SaveFile( f.buffer )); | return ( f.buffer && SaveFile( f.buffer )); | |||
} | } | |||
#endif | #endif | |||
/** Parse the given null terminated block of xml data. | /** Parse the given null terminated block of xml data. Passing in an | |||
encoding to this | ||||
method (either TIXML_ENCODING_LEGACY or TIXML_ENCODING_UTF8 | ||||
will force TinyXml | ||||
to use that encoding, regardless of what TinyXml might other | ||||
wise try to detect. | ||||
*/ | */ | |||
virtual const char* Parse( const char* p, TiXmlParsingData* data = 0 ); | virtual const char* Parse( const char* p, TiXmlParsingData* data = 0 , TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); | |||
/** Get the root element -- the only top level element -- of the doc ument. | /** Get the root element -- the only top level element -- of the doc ument. | |||
In well formed XML, there should only be one. TinyXml is tol erant of | In well formed XML, there should only be one. TinyXml is tol erant of | |||
multiple elements at the document level. | multiple elements at the document level. | |||
*/ | */ | |||
TiXmlElement* RootElement() const { return FirstChildE lement(); } | TiXmlElement* RootElement() const { return FirstChildE lement(); } | |||
/** If an error occurs, Error will be set to true. Also, | /** If an error occurs, Error will be set to true. Also, | |||
- The ErrorId() will contain the integer identifier of the e rror (not generally useful) | - The ErrorId() will contain the integer identifier of the e rror (not generally useful) | |||
- The ErrorDesc() method will return the name of the error. (very useful) | - The ErrorDesc() method will return the name of the error. (very useful) | |||
skipping to change at line 1160 | skipping to change at line 1193 | |||
void ClearError() { error = false; | void ClearError() { error = false; | |||
errorId = 0; | errorId = 0; | |||
errorDesc = ""; | errorDesc = ""; | |||
errorLocation.row = errorLocation.col = 0; | errorLocation.row = errorLocation.col = 0; | |||
//errorLocation.last = 0; | //errorLocation.last = 0; | |||
} | } | |||
/** Dump the document to standard out. */ | /** Dump the document to standard out. */ | |||
void Print() const { Pr int( stdout, 0 ); } | void Print() const { Pr int( stdout, 0 ); } | |||
// [internal use] | /// Print this Document to a FILE stream. | |||
virtual void Print( FILE* cfile, int depth = 0 ) const; | virtual void Print( FILE* cfile, int depth = 0 ) const; | |||
// [internal use] | // [internal use] | |||
void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData ); | void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding ); | |||
protected : | protected : | |||
virtual void StreamOut ( TIXML_OSTREAM * out) const; | virtual void StreamOut ( TIXML_OSTREAM * out) const; | |||
// [internal use] | // [internal use] | |||
virtual TiXmlNode* Clone() const; | virtual TiXmlNode* Clone() const; | |||
#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: | |||
TiXmlDocument( const TiXmlDocument& copy ); | void CopyTo( TiXmlDocument* target ) const; | |||
void operator=( const TiXmlDocument& copy ); | ||||
bool error; | bool error; | |||
int errorId; | int errorId; | |||
TIXML_STRING errorDesc; | TIXML_STRING errorDesc; | |||
int tabsize; | int tabsize; | |||
TiXmlCursor errorLocation; | TiXmlCursor errorLocation; | |||
}; | }; | |||
/** | /** | |||
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 | |||
End of changes. 75 change blocks. | ||||
122 lines changed or deleted | 171 lines changed or added | |||