1159b3361Sopenharmony_ci/*
2159b3361Sopenharmony_ciCopyright (c) 2000 Lee Thomason (www.grinninglizard.com)
3159b3361Sopenharmony_ci
4159b3361Sopenharmony_ciThis software is provided 'as-is', without any express or implied
5159b3361Sopenharmony_ciwarranty. In no event will the authors be held liable for any
6159b3361Sopenharmony_cidamages arising from the use of this software.
7159b3361Sopenharmony_ci
8159b3361Sopenharmony_ciPermission is granted to anyone to use this software for any
9159b3361Sopenharmony_cipurpose, including commercial applications, and to alter it and
10159b3361Sopenharmony_ciredistribute it freely, subject to the following restrictions:
11159b3361Sopenharmony_ci
12159b3361Sopenharmony_ci1. The origin of this software must not be misrepresented; you must
13159b3361Sopenharmony_cinot claim that you wrote the original software. If you use this
14159b3361Sopenharmony_cisoftware in a product, an acknowledgment in the product documentation
15159b3361Sopenharmony_ciwould be appreciated but is not required.
16159b3361Sopenharmony_ci
17159b3361Sopenharmony_ci2. Altered source versions must be plainly marked as such, and
18159b3361Sopenharmony_cimust not be misrepresented as being the original software.
19159b3361Sopenharmony_ci
20159b3361Sopenharmony_ci3. This notice may not be removed or altered from any source
21159b3361Sopenharmony_cidistribution.
22159b3361Sopenharmony_ci*/
23159b3361Sopenharmony_ci
24159b3361Sopenharmony_ci
25159b3361Sopenharmony_ci#ifndef TINYXML_INCLUDED
26159b3361Sopenharmony_ci#define TINYXML_INCLUDED
27159b3361Sopenharmony_ci
28159b3361Sopenharmony_ci#pragma warning( disable : 4530 )
29159b3361Sopenharmony_ci#pragma warning( disable : 4786 )
30159b3361Sopenharmony_ci
31159b3361Sopenharmony_ci#include <string>
32159b3361Sopenharmony_ci#include <stdio.h>
33159b3361Sopenharmony_ci#include <assert.h>
34159b3361Sopenharmony_ci
35159b3361Sopenharmony_ciclass TiXmlDocument;
36159b3361Sopenharmony_ciclass TiXmlElement;
37159b3361Sopenharmony_ciclass TiXmlComment;
38159b3361Sopenharmony_ciclass TiXmlUnknown;
39159b3361Sopenharmony_ciclass TiXmlAttribute;
40159b3361Sopenharmony_ciclass TiXmlText;
41159b3361Sopenharmony_ciclass TiXmlDeclaration;
42159b3361Sopenharmony_ci
43159b3361Sopenharmony_ci
44159b3361Sopenharmony_ci// Help out windows:
45159b3361Sopenharmony_ci#if defined( _DEBUG ) && !defined( DEBUG )
46159b3361Sopenharmony_ci	#define DEBUG
47159b3361Sopenharmony_ci#endif
48159b3361Sopenharmony_ci
49159b3361Sopenharmony_ci#if defined( DEBUG ) && defined( _MSC_VER )
50159b3361Sopenharmony_ci	#include <windows.h>
51159b3361Sopenharmony_ci	#define TIXML_LOG OutputDebugString
52159b3361Sopenharmony_ci#else
53159b3361Sopenharmony_ci	#define TIXML_LOG printf
54159b3361Sopenharmony_ci#endif
55159b3361Sopenharmony_ci
56159b3361Sopenharmony_ci
57159b3361Sopenharmony_ci/** TiXmlBase is a base class for every class in TinyXml.
58159b3361Sopenharmony_ci	It does little except to establish that TinyXml classes
59159b3361Sopenharmony_ci	can be printed and provide some utility functions.
60159b3361Sopenharmony_ci
61159b3361Sopenharmony_ci	In XML, the document and elements can contain
62159b3361Sopenharmony_ci	other elements and other types of nodes.
63159b3361Sopenharmony_ci
64159b3361Sopenharmony_ci	@verbatim
65159b3361Sopenharmony_ci	A Document can contain:	Element	(container or leaf)
66159b3361Sopenharmony_ci							Comment (leaf)
67159b3361Sopenharmony_ci							Unknown (leaf)
68159b3361Sopenharmony_ci							Declaration( leaf )
69159b3361Sopenharmony_ci
70159b3361Sopenharmony_ci	An Element can contain:	Element (container or leaf)
71159b3361Sopenharmony_ci							Text	(leaf)
72159b3361Sopenharmony_ci							Attributes (not on tree)
73159b3361Sopenharmony_ci							Comment (leaf)
74159b3361Sopenharmony_ci							Unknown (leaf)
75159b3361Sopenharmony_ci
76159b3361Sopenharmony_ci	A Decleration contains: Attributes (not on tree)
77159b3361Sopenharmony_ci	@endverbatim
78159b3361Sopenharmony_ci*/
79159b3361Sopenharmony_ciclass TiXmlBase
80159b3361Sopenharmony_ci{
81159b3361Sopenharmony_ci	friend class TiXmlNode;
82159b3361Sopenharmony_ci	friend class TiXmlElement;
83159b3361Sopenharmony_ci	friend class TiXmlDocument;
84159b3361Sopenharmony_ci
85159b3361Sopenharmony_ci  public:
86159b3361Sopenharmony_ci	TiXmlBase()								{}
87159b3361Sopenharmony_ci	virtual ~TiXmlBase()					{}
88159b3361Sopenharmony_ci
89159b3361Sopenharmony_ci	/**	All TinyXml classes can print themselves to a filestream.
90159b3361Sopenharmony_ci		This is a formatted print, and will insert tabs and newlines.
91159b3361Sopenharmony_ci
92159b3361Sopenharmony_ci		(For an unformatted stream, use the << operator.)
93159b3361Sopenharmony_ci	*/
94159b3361Sopenharmony_ci 	virtual void Print( FILE* cfile, int depth ) const = 0;
95159b3361Sopenharmony_ci
96159b3361Sopenharmony_ci	// [internal] Underlying implementation of the operator <<
97159b3361Sopenharmony_ci	virtual void StreamOut ( std::ostream* out ) const = 0;
98159b3361Sopenharmony_ci
99159b3361Sopenharmony_ci	/**	The world does not agree on whether white space should be kept or
100159b3361Sopenharmony_ci		not. In order to make everyone happy, these global, static functions
101159b3361Sopenharmony_ci		are provided to set whether or not TinyXml will condense all white space
102159b3361Sopenharmony_ci		into a single space or not. The default is to condense. Note changing these
103159b3361Sopenharmony_ci		values is not thread safe.
104159b3361Sopenharmony_ci	*/
105159b3361Sopenharmony_ci	static void SetCondenseWhiteSpace( bool condense )		{ condenseWhiteSpace = condense; }
106159b3361Sopenharmony_ci
107159b3361Sopenharmony_ci	/// Return the current white space setting.
108159b3361Sopenharmony_ci	static bool IsWhiteSpaceCondensed()						{ return condenseWhiteSpace; }
109159b3361Sopenharmony_ci
110159b3361Sopenharmony_ci  protected:
111159b3361Sopenharmony_ci	static const char* SkipWhiteSpace( const char* );
112159b3361Sopenharmony_ci	static bool StreamWhiteSpace( std::istream* in, std::string* tag );
113159b3361Sopenharmony_ci	static bool IsWhiteSpace( int c )		{ return ( isspace( c ) || c == '\n' || c == '\r' ); }
114159b3361Sopenharmony_ci
115159b3361Sopenharmony_ci	/*	Read to the specified character.
116159b3361Sopenharmony_ci		Returns true if the character found and no error.
117159b3361Sopenharmony_ci	*/
118159b3361Sopenharmony_ci	static bool StreamTo( std::istream* in, int character, std::string* tag );
119159b3361Sopenharmony_ci
120159b3361Sopenharmony_ci	/*	Reads an XML name into the string provided. Returns
121159b3361Sopenharmony_ci		a pointer just past the last character of the name,
122159b3361Sopenharmony_ci		or 0 if the function has an error.
123159b3361Sopenharmony_ci	*/
124159b3361Sopenharmony_ci	static const char* ReadName( const char*, std::string* name );
125159b3361Sopenharmony_ci
126159b3361Sopenharmony_ci	/*	Reads text. Returns a pointer past the given end tag.
127159b3361Sopenharmony_ci		Wickedly complex options, but it keeps the (sensitive) code in one place.
128159b3361Sopenharmony_ci	*/
129159b3361Sopenharmony_ci	static const char* ReadText(	const char* in,				// where to start
130159b3361Sopenharmony_ci									std::string* text,			// the string read
131159b3361Sopenharmony_ci									bool ignoreWhiteSpace,		// whether to keep the white space
132159b3361Sopenharmony_ci									const char* endTag,			// what ends this text
133159b3361Sopenharmony_ci									bool ignoreCase );			// whether to ignore case in the end tag
134159b3361Sopenharmony_ci
135159b3361Sopenharmony_ci	virtual const char* Parse( const char* p ) = 0;
136159b3361Sopenharmony_ci
137159b3361Sopenharmony_ci	// If an entity has been found, transform it into a character.
138159b3361Sopenharmony_ci	static const char* GetEntity( const char* in, char* value );
139159b3361Sopenharmony_ci
140159b3361Sopenharmony_ci	// Get a character, while interpreting entities.
141159b3361Sopenharmony_ci	inline static const char* GetChar( const char* p, char* value )
142159b3361Sopenharmony_ci											{
143159b3361Sopenharmony_ci												assert( p );
144159b3361Sopenharmony_ci												if ( *p == '&' )
145159b3361Sopenharmony_ci												{
146159b3361Sopenharmony_ci													return GetEntity( p, value );
147159b3361Sopenharmony_ci												}
148159b3361Sopenharmony_ci												else
149159b3361Sopenharmony_ci												{
150159b3361Sopenharmony_ci													*value = *p;
151159b3361Sopenharmony_ci													return p+1;
152159b3361Sopenharmony_ci												}
153159b3361Sopenharmony_ci											}
154159b3361Sopenharmony_ci
155159b3361Sopenharmony_ci	// Puts a string to a stream, expanding entities as it goes.
156159b3361Sopenharmony_ci	// Note this should not contian the '<', '>', etc, or they will be transformed into entities!
157159b3361Sopenharmony_ci	static void PutString( const std::string& str, std::ostream* stream );
158159b3361Sopenharmony_ci
159159b3361Sopenharmony_ci	// Return true if the next characters in the stream are any of the endTag sequences.
160159b3361Sopenharmony_ci	bool static StringEqual(	const char* p,
161159b3361Sopenharmony_ci								const char* endTag,
162159b3361Sopenharmony_ci								bool ignoreCase );
163159b3361Sopenharmony_ci
164159b3361Sopenharmony_ci
165159b3361Sopenharmony_ci	enum
166159b3361Sopenharmony_ci	{
167159b3361Sopenharmony_ci		TIXML_NO_ERROR = 0,
168159b3361Sopenharmony_ci		TIXML_ERROR,
169159b3361Sopenharmony_ci		TIXML_ERROR_OPENING_FILE,
170159b3361Sopenharmony_ci		TIXML_ERROR_OUT_OF_MEMORY,
171159b3361Sopenharmony_ci		TIXML_ERROR_PARSING_ELEMENT,
172159b3361Sopenharmony_ci		TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
173159b3361Sopenharmony_ci		TIXML_ERROR_READING_ELEMENT_VALUE,
174159b3361Sopenharmony_ci		TIXML_ERROR_READING_ATTRIBUTES,
175159b3361Sopenharmony_ci		TIXML_ERROR_PARSING_EMPTY,
176159b3361Sopenharmony_ci		TIXML_ERROR_READING_END_TAG,
177159b3361Sopenharmony_ci		TIXML_ERROR_PARSING_UNKNOWN,
178159b3361Sopenharmony_ci		TIXML_ERROR_PARSING_COMMENT,
179159b3361Sopenharmony_ci		TIXML_ERROR_PARSING_DECLARATION,
180159b3361Sopenharmony_ci		TIXML_ERROR_DOCUMENT_EMPTY,
181159b3361Sopenharmony_ci
182159b3361Sopenharmony_ci		TIXML_ERROR_STRING_COUNT
183159b3361Sopenharmony_ci	};
184159b3361Sopenharmony_ci	static const char* errorString[ TIXML_ERROR_STRING_COUNT ];
185159b3361Sopenharmony_ci
186159b3361Sopenharmony_ci  private:
187159b3361Sopenharmony_ci	struct Entity
188159b3361Sopenharmony_ci	{
189159b3361Sopenharmony_ci		const char*     str;
190159b3361Sopenharmony_ci		unsigned int	strLength;
191159b3361Sopenharmony_ci		int			    chr;
192159b3361Sopenharmony_ci	};
193159b3361Sopenharmony_ci	enum
194159b3361Sopenharmony_ci	{
195159b3361Sopenharmony_ci		NUM_ENTITY = 5,
196159b3361Sopenharmony_ci		MAX_ENTITY_LENGTH = 6
197159b3361Sopenharmony_ci
198159b3361Sopenharmony_ci	};
199159b3361Sopenharmony_ci	static Entity entity[ NUM_ENTITY ];
200159b3361Sopenharmony_ci	static bool condenseWhiteSpace;
201159b3361Sopenharmony_ci};
202159b3361Sopenharmony_ci
203159b3361Sopenharmony_ci
204159b3361Sopenharmony_ci/** The parent class for everything in the Document Object Model.
205159b3361Sopenharmony_ci	(Except for attributes, which are contained in elements.)
206159b3361Sopenharmony_ci	Nodes have siblings, a parent, and children. A node can be
207159b3361Sopenharmony_ci	in a document, or stand on its own. The type of a TiXmlNode
208159b3361Sopenharmony_ci	can be queried, and it can be cast to its more defined type.
209159b3361Sopenharmony_ci*/
210159b3361Sopenharmony_ciclass TiXmlNode : public TiXmlBase
211159b3361Sopenharmony_ci{
212159b3361Sopenharmony_ci  public:
213159b3361Sopenharmony_ci
214159b3361Sopenharmony_ci	/** An output stream operator, for every class. Note that this outputs
215159b3361Sopenharmony_ci		without any newlines or formatting, as opposed to Print(), which
216159b3361Sopenharmony_ci		includes tabs and new lines.
217159b3361Sopenharmony_ci
218159b3361Sopenharmony_ci		The operator<< and operator>> are not completely symmetric. Writing
219159b3361Sopenharmony_ci		a node to a stream is very well defined. You'll get a nice stream
220159b3361Sopenharmony_ci		of output, without any extra whitespace or newlines.
221159b3361Sopenharmony_ci
222159b3361Sopenharmony_ci		But reading is not as well defined. (As it always is.) If you create
223159b3361Sopenharmony_ci		a TiXmlElement (for example) and read that from an input stream,
224159b3361Sopenharmony_ci		the text needs to define an element or junk will result. This is
225159b3361Sopenharmony_ci		true of all input streams, but it's worth keeping in mind.
226159b3361Sopenharmony_ci
227159b3361Sopenharmony_ci		A TiXmlDocument will read nodes until it reads a root element.
228159b3361Sopenharmony_ci	*/
229159b3361Sopenharmony_ci	friend std::ostream& operator<< ( std::ostream& out, const TiXmlNode& base )
230159b3361Sopenharmony_ci	{
231159b3361Sopenharmony_ci		base.StreamOut( &out );
232159b3361Sopenharmony_ci		return out;
233159b3361Sopenharmony_ci	}
234159b3361Sopenharmony_ci
235159b3361Sopenharmony_ci	/** An input stream operator, for every class. Tolerant of newlines and
236159b3361Sopenharmony_ci		formatting, but doesn't expect them.
237159b3361Sopenharmony_ci	*/
238159b3361Sopenharmony_ci	friend std::istream& operator>> ( std::istream& in, TiXmlNode& base )
239159b3361Sopenharmony_ci	{
240159b3361Sopenharmony_ci		std::string tag;
241159b3361Sopenharmony_ci		tag.reserve( 8 * 1000 );
242159b3361Sopenharmony_ci		base.StreamIn( &in, &tag );
243159b3361Sopenharmony_ci
244159b3361Sopenharmony_ci		base.Parse( tag.c_str() );
245159b3361Sopenharmony_ci		return in;
246159b3361Sopenharmony_ci	}
247159b3361Sopenharmony_ci
248159b3361Sopenharmony_ci	/** The types of XML nodes supported by TinyXml. (All the
249159b3361Sopenharmony_ci		unsupported types are picked up by UNKNOWN.)
250159b3361Sopenharmony_ci	*/
251159b3361Sopenharmony_ci	enum NodeType
252159b3361Sopenharmony_ci	{
253159b3361Sopenharmony_ci		DOCUMENT,
254159b3361Sopenharmony_ci		ELEMENT,
255159b3361Sopenharmony_ci		COMMENT,
256159b3361Sopenharmony_ci		UNKNOWN,
257159b3361Sopenharmony_ci		TEXT,
258159b3361Sopenharmony_ci		DECLARATION,
259159b3361Sopenharmony_ci		TYPECOUNT
260159b3361Sopenharmony_ci	};
261159b3361Sopenharmony_ci
262159b3361Sopenharmony_ci	virtual ~TiXmlNode();
263159b3361Sopenharmony_ci
264159b3361Sopenharmony_ci	/** The meaning of 'value' changes for the specific type of
265159b3361Sopenharmony_ci		TiXmlNode.
266159b3361Sopenharmony_ci		@verbatim
267159b3361Sopenharmony_ci		Document:	filename of the xml file
268159b3361Sopenharmony_ci		Element:	name of the element
269159b3361Sopenharmony_ci		Comment:	the comment text
270159b3361Sopenharmony_ci		Unknown:	the tag contents
271159b3361Sopenharmony_ci		Text:		the text string
272159b3361Sopenharmony_ci		@endverbatim
273159b3361Sopenharmony_ci
274159b3361Sopenharmony_ci		The subclasses will wrap this function.
275159b3361Sopenharmony_ci	*/
276159b3361Sopenharmony_ci	const std::string& Value()	const			{ return value; }
277159b3361Sopenharmony_ci
278159b3361Sopenharmony_ci	/** Changes the value of the node. Defined as:
279159b3361Sopenharmony_ci		@verbatim
280159b3361Sopenharmony_ci		Document:	filename of the xml file
281159b3361Sopenharmony_ci		Element:	name of the element
282159b3361Sopenharmony_ci		Comment:	the comment text
283159b3361Sopenharmony_ci		Unknown:	the tag contents
284159b3361Sopenharmony_ci		Text:		the text string
285159b3361Sopenharmony_ci		@endverbatim
286159b3361Sopenharmony_ci	*/
287159b3361Sopenharmony_ci	void SetValue( const std::string& _value )		{ value = _value; }
288159b3361Sopenharmony_ci
289159b3361Sopenharmony_ci	/// Delete all the children of this node. Does not affect 'this'.
290159b3361Sopenharmony_ci	void Clear();
291159b3361Sopenharmony_ci
292159b3361Sopenharmony_ci	/// One step up the DOM.
293159b3361Sopenharmony_ci	TiXmlNode* Parent() const					{ return parent; }
294159b3361Sopenharmony_ci
295159b3361Sopenharmony_ci	TiXmlNode* FirstChild()	const	{ return firstChild; }		///< The first child of this node. Will be null if there are no children.
296159b3361Sopenharmony_ci	TiXmlNode* FirstChild( const std::string& value ) const;	///< The first child of this node with the matching 'value'. Will be null if none found.
297159b3361Sopenharmony_ci
298159b3361Sopenharmony_ci	TiXmlNode* LastChild() const	{ return lastChild; }		/// The last child of this node. Will be null if there are no children.
299159b3361Sopenharmony_ci	TiXmlNode* LastChild( const std::string& value ) const;		/// The last child of this node matching 'value'. Will be null if there are no children.
300159b3361Sopenharmony_ci
301159b3361Sopenharmony_ci	/** An alternate way to walk the children of a node.
302159b3361Sopenharmony_ci		One way to iterate over nodes is:
303159b3361Sopenharmony_ci		@verbatim
304159b3361Sopenharmony_ci			for( child = parent->FirstChild(); child; child = child->NextSibling() )
305159b3361Sopenharmony_ci		@endverbatim
306159b3361Sopenharmony_ci
307159b3361Sopenharmony_ci		IterateChildren does the same thing with the syntax:
308159b3361Sopenharmony_ci		@verbatim
309159b3361Sopenharmony_ci			child = 0;
310159b3361Sopenharmony_ci			while( child = parent->IterateChildren( child ) )
311159b3361Sopenharmony_ci		@endverbatim
312159b3361Sopenharmony_ci
313159b3361Sopenharmony_ci		IterateChildren takes the previous child as input and finds
314159b3361Sopenharmony_ci		the next one. If the previous child is null, it returns the
315159b3361Sopenharmony_ci		first. IterateChildren will return null when done.
316159b3361Sopenharmony_ci	*/
317159b3361Sopenharmony_ci	TiXmlNode* IterateChildren( TiXmlNode* previous ) const;
318159b3361Sopenharmony_ci
319159b3361Sopenharmony_ci	/// This flavor of IterateChildren searches for children with a particular 'value'
320159b3361Sopenharmony_ci	TiXmlNode* IterateChildren( const std::string& value, TiXmlNode* previous ) const;
321159b3361Sopenharmony_ci
322159b3361Sopenharmony_ci	/** Add a new node related to this. Adds a child past the LastChild.
323159b3361Sopenharmony_ci		Returns a pointer to the new object or NULL if an error occured.
324159b3361Sopenharmony_ci	*/
325159b3361Sopenharmony_ci	TiXmlNode* InsertEndChild( const TiXmlNode& addThis );
326159b3361Sopenharmony_ci
327159b3361Sopenharmony_ci	/** Add a new node related to this. Adds a child before the specified child.
328159b3361Sopenharmony_ci		Returns a pointer to the new object or NULL if an error occured.
329159b3361Sopenharmony_ci	*/
330159b3361Sopenharmony_ci	TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis );
331159b3361Sopenharmony_ci
332159b3361Sopenharmony_ci	/** Add a new node related to this. Adds a child after the specified child.
333159b3361Sopenharmony_ci		Returns a pointer to the new object or NULL if an error occured.
334159b3361Sopenharmony_ci	*/
335159b3361Sopenharmony_ci	TiXmlNode* InsertAfterChild(  TiXmlNode* afterThis, const TiXmlNode& addThis );
336159b3361Sopenharmony_ci
337159b3361Sopenharmony_ci	/** Replace a child of this node.
338159b3361Sopenharmony_ci		Returns a pointer to the new object or NULL if an error occured.
339159b3361Sopenharmony_ci	*/
340159b3361Sopenharmony_ci	TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis );
341159b3361Sopenharmony_ci
342159b3361Sopenharmony_ci	/// Delete a child of this node.
343159b3361Sopenharmony_ci	bool RemoveChild( TiXmlNode* removeThis );
344159b3361Sopenharmony_ci
345159b3361Sopenharmony_ci	/// Navigate to a sibling node.
346159b3361Sopenharmony_ci	TiXmlNode* PreviousSibling() const			{ return prev; }
347159b3361Sopenharmony_ci
348159b3361Sopenharmony_ci	/// Navigate to a sibling node.
349159b3361Sopenharmony_ci	TiXmlNode* PreviousSibling( const std::string& ) const;
350159b3361Sopenharmony_ci
351159b3361Sopenharmony_ci	/// Navigate to a sibling node.
352159b3361Sopenharmony_ci	TiXmlNode* NextSibling() const				{ return next; }
353159b3361Sopenharmony_ci
354159b3361Sopenharmony_ci	/// Navigate to a sibling node with the given 'value'.
355159b3361Sopenharmony_ci	TiXmlNode* NextSibling( const std::string& ) const;
356159b3361Sopenharmony_ci
357159b3361Sopenharmony_ci	/** Convenience function to get through elements.
358159b3361Sopenharmony_ci		Calls NextSibling and ToElement. Will skip all non-Element
359159b3361Sopenharmony_ci		nodes. Returns 0 if there is not another element.
360159b3361Sopenharmony_ci	*/
361159b3361Sopenharmony_ci	TiXmlElement* NextSiblingElement() const;
362159b3361Sopenharmony_ci
363159b3361Sopenharmony_ci	/** Convenience function to get through elements.
364159b3361Sopenharmony_ci		Calls NextSibling and ToElement. Will skip all non-Element
365159b3361Sopenharmony_ci		nodes. Returns 0 if there is not another element.
366159b3361Sopenharmony_ci	*/
367159b3361Sopenharmony_ci	TiXmlElement* NextSiblingElement( const std::string& ) const;
368159b3361Sopenharmony_ci
369159b3361Sopenharmony_ci	/// Convenience function to get through elements.
370159b3361Sopenharmony_ci	TiXmlElement* FirstChildElement()	const;
371159b3361Sopenharmony_ci
372159b3361Sopenharmony_ci	/// Convenience function to get through elements.
373159b3361Sopenharmony_ci	TiXmlElement* FirstChildElement( const std::string& value ) const;
374159b3361Sopenharmony_ci
375159b3361Sopenharmony_ci	/// Query the type (as an enumerated value, above) of this node.
376159b3361Sopenharmony_ci	virtual int Type() const	{ return type; }
377159b3361Sopenharmony_ci
378159b3361Sopenharmony_ci	/** Return a pointer to the Document this node lives in.
379159b3361Sopenharmony_ci		Returns null if not in a document.
380159b3361Sopenharmony_ci	*/
381159b3361Sopenharmony_ci	TiXmlDocument* GetDocument() const;
382159b3361Sopenharmony_ci
383159b3361Sopenharmony_ci	/// Returns true if this node has no children.
384159b3361Sopenharmony_ci	bool NoChildren() const						{ return !firstChild; }
385159b3361Sopenharmony_ci
386159b3361Sopenharmony_ci	TiXmlDocument* ToDocument()	const		{ return ( this && type == DOCUMENT ) ? (TiXmlDocument*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type.
387159b3361Sopenharmony_ci	TiXmlElement*  ToElement() const		{ return ( this && type == ELEMENT  ) ? (TiXmlElement*)  this : 0; } ///< Cast to a more defined type. Will return null not of the requested type.
388159b3361Sopenharmony_ci	TiXmlComment*  ToComment() const		{ return ( this && type == COMMENT  ) ? (TiXmlComment*)  this : 0; } ///< Cast to a more defined type. Will return null not of the requested type.
389159b3361Sopenharmony_ci	TiXmlUnknown*  ToUnknown() const		{ return ( this && type == UNKNOWN  ) ? (TiXmlUnknown*)  this : 0; } ///< Cast to a more defined type. Will return null not of the requested type.
390159b3361Sopenharmony_ci	TiXmlText*	   ToText()    const		{ return ( this && type == TEXT     ) ? (TiXmlText*)     this : 0; } ///< Cast to a more defined type. Will return null not of the requested type.
391159b3361Sopenharmony_ci	TiXmlDeclaration* ToDeclaration() const	{ return ( this && type == DECLARATION ) ? (TiXmlDeclaration*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type.
392159b3361Sopenharmony_ci
393159b3361Sopenharmony_ci	virtual TiXmlNode* Clone() const = 0;
394159b3361Sopenharmony_ci
395159b3361Sopenharmony_ci	// The real work of the input operator.
396159b3361Sopenharmony_ci	virtual void StreamIn( std::istream* in, std::string* tag ) = 0;
397159b3361Sopenharmony_ci
398159b3361Sopenharmony_ci  protected:
399159b3361Sopenharmony_ci	TiXmlNode( NodeType type );
400159b3361Sopenharmony_ci
401159b3361Sopenharmony_ci	// The node is passed in by ownership. This object will delete it.
402159b3361Sopenharmony_ci	TiXmlNode* LinkEndChild( TiXmlNode* addThis );
403159b3361Sopenharmony_ci
404159b3361Sopenharmony_ci	// Figure out what is at *p, and parse it. Returns null if it is not an xml node.
405159b3361Sopenharmony_ci	TiXmlNode* Identify( const char* start );
406159b3361Sopenharmony_ci
407159b3361Sopenharmony_ci	void CopyToClone( TiXmlNode* target ) const	{ target->value = value; }
408159b3361Sopenharmony_ci
409159b3361Sopenharmony_ci	TiXmlNode*		parent;
410159b3361Sopenharmony_ci	NodeType		type;
411159b3361Sopenharmony_ci
412159b3361Sopenharmony_ci	TiXmlNode*		firstChild;
413159b3361Sopenharmony_ci	TiXmlNode*		lastChild;
414159b3361Sopenharmony_ci
415159b3361Sopenharmony_ci	std::string		value;
416159b3361Sopenharmony_ci
417159b3361Sopenharmony_ci	TiXmlNode*		prev;
418159b3361Sopenharmony_ci	TiXmlNode*		next;
419159b3361Sopenharmony_ci};
420159b3361Sopenharmony_ci
421159b3361Sopenharmony_ci
422159b3361Sopenharmony_ci/** An attribute is a name-value pair. Elements have an arbitrary
423159b3361Sopenharmony_ci	number of attributes, each with a unique name.
424159b3361Sopenharmony_ci
425159b3361Sopenharmony_ci	@note The attributes are not TiXmlNodes, since they are not
426159b3361Sopenharmony_ci		  part of the tinyXML document object model. There are other
427159b3361Sopenharmony_ci		  suggested ways to look at this problem.
428159b3361Sopenharmony_ci
429159b3361Sopenharmony_ci	@note Attributes have a parent
430159b3361Sopenharmony_ci*/
431159b3361Sopenharmony_ciclass TiXmlAttribute : public TiXmlBase
432159b3361Sopenharmony_ci{
433159b3361Sopenharmony_ci	friend class TiXmlAttributeSet;
434159b3361Sopenharmony_ci
435159b3361Sopenharmony_ci  public:
436159b3361Sopenharmony_ci	/// Construct an empty attribute.
437159b3361Sopenharmony_ci	TiXmlAttribute() : prev( 0 ), next( 0 )	{}
438159b3361Sopenharmony_ci
439159b3361Sopenharmony_ci	/// Construct an attribute with a name and value.
440159b3361Sopenharmony_ci	TiXmlAttribute( const std::string& _name, const std::string& _value )	: name( _name ), value( _value ), prev( 0 ), next( 0 ) {}
441159b3361Sopenharmony_ci
442159b3361Sopenharmony_ci	const std::string& Name()  const { return name; }		///< Return the name of this attribute.
443159b3361Sopenharmony_ci
444159b3361Sopenharmony_ci	const std::string& Value() const { return value; }		///< Return the value of this attribute.
445159b3361Sopenharmony_ci	const int          IntValue() const;					///< Return the value of this attribute, converted to an integer.
446159b3361Sopenharmony_ci	const double	   DoubleValue() const;					///< Return the value of this attribute, converted to a double.
447159b3361Sopenharmony_ci
448159b3361Sopenharmony_ci	void SetName( const std::string& _name )	{ name = _name; }		///< Set the name of this attribute.
449159b3361Sopenharmony_ci	void SetValue( const std::string& _value )	{ value = _value; }		///< Set the value.
450159b3361Sopenharmony_ci	void SetIntValue( int value );										///< Set the value from an integer.
451159b3361Sopenharmony_ci	void SetDoubleValue( double value );								///< Set the value from a double.
452159b3361Sopenharmony_ci
453159b3361Sopenharmony_ci	/// Get the next sibling attribute in the DOM. Returns null at end.
454159b3361Sopenharmony_ci	TiXmlAttribute* Next() const;
455159b3361Sopenharmony_ci	/// Get the previous sibling attribute in the DOM. Returns null at beginning.
456159b3361Sopenharmony_ci	TiXmlAttribute* Previous() const;
457159b3361Sopenharmony_ci
458159b3361Sopenharmony_ci	bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; }
459159b3361Sopenharmony_ci	bool operator<( const TiXmlAttribute& rhs )	 const { return name < rhs.name; }
460159b3361Sopenharmony_ci	bool operator>( const TiXmlAttribute& rhs )  const { return name > rhs.name; }
461159b3361Sopenharmony_ci
462159b3361Sopenharmony_ci	/*	[internal use]
463159b3361Sopenharmony_ci		Attribtue parsing starts: first letter of the name
464159b3361Sopenharmony_ci						 returns: the next char after the value end quote
465159b3361Sopenharmony_ci	*/
466159b3361Sopenharmony_ci	virtual const char* Parse( const char* p );
467159b3361Sopenharmony_ci
468159b3361Sopenharmony_ci	// [internal use]
469159b3361Sopenharmony_ci 	virtual void Print( FILE* cfile, int depth ) const;
470159b3361Sopenharmony_ci
471159b3361Sopenharmony_ci	// [internal use]
472159b3361Sopenharmony_ci	virtual void StreamOut( std::ostream* out ) const;
473159b3361Sopenharmony_ci
474159b3361Sopenharmony_ci	// [internal use]
475159b3361Sopenharmony_ci	// Set the document pointer so the attribute can report errors.
476159b3361Sopenharmony_ci	void SetDocument( TiXmlDocument* doc )	{ document = doc; }
477159b3361Sopenharmony_ci
478159b3361Sopenharmony_ci  private:
479159b3361Sopenharmony_ci	TiXmlDocument*	document;	// A pointer back to a document, for error reporting.
480159b3361Sopenharmony_ci	std::string		name;
481159b3361Sopenharmony_ci	std::string		value;
482159b3361Sopenharmony_ci
483159b3361Sopenharmony_ci	TiXmlAttribute*	prev;
484159b3361Sopenharmony_ci	TiXmlAttribute*	next;
485159b3361Sopenharmony_ci};
486159b3361Sopenharmony_ci
487159b3361Sopenharmony_ci
488159b3361Sopenharmony_ci/*	A class used to manage a group of attributes.
489159b3361Sopenharmony_ci	It is only used internally, both by the ELEMENT and the DECLARATION.
490159b3361Sopenharmony_ci
491159b3361Sopenharmony_ci	The set can be changed transparent to the Element and Declaration
492159b3361Sopenharmony_ci	classes that use it, but NOT transparent to the Attribute
493159b3361Sopenharmony_ci	which has to implement a next() and previous() method. Which makes
494159b3361Sopenharmony_ci	it a bit problematic and prevents the use of STL.
495159b3361Sopenharmony_ci
496159b3361Sopenharmony_ci	This version is implemented with circular lists because:
497159b3361Sopenharmony_ci		- I like circular lists
498159b3361Sopenharmony_ci		- it demonstrates some independence from the (typical) doubly linked list.
499159b3361Sopenharmony_ci*/
500159b3361Sopenharmony_ciclass TiXmlAttributeSet
501159b3361Sopenharmony_ci{
502159b3361Sopenharmony_ci  public:
503159b3361Sopenharmony_ci	TiXmlAttributeSet();
504159b3361Sopenharmony_ci	~TiXmlAttributeSet();
505159b3361Sopenharmony_ci
506159b3361Sopenharmony_ci	void Add( TiXmlAttribute* attribute );
507159b3361Sopenharmony_ci	void Remove( TiXmlAttribute* attribute );
508159b3361Sopenharmony_ci
509159b3361Sopenharmony_ci	TiXmlAttribute* First() const	{ return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }
510159b3361Sopenharmony_ci	TiXmlAttribute* Last()  const	{ return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }
511159b3361Sopenharmony_ci
512159b3361Sopenharmony_ci	TiXmlAttribute*	Find( const std::string& name ) const;
513159b3361Sopenharmony_ci
514159b3361Sopenharmony_ci  private:
515159b3361Sopenharmony_ci	TiXmlAttribute sentinel;
516159b3361Sopenharmony_ci};
517159b3361Sopenharmony_ci
518159b3361Sopenharmony_ci
519159b3361Sopenharmony_ci/** The element is a container class. It has a value, the element name,
520159b3361Sopenharmony_ci	and can contain other elements, text, comments, and unknowns.
521159b3361Sopenharmony_ci	Elements also contain an arbitrary number of attributes.
522159b3361Sopenharmony_ci*/
523159b3361Sopenharmony_ciclass TiXmlElement : public TiXmlNode
524159b3361Sopenharmony_ci{
525159b3361Sopenharmony_ci  public:
526159b3361Sopenharmony_ci	/// Construct an element.
527159b3361Sopenharmony_ci	TiXmlElement( const std::string& value );
528159b3361Sopenharmony_ci
529159b3361Sopenharmony_ci	virtual ~TiXmlElement();
530159b3361Sopenharmony_ci
531159b3361Sopenharmony_ci	/** Given an attribute name, attribute returns the value
532159b3361Sopenharmony_ci		for the attribute of that name, or null if none exists.
533159b3361Sopenharmony_ci	*/
534159b3361Sopenharmony_ci	const std::string* Attribute( const std::string& name ) const;
535159b3361Sopenharmony_ci
536159b3361Sopenharmony_ci	/** Given an attribute name, attribute returns the value
537159b3361Sopenharmony_ci		for the attribute of that name, or null if none exists.
538159b3361Sopenharmony_ci	*/
539159b3361Sopenharmony_ci	const std::string* Attribute( const std::string& name, int* i ) const;
540159b3361Sopenharmony_ci
541159b3361Sopenharmony_ci	/** Sets an attribute of name to a given value. The attribute
542159b3361Sopenharmony_ci		will be created if it does not exist, or changed if it does.
543159b3361Sopenharmony_ci	*/
544159b3361Sopenharmony_ci	void SetAttribute( const std::string& name,
545159b3361Sopenharmony_ci					   const std::string& value );
546159b3361Sopenharmony_ci
547159b3361Sopenharmony_ci	/** Sets an attribute of name to a given value. The attribute
548159b3361Sopenharmony_ci		will be created if it does not exist, or changed if it does.
549159b3361Sopenharmony_ci	*/
550159b3361Sopenharmony_ci	void SetAttribute( const std::string& name,
551159b3361Sopenharmony_ci					   int value );
552159b3361Sopenharmony_ci
553159b3361Sopenharmony_ci	/** Deletes an attribute with the given name.
554159b3361Sopenharmony_ci	*/
555159b3361Sopenharmony_ci	void RemoveAttribute( const std::string& name );
556159b3361Sopenharmony_ci
557159b3361Sopenharmony_ci	TiXmlAttribute* FirstAttribute() const	{ return attributeSet.First(); }		///< Access the first attribute in this element.
558159b3361Sopenharmony_ci	TiXmlAttribute* LastAttribute()	const 	{ return attributeSet.Last(); }		///< Access the last attribute in this element.
559159b3361Sopenharmony_ci
560159b3361Sopenharmony_ci	// [internal use] Creates a new Element and returs it.
561159b3361Sopenharmony_ci	virtual TiXmlNode* Clone() const;
562159b3361Sopenharmony_ci	// [internal use]
563159b3361Sopenharmony_ci 	virtual void Print( FILE* cfile, int depth ) const;
564159b3361Sopenharmony_ci	// [internal use]
565159b3361Sopenharmony_ci	virtual void StreamOut ( std::ostream* out ) const;
566159b3361Sopenharmony_ci	// [internal use]
567159b3361Sopenharmony_ci	virtual void StreamIn( std::istream* in, std::string* tag );
568159b3361Sopenharmony_ci
569159b3361Sopenharmony_ci  protected:
570159b3361Sopenharmony_ci	/*	[internal use]
571159b3361Sopenharmony_ci		Attribtue parsing starts: next char past '<'
572159b3361Sopenharmony_ci						 returns: next char past '>'
573159b3361Sopenharmony_ci	*/
574159b3361Sopenharmony_ci	virtual const char* Parse( const char* p );
575159b3361Sopenharmony_ci
576159b3361Sopenharmony_ci	/*	[internal use]
577159b3361Sopenharmony_ci		Reads the "value" of the element -- another element, or text.
578159b3361Sopenharmony_ci		This should terminate with the current end tag.
579159b3361Sopenharmony_ci	*/
580159b3361Sopenharmony_ci	const char* ReadValue( const char* in );
581159b3361Sopenharmony_ci	bool ReadValue( std::istream* in );
582159b3361Sopenharmony_ci
583159b3361Sopenharmony_ci  private:
584159b3361Sopenharmony_ci	TiXmlAttributeSet attributeSet;
585159b3361Sopenharmony_ci};
586159b3361Sopenharmony_ci
587159b3361Sopenharmony_ci
588159b3361Sopenharmony_ci/**	An XML comment.
589159b3361Sopenharmony_ci*/
590159b3361Sopenharmony_ciclass TiXmlComment : public TiXmlNode
591159b3361Sopenharmony_ci{
592159b3361Sopenharmony_ci  public:
593159b3361Sopenharmony_ci	/// Constructs an empty comment.
594159b3361Sopenharmony_ci	TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {}
595159b3361Sopenharmony_ci	virtual ~TiXmlComment()	{}
596159b3361Sopenharmony_ci
597159b3361Sopenharmony_ci	// [internal use] Creates a new Element and returs it.
598159b3361Sopenharmony_ci	virtual TiXmlNode* Clone() const;
599159b3361Sopenharmony_ci	// [internal use]
600159b3361Sopenharmony_ci 	virtual void Print( FILE* cfile, int depth ) const;
601159b3361Sopenharmony_ci	// [internal use]
602159b3361Sopenharmony_ci	virtual void StreamOut ( std::ostream* out ) const;
603159b3361Sopenharmony_ci	// [internal use]
604159b3361Sopenharmony_ci	virtual void StreamIn( std::istream* in, std::string* tag );
605159b3361Sopenharmony_ci
606159b3361Sopenharmony_ci  protected:
607159b3361Sopenharmony_ci	/*	[internal use]
608159b3361Sopenharmony_ci		Attribtue parsing starts: at the ! of the !--
609159b3361Sopenharmony_ci						 returns: next char past '>'
610159b3361Sopenharmony_ci	*/
611159b3361Sopenharmony_ci	virtual const char* Parse( const char* p );
612159b3361Sopenharmony_ci};
613159b3361Sopenharmony_ci
614159b3361Sopenharmony_ci
615159b3361Sopenharmony_ci/** XML text. Contained in an element.
616159b3361Sopenharmony_ci*/
617159b3361Sopenharmony_ciclass TiXmlText : public TiXmlNode
618159b3361Sopenharmony_ci{
619159b3361Sopenharmony_ci  public:
620159b3361Sopenharmony_ci	TiXmlText( const std::string& initValue )  : TiXmlNode( TiXmlNode::TEXT ) { SetValue( initValue ); }
621159b3361Sopenharmony_ci	virtual ~TiXmlText() {}
622159b3361Sopenharmony_ci
623159b3361Sopenharmony_ci
624159b3361Sopenharmony_ci	// [internal use] Creates a new Element and returns it.
625159b3361Sopenharmony_ci	virtual TiXmlNode* Clone() const;
626159b3361Sopenharmony_ci	// [internal use]
627159b3361Sopenharmony_ci 	virtual void Print( FILE* cfile, int depth ) const;
628159b3361Sopenharmony_ci	// [internal use]
629159b3361Sopenharmony_ci	virtual void StreamOut ( std::ostream* out ) const;
630159b3361Sopenharmony_ci	// [internal use]
631159b3361Sopenharmony_ci	bool Blank() const;	// returns true if all white space and new lines
632159b3361Sopenharmony_ci	/*	[internal use]
633159b3361Sopenharmony_ci		Attribtue parsing starts: First char of the text
634159b3361Sopenharmony_ci						 returns: next char past '>'
635159b3361Sopenharmony_ci	*/
636159b3361Sopenharmony_ci	virtual const char* Parse( const char* p );
637159b3361Sopenharmony_ci	// [internal use]
638159b3361Sopenharmony_ci	virtual void StreamIn( std::istream* in, std::string* tag );
639159b3361Sopenharmony_ci};
640159b3361Sopenharmony_ci
641159b3361Sopenharmony_ci
642159b3361Sopenharmony_ci/** In correct XML the declaration is the first entry in the file.
643159b3361Sopenharmony_ci	@verbatim
644159b3361Sopenharmony_ci		<?xml version="1.0" standalone="yes"?>
645159b3361Sopenharmony_ci	@endverbatim
646159b3361Sopenharmony_ci
647159b3361Sopenharmony_ci	TinyXml will happily read or write files without a declaration,
648159b3361Sopenharmony_ci	however. There are 3 possible attributes to the declaration:
649159b3361Sopenharmony_ci	version, encoding, and standalone.
650159b3361Sopenharmony_ci
651159b3361Sopenharmony_ci	Note: In this version of the code, the attributes are
652159b3361Sopenharmony_ci	handled as special cases, not generic attributes, simply
653159b3361Sopenharmony_ci	because there can only be at most 3 and they are always the same.
654159b3361Sopenharmony_ci*/
655159b3361Sopenharmony_ciclass TiXmlDeclaration : public TiXmlNode
656159b3361Sopenharmony_ci{
657159b3361Sopenharmony_ci  public:
658159b3361Sopenharmony_ci	/// Construct an empty declaration.
659159b3361Sopenharmony_ci	TiXmlDeclaration()   : TiXmlNode( TiXmlNode::DECLARATION ) {}
660159b3361Sopenharmony_ci
661159b3361Sopenharmony_ci	/// Construct.
662159b3361Sopenharmony_ci	TiXmlDeclaration( const std::string& version,
663159b3361Sopenharmony_ci					  const std::string& encoding,
664159b3361Sopenharmony_ci					  const std::string& standalone );
665159b3361Sopenharmony_ci
666159b3361Sopenharmony_ci	virtual ~TiXmlDeclaration()	{}
667159b3361Sopenharmony_ci
668159b3361Sopenharmony_ci	/// Version. Will return empty if none was found.
669159b3361Sopenharmony_ci	const std::string& Version() const		{ return version; }
670159b3361Sopenharmony_ci	/// Encoding. Will return empty if none was found.
671159b3361Sopenharmony_ci	const std::string& Encoding() const		{ return encoding; }
672159b3361Sopenharmony_ci	/// Is this a standalone document?
673159b3361Sopenharmony_ci	const std::string& Standalone() const		{ return standalone; }
674159b3361Sopenharmony_ci
675159b3361Sopenharmony_ci	// [internal use] Creates a new Element and returs it.
676159b3361Sopenharmony_ci	virtual TiXmlNode* Clone() const;
677159b3361Sopenharmony_ci	// [internal use]
678159b3361Sopenharmony_ci 	virtual void Print( FILE* cfile, int depth ) const;
679159b3361Sopenharmony_ci	// [internal use]
680159b3361Sopenharmony_ci	virtual void StreamOut ( std::ostream* out ) const;
681159b3361Sopenharmony_ci	// [internal use]
682159b3361Sopenharmony_ci	virtual void StreamIn( std::istream* in, std::string* tag );
683159b3361Sopenharmony_ci
684159b3361Sopenharmony_ci  protected:
685159b3361Sopenharmony_ci	//	[internal use]
686159b3361Sopenharmony_ci	//	Attribtue parsing starts: next char past '<'
687159b3361Sopenharmony_ci	//					 returns: next char past '>'
688159b3361Sopenharmony_ci
689159b3361Sopenharmony_ci	virtual const char* Parse( const char* p );
690159b3361Sopenharmony_ci
691159b3361Sopenharmony_ci  private:
692159b3361Sopenharmony_ci	std::string version;
693159b3361Sopenharmony_ci	std::string encoding;
694159b3361Sopenharmony_ci	std::string standalone;
695159b3361Sopenharmony_ci};
696159b3361Sopenharmony_ci
697159b3361Sopenharmony_ci
698159b3361Sopenharmony_ci/** Any tag that tinyXml doesn't recognize is save as an
699159b3361Sopenharmony_ci	unknown. It is a tag of text, but should not be modified.
700159b3361Sopenharmony_ci	It will be written back to the XML, unchanged, when the file
701159b3361Sopenharmony_ci	is saved.
702159b3361Sopenharmony_ci*/
703159b3361Sopenharmony_ciclass TiXmlUnknown : public TiXmlNode
704159b3361Sopenharmony_ci{
705159b3361Sopenharmony_ci  public:
706159b3361Sopenharmony_ci	TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {}
707159b3361Sopenharmony_ci	virtual ~TiXmlUnknown() {}
708159b3361Sopenharmony_ci
709159b3361Sopenharmony_ci	// [internal use]
710159b3361Sopenharmony_ci	virtual TiXmlNode* Clone() const;
711159b3361Sopenharmony_ci	// [internal use]
712159b3361Sopenharmony_ci 	virtual void Print( FILE* cfile, int depth ) const;
713159b3361Sopenharmony_ci	// [internal use]
714159b3361Sopenharmony_ci	virtual void StreamOut ( std::ostream* out ) const;
715159b3361Sopenharmony_ci	// [internal use]
716159b3361Sopenharmony_ci	virtual void StreamIn( std::istream* in, std::string* tag );
717159b3361Sopenharmony_ci
718159b3361Sopenharmony_ci  protected:
719159b3361Sopenharmony_ci	/*	[internal use]
720159b3361Sopenharmony_ci		Attribute parsing starts: First char of the text
721159b3361Sopenharmony_ci						 returns: next char past '>'
722159b3361Sopenharmony_ci	*/
723159b3361Sopenharmony_ci	virtual const char* Parse( const char* p );
724159b3361Sopenharmony_ci};
725159b3361Sopenharmony_ci
726159b3361Sopenharmony_ci
727159b3361Sopenharmony_ci/** Always the top level node. A document binds together all the
728159b3361Sopenharmony_ci	XML pieces. It can be saved, loaded, and printed to the screen.
729159b3361Sopenharmony_ci	The 'value' of a document node is the xml file name.
730159b3361Sopenharmony_ci*/
731159b3361Sopenharmony_ciclass TiXmlDocument : public TiXmlNode
732159b3361Sopenharmony_ci{
733159b3361Sopenharmony_ci  public:
734159b3361Sopenharmony_ci	/// Create an empty document, that has no name.
735159b3361Sopenharmony_ci	TiXmlDocument();
736159b3361Sopenharmony_ci	/// Create a document with a name. The name of the document is also the filename of the xml.
737159b3361Sopenharmony_ci	TiXmlDocument( const std::string& documentName );
738159b3361Sopenharmony_ci
739159b3361Sopenharmony_ci	virtual ~TiXmlDocument() {}
740159b3361Sopenharmony_ci
741159b3361Sopenharmony_ci	/** Load a file using the current document value.
742159b3361Sopenharmony_ci		Returns true if successful. Will delete any existing
743159b3361Sopenharmony_ci		document data before loading.
744159b3361Sopenharmony_ci	*/
745159b3361Sopenharmony_ci	bool LoadFile();
746159b3361Sopenharmony_ci	/// Save a file using the current document value. Returns true if successful.
747159b3361Sopenharmony_ci	bool SaveFile() const;
748159b3361Sopenharmony_ci	/// Load a file using the given filename. Returns true if successful.
749159b3361Sopenharmony_ci	bool LoadFile( const std::string& filename );
750159b3361Sopenharmony_ci	/// Save a file using the given filename. Returns true if successful.
751159b3361Sopenharmony_ci	bool SaveFile( const std::string& filename ) const;
752159b3361Sopenharmony_ci
753159b3361Sopenharmony_ci	/// Parse the given null terminated block of xml data.
754159b3361Sopenharmony_ci	virtual const char* Parse( const char* p );
755159b3361Sopenharmony_ci
756159b3361Sopenharmony_ci	/** Get the root element -- the only top level element -- of the document.
757159b3361Sopenharmony_ci		In well formed XML, there should only be one. TinyXml is tolerant of
758159b3361Sopenharmony_ci		multiple elements at the document level.
759159b3361Sopenharmony_ci	*/
760159b3361Sopenharmony_ci	TiXmlElement* RootElement() const		{ return FirstChildElement(); }
761159b3361Sopenharmony_ci
762159b3361Sopenharmony_ci	/// If, during parsing, a error occurs, Error will be set to true.
763159b3361Sopenharmony_ci	bool Error() const						{ return error; }
764159b3361Sopenharmony_ci
765159b3361Sopenharmony_ci	/// Contains a textual (english) description of the error if one occurs.
766159b3361Sopenharmony_ci	const std::string& ErrorDesc() const	{ return errorDesc; }
767159b3361Sopenharmony_ci
768159b3361Sopenharmony_ci	/** Generally, you probably want the error string ( ErrorDesc() ). But if you
769159b3361Sopenharmony_ci		prefer the ErrorId, this function will fetch it.
770159b3361Sopenharmony_ci	*/
771159b3361Sopenharmony_ci	const int ErrorId()	const				{ return errorId; }
772159b3361Sopenharmony_ci
773159b3361Sopenharmony_ci	/// If you have handled the error, it can be reset with this call.
774159b3361Sopenharmony_ci	void ClearError()						{ error = false; errorId = 0; errorDesc = ""; }
775159b3361Sopenharmony_ci
776159b3361Sopenharmony_ci	/** Dump the document to standard out. */
777159b3361Sopenharmony_ci	void Print() const								{ Print( stdout, 0 ); }
778159b3361Sopenharmony_ci
779159b3361Sopenharmony_ci	// [internal use]
780159b3361Sopenharmony_ci 	virtual void Print( FILE* cfile, int depth = 0 ) const;
781159b3361Sopenharmony_ci	// [internal use]
782159b3361Sopenharmony_ci	virtual void StreamOut ( std::ostream* out ) const;
783159b3361Sopenharmony_ci	// [internal use]
784159b3361Sopenharmony_ci	virtual TiXmlNode* Clone() const;
785159b3361Sopenharmony_ci	// [internal use]
786159b3361Sopenharmony_ci	void SetError( int err ) {		assert( err > 0 && err < TIXML_ERROR_STRING_COUNT );
787159b3361Sopenharmony_ci									error   = true;
788159b3361Sopenharmony_ci									errorId = err;
789159b3361Sopenharmony_ci									errorDesc = errorString[ errorId ]; }
790159b3361Sopenharmony_ci	// [internal use]
791159b3361Sopenharmony_ci	virtual void StreamIn( std::istream* in, std::string* tag );
792159b3361Sopenharmony_ci
793159b3361Sopenharmony_ci  protected:
794159b3361Sopenharmony_ci
795159b3361Sopenharmony_ci  private:
796159b3361Sopenharmony_ci	bool error;
797159b3361Sopenharmony_ci	int  errorId;
798159b3361Sopenharmony_ci	std::string errorDesc;
799159b3361Sopenharmony_ci};
800159b3361Sopenharmony_ci
801159b3361Sopenharmony_ci
802159b3361Sopenharmony_ci
803159b3361Sopenharmony_ci#endif
804159b3361Sopenharmony_ci
805