⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 txml.hpp

📁 j2me is based on j2mepolish, client & server for mobile application.
💻 HPP
📖 第 1 页 / 共 5 页
字号:
/*
www.sourceforge.net/projects/tinyxml
Original code (2.0 and earlier )copyright (c) 2000-2006 Lee Thomason (www.grinninglizard.com)

this software is provided 'as-is', without any express or implied
warranty. In no_ event will the authors be held liable for any
damages arising from the use of this software.

Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it_ and
redistribute it_ freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.

2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.

3. this notice may not be removed or altered from any source
distribution.
*/


#ifndef TINYXML_INCLUDED
#define TINYXML_INCLUDED

#ifndef TIXML_USE_STL
#define TIXML_USE_STL
#endif

#define HAL_BOOST_SERIALIZATION_COMPAT

#ifdef _MSC_VER
#pragma warning( push )
#pragma warning( disable : 4530 )
#pragma warning( disable : 4786 )
#endif

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

// Help out windows:
#if defined( _DEBUG ) && !defined( DEBUG )
#define DEBUG
#endif

#ifdef TIXML_USE_STL
	#include <string>
 	#include <iostream>
	#include <sstream>
	#define TIXML_STRING		std::string
#else
	#include "tinystr.h"
	#define TIXML_STRING		TiXmlString
#endif

namespace aux { namespace xml
{

// Deprecated library function hell. Compilers want to use the
// new safe versions. this probably doesn't fully address the problem,
// but it_ gets closer. There are_ too many compilers for me to fully
// test_. If you get compilation troubles, undefine TIXML_SAFE
#define TIXML_SAFE

#ifdef TIXML_SAFE
	#if defined(_MSC_VER) && (_MSC_VER >= 1400 )
		// Microsoft visual studio, version_ 2005 and higher.
		#define TIXML_SNPRINTF _snprintf_s
		#define TIXML_SNSCANF  _snscanf_s
		#define TIXML_SSCANF   sscanf_s
	#elif defined(_MSC_VER) && (_MSC_VER >= 1200 )
		// Microsoft visual studio, version_ 6 and higher.
		//#pragma message( "Using _sn* functions." )
		#define TIXML_SNPRINTF _snprintf
		#define TIXML_SNSCANF  _snscanf
		#define TIXML_SSCANF   sscanf
	#elif defined(__GNUC__) && (__GNUC__ >= 3 )
		// GCC version_ 3 and higher.s
		//#warning( "Using sn* functions." )
		#define TIXML_SNPRINTF snprintf
		#define TIXML_SNSCANF  snscanf
		#define TIXML_SSCANF   sscanf
	#else
		#define TIXML_SSCANF   sscanf
	#endif
#endif	

class document;
class element;
class comment;
class unknown;
class attribute;
class text;
class declaration;
class parsing_data;

const int TIXML_MAJOR_VERSION = 2;
const int TIXML_MINOR_VERSION = 5;
const int TIXML_PATCH_VERSION = 3;

/*	Internal structure for tracking location_ of items 
	in the XML file_.
*/
struct cursor
{
	cursor()		{ clear(); }
	void clear()		{ row_ = col = -1; }

	int row_;	// 0 based.
	int col;	// 0 based.
};


/**
	If you call the accept() method, it_ requires being passed a visitor
	class to handle_ callbacks. For nodes that contain other nodes (document, element)
	you will get called with a visit_enter/visit_exit pair. Nodes that are_ always leaves
	are_ simple called with visit().

	If you return 'true' from a visit method, recursive parsing_ will continue. If you return
	false, <b>no_ children_ of this node_ or its sibilings</b> will be Visited.

	All flavors of visit methods have a default implementation that returns 'true' (continue 
	visiting). You need to only override methods that are_ interesting to you.

	Generally accept() is called on the document, although all nodes suppert Visiting.

	You should never change the document_ from a callback.

	@sa node::accept()
*/
class visitor
{
public:
	virtual ~visitor() {}

	/// visit a document_.
	virtual bool visit_enter( const document& /*doc*/ )			{ return true; }
	/// visit a document_.
	virtual bool visit_exit( const document& /*doc*/ )			{ return true; }

	/// visit an element_.
	virtual bool visit_enter( const element& /*element_*/, const attribute* /*firstAttribute*/ )	{ return true; }
	/// visit an element_.
	virtual bool visit_exit( const element& /*element_*/ )		{ return true; }

	/// visit a declaration_
	virtual bool visit( const declaration& /*declaration_*/ )	{ return true; }
	/// visit a text_ node_
	virtual bool visit( const text& /*text_*/ )					{ return true; }
	/// visit a comment_ node_
	virtual bool visit( const comment& /*comment_*/ )			{ return true; }
	/// visit an unknow node_
	virtual bool visit( const unknown& /*unknown_*/ )			{ return true; }
};

// Only used by get_attribute::query functions
enum 
{ 
	TIXML_SUCCESS,
	TIXML_NO_ATTRIBUTE,
	TIXML_WRONG_TYPE
};


// Used by the parsing_ routines.
enum encoding
{
	TIXML_ENCODING_UNKNOWN,
	TIXML_ENCODING_UTF8,
	TIXML_ENCODING_LEGACY
};

const encoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN;

/** base is a base_ class for every class in TinyXml.
	it does little except to establish that TinyXml classes
	can be printed and provide some utility functions.

	In XML, the document_ and elements can contain
	other elements and other types of nodes.

	@verbatim
	A document can contain:	element	(container or leaf)
							comment (leaf)
							unknown (leaf)
							declaration( leaf )

	An element can contain:	element (container or leaf)
							text	(leaf)
							attributes (not on tree)
							comment (leaf)
							unknown (leaf)

	A Decleration contains: attributes (not on tree)
	@endverbatim
*/
class base
{
	friend class node;
	friend class element;
	friend class document;

public:
	base()	:	userData(0)		{}
	virtual ~base()			{}

	/**	All TinyXml classes can print_ themselves to a filestream
		or the string class (TiXmlString in non-STL mode, std::string
		in STL mode.) Either or both cfile and str can be null.
		
		this is a formatted print_, and will insert 
		tabs and newlines.
		
		(For an unformatted stream_, use the << operator.)
	*/
	virtual void print( FILE* cfile, int depth ) const = 0;

	/**	The world_ does not agree on whether white_ space should be kept or
		not. In order to make everyone happy, these global, static functions
		are_ provided to set whether or not TinyXml will condense_ all white_ space
		into a single space or not. The default is to condense_. Note changing this
		value_ is not thread safe.
	*/
	static void set_condense_white_space( bool condense_ )		{ condenseWhiteSpace = condense_; }

	/// Return the current white_ space setting.
	static bool is_white_space_condensed()						{ return condenseWhiteSpace; }

	/** Return the position, in the original source file_, of this node_ or attribute_.
		The row_ and column_ are_ 1-based. (That is the first_ row_ and first_ column_ is
		1,1). If the returns values are_ 0 or less, then the parser does not have
		a row_ and column_ value_.

		Generally, the row_ and column_ value_ will be set when the document::Load(),
		document::load_file(), or any node::parse() is called. it will NOT be set
		when the DOM was created from operator>>.

		The values reflect the initial load. Once the DOM is modified programmatically
		(by adding or changing nodes and attributes_) the new values will NOT update to
		reflect changes in the document_.

		There is a minor performance cost to computing the row_ and column_. Computation
		can be disabled if document::set_tab_size() is called with 0 as the value_.

		@sa document::set_tab_size()
	*/
	int row() const			{ return location_.row_ + 1; }
	int column() const		{ return location_.col + 1; }	///< See row()

	void  set_user_data( void* user )			{ userData = user; }	///< Set a pointer to arbitrary user data.
	void* get_user_data()						{ return userData; }	///< Get a pointer to arbitrary user data.
	const void* get_user_data() const 		{ return userData; }	///< Get a pointer to arbitrary user data.

	// Table that returs, for a given lead byte, the total number of bytes
	// in the UTF-8 sequence.
	static const int utf8ByteTable[256];

	virtual const char* parse(	const char* p, 
								parsing_data* data, 
								encoding encoding_ /*= TIXML_ENCODING_UNKNOWN */ ) = 0;

	/** Expands entities in a string. Note this should not contian the tag's '<', '>', etc, 
		or they will be transformed into entities!
	*/
	static void encode_string( const TIXML_STRING& str, TIXML_STRING* out );

	enum
	{
		TIXML_NO_ERROR = 0,
		TIXML_ERROR,
		TIXML_ERROR_OPENING_FILE,
		TIXML_ERROR_OUT_OF_MEMORY,
		TIXML_ERROR_PARSING_ELEMENT,
		TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME,
		TIXML_ERROR_READING_ELEMENT_VALUE,
		TIXML_ERROR_READING_ATTRIBUTES,
		TIXML_ERROR_PARSING_EMPTY,
		TIXML_ERROR_READING_END_TAG,
		TIXML_ERROR_PARSING_UNKNOWN,
		TIXML_ERROR_PARSING_COMMENT,
		TIXML_ERROR_PARSING_DECLARATION,
		TIXML_ERROR_DOCUMENT_EMPTY,
		TIXML_ERROR_EMBEDDED_NULL,
		TIXML_ERROR_PARSING_CDATA,
		TIXML_ERROR_DOCUMENT_TOP_ONLY,

		TIXML_ERROR_STRING_COUNT
	};

protected:

	static const char* skip_white_space( const char*, encoding encoding_ );
	inline static bool is_white_space( char c )		
	{ 
		return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' ); 
	}
	inline static bool is_white_space( int c )
	{
		if ( c < 256 )
			return is_white_space( (char) c );
		return false;	// Again, only truly correct_ for English/Latin...but usually works.
	}

	#ifdef TIXML_USE_STL
	static bool	stream_white_space( std::istream * in, TIXML_STRING * tag );
	static bool stream_to( std::istream * in, int character, TIXML_STRING * tag );
	#endif

	/*	reads an XML name_ into the string provided. Returns
		a pointer just past the last_ character of the name_,
		or 0 if the function has an error_.
	*/
	static const char* read_name( const char* p, TIXML_STRING* name_, encoding encoding_ );

	/*	reads text_. Returns a pointer past the given end tag.
		Wickedly complex options, but it_ keeps the (sensitive) code in one place.
	*/
	static const char* read_text(	const char* in,				// where to start_
									TIXML_STRING* text_,			// the string read_
									bool ignoreWhiteSpace,		// whether to keep the white_ space
									const char* endTag,			// what ends this text_
									bool ignoreCase,			// whether to ignore case in the end tag
									encoding encoding_ );	// the current encoding_

	// If an entity_ has been found, transform it_ into a character.
	static const char* get_entity( const char* in, char* value_, int* length, encoding encoding_ );

	// Get a character, while interpreting entities.
	// The length can be from 0 to 4 bytes.
	inline static const char* get_char( const char* p, char* _value, int* length, encoding encoding_ )
	{
		assert( p );
		if ( encoding_ == TIXML_ENCODING_UTF8 )
		{
			*length = utf8ByteTable[ *((const unsigned char*)p) ];
			assert( *length >= 0 && *length < 5 );
		}
		else
		{
			*length = 1;
		}

		if ( *length == 1 )
		{
			if ( *p == '&' )
				return get_entity( p, _value, length, encoding_ );
			*_value = *p;
			return p+1;
		}
		else if ( *length )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -