tinystr.h   tinystr.h 
skipping to change at line 81 skipping to change at line 81
// Error value for find primitive // Error value for find primitive
static const size_type npos; // = -1; static const size_type npos; // = -1;
// TiXmlString empty constructor // TiXmlString empty constructor
TiXmlString () : rep_(&nullrep_) TiXmlString () : rep_(&nullrep_)
{ {
} }
// TiXmlString copy constructor // TiXmlString copy constructor
TiXmlString ( const TiXmlString & copy) TiXmlString ( const TiXmlString & copy) : rep_(0)
{ {
init(copy.length()); init(copy.length());
memcpy(start(), copy.data(), length()); memcpy(start(), copy.data(), length());
} }
// TiXmlString constructor, based on a string // TiXmlString constructor, based on a string
TIXML_EXPLICIT TiXmlString ( const char * copy) TIXML_EXPLICIT TiXmlString ( const char * copy) : rep_(0)
{ {
init( static_cast<size_type>( strlen(copy) )); init( static_cast<size_type>( strlen(copy) ));
memcpy(start(), copy, length()); memcpy(start(), copy, length());
} }
// TiXmlString constructor, based on a string // TiXmlString constructor, based on a string
TIXML_EXPLICIT TiXmlString ( const char * str, size_type len) TIXML_EXPLICIT TiXmlString ( const char * str, size_type len) : rep_ (0)
{ {
init(len); init(len);
memcpy(start(), str, len); memcpy(start(), str, len);
} }
// TiXmlString destructor // TiXmlString destructor
~TiXmlString () ~TiXmlString ()
{ {
quit(); quit();
} }
 End of changes. 3 change blocks. 
3 lines changed or deleted 3 lines changed or added


 tinyxml.h   tinyxml.h 
/* /*
www.sourceforge.net/projects/tinyxml www.sourceforge.net/projects/tinyxml
Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.g rinninglizard.com) Original code (2.0 and earlier )copyright (c) 2000-2006 Lee Thomason (www.g rinninglizard.com)
This software is provided 'as-is', without any express or implied This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any warranty. In no event will the authors be held liable for any
damages arising from the use of this software. damages arising from the use of this software.
Permission is granted to anyone to use this software for any Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions: redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must 1. The origin of this software must not be misrepresented; you must
skipping to change at line 48 skipping to change at line 48
#include <assert.h> #include <assert.h>
// Help out windows: // Help out windows:
#if defined( _DEBUG ) && !defined( DEBUG ) #if defined( _DEBUG ) && !defined( DEBUG )
#define DEBUG #define DEBUG
#endif #endif
#ifdef TIXML_USE_STL #ifdef TIXML_USE_STL
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <sstream>
#define TIXML_STRING std::string #define TIXML_STRING std::string
#define TIXML_ISTREAM std::istream
#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
#endif #endif
// Deprecated library function hell. Compilers want to use the // Deprecated library function hell. Compilers want to use the
// new safe versions. This probably doesn't fully address the problem, // new safe versions. This probably doesn't fully address the problem,
// but it gets closer. There are too many compilers for me to fully // but it gets closer. There are too many compilers for me to fully
// test. If you get compilation troubles, undefine TIXML_SAFE // test. If you get compilation troubles, undefine TIXML_SAFE
#define TIXML_SAFE
#define TIXML_SAFE // TinyXml isn't fully buffer overrun protec ted, safe code. This is work in progress.
#ifdef TIXML_SAFE #ifdef TIXML_SAFE
#if defined(_MSC_VER) && (_MSC_VER >= 1400 ) #if defined(_MSC_VER) && (_MSC_VER >= 1400 )
// Microsoft visual studio, version 2005 and higher. // Microsoft visual studio, version 2005 and higher.
#define TIXML_SNPRINTF _snprintf_s #define TIXML_SNPRINTF _snprintf_s
#define TIXML_SNSCANF _snscanf_s #define TIXML_SNSCANF _snscanf_s
#elif defined(_MSC_VER) && (_MSC_VER >= 1200 ) #elif defined(_MSC_VER) && (_MSC_VER >= 1200 )
// Microsoft visual studio, version 6 and higher. // Microsoft visual studio, version 6 and higher.
//#pragma message( "Using _sn* functions." ) //#pragma message( "Using _sn* functions." )
#define TIXML_SNPRINTF _snprintf #define TIXML_SNPRINTF _snprintf
#define TIXML_SNSCANF _snscanf #define TIXML_SNSCANF _snscanf
skipping to change at line 91 skipping to change at line 89
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 = 4; const int TIXML_MINOR_VERSION = 5;
const int TIXML_PATCH_VERSION = 3; 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.
int col; // 0 based. int col; // 0 based.
}; };
/**
If you call the Accept() method, it requires being passed a TiXmlVis
itor
class to handle callbacks. For nodes that contain other nodes (Docum
ent, Element)
you will get called with a VisitEnter/VisitExit pair. Nodes that are
always leaves
are simple called with Visit().
If you return 'true' from a Visit method, recursive parsing will con
tinue. If you return
false, <b>no children of this node or its sibilings</b> will be Visi
ted.
All flavors of Visit methods have a default implementation that retu
rns 'true' (continue
visiting). You need to only override methods that are interesting to
you.
Generally Accept() is called on the TiXmlDocument, although all node
s suppert Visiting.
You should never change the document from a callback.
@sa TiXmlNode::Accept()
*/
class TiXmlVisitor
{
public:
virtual ~TiXmlVisitor() {}
/// Visit a document.
virtual bool VisitEnter( const TiXmlDocument& doc ) { return tru
e; }
/// Visit a document.
virtual bool VisitExit( const TiXmlDocument& doc ) { return tru
e; }
/// Visit an element.
virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAtt
ribute* firstAttribute ) { return true; }
/// Visit an element.
virtual bool VisitExit( const TiXmlElement& element )
{ retur
n true; }
/// Visit a declaration
virtual bool Visit( const TiXmlDeclaration& declaration )
{ return true; }
/// Visit a text node
virtual bool Visit( const TiXmlText& text )
{ return true; }
/// Visit a comment node
virtual bool Visit( const TiXmlComment& comment )
{ return true; }
/// Visit an unknow node
virtual bool Visit( const TiXmlUnknown& unknown )
{ return true; }
};
// 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. // Used by the parsing routines.
enum TiXmlEncoding enum TiXmlEncoding
skipping to change at line 153 skipping to change at line 194
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 or the string class (TiXmlString in non-STL mode, std::strin
. g
in STL mode.) Either or both cfile and str can be null.
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
not. In order to make everyone happy, these global, static f unctions not. In order to make everyone happy, these global, static f unctions
are provided to set whether or not TinyXml will condense all white space are provided to set whether or not TinyXml will condense all white space
into a single space or not. The default is to condense. Note changing this into a single space or not. The default is to condense. Note changing this
values is not thread safe. value is not thread safe.
*/ */
static void SetCondenseWhiteSpace( bool condense ) { co ndenseWhiteSpace = condense; } static void SetCondenseWhiteSpace( bool condense ) { co ndenseWhiteSpace = condense; }
/// Return the current white space setting. /// Return the current white space setting.
static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; } static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; }
/** Return the position, in the original source file, of this node o r attribute. /** Return the position, in the original source file, of this node o r attribute.
The row and column are 1-based. (That is the first row and f irst column is The row and column are 1-based. (That is the first row and f irst column is
1,1). If the returns values are 0 or less, then the parser d oes not have 1,1). If the returns values are 0 or less, then the parser d oes not have
a row and column value. a row and column value.
skipping to change at line 195 skipping to change at line 240
reflect changes in the document. reflect changes in the document.
There is a minor performance cost to computing the row and c olumn. Computation There is a minor performance cost to computing the row and c olumn. Computation
can be disabled if TiXmlDocument::SetTabSize() is called wit h 0 as the value. can be disabled if TiXmlDocument::SetTabSize() is called wit h 0 as the value.
@sa TiXmlDocument::SetTabSize() @sa TiXmlDocument::SetTabSize()
*/ */
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 ///< Set a pointer to arbitrary user data.
turn userData; } void* GetUserData() { re
turn userData; } ///< Get a pointer to arbitrary user data.
const void* GetUserData() const { return userData; }
///< Get a pointer to arbitrary user data.
// 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, virtual const char* Parse( const char* p,
TiXmlParsing Data* data, TiXmlParsing Data* data,
TiXmlEncodin g encoding /*= TIXML_ENCODING_UNKNOWN */ ) = 0; TiXmlEncodin g encoding /*= TIXML_ENCODING_UNKNOWN */ ) = 0;
enum enum
skipping to change at line 224 skipping to change at line 270
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_PARSING_CDATA,
TIXML_ERROR_DOCUMENT_TOP_ONLY,
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 252 skipping to change at line 299
{ {
return ( isspace( (unsigned char) c ) || c == '\n' || c == ' \r' ); return ( isspace( (unsigned char) c ) || c == '\n' || c == ' \r' );
} }
inline static bool IsWhiteSpace( int c ) inline static bool IsWhiteSpace( int c )
{ {
if ( c < 256 ) if ( c < 256 )
return IsWhiteSpace( (char) c ); return IsWhiteSpace( (char) c );
return false; // Again, only truly correct for English/Lat in...but usually works. return false; // Again, only truly correct for English/Lat in...but usually works.
} }
virtual void StreamOut (TIXML_OSTREAM *) const = 0;
#ifdef TIXML_USE_STL #ifdef TIXML_USE_STL
static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * static bool StreamWhiteSpace( std::istream * in, TIXML_STRING *
tag ); tag );
static bool StreamTo( TIXML_ISTREAM * in, int character, TIXML_S static bool StreamTo( std::istream * in, int character, TIXML_STRING
TRING * tag ); * 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, TiXm lEncoding encoding ); 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.
skipping to change at line 285 skipping to change at line 330
// 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, TiXmlEncoding encoding ); 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* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding ) inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding )
{ {
assert( p ); assert( p );
if ( encoding == TIXML_ENCODING_UTF8 ) if ( encoding == TIXML_ENCODING_UTF8 )
{ {
*length = utf8ByteTable[ *((unsigned char*)p) ]; *length = utf8ByteTable[ *((const unsigned char*)p) ];
assert( *length >= 0 && *length < 5 ); assert( *length >= 0 && *length < 5 );
} }
else else
{ {
*length = 1; *length = 1;
} }
if ( *length == 1 ) if ( *length == 1 )
{ {
if ( *p == '&' ) if ( *p == '&' )
skipping to change at line 318 skipping to change at line 363
} }
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_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 English 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 );
skipping to change at line 415 skipping to change at line 458
true of all input streams, but it's worth keeping in min d. true of all input streams, but it's worth keeping in min d.
A TiXmlDocument will read nodes until it reads a root el ement, and A TiXmlDocument will read nodes until it reads a root el ement, and
all the children of that root element. all the children of that root element.
*/ */
friend std::ostream& operator<< (std::ostream& out, const TiXmlN ode& base); friend std::ostream& operator<< (std::ostream& out, const TiXmlN ode& base);
/// Appends the XML node or attribute to a std::string. /// Appends the XML node or attribute to a std::string.
friend std::string& operator<< (std::string& out, const TiXm lNode& base ); friend std::string& operator<< (std::string& out, const TiXm lNode& base );
#else
// Used internally, not part of the public API.
friend TIXML_OSTREAM& operator<< (TIXML_OSTREAM& out, const TiXm
lNode& base);
#endif #endif
/** The types of XML nodes supported by TinyXml. (All the /** The types of XML nodes supported by TinyXml. (All the
unsupported types are picked up by UNKNOWN.) unsupported types are picked up by UNKNOWN.)
*/ */
enum NodeType enum NodeType
{ {
DOCUMENT, DOCUMENT,
ELEMENT, ELEMENT,
COMMENT, COMMENT,
skipping to change at line 649 skipping to change at line 689
virtual TiXmlComment* ToComment() { return 0; } ///< C ast to a more defined type. Will return null if not of the requested type. virtual TiXmlComment* ToComment() { return 0; } ///< C ast to a more defined type. Will return null if not of the requested type.
virtual TiXmlUnknown* ToUnknown() { return 0; } // /< Cast to a more defined type. Will return null if not of the requested ty pe. virtual TiXmlUnknown* ToUnknown() { return 0; } // /< Cast to a more defined type. Will return null if not of the requested ty pe.
virtual TiXmlText* ToText() { return 0; } // /< Cast to a more defined type. Will return null if not of the requested ty pe. virtual TiXmlText* ToText() { return 0; } // /< Cast to a more defined type. Will return null if not of the requested ty pe.
virtual TiXmlDeclaration* ToDeclaration() { return 0; } ///< C ast to a more defined type. Will return null if not of the requested type. virtual TiXmlDeclaration* ToDeclaration() { return 0; } ///< C ast to a more defined type. Will return null if not of the requested type.
/** Create an exact duplicate of this node and return it. The memory must be deleted /** Create an exact duplicate of this node and return it. The memory must be deleted
by the caller. by the caller.
*/ */
virtual TiXmlNode* Clone() const = 0; virtual TiXmlNode* Clone() const = 0;
/** Accept a hierchical visit the nodes in the TinyXML DOM. Every no
de in the
XML tree will be conditionally visited and the host will be
called back
via the TiXmlVisitor interface.
This is essentially a SAX interface for TinyXML. (Note howev
er it doesn't re-parse
the XML for the callbacks, so the performance of TinyXML is
unchanged by using this
interface versus any other.)
The interface has been based on ideas from:
- http://www.saxproject.org/
- http://c2.com/cgi/wiki?HierarchicalVisitorPattern
Which are both good references for "visiting".
An example of using Accept():
@verbatim
TiXmlPrinter printer;
tinyxmlDoc.Accept( &printer );
const char* xmlcstr = printer.CStr();
@endverbatim
*/
virtual bool Accept( TiXmlVisitor* visitor ) const = 0;
protected: protected:
TiXmlNode( NodeType _type ); TiXmlNode( NodeType _type );
// Copy to the allocated object. Shared functionality between Clone, Copy constructor, // Copy to the allocated object. Shared functionality between Clone, Copy constructor,
// and the assignment operator. // and the assignment operator.
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( std::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 );
TiXmlNode* parent; TiXmlNode* parent;
NodeType type; NodeType type;
TiXmlNode* firstChild; TiXmlNode* firstChild;
TiXmlNode* lastChild; TiXmlNode* lastChild;
skipping to change at line 719 skipping to change at line 783
/// Construct an attribute with a name and value. /// Construct an attribute with a name and value.
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 const char* Name() const { return name.c_str(
(); } ///< Return the name of this attribute. ); } ///< Return the name of this attribute.
const char* Value() const { return value.c_str const char* Value() const { return value.c_str
(); } ///< Return the value of this attribute. (); } ///< Return the value of this attribute.
#ifdef TIXML_USE_STL
const std::string& ValueStr() const { return value; }
///< Return the value of this attribute.
#endif
int IntValue() const; ///< Return the value o f this attribute, converted to an integer. int IntValue() const; ///< Return the value o f this attribute, converted to an integer.
double DoubleValue() const; ///< Return the value of this attribute , converted to a double. double DoubleValue() const; ///< Return the value of this attribute , converted to a double.
// Get the tinyxml string representation // Get the tinyxml string representation
const TIXML_STRING& NameTStr() const { return name; } const TIXML_STRING& NameTStr() const { return name; }
/** 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
skipping to change at line 770 skipping to change at line 837
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; }
/* Attribute parsing starts: first letter of the name /* Attribute 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, Ti XmlEncoding encoding ); virtual const char* Parse( const char* p, TiXmlParsingData* data, Ti XmlEncoding encoding );
// Prints this Attribute to a FILE stream. // Prints this Attribute to a FILE stream.
virtual void Print( FILE* cfile, int depth ) const; virtual void Print( FILE* cfile, int depth ) const {
Print( cfile, depth, 0 );
}
void Print( FILE* cfile, int depth, TIXML_STRING* str ) 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.
TiXmlDocument* document; // A pointer back to a document, for error reporting. TiXmlDocument* document; // A pointer back to a document, for error reporting.
TIXML_STRING name; TIXML_STRING name;
skipping to change at line 887 skipping to change at line 956
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 QueryFloatAttribute( 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 );
if ( result == TIXML_SUCCESS ) { if ( result == TIXML_SUCCESS ) {
*_value = (float)d; *_value = (float)d;
} }
return result; return result;
} }
#ifdef TIXML_USE_STL
/** Template form of the attribute query which will try to read the
attribute into the specified type. Very easy, very powerful,
but
be careful to make sure to call this with the correct type.
@return TIXML_SUCCESS, TIXML_WRONG_TYPE, or TIXML_NO_ATTRIBU
TE
*/
template< typename T > int QueryValueAttribute( const std::string& n
ame, T* outValue ) const
{
const TiXmlAttribute* node = attributeSet.Find( name );
if ( !node )
return TIXML_NO_ATTRIBUTE;
std::stringstream sstream( node->ValueStr() );
sstream >> *outValue;
if ( !sstream.fail() )
return TIXML_SUCCESS;
return TIXML_WRONG_TYPE;
}
#endif
/** 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 ); }
skipping to change at line 975 skipping to change at line 1064
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 );
virtual const TiXmlElement* ToElement() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. virtual const TiXmlElement* ToElement() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
virtual TiXmlElement* ToElement() { return t his; } ///< Cast to a more defined type. Will return null not of the reques ted type. virtual TiXmlElement* ToElement() { return t his; } ///< Cast to a more defined type. Will return null not of the reques ted type.
/** Walk the XML tree visiting this node and all of its children.
*/
virtual bool Accept( TiXmlVisitor* visitor ) const;
protected: protected:
void CopyTo( TiXmlElement* target ) const; void CopyTo( TiXmlElement* target ) const;
void ClearThis(); // like clear, but initializes 'this' object as well 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( std::istream * in, TIXML_STRING * tag );
#endif #endif
virtual void StreamOut( TIXML_OSTREAM * out ) const;
/* [internal use] /* [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, T iXmlEncoding encoding ); const char* ReadValue( const char* in, TiXmlParsingData* prevData, T iXmlEncoding encoding );
private: private:
TiXmlAttributeSet attributeSet; TiXmlAttributeSet attributeSet;
}; };
skipping to change at line 1011 skipping to change at line 1102
public: public:
/// Constructs an empty comment. /// Constructs an empty comment.
TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {} TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
TiXmlComment( const TiXmlComment& ); TiXmlComment( const TiXmlComment& );
void operator=( const TiXmlComment& base ); void operator=( const TiXmlComment& base );
virtual ~TiXmlComment() {} virtual ~TiXmlComment() {}
/// Returns a copy of this Comment. /// Returns a copy of this Comment.
virtual TiXmlNode* Clone() const; virtual TiXmlNode* Clone() const;
/// Write this Comment to a FILE stream. // 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 !-- /* Attribtue parsing starts: at the ! of the !--
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 );
virtual const TiXmlComment* ToComment() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. virtual const TiXmlComment* ToComment() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
virtual TiXmlComment* ToComment() { return this; } ///< Cast to a m ore defined type. Will return null not of the requested type. virtual TiXmlComment* ToComment() { return this; } ///< Cast to a m ore defined type. Will return null not of the requested type.
/** Walk the XML tree visiting this node and all of its children.
*/
virtual bool Accept( TiXmlVisitor* visitor ) const;
protected: protected:
void CopyTo( TiXmlComment* target ) const; 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( std::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. A text node can have 2 ways to output the next. "normal" outp ut /** 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 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 you generally want to leave it alone, but you can change the output mode with
SetCDATA() and query it with CDATA(). SetCDATA() and query it with CDATA().
*/ */
skipping to change at line 1067 skipping to change at line 1162
TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TE XT) TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TE XT)
{ {
SetValue( initValue ); SetValue( initValue );
cdata = false; 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. /// Queries whether this represents text using a CDATA section.
bool CDATA() { return cdata; } bool CDATA() const { return cdata; }
/// Turns on or off a CDATA representation of text. /// Turns on or off a CDATA representation of text.
void SetCDATA( bool _cdata ) { cdata = _cdata; } 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 );
virtual const TiXmlText* ToText() const { return this; } ///< Cast t o a more defined type. Will return null not of the requested type. virtual const TiXmlText* ToText() const { return this; } ///< Cast t o a more defined type. Will return null not of the requested type.
virtual TiXmlText* ToText() { return this; } ///< Cast t o a more defined type. Will return null not of the requested type. virtual TiXmlText* ToText() { return this; } ///< Cast t o a more defined type. Will return null not of the requested type.
/** Walk the XML tree visiting this node and all of its children.
*/
virtual bool Accept( TiXmlVisitor* content ) const;
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;
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( std::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 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
skipping to change at line 1141 skipping to change at line 1239
/// Version. Will return an empty string if none was found. /// Version. Will return an empty string if none was found.
const char *Version() const { return version.c_s tr (); } const char *Version() const { return version.c_s tr (); }
/// Encoding. Will return an empty string if none was found. /// Encoding. Will return an empty string if none was found.
const char *Encoding() const { return encoding.c_str (); } 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 () ; }
/// Creates a copy of this Declaration and returns it. /// Creates a copy of this Declaration and returns it.
virtual TiXmlNode* Clone() const; virtual TiXmlNode* Clone() const;
/// Print this declaration to a FILE stream. // Print this declaration to a FILE stream.
virtual void Print( FILE* cfile, int depth ) const; virtual void Print( FILE* cfile, int depth, TIXML_STRING* str ) cons
t;
virtual void Print( FILE* cfile, int depth ) const {
Print( cfile, depth, 0 );
}
virtual const char* Parse( const char* p, TiXmlParsingData* data, Ti XmlEncoding encoding ); virtual const char* Parse( const char* p, TiXmlParsingData* data, Ti XmlEncoding encoding );
virtual const TiXmlDeclaration* ToDeclaration() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. virtual const TiXmlDeclaration* ToDeclaration() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
virtual TiXmlDeclaration* ToDeclaration() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. virtual TiXmlDeclaration* ToDeclaration() { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
/** Walk the XML tree visiting this node and all of its children.
*/
virtual bool Accept( TiXmlVisitor* visitor ) const;
protected: protected:
void CopyTo( TiXmlDeclaration* target ) const; 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( std::istream * in, TIXML_STRING * tag );
#endif #endif
virtual void StreamOut ( TIXML_OSTREAM * out) const;
private: private:
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.
skipping to change at line 1182 skipping to change at line 1286
{ {
public: public:
TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {} TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
virtual ~TiXmlUnknown() {} virtual ~TiXmlUnknown() {}
TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNK NOWN ) { copy.CopyTo( this ); } TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNK NOWN ) { copy.CopyTo( this ); }
void operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); } void operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); }
/// Creates a copy of this Unknown and returns it. /// Creates a copy of this Unknown and returns it.
virtual TiXmlNode* Clone() const; virtual TiXmlNode* Clone() const;
/// Print this Unknown to a FILE stream. // 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 ); virtual const char* Parse( const char* p, TiXmlParsingData* data, Ti XmlEncoding encoding );
virtual const TiXmlUnknown* ToUnknown() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. virtual const TiXmlUnknown* ToUnknown() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
virtual TiXmlUnknown* ToUnknown() { return this; } ///< Cast to a more defined type. Will return null not of the requested ty pe. virtual TiXmlUnknown* ToUnknown() { return this; } ///< Cast to a more defined type. Will return null not of the requested ty pe.
/** Walk the XML tree visiting this node and all of its children.
*/
virtual bool Accept( TiXmlVisitor* content ) const;
protected: protected:
void CopyTo( TiXmlUnknown* target ) const; 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( std::istream * in, TIXML_STRING * tag );
#endif #endif
virtual void StreamOut ( TIXML_OSTREAM * out ) const;
private: private:
}; };
/** 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
skipping to change at line 1333 skipping to change at line 1440
/** If you have handled the error, it can be reset with this call. T he error /** If you have handled the error, it can be reset with this call. T he error
state is automatically cleared if you Parse a new XML block. state is automatically cleared if you Parse a new XML block.
*/ */
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. */ /** Write the document to standard out using formatted printing ("pr etty print"). */
void Print() const { Pr int( stdout, 0 ); } void Print() const { Pr int( stdout, 0 ); }
/* Write the document to a string using formatted printing ("pretty
print"). This
will allocate a character array (new char[]) and return it a
s a pointer. The
calling code pust call delete[] on the return char* to avoid
a memory leak.
*/
//char* PrintToMemory() const;
/// Print this Document to a FILE stream. /// 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, TiXmlEncoding encoding ); void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );
virtual const TiXmlDocument* ToDocument() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. virtual const TiXmlDocument* ToDocument() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
virtual TiXmlDocument* ToDocument() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. virtual TiXmlDocument* ToDocument() { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
/** Walk the XML tree visiting this node and all of its children.
*/
virtual bool Accept( TiXmlVisitor* content ) const;
protected : protected :
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( std::istream * in, TIXML_STRING * tag );
#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;
skipping to change at line 1403 skipping to change at line 1519
{ {
// Finally do something useful. // Finally do something useful.
@endverbatim @endverbatim
And that doesn't even cover "else" cases. TiXmlHandle addresses the verbosity And that doesn't even cover "else" cases. TiXmlHandle addresses the verbosity
of such code. A TiXmlHandle checks for null pointers so it is pe rfectly safe of such code. A TiXmlHandle checks for null pointers so it is pe rfectly safe
and correct to use: and correct to use:
@verbatim @verbatim
TiXmlHandle docHandle( &document ); TiXmlHandle docHandle( &document );
TiXmlElement* child2 = docHandle.FirstChild( "Document" ).FirstChild ( "Element" ).Child( "Child", 1 ).Element(); TiXmlElement* child2 = docHandle.FirstChild( "Document" ).FirstChild ( "Element" ).Child( "Child", 1 ).ToElement();
if ( child2 ) if ( child2 )
{ {
// do something useful // do something useful
@endverbatim @endverbatim
Which is MUCH more concise and useful. Which is MUCH more concise and useful.
It is also safe to copy handles - internally they are nothing more t han node pointers. It is also safe to copy handles - internally they are nothing more t han node pointers.
@verbatim @verbatim
TiXmlHandle handleCopy = handle; TiXmlHandle handleCopy = handle;
@endverbatim @endverbatim
What they should not be used for is iteration: What they should not be used for is iteration:
@verbatim @verbatim
int i=0; int i=0;
while ( true ) while ( true )
{ {
TiXmlElement* child = docHandle.FirstChild( "Document" ).Fir stChild( "Element" ).Child( "Child", i ).Element(); TiXmlElement* child = docHandle.FirstChild( "Document" ).Fir stChild( "Element" ).Child( "Child", i ).ToElement();
if ( !child ) if ( !child )
break; break;
// do something // do something
++i; ++i;
} }
@endverbatim @endverbatim
It seems reasonable, but it is in fact two embedded while loops. The Child method is It seems reasonable, but it is in fact two embedded while loops. The Child method is
a linear walk to find the element, so this code would iterate much m ore than it needs a linear walk to find the element, so this code would iterate much m ore than it needs
to. Instead, prefer: to. Instead, prefer:
@verbatim @verbatim
TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild( "Child" ).Element(); TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild( "Child" ).ToElement();
for( child; child; child=child->NextSiblingElement() ) for( child; child; child=child->NextSiblingElement() )
{ {
// do something // do something
} }
@endverbatim @endverbatim
*/ */
class TiXmlHandle class TiXmlHandle
{ {
public: public:
skipping to change at line 1488 skipping to change at line 1604
TiXmlHandle ChildElement( int index ) const; TiXmlHandle ChildElement( int index ) const;
#ifdef TIXML_USE_STL #ifdef TIXML_USE_STL
TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); } TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); }
TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); } TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); }
TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); } TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); }
TiXmlHandle ChildElement( const std::string& _value, int index ) con st { return ChildElement( _value.c_str(), index ); } TiXmlHandle ChildElement( const std::string& _value, int index ) con st { return ChildElement( _value.c_str(), index ); }
#endif #endif
/// Return the handle as a TiXmlNode. This may return null. /** Return the handle as a TiXmlNode. This may return null.
TiXmlNode* Node() const { return node; } */
/// Return the handle as a TiXmlElement. This may return null. TiXmlNode* ToNode() const { return node; }
TiXmlElement* Element() const { return ( ( node && node->ToElement /** Return the handle as a TiXmlElement. This may return null.
() ) ? node->ToElement() : 0 ); } */
/// Return the handle as a TiXmlText. This may return null. TiXmlElement* ToElement() const { return ( ( node && node->T
TiXmlText* Text() const { return ( ( node && node->T oElement() ) ? node->ToElement() : 0 ); }
oText() ) ? node->ToText() : 0 ); } /** Return the handle as a TiXmlText. This may return null.
/// Return the handle as a TiXmlUnknown. This may return null; */
TiXmlUnknown* Unknown() const { return ( ( node && TiXmlText* ToText() const { return ( ( node &&
node->ToUnknown() ) ? node->ToUnknown() : 0 ); } node->ToText() ) ? node->ToText() : 0 ); }
/** Return the handle as a TiXmlUnknown. This may return null.
*/
TiXmlUnknown* ToUnknown() const { return ( ( node && node->T
oUnknown() ) ? node->ToUnknown() : 0 ); }
/** @deprecated use ToNode.
Return the handle as a TiXmlNode. This may return null.
*/
TiXmlNode* Node() const { return ToNode(); }
/** @deprecated use ToElement.
Return the handle as a TiXmlElement. This may return null.
*/
TiXmlElement* Element() const { return ToElement(); }
/** @deprecated use ToText()
Return the handle as a TiXmlText. This may return null.
*/
TiXmlText* Text() const { return ToText(); }
/** @deprecated use ToUnknown()
Return the handle as a TiXmlUnknown. This may return null.
*/
TiXmlUnknown* Unknown() const { return ToUnknown(); }
private: private:
TiXmlNode* node; TiXmlNode* node;
}; };
/** Print to memory functionality. The TiXmlPrinter is useful when you need
to:
-# Print to memory (especially in non-STL mode)
-# Control formatting (line endings, etc.)
When constructed, the TiXmlPrinter is in its default "pretty printin
g" mode.
Before calling Accept() you can call methods to control the printing
of the XML document. After TiXmlNode::Accept() is called, the printe
d document can
be accessed via the CStr(), Str(), and Size() methods.
TiXmlPrinter uses the Visitor API.
@verbatim
TiXmlPrinter printer;
printer.SetIndent( "\t" );
doc.Accept( &printer );
fprintf( stdout, "%s", printer.CStr() );
@endverbatim
*/
class TiXmlPrinter : public TiXmlVisitor
{
public:
TiXmlPrinter() : depth( 0 ), simpleTextPrint( false ),
buffer(), indent( " " ), lineBre
ak( "\n" ) {}
virtual bool VisitEnter( const TiXmlDocument& doc );
virtual bool VisitExit( const TiXmlDocument& doc );
virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAtt
ribute* firstAttribute );
virtual bool VisitExit( const TiXmlElement& element );
virtual bool Visit( const TiXmlDeclaration& declaration );
virtual bool Visit( const TiXmlText& text );
virtual bool Visit( const TiXmlComment& comment );
virtual bool Visit( const TiXmlUnknown& unknown );
/** Set the indent characters for printing. By default 4 spaces
but tab (\t) is also useful, or null/empty string for no ind
entation.
*/
void SetIndent( const char* _indent ) { indent = _
indent ? _indent : "" ; }
/// Query the indention string.
const char* Indent()
{ return indent.c_str(); }
/** Set the line breaking string. By default set to newline (\n).
Some operating systems prefer other characters, or can be
set to the null/empty string for no indenation.
*/
void SetLineBreak( const char* _lineBreak ) { lineBreak
= _lineBreak ? _lineBreak : ""; }
/// Query the current line breaking string.
const char* LineBreak()
{ return lineBreak.c_str(); }
/** Switch over to "stream printing" which is the most dense formatt
ing without
linebreaks. Common when the XML is needed for network transm
ission.
*/
void SetStreamPrinting()
{ indent = "";
lineBreak = "";
}
/// Return the result.
const char* CStr()
{ return buffer.c_str(); }
/// Return the length of the result string.
size_t Size()
{ return buffer.size(); }
#ifdef TIXML_USE_STL
/// Return the result.
const std::string& Str()
{ return buffer; }
#endif
private:
void DoIndent() {
for( int i=0; i<depth; ++i )
buffer += indent;
}
void DoLineBreak() {
buffer += lineBreak;
}
int depth;
bool simpleTextPrint;
TIXML_STRING buffer;
TIXML_STRING indent;
TIXML_STRING lineBreak;
};
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning( pop ) #pragma warning( pop )
#endif #endif
#endif #endif
 End of changes. 54 change blocks. 
71 lines changed or deleted 337 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/