PageRenderTime 120ms CodeModel.GetById 53ms app.highlight 53ms RepoModel.GetById 2ms app.codeStats 0ms

/thirdparty/tinyxml/tinyxml.h

http://crashrpt.googlecode.com/
C++ Header | 1800 lines | 802 code | 259 blank | 739 comment | 38 complexity | 523b99e91c60a99d0ed4b936197eb366 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1/*
   2www.sourceforge.net/projects/tinyxml
   3Original code (2.0 and earlier )copyright (c) 2000-2006 Lee Thomason (www.grinninglizard.com)
   4
   5This software is provided 'as-is', without any express or implied
   6warranty. In no event will the authors be held liable for any
   7damages arising from the use of this software.
   8
   9Permission is granted to anyone to use this software for any
  10purpose, including commercial applications, and to alter it and
  11redistribute it freely, subject to the following restrictions:
  12
  131. The origin of this software must not be misrepresented; you must
  14not claim that you wrote the original software. If you use this
  15software in a product, an acknowledgment in the product documentation
  16would be appreciated but is not required.
  17
  182. Altered source versions must be plainly marked as such, and
  19must not be misrepresented as being the original software.
  20
  213. This notice may not be removed or altered from any source
  22distribution.
  23*/
  24
  25
  26#ifndef TINYXML_INCLUDED
  27#define TINYXML_INCLUDED
  28
  29#ifdef _MSC_VER
  30#pragma warning( push )
  31#pragma warning( disable : 4530 )
  32#pragma warning( disable : 4786 )
  33#endif
  34
  35#include <ctype.h>
  36#include <stdio.h>
  37#include <stdlib.h>
  38#include <string.h>
  39#include <assert.h>
  40
  41// Help out windows:
  42#if defined( _DEBUG ) && !defined( DEBUG )
  43#define DEBUG
  44#endif
  45
  46#ifdef TIXML_USE_STL
  47	#include <string>
  48 	#include <iostream>
  49	#include <sstream>
  50	#define TIXML_STRING		std::string
  51#else
  52	#include "tinystr.h"
  53	#define TIXML_STRING		TiXmlString
  54#endif
  55
  56// Deprecated library function hell. Compilers want to use the
  57// new safe versions. This probably doesn't fully address the problem,
  58// but it gets closer. There are too many compilers for me to fully
  59// test. If you get compilation troubles, undefine TIXML_SAFE
  60#define TIXML_SAFE
  61
  62#ifdef TIXML_SAFE
  63	#if defined(_MSC_VER) && (_MSC_VER >= 1400 )
  64		// Microsoft visual studio, version 2005 and higher.
  65		#define TIXML_SNPRINTF _snprintf_s
  66		#define TIXML_SSCANF   sscanf_s
  67	#elif defined(_MSC_VER) && (_MSC_VER >= 1200 )
  68		// Microsoft visual studio, version 6 and higher.
  69		//#pragma message( "Using _sn* functions." )
  70		#define TIXML_SNPRINTF _snprintf
  71		#define TIXML_SSCANF   sscanf
  72	#elif defined(__GNUC__) && (__GNUC__ >= 3 )
  73		// GCC version 3 and higher.s
  74		//#warning( "Using sn* functions." )
  75		#define TIXML_SNPRINTF snprintf
  76		#define TIXML_SSCANF   sscanf
  77	#else
  78		#define TIXML_SNPRINTF snprintf
  79		#define TIXML_SSCANF   sscanf
  80	#endif
  81#endif	
  82
  83class TiXmlDocument;
  84class TiXmlElement;
  85class TiXmlComment;
  86class TiXmlUnknown;
  87class TiXmlAttribute;
  88class TiXmlText;
  89class TiXmlDeclaration;
  90class TiXmlParsingData;
  91
  92const int TIXML_MAJOR_VERSION = 2;
  93const int TIXML_MINOR_VERSION = 6;
  94const int TIXML_PATCH_VERSION = 1;
  95
  96/*	Internal structure for tracking location of items 
  97	in the XML file.
  98*/
  99struct TiXmlCursor
 100{
 101	TiXmlCursor()		{ Clear(); }
 102	void Clear()		{ row = col = -1; }
 103
 104	int row;	// 0 based.
 105	int col;	// 0 based.
 106};
 107
 108
 109/**
 110	Implements the interface to the "Visitor pattern" (see the Accept() method.)
 111	If you call the Accept() method, it requires being passed a TiXmlVisitor
 112	class to handle callbacks. For nodes that contain other nodes (Document, Element)
 113	you will get called with a VisitEnter/VisitExit pair. Nodes that are always leaves
 114	are simply called with Visit().
 115
 116	If you return 'true' from a Visit method, recursive parsing will continue. If you return
 117	false, <b>no children of this node or its sibilings</b> will be Visited.
 118
 119	All flavors of Visit methods have a default implementation that returns 'true' (continue 
 120	visiting). You need to only override methods that are interesting to you.
 121
 122	Generally Accept() is called on the TiXmlDocument, although all nodes suppert Visiting.
 123
 124	You should never change the document from a callback.
 125
 126	@sa TiXmlNode::Accept()
 127*/
 128class TiXmlVisitor
 129{
 130public:
 131	virtual ~TiXmlVisitor() {}
 132
 133	/// Visit a document.
 134	virtual bool VisitEnter( const TiXmlDocument& /*doc*/ )			{ return true; }
 135	/// Visit a document.
 136	virtual bool VisitExit( const TiXmlDocument& /*doc*/ )			{ return true; }
 137
 138	/// Visit an element.
 139	virtual bool VisitEnter( const TiXmlElement& /*element*/, const TiXmlAttribute* /*firstAttribute*/ )	{ return true; }
 140	/// Visit an element.
 141	virtual bool VisitExit( const TiXmlElement& /*element*/ )		{ return true; }
 142
 143	/// Visit a declaration
 144	virtual bool Visit( const TiXmlDeclaration& /*declaration*/ )	{ return true; }
 145	/// Visit a text node
 146	virtual bool Visit( const TiXmlText& /*text*/ )					{ return true; }
 147	/// Visit a comment node
 148	virtual bool Visit( const TiXmlComment& /*comment*/ )			{ return true; }
 149	/// Visit an unknow node
 150	virtual bool Visit( const TiXmlUnknown& /*unknown*/ )			{ return true; }
 151};
 152
 153// Only used by Attribute::Query functions
 154enum 
 155{ 
 156	TIXML_SUCCESS,
 157	TIXML_NO_ATTRIBUTE,
 158	TIXML_WRONG_TYPE
 159};
 160
 161
 162// Used by the parsing routines.
 163enum TiXmlEncoding
 164{
 165	TIXML_ENCODING_UNKNOWN,
 166	TIXML_ENCODING_UTF8,
 167	TIXML_ENCODING_LEGACY
 168};
 169
 170const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;
 171
 172/** TiXmlBase is a base class for every class in TinyXml.
 173	It does little except to establish that TinyXml classes
 174	can be printed and provide some utility functions.
 175
 176	In XML, the document and elements can contain
 177	other elements and other types of nodes.
 178
 179	@verbatim
 180	A Document can contain:	Element	(container or leaf)
 181							Comment (leaf)
 182							Unknown (leaf)
 183							Declaration( leaf )
 184
 185	An Element can contain:	Element (container or leaf)
 186							Text	(leaf)
 187							Attributes (not on tree)
 188							Comment (leaf)
 189							Unknown (leaf)
 190
 191	A Decleration contains: Attributes (not on tree)
 192	@endverbatim
 193*/
 194class TiXmlBase
 195{
 196	friend class TiXmlNode;
 197	friend class TiXmlElement;
 198	friend class TiXmlDocument;
 199
 200public:
 201	TiXmlBase()	:	userData(0)		{}
 202	virtual ~TiXmlBase()			{}
 203
 204	/**	All TinyXml classes can print themselves to a filestream
 205		or the string class (TiXmlString in non-STL mode, std::string
 206		in STL mode.) Either or both cfile and str can be null.
 207		
 208		This is a formatted print, and will insert 
 209		tabs and newlines.
 210		
 211		(For an unformatted stream, use the << operator.)
 212	*/
 213	virtual void Print( FILE* cfile, int depth ) const = 0;
 214
 215	/**	The world does not agree on whether white space should be kept or
 216		not. In order to make everyone happy, these global, static functions
 217		are provided to set whether or not TinyXml will condense all white space
 218		into a single space or not. The default is to condense. Note changing this
 219		value is not thread safe.
 220	*/
 221	static void SetCondenseWhiteSpace( bool condense )		{ condenseWhiteSpace = condense; }
 222
 223	/// Return the current white space setting.
 224	static bool IsWhiteSpaceCondensed()						{ return condenseWhiteSpace; }
 225
 226	/** Return the position, in the original source file, of this node or attribute.
 227		The row and column are 1-based. (That is the first row and first column is
 228		1,1). If the returns values are 0 or less, then the parser does not have
 229		a row and column value.
 230
 231		Generally, the row and column value will be set when the TiXmlDocument::Load(),
 232		TiXmlDocument::LoadFile(), or any TiXmlNode::Parse() is called. It will NOT be set
 233		when the DOM was created from operator>>.
 234
 235		The values reflect the initial load. Once the DOM is modified programmatically
 236		(by adding or changing nodes and attributes) the new values will NOT update to
 237		reflect changes in the document.
 238
 239		There is a minor performance cost to computing the row and column. Computation
 240		can be disabled if TiXmlDocument::SetTabSize() is called with 0 as the value.
 241
 242		@sa TiXmlDocument::SetTabSize()
 243	*/
 244	int Row() const			{ return location.row + 1; }
 245	int Column() const		{ return location.col + 1; }	///< See Row()
 246
 247	void  SetUserData( void* user )			{ userData = user; }	///< Set a pointer to arbitrary user data.
 248	void* GetUserData()						{ return userData; }	///< Get a pointer to arbitrary user data.
 249	const void* GetUserData() const 		{ return userData; }	///< Get a pointer to arbitrary user data.
 250
 251	// Table that returs, for a given lead byte, the total number of bytes
 252	// in the UTF-8 sequence.
 253	static const int utf8ByteTable[256];
 254
 255	virtual const char* Parse(	const char* p, 
 256								TiXmlParsingData* data, 
 257								TiXmlEncoding encoding /*= TIXML_ENCODING_UNKNOWN */ ) = 0;
 258
 259	/** Expands entities in a string. Note this should not contian the tag's '<', '>', etc, 
 260		or they will be transformed into entities!
 261	*/
 262	static void EncodeString( const TIXML_STRING& str, TIXML_STRING* out );
 263
 264	enum
 265	{
 266		TIXML_NO_ERROR = 0,
 267		TIXML_ERROR,
 268		TIXML_ERROR_OPENING_FILE,
 269		TIXML_ERROR_PARSING_ELEMENT,
 270		TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
 271		TIXML_ERROR_READING_ELEMENT_VALUE,
 272		TIXML_ERROR_READING_ATTRIBUTES,
 273		TIXML_ERROR_PARSING_EMPTY,
 274		TIXML_ERROR_READING_END_TAG,
 275		TIXML_ERROR_PARSING_UNKNOWN,
 276		TIXML_ERROR_PARSING_COMMENT,
 277		TIXML_ERROR_PARSING_DECLARATION,
 278		TIXML_ERROR_DOCUMENT_EMPTY,
 279		TIXML_ERROR_EMBEDDED_NULL,
 280		TIXML_ERROR_PARSING_CDATA,
 281		TIXML_ERROR_DOCUMENT_TOP_ONLY,
 282
 283		TIXML_ERROR_STRING_COUNT
 284	};
 285
 286protected:
 287
 288	static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding );
 289
 290	inline static bool IsWhiteSpace( char c )		
 291	{ 
 292		return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' ); 
 293	}
 294	inline static bool IsWhiteSpace( int c )
 295	{
 296		if ( c < 256 )
 297			return IsWhiteSpace( (char) c );
 298		return false;	// Again, only truly correct for English/Latin...but usually works.
 299	}
 300
 301	#ifdef TIXML_USE_STL
 302	static bool	StreamWhiteSpace( std::istream * in, TIXML_STRING * tag );
 303	static bool StreamTo( std::istream * in, int character, TIXML_STRING * tag );
 304	#endif
 305
 306	/*	Reads an XML name into the string provided. Returns
 307		a pointer just past the last character of the name,
 308		or 0 if the function has an error.
 309	*/
 310	static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding );
 311
 312	/*	Reads text. Returns a pointer past the given end tag.
 313		Wickedly complex options, but it keeps the (sensitive) code in one place.
 314	*/
 315	static const char* ReadText(	const char* in,				// where to start
 316									TIXML_STRING* text,			// the string read
 317									bool ignoreWhiteSpace,		// whether to keep the white space
 318									const char* endTag,			// what ends this text
 319									bool ignoreCase,			// whether to ignore case in the end tag
 320									TiXmlEncoding encoding );	// the current encoding
 321
 322	// If an entity has been found, transform it into a character.
 323	static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding );
 324
 325	// Get a character, while interpreting entities.
 326	// The length can be from 0 to 4 bytes.
 327	inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding )
 328	{
 329		assert( p );
 330		if ( encoding == TIXML_ENCODING_UTF8 )
 331		{
 332			*length = utf8ByteTable[ *((const unsigned char*)p) ];
 333			assert( *length >= 0 && *length < 5 );
 334		}
 335		else
 336		{
 337			*length = 1;
 338		}
 339
 340		if ( *length == 1 )
 341		{
 342			if ( *p == '&' )
 343				return GetEntity( p, _value, length, encoding );
 344			*_value = *p;
 345			return p+1;
 346		}
 347		else if ( *length )
 348		{
 349			//strncpy( _value, p, *length );	// lots of compilers don't like this function (unsafe),
 350												// and the null terminator isn't needed
 351			for( int i=0; p[i] && i<*length; ++i ) {
 352				_value[i] = p[i];
 353			}
 354			return p + (*length);
 355		}
 356		else
 357		{
 358			// Not valid text.
 359			return 0;
 360		}
 361	}
 362
 363	// Return true if the next characters in the stream are any of the endTag sequences.
 364	// Ignore case only works for english, and should only be relied on when comparing
 365	// to English words: StringEqual( p, "version", true ) is fine.
 366	static bool StringEqual(	const char* p,
 367								const char* endTag,
 368								bool ignoreCase,
 369								TiXmlEncoding encoding );
 370
 371	static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
 372
 373	TiXmlCursor location;
 374
 375    /// Field containing a generic user pointer
 376	void*			userData;
 377	
 378	// None of these methods are reliable for any language except English.
 379	// Good for approximation, not great for accuracy.
 380	static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding );
 381	static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding );
 382	inline static int ToLower( int v, TiXmlEncoding encoding )
 383	{
 384		if ( encoding == TIXML_ENCODING_UTF8 )
 385		{
 386			if ( v < 128 ) return tolower( v );
 387			return v;
 388		}
 389		else
 390		{
 391			return tolower( v );
 392		}
 393	}
 394	static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length );
 395
 396private:
 397	TiXmlBase( const TiXmlBase& );				// not implemented.
 398	void operator=( const TiXmlBase& base );	// not allowed.
 399
 400	struct Entity
 401	{
 402		const char*     str;
 403		unsigned int	strLength;
 404		char		    chr;
 405	};
 406	enum
 407	{
 408		NUM_ENTITY = 5,
 409		MAX_ENTITY_LENGTH = 6
 410
 411	};
 412	static Entity entity[ NUM_ENTITY ];
 413	static bool condenseWhiteSpace;
 414};
 415
 416
 417/** The parent class for everything in the Document Object Model.
 418	(Except for attributes).
 419	Nodes have siblings, a parent, and children. A node can be
 420	in a document, or stand on its own. The type of a TiXmlNode
 421	can be queried, and it can be cast to its more defined type.
 422*/
 423class TiXmlNode : public TiXmlBase
 424{
 425	friend class TiXmlDocument;
 426	friend class TiXmlElement;
 427
 428public:
 429	#ifdef TIXML_USE_STL	
 430
 431	    /** An input stream operator, for every class. Tolerant of newlines and
 432		    formatting, but doesn't expect them.
 433	    */
 434	    friend std::istream& operator >> (std::istream& in, TiXmlNode& base);
 435
 436	    /** An output stream operator, for every class. Note that this outputs
 437		    without any newlines or formatting, as opposed to Print(), which
 438		    includes tabs and new lines.
 439
 440		    The operator<< and operator>> are not completely symmetric. Writing
 441		    a node to a stream is very well defined. You'll get a nice stream
 442		    of output, without any extra whitespace or newlines.
 443		    
 444		    But reading is not as well defined. (As it always is.) If you create
 445		    a TiXmlElement (for example) and read that from an input stream,
 446		    the text needs to define an element or junk will result. This is
 447		    true of all input streams, but it's worth keeping in mind.
 448
 449		    A TiXmlDocument will read nodes until it reads a root element, and
 450			all the children of that root element.
 451	    */	
 452	    friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base);
 453
 454		/// Appends the XML node or attribute to a std::string.
 455		friend std::string& operator<< (std::string& out, const TiXmlNode& base );
 456
 457	#endif
 458
 459	/** The types of XML nodes supported by TinyXml. (All the
 460			unsupported types are picked up by UNKNOWN.)
 461	*/
 462	enum NodeType
 463	{
 464		TINYXML_DOCUMENT,
 465		TINYXML_ELEMENT,
 466		TINYXML_COMMENT,
 467		TINYXML_UNKNOWN,
 468		TINYXML_TEXT,
 469		TINYXML_DECLARATION,
 470		TINYXML_TYPECOUNT
 471	};
 472
 473	virtual ~TiXmlNode();
 474
 475	/** The meaning of 'value' changes for the specific type of
 476		TiXmlNode.
 477		@verbatim
 478		Document:	filename of the xml file
 479		Element:	name of the element
 480		Comment:	the comment text
 481		Unknown:	the tag contents
 482		Text:		the text string
 483		@endverbatim
 484
 485		The subclasses will wrap this function.
 486	*/
 487	const char *Value() const { return value.c_str (); }
 488
 489    #ifdef TIXML_USE_STL
 490	/** Return Value() as a std::string. If you only use STL,
 491	    this is more efficient than calling Value().
 492		Only available in STL mode.
 493	*/
 494	const std::string& ValueStr() const { return value; }
 495	#endif
 496
 497	const TIXML_STRING& ValueTStr() const { return value; }
 498
 499	/** Changes the value of the node. Defined as:
 500		@verbatim
 501		Document:	filename of the xml file
 502		Element:	name of the element
 503		Comment:	the comment text
 504		Unknown:	the tag contents
 505		Text:		the text string
 506		@endverbatim
 507	*/
 508	void SetValue(const char * _value) { value = _value;}
 509
 510    #ifdef TIXML_USE_STL
 511	/// STL std::string form.
 512	void SetValue( const std::string& _value )	{ value = _value; }
 513	#endif
 514
 515	/// Delete all the children of this node. Does not affect 'this'.
 516	void Clear();
 517
 518	/// One step up the DOM.
 519	TiXmlNode* Parent()							{ return parent; }
 520	const TiXmlNode* Parent() const				{ return parent; }
 521
 522	const TiXmlNode* FirstChild()	const		{ return firstChild; }	///< The first child of this node. Will be null if there are no children.
 523	TiXmlNode* FirstChild()						{ return firstChild; }
 524	const TiXmlNode* FirstChild( const char * value ) const;			///< The first child of this node with the matching 'value'. Will be null if none found.
 525	/// The first child of this node with the matching 'value'. Will be null if none found.
 526	TiXmlNode* FirstChild( const char * _value ) {
 527		// Call through to the const version - safe since nothing is changed. Exiting syntax: cast this to a const (always safe)
 528		// call the method, cast the return back to non-const.
 529		return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->FirstChild( _value ));
 530	}
 531	const TiXmlNode* LastChild() const	{ return lastChild; }		/// The last child of this node. Will be null if there are no children.
 532	TiXmlNode* LastChild()	{ return lastChild; }
 533	
 534	const TiXmlNode* LastChild( const char * value ) const;			/// The last child of this node matching 'value'. Will be null if there are no children.
 535	TiXmlNode* LastChild( const char * _value ) {
 536		return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->LastChild( _value ));
 537	}
 538
 539    #ifdef TIXML_USE_STL
 540	const TiXmlNode* FirstChild( const std::string& _value ) const	{	return FirstChild (_value.c_str ());	}	///< STL std::string form.
 541	TiXmlNode* FirstChild( const std::string& _value )				{	return FirstChild (_value.c_str ());	}	///< STL std::string form.
 542	const TiXmlNode* LastChild( const std::string& _value ) const	{	return LastChild (_value.c_str ());	}	///< STL std::string form.
 543	TiXmlNode* LastChild( const std::string& _value )				{	return LastChild (_value.c_str ());	}	///< STL std::string form.
 544	#endif
 545
 546	/** An alternate way to walk the children of a node.
 547		One way to iterate over nodes is:
 548		@verbatim
 549			for( child = parent->FirstChild(); child; child = child->NextSibling() )
 550		@endverbatim
 551
 552		IterateChildren does the same thing with the syntax:
 553		@verbatim
 554			child = 0;
 555			while( child = parent->IterateChildren( child ) )
 556		@endverbatim
 557
 558		IterateChildren takes the previous child as input and finds
 559		the next one. If the previous child is null, it returns the
 560		first. IterateChildren will return null when done.
 561	*/
 562	const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const;
 563	TiXmlNode* IterateChildren( const TiXmlNode* previous ) {
 564		return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( previous ) );
 565	}
 566
 567	/// This flavor of IterateChildren searches for children with a particular 'value'
 568	const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const;
 569	TiXmlNode* IterateChildren( const char * _value, const TiXmlNode* previous ) {
 570		return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( _value, previous ) );
 571	}
 572
 573    #ifdef TIXML_USE_STL
 574	const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const	{	return IterateChildren (_value.c_str (), previous);	}	///< STL std::string form.
 575	TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) {	return IterateChildren (_value.c_str (), previous);	}	///< STL std::string form.
 576	#endif
 577
 578	/** Add a new node related to this. Adds a child past the LastChild.
 579		Returns a pointer to the new object or NULL if an error occured.
 580	*/
 581	TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
 582
 583
 584	/** Add a new node related to this. Adds a child past the LastChild.
 585
 586		NOTE: the node to be added is passed by pointer, and will be
 587		henceforth owned (and deleted) by tinyXml. This method is efficient
 588		and avoids an extra copy, but should be used with care as it
 589		uses a different memory model than the other insert functions.
 590
 591		@sa InsertEndChild
 592	*/
 593	TiXmlNode* LinkEndChild( TiXmlNode* addThis );
 594
 595	/** Add a new node related to this. Adds a child before the specified child.
 596		Returns a pointer to the new object or NULL if an error occured.
 597	*/
 598	TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
 599
 600	/** Add a new node related to this. Adds a child after the specified child.
 601		Returns a pointer to the new object or NULL if an error occured.
 602	*/
 603	TiXmlNode* InsertAfterChild(  TiXmlNode* afterThis, const TiXmlNode& addThis );
 604
 605	/** Replace a child of this node.
 606		Returns a pointer to the new object or NULL if an error occured.
 607	*/
 608	TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
 609
 610	/// Delete a child of this node.
 611	bool RemoveChild( TiXmlNode* removeThis );
 612
 613	/// Navigate to a sibling node.
 614	const TiXmlNode* PreviousSibling() const			{ return prev; }
 615	TiXmlNode* PreviousSibling()						{ return prev; }
 616
 617	/// Navigate to a sibling node.
 618	const TiXmlNode* PreviousSibling( const char * ) const;
 619	TiXmlNode* PreviousSibling( const char *_prev ) {
 620		return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->PreviousSibling( _prev ) );
 621	}
 622
 623    #ifdef TIXML_USE_STL
 624	const TiXmlNode* PreviousSibling( const std::string& _value ) const	{	return PreviousSibling (_value.c_str ());	}	///< STL std::string form.
 625	TiXmlNode* PreviousSibling( const std::string& _value ) 			{	return PreviousSibling (_value.c_str ());	}	///< STL std::string form.
 626	const TiXmlNode* NextSibling( const std::string& _value) const		{	return NextSibling (_value.c_str ());	}	///< STL std::string form.
 627	TiXmlNode* NextSibling( const std::string& _value) 					{	return NextSibling (_value.c_str ());	}	///< STL std::string form.
 628	#endif
 629
 630	/// Navigate to a sibling node.
 631	const TiXmlNode* NextSibling() const				{ return next; }
 632	TiXmlNode* NextSibling()							{ return next; }
 633
 634	/// Navigate to a sibling node with the given 'value'.
 635	const TiXmlNode* NextSibling( const char * ) const;
 636	TiXmlNode* NextSibling( const char* _next ) {
 637		return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->NextSibling( _next ) );
 638	}
 639
 640	/** Convenience function to get through elements.
 641		Calls NextSibling and ToElement. Will skip all non-Element
 642		nodes. Returns 0 if there is not another element.
 643	*/
 644	const TiXmlElement* NextSiblingElement() const;
 645	TiXmlElement* NextSiblingElement() {
 646		return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement() );
 647	}
 648
 649	/** Convenience function to get through elements.
 650		Calls NextSibling and ToElement. Will skip all non-Element
 651		nodes. Returns 0 if there is not another element.
 652	*/
 653	const TiXmlElement* NextSiblingElement( const char * ) const;
 654	TiXmlElement* NextSiblingElement( const char *_next ) {
 655		return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement( _next ) );
 656	}
 657
 658    #ifdef TIXML_USE_STL
 659	const TiXmlElement* NextSiblingElement( const std::string& _value) const	{	return NextSiblingElement (_value.c_str ());	}	///< STL std::string form.
 660	TiXmlElement* NextSiblingElement( const std::string& _value)				{	return NextSiblingElement (_value.c_str ());	}	///< STL std::string form.
 661	#endif
 662
 663	/// Convenience function to get through elements.
 664	const TiXmlElement* FirstChildElement()	const;
 665	TiXmlElement* FirstChildElement() {
 666		return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement() );
 667	}
 668
 669	/// Convenience function to get through elements.
 670	const TiXmlElement* FirstChildElement( const char * _value ) const;
 671	TiXmlElement* FirstChildElement( const char * _value ) {
 672		return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement( _value ) );
 673	}
 674
 675    #ifdef TIXML_USE_STL
 676	const TiXmlElement* FirstChildElement( const std::string& _value ) const	{	return FirstChildElement (_value.c_str ());	}	///< STL std::string form.
 677	TiXmlElement* FirstChildElement( const std::string& _value )				{	return FirstChildElement (_value.c_str ());	}	///< STL std::string form.
 678	#endif
 679
 680	/** Query the type (as an enumerated value, above) of this node.
 681		The possible types are: DOCUMENT, ELEMENT, COMMENT,
 682								UNKNOWN, TEXT, and DECLARATION.
 683	*/
 684	int Type() const	{ return type; }
 685
 686	/** Return a pointer to the Document this node lives in.
 687		Returns null if not in a document.
 688	*/
 689	const TiXmlDocument* GetDocument() const;
 690	TiXmlDocument* GetDocument() {
 691		return const_cast< TiXmlDocument* >( (const_cast< const TiXmlNode* >(this))->GetDocument() );
 692	}
 693
 694	/// Returns true if this node has no children.
 695	bool NoChildren() const						{ return !firstChild; }
 696
 697	virtual const TiXmlDocument*    ToDocument()    const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
 698	virtual const TiXmlElement*     ToElement()     const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
 699	virtual const TiXmlComment*     ToComment()     const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
 700	virtual const TiXmlUnknown*     ToUnknown()     const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
 701	virtual const TiXmlText*        ToText()        const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
 702	virtual const TiXmlDeclaration* ToDeclaration() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
 703
 704	virtual TiXmlDocument*          ToDocument()    { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
 705	virtual TiXmlElement*           ToElement()	    { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
 706	virtual TiXmlComment*           ToComment()     { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
 707	virtual TiXmlUnknown*           ToUnknown()	    { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
 708	virtual TiXmlText*	            ToText()        { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
 709	virtual TiXmlDeclaration*       ToDeclaration() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type.
 710
 711	/** Create an exact duplicate of this node and return it. The memory must be deleted
 712		by the caller. 
 713	*/
 714	virtual TiXmlNode* Clone() const = 0;
 715
 716	/** Accept a hierchical visit the nodes in the TinyXML DOM. Every node in the 
 717		XML tree will be conditionally visited and the host will be called back
 718		via the TiXmlVisitor interface.
 719
 720		This is essentially a SAX interface for TinyXML. (Note however it doesn't re-parse
 721		the XML for the callbacks, so the performance of TinyXML is unchanged by using this
 722		interface versus any other.)
 723
 724		The interface has been based on ideas from:
 725
 726		- http://www.saxproject.org/
 727		- http://c2.com/cgi/wiki?HierarchicalVisitorPattern 
 728
 729		Which are both good references for "visiting".
 730
 731		An example of using Accept():
 732		@verbatim
 733		TiXmlPrinter printer;
 734		tinyxmlDoc.Accept( &printer );
 735		const char* xmlcstr = printer.CStr();
 736		@endverbatim
 737	*/
 738	virtual bool Accept( TiXmlVisitor* visitor ) const = 0;
 739
 740protected:
 741	TiXmlNode( NodeType _type );
 742
 743	// Copy to the allocated object. Shared functionality between Clone, Copy constructor,
 744	// and the assignment operator.
 745	void CopyTo( TiXmlNode* target ) const;
 746
 747	#ifdef TIXML_USE_STL
 748	    // The real work of the input operator.
 749	virtual void StreamIn( std::istream* in, TIXML_STRING* tag ) = 0;
 750	#endif
 751
 752	// Figure out what is at *p, and parse it. Returns null if it is not an xml node.
 753	TiXmlNode* Identify( const char* start, TiXmlEncoding encoding );
 754
 755	TiXmlNode*		parent;
 756	NodeType		type;
 757
 758	TiXmlNode*		firstChild;
 759	TiXmlNode*		lastChild;
 760
 761	TIXML_STRING	value;
 762
 763	TiXmlNode*		prev;
 764	TiXmlNode*		next;
 765
 766private:
 767	TiXmlNode( const TiXmlNode& );				// not implemented.
 768	void operator=( const TiXmlNode& base );	// not allowed.
 769};
 770
 771
 772/** An attribute is a name-value pair. Elements have an arbitrary
 773	number of attributes, each with a unique name.
 774
 775	@note The attributes are not TiXmlNodes, since they are not
 776		  part of the tinyXML document object model. There are other
 777		  suggested ways to look at this problem.
 778*/
 779class TiXmlAttribute : public TiXmlBase
 780{
 781	friend class TiXmlAttributeSet;
 782
 783public:
 784	/// Construct an empty attribute.
 785	TiXmlAttribute() : TiXmlBase()
 786	{
 787		document = 0;
 788		prev = next = 0;
 789	}
 790
 791	#ifdef TIXML_USE_STL
 792	/// std::string constructor.
 793	TiXmlAttribute( const std::string& _name, const std::string& _value )
 794	{
 795		name = _name;
 796		value = _value;
 797		document = 0;
 798		prev = next = 0;
 799	}
 800	#endif
 801
 802	/// Construct an attribute with a name and value.
 803	TiXmlAttribute( const char * _name, const char * _value )
 804	{
 805		name = _name;
 806		value = _value;
 807		document = 0;
 808		prev = next = 0;
 809	}
 810
 811	const char*		Name()  const		{ return name.c_str(); }		///< Return the name of this attribute.
 812	const char*		Value() const		{ return value.c_str(); }		///< Return the value of this attribute.
 813	#ifdef TIXML_USE_STL
 814	const std::string& ValueStr() const	{ return value; }				///< Return the value of this attribute.
 815	#endif
 816	int				IntValue() const;									///< Return the value of this attribute, converted to an integer.
 817	double			DoubleValue() const;								///< Return the value of this attribute, converted to a double.
 818
 819	// Get the tinyxml string representation
 820	const TIXML_STRING& NameTStr() const { return name; }
 821
 822	/** QueryIntValue examines the value string. It is an alternative to the
 823		IntValue() method with richer error checking.
 824		If the value is an integer, it is stored in 'value' and 
 825		the call returns TIXML_SUCCESS. If it is not
 826		an integer, it returns TIXML_WRONG_TYPE.
 827
 828		A specialized but useful call. Note that for success it returns 0,
 829		which is the opposite of almost all other TinyXml calls.
 830	*/
 831	int QueryIntValue( int* _value ) const;
 832	/// QueryDoubleValue examines the value string. See QueryIntValue().
 833	int QueryDoubleValue( double* _value ) const;
 834
 835	void SetName( const char* _name )	{ name = _name; }				///< Set the name of this attribute.
 836	void SetValue( const char* _value )	{ value = _value; }				///< Set the value.
 837
 838	void SetIntValue( int _value );										///< Set the value from an integer.
 839	void SetDoubleValue( double _value );								///< Set the value from a double.
 840
 841    #ifdef TIXML_USE_STL
 842	/// STL std::string form.
 843	void SetName( const std::string& _name )	{ name = _name; }	
 844	/// STL std::string form.	
 845	void SetValue( const std::string& _value )	{ value = _value; }
 846	#endif
 847
 848	/// Get the next sibling attribute in the DOM. Returns null at end.
 849	const TiXmlAttribute* Next() const;
 850	TiXmlAttribute* Next() {
 851		return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Next() ); 
 852	}
 853
 854	/// Get the previous sibling attribute in the DOM. Returns null at beginning.
 855	const TiXmlAttribute* Previous() const;
 856	TiXmlAttribute* Previous() {
 857		return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Previous() ); 
 858	}
 859
 860	bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
 861	bool operator<( const TiXmlAttribute& rhs )	 const { return name < rhs.name; }
 862	bool operator>( const TiXmlAttribute& rhs )  const { return name > rhs.name; }
 863
 864	/*	Attribute parsing starts: first letter of the name
 865						 returns: the next char after the value end quote
 866	*/
 867	virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
 868
 869	// Prints this Attribute to a FILE stream.
 870	virtual void Print( FILE* cfile, int depth ) const {
 871		Print( cfile, depth, 0 );
 872	}
 873	void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
 874
 875	// [internal use]
 876	// Set the document pointer so the attribute can report errors.
 877	void SetDocument( TiXmlDocument* doc )	{ document = doc; }
 878
 879private:
 880	TiXmlAttribute( const TiXmlAttribute& );				// not implemented.
 881	void operator=( const TiXmlAttribute& base );	// not allowed.
 882
 883	TiXmlDocument*	document;	// A pointer back to a document, for error reporting.
 884	TIXML_STRING name;
 885	TIXML_STRING value;
 886	TiXmlAttribute*	prev;
 887	TiXmlAttribute*	next;
 888};
 889
 890
 891/*	A class used to manage a group of attributes.
 892	It is only used internally, both by the ELEMENT and the DECLARATION.
 893	
 894	The set can be changed transparent to the Element and Declaration
 895	classes that use it, but NOT transparent to the Attribute
 896	which has to implement a next() and previous() method. Which makes
 897	it a bit problematic and prevents the use of STL.
 898
 899	This version is implemented with circular lists because:
 900		- I like circular lists
 901		- it demonstrates some independence from the (typical) doubly linked list.
 902*/
 903class TiXmlAttributeSet
 904{
 905public:
 906	TiXmlAttributeSet();
 907	~TiXmlAttributeSet();
 908
 909	void Add( TiXmlAttribute* attribute );
 910	void Remove( TiXmlAttribute* attribute );
 911
 912	const TiXmlAttribute* First()	const	{ return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
 913	TiXmlAttribute* First()					{ return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
 914	const TiXmlAttribute* Last() const		{ return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
 915	TiXmlAttribute* Last()					{ return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
 916
 917	TiXmlAttribute*	Find( const char* _name ) const;
 918	TiXmlAttribute* FindOrCreate( const char* _name );
 919
 920#	ifdef TIXML_USE_STL
 921	TiXmlAttribute*	Find( const std::string& _name ) const;
 922	TiXmlAttribute* FindOrCreate( const std::string& _name );
 923#	endif
 924
 925
 926private:
 927	//*ME:	Because of hidden/disabled copy-construktor in TiXmlAttribute (sentinel-element),
 928	//*ME:	this class must be also use a hidden/disabled copy-constructor !!!
 929	TiXmlAttributeSet( const TiXmlAttributeSet& );	// not allowed
 930	void operator=( const TiXmlAttributeSet& );	// not allowed (as TiXmlAttribute)
 931
 932	TiXmlAttribute sentinel;
 933};
 934
 935
 936/** The element is a container class. It has a value, the element name,
 937	and can contain other elements, text, comments, and unknowns.
 938	Elements also contain an arbitrary number of attributes.
 939*/
 940class TiXmlElement : public TiXmlNode
 941{
 942public:
 943	/// Construct an element.
 944	TiXmlElement (const char * in_value);
 945
 946	#ifdef TIXML_USE_STL
 947	/// std::string constructor.
 948	TiXmlElement( const std::string& _value );
 949	#endif
 950
 951	TiXmlElement( const TiXmlElement& );
 952
 953	void operator=( const TiXmlElement& base );
 954
 955	virtual ~TiXmlElement();
 956
 957	/** Given an attribute name, Attribute() returns the value
 958		for the attribute of that name, or null if none exists.
 959	*/
 960	const char* Attribute( const char* name ) const;
 961
 962	/** Given an attribute name, Attribute() returns the value
 963		for the attribute of that name, or null if none exists.
 964		If the attribute exists and can be converted to an integer,
 965		the integer value will be put in the return 'i', if 'i'
 966		is non-null.
 967	*/
 968	const char* Attribute( const char* name, int* i ) const;
 969
 970	/** Given an attribute name, Attribute() returns the value
 971		for the attribute of that name, or null if none exists.
 972		If the attribute exists and can be converted to an double,
 973		the double value will be put in the return 'd', if 'd'
 974		is non-null.
 975	*/
 976	const char* Attribute( const char* name, double* d ) const;
 977
 978	/** QueryIntAttribute examines the attribute - it is an alternative to the
 979		Attribute() method with richer error checking.
 980		If the attribute is an integer, it is stored in 'value' and 
 981		the call returns TIXML_SUCCESS. If it is not
 982		an integer, it returns TIXML_WRONG_TYPE. If the attribute
 983		does not exist, then TIXML_NO_ATTRIBUTE is returned.
 984	*/	
 985	int QueryIntAttribute( const char* name, int* _value ) const;
 986	/// QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
 987	int QueryDoubleAttribute( const char* name, double* _value ) const;
 988	/// QueryFloatAttribute examines the attribute - see QueryIntAttribute().
 989	int QueryFloatAttribute( const char* name, float* _value ) const {
 990		double d;
 991		int result = QueryDoubleAttribute( name, &d );
 992		if ( result == TIXML_SUCCESS ) {
 993			*_value = (float)d;
 994		}
 995		return result;
 996	}
 997
 998    #ifdef TIXML_USE_STL
 999	/// QueryStringAttribute examines the attribute - see QueryIntAttribute().
1000	int QueryStringAttribute( const char* name, std::string* _value ) const {
1001		const char* cstr = Attribute( name );
1002		if ( cstr ) {
1003			*_value = std::string( cstr );
1004			return TIXML_SUCCESS;
1005		}
1006		return TIXML_NO_ATTRIBUTE;
1007	}
1008
1009	/** Template form of the attribute query which will try to read the
1010		attribute into the specified type. Very easy, very powerful, but
1011		be careful to make sure to call this with the correct type.
1012		
1013		NOTE: This method doesn't work correctly for 'string' types that contain spaces.
1014
1015		@return TIXML_SUCCESS, TIXML_WRONG_TYPE, or TIXML_NO_ATTRIBUTE
1016	*/
1017	template< typename T > int QueryValueAttribute( const std::string& name, T* outValue ) const
1018	{
1019		const TiXmlAttribute* node = attributeSet.Find( name );
1020		if ( !node )
1021			return TIXML_NO_ATTRIBUTE;
1022
1023		std::stringstream sstream( node->ValueStr() );
1024		sstream >> *outValue;
1025		if ( !sstream.fail() )
1026			return TIXML_SUCCESS;
1027		return TIXML_WRONG_TYPE;
1028	}
1029
1030	int QueryValueAttribute( const std::string& name, std::string* outValue ) const
1031	{
1032		const TiXmlAttribute* node = attributeSet.Find( name );
1033		if ( !node )
1034			return TIXML_NO_ATTRIBUTE;
1035		*outValue = node->ValueStr();
1036		return TIXML_SUCCESS;
1037	}
1038	#endif
1039
1040	/** Sets an attribute of name to a given value. The attribute
1041		will be created if it does not exist, or changed if it does.
1042	*/
1043	void SetAttribute( const char* name, const char * _value );
1044
1045    #ifdef TIXML_USE_STL
1046	const std::string* Attribute( const std::string& name ) const;
1047	const std::string* Attribute( const std::string& name, int* i ) const;
1048	const std::string* Attribute( const std::string& name, double* d ) const;
1049	int QueryIntAttribute( const std::string& name, int* _value ) const;
1050	int QueryDoubleAttribute( const std::string& name, double* _value ) const;
1051
1052	/// STL std::string form.
1053	void SetAttribute( const std::string& name, const std::string& _value );
1054	///< STL std::string form.
1055	void SetAttribute( const std::string& name, int _value );
1056	///< STL std::string form.
1057	void SetDoubleAttribute( const std::string& name, double value );
1058	#endif
1059
1060	/** Sets an attribute of name to a given value. The attribute
1061		will be created if it does not exist, or changed if it does.
1062	*/
1063	void SetAttribute( const char * name, int value );
1064
1065	/** Sets an attribute of name to a given value. The attribute
1066		will be created if it does not exist, or changed if it does.
1067	*/
1068	void SetDoubleAttribute( const char * name, double value );
1069
1070	/** Deletes an attribute with the given name.
1071	*/
1072	void RemoveAttribute( const char * name );
1073    #ifdef TIXML_USE_STL
1074	void RemoveAttribute( const std::string& name )	{	RemoveAttribute (name.c_str ());	}	///< STL std::string form.
1075	#endif
1076
1077	const TiXmlAttribute* FirstAttribute() const	{ return attributeSet.First(); }		///< Access the first attribute in this element.
1078	TiXmlAttribute* FirstAttribute() 				{ return attributeSet.First(); }
1079	const TiXmlAttribute* LastAttribute()	const 	{ return attributeSet.Last(); }		///< Access the last attribute in this element.
1080	TiXmlAttribute* LastAttribute()					{ return attributeSet.Last(); }
1081
1082	/** Convenience function for easy access to the text inside an element. Although easy
1083		and concise, GetText() is limited compared to getting the TiXmlText child
1084		and accessing it directly.
1085	
1086		If the first child of 'this' is a TiXmlText, the GetText()
1087		returns the character string of the Text node, else null is returned.
1088
1089		This is a convenient method for getting the text of simple contained text:
1090		@verbatim
1091		<foo>This is text</foo>
1092		const char* str = fooElement->GetText();
1093		@endverbatim
1094
1095		'str' will be a pointer to "This is text". 
1096		
1097		Note that this function can be misleading. If the element foo was created from
1098		this XML:
1099		@verbatim
1100		<foo><b>This is text</b></foo> 
1101		@endverbatim
1102
1103		then the value of str would be null. The first child node isn't a text node, it is
1104		another element. From this XML:
1105		@verbatim
1106		<foo>This is <b>text</b></foo> 
1107		@endverbatim
1108		GetText() will return "This is ".
1109
1110		WARNING: GetText() accesses a child node - don't become confused with the 
1111				 similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are 
1112				 safe type casts on the referenced node.
1113	*/
1114	const char* GetText() const;
1115
1116	/// Creates a new Element and returns it - the returned element is a copy.
1117	virtual TiXmlNode* Clone() const;
1118	// Print the Element to a FILE stream.
1119	virtual void Print( FILE* cfile, int depth ) const;
1120
1121	/*	Attribtue parsing starts: next char past '<'
1122						 returns: next char past '>'
1123	*/
1124	virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1125
1126	virtual const TiXmlElement*     ToElement()     const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
1127	virtual TiXmlElement*           ToElement()	          { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
1128
1129	/** Walk the XML tree visiting this node and all of its children. 
1130	*/
1131	virtual bool Accept( TiXmlVisitor* visitor ) const;
1132
1133protected:
1134
1135	void CopyTo( TiXmlElement* target ) const;
1136	void ClearThis();	// like clear, but initializes 'this' object as well
1137
1138	// Used to be public [internal use]
1139	#ifdef TIXML_USE_STL
1140	virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1141	#endif
1142	/*	[internal use]
1143		Reads the "value" of the element -- another element, or text.
1144		This should terminate with the current end tag.
1145	*/
1146	const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding );
1147
1148private:
1149	TiXmlAttributeSet attributeSet;
1150};
1151
1152
1153/**	An XML comment.
1154*/
1155class TiXmlComment : public TiXmlNode
1156{
1157public:
1158	/// Constructs an empty comment.
1159	TiXmlComment() : TiXmlNode( TiXmlNode::TINYXML_COMMENT ) {}
1160	/// Construct a comment from text.
1161	TiXmlComment( const char* _value ) : TiXmlNode( TiXmlNode::TINYXML_COMMENT ) {
1162		SetValue( _value );
1163	}
1164	TiXmlComment( const TiXmlComment& );
1165	void operator=( const TiXmlComment& base );
1166
1167	virtual ~TiXmlComment()	{}
1168
1169	/// Returns a copy of this Comment.
1170	virtual TiXmlNode* Clone() const;
1171	// Write this Comment to a FILE stream.
1172	virtual void Print( FILE* cfile, int depth ) const;
1173
1174	/*	Attribtue parsing starts: at the ! of the !--
1175						 returns: next char past '>'
1176	*/
1177	virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1178
1179	virtual const TiXmlComment*  ToComment() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
1180	virtual TiXmlComment*  ToComment() { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
1181
1182	/** Walk the XML tree visiting this node and all of its children. 
1183	*/
1184	virtual bool Accept( TiXmlVisitor* visitor ) const;
1185
1186protected:
1187	void CopyTo( TiXmlComment* target ) const;
1188
1189	// used to be public
1190	#ifdef TIXML_USE_STL
1191	virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1192	#endif
1193//	virtual void StreamOut( TIXML_OSTREAM * out ) const;
1194
1195private:
1196
1197};
1198
1199
1200/** XML text. A text node can have 2 ways to output the next. "normal" output 
1201	and CDATA. It will default to the mode it was parsed from the XML file and
1202	you generally want to leave it alone, but you can change the output mode with 
1203	SetCDATA() and query it with CDATA().
1204*/
1205class TiXmlText : public TiXmlNode
1206{
1207	friend class TiXmlElement;
1208public:
1209	/** Constructor for text element. By default, it is treated as 
1210		normal, encoded text. If you want it be output as a CDATA text
1211		element, set the parameter _cdata to 'true'
1212	*/
1213	TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TINYXML_TEXT)
1214	{
1215		SetValue( initValue );
1216		cdata = false;
1217	}
1218	virtual ~TiXmlText() {}
1219
1220	#ifdef TIXML_USE_STL
1221	/// Constructor.
1222	TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TINYXML_TEXT)
1223	{
1224		SetValue( initValue );
1225		cdata = false;
1226	}
1227	#endif
1228
1229	TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TINYXML_TEXT )	{ copy.CopyTo( this ); }
1230	void operator=( const TiXmlText& base )							 	{ base.CopyTo( this ); }
1231
1232	// Write this text object to a FILE stream.
1233	virtual void Print( FILE* cfile, int depth ) const;
1234
1235	/// Queries whether this represents text using a CDATA section.
1236	bool CDATA() const				{ return cdata; }
1237	/// Turns on or off a CDATA representation of text.
1238	void SetCDATA( bool _cdata )	{ cdata = _cdata; }
1239
1240	virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1241
1242	virtual const TiXmlText* ToText() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
1243	virtual TiXmlText*       ToText()       { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
1244
1245	/** Walk the XML tree visiting this node and all of its children. 
1246	*/
1247	virtual bool Accept( TiXmlVisitor* content ) const;
1248
1249protected :
1250	///  [internal use] Creates a new Element and returns it.
1251	virtual TiXmlNode* Clone() const;
1252	void CopyTo( TiXmlText* target ) const;
1253
1254	bool Blank() const;	// returns true if all white space and new lines
1255	// [internal use]
1256	#ifdef TIXML_USE_STL
1257	virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1258	#endif
1259
1260private:
1261	bool cdata;			// true if this should be input and output as a CDATA style text element
1262};
1263
1264
1265/** In correct XML the declaration is the first entry in the file.
1266	@verbatim
1267		<?xml version="1.0" standalone="yes"?>
1268	@endverbatim
1269
1270	TinyXml will happily read or write files without a declaration,
1271	however. There are 3 possible attributes to the declaration:
1272	version, encoding, and standalone.
1273
1274	Note: In this version of the code, the attributes are
1275	handled as special cases, not generic attributes, simply
1276	because there can only be at most 3 and they are always the same.
1277*/
1278class TiXmlDeclaration : public TiXmlNode
1279{
1280public:
1281	/// Construct an empty declaration.
1282	TiXmlDeclaration()   : TiXmlNode( TiXmlNode::TINYXML_DECLARATION ) {}
1283
1284#ifdef TIXML_USE_STL
1285	/// Constructor.
1286	TiXmlDeclaration(	const std::string& _version,
1287						const std::string& _encoding,
1288						const std::string& _standalone );
1289#endif
1290
1291	/// Construct.
1292	TiXmlDeclaration(	const char* _version,
1293						const char* _encoding,
1294						const char* _standalone );
1295
1296	TiXmlDeclaration( const TiXmlDeclaration& copy );
1297	void operator=( const TiXmlDeclaration& copy );
1298
1299	virtual ~TiXmlDeclaration()	{}
1300
1301	/// Version. Will return an empty string if none was found.
1302	const char *Version() const			{ return version.c_str (); }
1303	/// Encoding. Will return an empty string if none was found.
1304	const char *Encoding() const		{ return encoding.c_str (); }
1305	/// Is this a standalone document?
1306	const char *Standalone() const		{ return standalone.c_str (); }
1307
1308	/// Creates a copy of this Declaration and returns it.
1309	virtual TiXmlNode* Clone() const;
1310	// Print this declaration to a FILE stream.
1311	virtual void Print( FILE* cfile, int depth, TIXML_STRING* str ) const;
1312	virtual void Print( FILE* cfile, int depth ) const {
1313		Print( cfile, depth, 0 );
1314	}
1315
1316	virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1317
1318	virtual const TiXmlDeclaration* ToDeclaration() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
1319	virtual TiXmlDeclaration*       ToDeclaration()       { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
1320
1321	/** Walk the XML tree visiting this node and all of its children. 
1322	*/
1323	virtual bool Accept( TiXmlVisitor* visitor ) const;
1324
1325protected:
1326	void CopyTo( TiXmlDeclaration* target ) const;
1327	// used to be public
1328	#ifdef TIXML_USE_STL
1329	virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1330	#endif
1331
1332private:
1333
1334	TIXML_STRING version;
1335	TIXML_STRING encoding;
1336	TIXML_STRING standalone;
1337};
1338
1339
1340/** Any tag that tinyXml doesn't recognize is saved as an
1341	unknown. It is a tag of text, but should not be modified.
1342	It will be written back to the XML, unchanged, when the file
1343	is saved.
1344
1345	DTD tags get thrown into TiXmlUnknowns.
1346*/
1347class TiXmlUnknown : public TiXmlNode
1348{
1349public:
1350	TiXmlUnknown() : TiXmlNode( TiXmlNode::TINYXML_UNKNOWN )	{}
1351	virtual ~TiXmlUnknown() {}
1352
1353	TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::TINYXML_UNKNOWN )		{ copy.CopyTo( this ); }
1354	void operator=( const TiXmlUnknown& copy )										{ copy.CopyTo( this ); }
1355
1356	/// Creates a copy of this Unknown and returns it.
1357	virtual TiXmlNode* Clone() const;
1358	// Print this Unknown to a FILE stream.
1359	virtual void Print( FILE* cfile, int depth ) const;
1360
1361	virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
1362
1363	virtual const TiXmlUnknown*     ToUnknown()     const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
1364	virtual TiXmlUnknown*           ToUnknown()	    { return this; } ///< Cast to a more defined type. Will return null not of the requested type.
1365
1366	/** Walk the XML tree visiting this node and all of its children. 
1367	*/
1368	virtual bool Accept( TiXmlVisitor* content ) const;
1369
1370protected:
1371	void CopyTo( TiXmlUnknown* target ) const;
1372
1373	#ifdef TIXML_USE_STL
1374	virtual void StreamIn( std::istream * in, TIXML_STRING * tag );
1375	#endif
1376
1377private:
1378
1379};
1380
1381
1382/** Always the top level node. A document binds together all the
1383	XML pieces. It can be saved, loaded, and printed to the screen.
1384	The 'value' of a document node is the xml file name.
1385*/
1386class TiXmlDocument : public TiXmlNode
1387{
1388public:
1389	/// Create an empty document, that has no name.
1390	TiXmlDocument();
1391	/// Create a document with a name. The name of the document is also the filename of the xml.
1392	TiXmlDocument( const char * documentName );
1393
1394	#ifdef TIXML_USE_STL
1395	/// Constructor.
1396	TiXmlDocument( const std::string& documentName );
1397	#endif
1398
1399	TiXmlDocument( const TiXmlDocument& copy );
1400	void operator=( const TiXmlDocument& copy );
1401
1402	virtual ~TiXmlDocument() {}
1403
1404	/** Load a file using the current document value.
1405		Returns tru…

Large files files are truncated, but you can click here to view the full file