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

📄 txml.hpp

📁 j2me is based on j2mepolish, client & server for mobile application.
💻 HPP
📖 第 1 页 / 共 5 页
字号:
		{
			//strncpy( _value, p, *length );	// lots of compilers don't like this function (unsafe),
												// and the null terminator isn't needed
			for( int i=0; p[i] && i<*length; ++i ) {
				_value[i] = p[i];
			}
			return p + (*length);
		}
		else
		{
			// Not valid text_.
			return 0;
		}
	}

	// Return true if the next_ characters in the stream_ are_ any of the endTag sequences.
	// Ignore case only works for english, and should only be relied on when comparing
	// to English words: string_equal( p, "version", true ) is fine.
	static bool string_equal(	const char* p,
								const char* endTag,
								bool ignoreCase,
								encoding encoding_ );

	static const char* errorString[ TIXML_ERROR_STRING_COUNT ];

	cursor location_;

    /// Field containing a generic user pointer
	void*			userData;
	
	// None of these methods are_ reliable for any language except English.
	// Good for approximation, not great for accuracy.
	static int is_alpha( unsigned char anyByte, encoding encoding_ );
	static int is_alpha_num( unsigned char anyByte, encoding encoding_ );
	inline static int to_lower( int v, encoding encoding_ )
	{
		if ( encoding_ == TIXML_ENCODING_UTF8 )
		{
			if ( v < 128 ) return tolower( v );
			return v;
		}
		else
		{
			return tolower( v );
		}
	}
	static void convert_u_t_f32_to_u_t_f8( unsigned long input, char* output_, int* length );

private:
	base( const base& );				// not implemented.
	void operator=( const base& base_ );	// not allowed.

	struct entity
	{
		const char*     str;
		unsigned int	strLength;
		char		    chr;
	};
	enum
	{
		NUM_ENTITY = 5,
		MAX_ENTITY_LENGTH = 6

	};
	static entity entity_[ NUM_ENTITY ];
	static bool condenseWhiteSpace;
};


/** The parent_ class for everything in the document Object Model.
	(Except for attributes_).
	Nodes have siblings, a parent_, and children_. A node_ can be
	in a document_, or stand on its own. The type_ of a node
	can be queried, and it_ can be cast to its more defined type_.
*/
class node : public base
{
	friend class document;
	friend class element;

public:
	#ifdef TIXML_USE_STL	

	    /** An input stream_ operator, for every class. Tolerant of newlines and
		    formatting, but doesn't expect them.
	    */
	    friend std::istream& operator >> (std::istream& in, node& base_);

	    /** An output_ stream_ operator, for every class. Note that this outputs
		    without any newlines or formatting, as opposed to print(), which
		    includes tabs and new lines.

		    The operator<< and operator>> are_ not completely symmetric. Writing
		    a node_ to a stream_ is very well defined. You'll get a nice stream_
		    of output_, without any extra whitespace_ or newlines.
		    
		    But reading is not as well defined. (As it_ always is.) If you create
		    a element (for example) and read_ that from an input stream_,
		    the text_ needs to define an element_ or junk will result. this is
		    true of all input streams, but it_'s worth keeping in mind.

		    A document will read_ nodes until it_ reads_ a root_ element_, and
			all the children_ of that root_ element_.
	    */	
	    friend std::ostream& operator<< (std::ostream& out, const node& base_);

		/// Appends the XML node_ or attribute_ to a std::string.
		friend std::string& operator<< (std::string& out, const node& base_ );

	#endif

	/** The types of XML nodes supported by TinyXml. (All the
			unsupported types are_ picked up by UNKNOWN.)
	*/
	enum node_type
	{
		DOCUMENT,
		ELEMENT,
		COMMENT,
		UNKNOWN,
		TEXT,
		DECLARATION,
		TYPECOUNT
	};

	virtual ~node();

	/** The meaning of 'value_' changes for the specific type_ of
		node.
		@verbatim
		document:	filename of the xml file_
		element:	name_ of the element_
		comment:	the comment_ text_
		unknown:	the tag contents
		text:		the text_ string
		@endverbatim

		The subclasses will wrap this function.
	*/
	const char *value() const { return value_.c_str (); }

    #ifdef TIXML_USE_STL
	/** Return value() as a std::string. If you only use STL,
	    this is more efficient than calling value().
		Only available in STL mode.
	*/
	const std::string& value_str() const { return value_; }
	#endif

	const TIXML_STRING& value_t_str() const { return value_; }

	/** Changes the value_ of the node_. Defined as:
		@verbatim
		document:	filename of the xml file_
		element:	name_ of the element_
		comment:	the comment_ text_
		unknown:	the tag contents
		text:		the text_ string
		@endverbatim
	*/
	void set_value(const char * _value) { value_ = _value;}

    #ifdef TIXML_USE_STL
	/// STL std::string form.
	void set_value( const std::string& _value )	{ value_ = _value; }
	#endif

	/// Delete all the children_ of this node_. Does not affect 'this'.
	void clear();

	/// One step up the DOM.
	node* parent()							{ return parent_; }
	const node* parent() const				{ return parent_; }

	const node* first_child()	const		{ return firstChild; }	///< The first_ child_ of this node_. Will be null if there are_ no_ children_.
	node* first_child()						{ return firstChild; }
	const node* first_child( const char * value_ ) const;			///< The first_ child_ of this node_ with the matching 'value_'. Will be null if none found.
	/// The first_ child_ of this node_ with the matching 'value_'. Will be null if none found.
	node* first_child( const char * _value ) {
		// Call through to the const version_ - safe since nothing is changed. exiting syntax: cast this to a const (always safe)
		// call the method, cast the return back to non-const.
		return const_cast< node* > ((const_cast< const node* >(this))->first_child( _value ));
	}
	const node* last_child() const	{ return lastChild; }		/// The last_ child_ of this node_. Will be null if there are_ no_ children_.
	node* last_child()	{ return lastChild; }
	
	const node* last_child( const char * value_ ) const;			/// The last_ child_ of this node_ matching 'value_'. Will be null if there are_ no_ children_.
	node* last_child( const char * _value ) {
		return const_cast< node* > ((const_cast< const node* >(this))->last_child( _value ));
	}

    #ifdef TIXML_USE_STL
	const node* first_child( const std::string& _value ) const	{	return first_child (_value.c_str ());	}	///< STL std::string form.
	node* first_child( const std::string& _value )				{	return first_child (_value.c_str ());	}	///< STL std::string form.
	const node* last_child( const std::string& _value ) const	{	return last_child (_value.c_str ());	}	///< STL std::string form.
	node* last_child( const std::string& _value )				{	return last_child (_value.c_str ());	}	///< STL std::string form.
	#endif

	/** An alternate way to walk the children_ of a node_.
		One way to iterate over nodes is:
		@verbatim
			for( child_ = parent_->first_child(); child_; child_ = child_->next_sibling() )
		@endverbatim

		iterate_children does the same thing with the syntax:
		@verbatim
			child_ = 0;
			while( child_ = parent_->iterate_children( child_ ) )
		@endverbatim

		iterate_children takes the previous_ child_ as input and finds
		the next_ one. If the previous_ child_ is null, it_ returns the
		first_. iterate_children will return null when done.
	*/
	const node* iterate_children( const node* previous_ ) const;
	node* iterate_children( const node* previous_ ) {
		return const_cast< node* >( (const_cast< const node* >(this))->iterate_children( previous_ ) );
	}

	/// this flavor of iterate_children searches for children_ with a particular 'value_'
	const node* iterate_children( const char * value_, const node* previous_ ) const;
	node* iterate_children( const char * _value, const node* previous_ ) {
		return const_cast< node* >( (const_cast< const node* >(this))->iterate_children( _value, previous_ ) );
	}

    #ifdef TIXML_USE_STL
	const node* iterate_children( const std::string& _value, const node* previous_ ) const	{	return iterate_children (_value.c_str (), previous_);	}	///< STL std::string form.
	node* iterate_children( const std::string& _value, const node* previous_ ) {	return iterate_children (_value.c_str (), previous_);	}	///< STL std::string form.
	#endif

	/** add a new node_ related to this. Adds a child_ past the last_child.
		Returns a pointer to the new object or NULL if an error_ occured.
	*/
	node* insert_end_child( const node& addThis );


	/** add a new node_ related to this. Adds a child_ past the last_child.

		NOTE: the node_ to be added is passed by pointer, and will be
		henceforth owned (and deleted) by tinyXml. this method is efficient
		and avoids an extra copy_, but should be used with care as it_
		uses a different memory_ model than the other insert functions.

		@sa insert_end_child
	*/
	node* link_end_child( node* addThis );

	/** add a new node_ related to this. Adds a child_ before the specified child_.
		Returns a pointer to the new object or NULL if an error_ occured.
	*/
	node* insert_before_child( node* beforeThis, const node& addThis );

	/** add a new node_ related to this. Adds a child_ after the specified child_.
		Returns a pointer to the new object or NULL if an error_ occured.
	*/
	node* insert_after_child(  node* afterThis, const node& addThis );

	/** Replace a child_ of this node_.
		Returns a pointer to the new object or NULL if an error_ occured.
	*/
	node* replace_child( node* replaceThis, const node& withThis );

	/// Delete a child_ of this node_.
	bool remove_child( node* removeThis );

	/// Navigate to a sibling_ node_.
	const node* previous_sibling() const			{ return prev; }
	node* previous_sibling()						{ return prev; }

	/// Navigate to a sibling_ node_.
	const node* previous_sibling( const char * ) const;
	node* previous_sibling( const char *_prev ) {
		return const_cast< node* >( (const_cast< const node* >(this))->previous_sibling( _prev ) );
	}

    #ifdef TIXML_USE_STL
	const node* previous_sibling( const std::string& _value ) const	{	return previous_sibling (_value.c_str ());	}	///< STL std::string form.
	node* previous_sibling( const std::string& _value ) 			{	return previous_sibling (_value.c_str ());	}	///< STL std::string form.
	const node* next_sibling( const std::string& _value) const		{	return next_sibling (_value.c_str ());	}	///< STL std::string form.
	node* next_sibling( const std::string& _value) 					{	return next_sibling (_value.c_str ());	}	///< STL std::string form.
	#endif

	/// Navigate to a sibling_ node_.
	const node* next_sibling() const				{ return next_; }
	node* next_sibling()							{ return next_; }

	/// Navigate to a sibling_ node_ with the given 'value_'.
	const node* next_sibling( const char * ) const;
	node* next_sibling( const char* _next ) {
		return const_cast< node* >( (const_cast< const node* >(this))->next_sibling( _next ) );
	}

	/** Convenience function to get through elements.
		Calls next_sibling and to_element. Will skip all non-element
		nodes. Returns 0 if there is not another element_.
	*/
	const element* next_sibling_element() const;
	element* next_sibling_element() {
		return const_cast< element* >( (const_cast< const node* >(this))->next_sibling_element() );
	}

	/** Convenience function to get through elements.
		Calls next_sibling and to_element. Will skip all non-element
		nodes. Returns 0 if there is not another element_.
	*/
	const element* next_sibling_element( const char * ) const;
	element* next_sibling_element( const char *_next ) {
		return const_cast< element* >( (const_cast< const node* >(this))->next_sibling_element( _next ) );
	}

    #ifdef TIXML_USE_STL
	const element* next_sibling_element( const std::string& _value) const	{	return next_sibling_element (_value.c_str ());	}	///< STL std::string form.
	element* next_sibling_element( const std::string& _value)				{	return next_sibling_element (_value.c_str ());	}	///< STL std::string form.
	#endif

	/// Convenience function to get through elements.
	const element* first_child_element()	const;
	element* first_child_element() {
		return const_cast< element* >( (const_cast< const node* >(this))->first_child_element() );
	}

	/// Convenience function to get through elements.
	const element* first_child_element( const char * _value ) const;
	element* first_child_element( const char * _value ) {
		return const_cast< element* >( (const_cast< const node* >(this))->first_child_element( _value ) );
	}

    #ifdef TIXML_USE_STL
	const element* first_child_element( const std::string& _value ) const	{	return first_child_element (_value.c_str ());	}	///< STL std::string form.
	element* first_child_element( const std::string& _value )				{	return first_child_element (_value.c_str ());	}	///< STL std::string form.
	#endif

	/** query the type_ (as an enumerated value_, above) of this node_.
		The possible types are_: DOCUMENT, ELEMENT, COMMENT,
								UNKNOWN, TEXT, and DECLARATION.
	*/
	int type() const	{ return type_; }

	/** Return a pointer to the document this node_ lives in.
		Returns null if not in a document_.
	*/
	const document* get_document() const;
	document* get_document() {
		return const_cast< document* >( (const_cast< const node* >(this))->get_document() );
	}

	/// Returns true if this node_ has no_ children_.
	bool no_children() const						{ return !firstChild; }

	virtual const document*    to_document()    const { return 0; } ///< Cast to a more defined type_. Will return null if not of the requested type_.
	virtual const element*     to_element()     const { return 0; } ///< Cast to a more defined type_. Will return null if not of the requested type_.
	virtual const comment*     to_comment()     const { return 0; } ///< Cast to a more defined type_. Will return null if not of the requested type_.
	virtual const unknown*     to_unknown()     const { return 0; } ///< Cast to a more defined type_. Will return null if not of the requested type_.
	virtual const text*        to_text()        const { return 0; } ///< Cast to a more defined type_. Will return null if not of the requested type_.
	virtual const declaration* to_declaration() const { return 0; } ///< Cast to a more defined type_. Will return null if not of the requested type_.

	virtual document*          to_document()    { return 0; } ///< Cast to a more defined type_. Will return null if not of the requested type_.

⌨️ 快捷键说明

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