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

📄 tinyxmla.h

📁 文字編輯器源碼 Text editor source code
💻 H
📖 第 1 页 / 共 3 页
字号:
		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 InsertEndChild	*/	TiXmlNodeA* LinkEndChild( TiXmlNodeA* 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.	*/	TiXmlNodeA* InsertBeforeChild( TiXmlNodeA* beforeThis, const TiXmlNodeA& 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.	*/	TiXmlNodeA* InsertAfterChild(  TiXmlNodeA* afterThis, const TiXmlNodeA& addThis );	/** Replace a child of this node.		Returns a pointer to the new object or NULL if an error occured.	*/	TiXmlNodeA* ReplaceChild( TiXmlNodeA* replaceThis, const TiXmlNodeA& withThis );	/// Delete a child of this node.	bool RemoveChild( TiXmlNodeA* removeThis );	/// Navigate to a sibling node.	TiXmlNodeA* PreviousSibling() const			{ return prev; }	/// Navigate to a sibling node.	TiXmlNodeA* PreviousSibling( const char * ) const;    #ifdef TIXMLA_USE_STL	TiXmlNodeA* PreviousSibling( const std::string& _value ) const	{	return PreviousSibling (_value.c_str ());	}	///< STL std::string form.	TiXmlNodeA* NextSibling( const std::string& _value) const		{	return NextSibling (_value.c_str ());	}	///< STL std::string form.	#endif	/// Navigate to a sibling node.	TiXmlNodeA* NextSibling() const				{ return next; }	/// Navigate to a sibling node with the given 'value'.	TiXmlNodeA* NextSibling( const char * ) const;	/** Convenience function to get through elements.		Calls NextSibling and ToElement. Will skip all non-Element		nodes. Returns 0 if there is not another element.	*/	TiXmlElementA* NextSiblingElement() const;	/** Convenience function to get through elements.		Calls NextSibling and ToElement. Will skip all non-Element		nodes. Returns 0 if there is not another element.	*/	TiXmlElementA* NextSiblingElement( const char * ) const;    #ifdef TIXMLA_USE_STL	TiXmlElementA* NextSiblingElement( const std::string& _value) const	{	return NextSiblingElement (_value.c_str ());	}	///< STL std::string form.	#endif	/// Convenience function to get through elements.	TiXmlElementA* FirstChildElement()	const;	/// Convenience function to get through elements.	TiXmlElementA* FirstChildElement( const char * value ) const;    #ifdef TIXMLA_USE_STL	TiXmlElementA* FirstChildElement( const std::string& _value ) const	{	return FirstChildElement (_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.	*/	virtual int Type() const	{ return type; }	/** Return a pointer to the Document this node lives in.		Returns null if not in a document.	*/	TiXmlDocumentA* GetDocument() const;	/// Returns true if this node has no children.	bool NoChildren() const						{ return !firstChild; }	TiXmlDocumentA* ToDocument()	const		{ return ( this && type == DOCUMENT ) ? (TiXmlDocumentA*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type.	TiXmlElementA*  ToElement() const		{ return ( this && type == ELEMENT  ) ? (TiXmlElementA*)  this : 0; } ///< Cast to a more defined type. Will return null not of the requested type.	TiXmlCommentA*  ToComment() const		{ return ( this && type == COMMENT  ) ? (TiXmlCommentA*)  this : 0; } ///< Cast to a more defined type. Will return null not of the requested type.	TiXmlUnknownA*  ToUnknown() const		{ return ( this && type == UNKNOWN  ) ? (TiXmlUnknownA*)  this : 0; } ///< Cast to a more defined type. Will return null not of the requested type.	TiXmlTextA*	   ToText()    const		{ return ( this && type == TEXT     ) ? (TiXmlTextA*)     this : 0; } ///< Cast to a more defined type. Will return null not of the requested type.	TiXmlDeclarationA* ToDeclaration() const	{ return ( this && type == DECLARATION ) ? (TiXmlDeclarationA*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type.	virtual TiXmlNodeA* Clone() const = 0;	void  SetUserData( void* user )			{ userData = user; }	void* GetUserData()						{ return userData; }protected:	TiXmlNodeA( NodeType type );	#ifdef TIXMLA_USE_STL	    // The real work of the input operator.	    virtual void StreamIn( TIXMLA_ISTREAM* in, TIXMLA_STRING* tag ) = 0;	#endif	// Figure out what is at *p, and parse it. Returns null if it is not an xml node.	TiXmlNodeA* Identify( const char* start );	void CopyToClone( TiXmlNodeA* target ) const	{ target->SetValue (value.c_str() );												  target->userData = userData; }	// Internal Value function returning a TIXMLA_STRING	TIXMLA_STRING SValue() const	{ return value ; }	TiXmlNodeA*		parent;	NodeType		type;	TiXmlNodeA*		firstChild;	TiXmlNodeA*		lastChild;	TIXMLA_STRING	value;	TiXmlNodeA*		prev;	TiXmlNodeA*		next;	void*			userData;};/** An attribute is a name-value pair. Elements have an arbitrary	number of attributes, each with a unique name.	@note The attributes are not TiXmlNodes, since they are not		  part of the tinyXML document object model. There are other		  suggested ways to look at this problem.*/class TiXmlAttributeA : public TiXmlBaseA{	friend class TiXmlAttributeSetA;public:	/// Construct an empty attribute.	TiXmlAttributeA()	{		document = 0;		prev = next = 0;	}	#ifdef TIXMLA_USE_STL	/// std::string constructor.	TiXmlAttributeA( const std::string& _name, const std::string& _value )	{		name = _name;		value = _value;		document = 0;		prev = next = 0;	}	#endif	/// Construct an attribute with a name and value.	TiXmlAttributeA( const char * _name, const char * _value )	{		name = _name;		value = _value;		document = 0;		prev = next = 0;	}	const char*		Name()  const		{ return name.c_str (); }		///< Return the name of this attribute.	const char*		Value() const		{ return value.c_str (); }		///< Return the value of this attribute.	const int       IntValue() const;									///< Return the value of this attribute, converted to an integer.	const double	DoubleValue() const;								///< Return the value of this attribute, converted to a double.	/** QueryIntValue examines the value string. It is an alternative to the		IntValue() method with richer error checking.		If the value is an integer, it is stored in 'value' and 		the call returns TIXMLA_SUCCESS. If it is not		an integer, it returns TIXMLA_WRONG_TYPE.		A specialized but useful call. Note that for success it returns 0,		which is the opposite of almost all other TinyXml calls.	*/	int QueryIntValue( int* value ) const;	/// QueryDoubleValue examines the value string. See QueryIntValue().	int QueryDoubleValue( double* value ) const;	void SetName( const char* _name )	{ name = _name; }				///< Set the name of this attribute.	void SetValue( const char* _value )	{ value = _value; }				///< Set the value.	void SetIntValue( int value );										///< Set the value from an integer.	void SetDoubleValue( double value );								///< Set the value from a double.    #ifdef TIXMLA_USE_STL	/// STL std::string form.	void SetName( const std::string& _name )		{			StringToBuffer buf( _name );		SetName ( buf.buffer ? buf.buffer : "error" );		}	/// STL std::string form.		void SetValue( const std::string& _value )		{			StringToBuffer buf( _value );		SetValue( buf.buffer ? buf.buffer : "error" );		}	#endif	/// Get the next sibling attribute in the DOM. Returns null at end.	TiXmlAttributeA* Next() const;	/// Get the previous sibling attribute in the DOM. Returns null at beginning.	TiXmlAttributeA* Previous() const;	bool operator==( const TiXmlAttributeA& rhs ) const { return rhs.name == name; }	bool operator<( const TiXmlAttributeA& rhs )	 const { return name < rhs.name; }	bool operator>( const TiXmlAttributeA& rhs )  const { return name > rhs.name; }	/*	[internal use]		Attribtue parsing starts: first letter of the name						 returns: the next char after the value end quote	*/	virtual const char* Parse( const char* p, TiXmlParsingDataA* data );	// [internal use]	virtual void Print( FILE* cfile, int depth ) const;	virtual void StreamOut( TIXMLA_OSTREAM * out ) const;	// [internal use]	// Set the document pointer so the attribute can report errors.	void SetDocument( TiXmlDocumentA* doc )	{ document = doc; }private:	TiXmlDocumentA*	document;	// A pointer back to a document, for error reporting.	TIXMLA_STRING name;	TIXMLA_STRING value;	TiXmlAttributeA*	prev;	TiXmlAttributeA*	next;};/*	A class used to manage a group of attributes.	It is only used internally, both by the ELEMENT and the DECLARATION.		The set can be changed transparent to the Element and Declaration	classes that use it, but NOT transparent to the Attribute	which has to implement a next() and previous() method. Which makes	it a bit problematic and prevents the use of STL.	This version is implemented with circular lists because:		- I like circular lists		- it demonstrates some independence from the (typical) doubly linked list.*/class TiXmlAttributeSetA{public:	TiXmlAttributeSetA();	~TiXmlAttributeSetA();	void Add( TiXmlAttributeA* attribute );	void Remove( TiXmlAttributeA* attribute );	TiXmlAttributeA* First() const	{ return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; }	TiXmlAttributeA* Last()  const	{ return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; }	TiXmlAttributeA*	Find( const char * name ) const;private:	TiXmlAttributeA sentinel;};/** The element is a container class. It has a value, the element name,	and can contain other elements, text, comments, and unknowns.	Elements also contain an arbitrary number of attributes.*/class TiXmlElementA : public TiXmlNodeA{public:	/// Construct an element.	TiXmlElementA (const char * in_value);	#ifdef TIXMLA_USE_STL	/// std::string constructor.	TiXmlElementA( const std::string& _value ) : 	TiXmlNodeA( TiXmlNodeA::ELEMENT )	{		firstChild = lastChild = 0;		value = _value;	}	#endif	virtual ~TiXmlElementA();	/** Given an attribute name, Attribute() returns the value		for the attribute of that name, or null if none exists.	*/	const char* Attribute( const char* name ) const;	/** Given an attribute name, Attribute() returns the value		for the attribute of that name, or null if none exists.		If the attribute exists and can be converted to an integer,		the integer value will be put in the return 'i', if 'i'		is non-null.	*/	const char* Attribute( const char* name, int* i ) const;	/** Given an attribute name, Attribute() returns the value		for the attribute of that name, or null if none exists.		If the attribute exists and can be converted to an double,		the double value will be put in the return 'd', if 'd'		is non-null.	*/	const char* Attribute( const char* name, double* d ) const;	/** QueryIntAttribute examines the attribute - it is an alternative to the		Attribute() method with richer error checking.		If the attribute is an integer, it is stored in 'value' and 		the call returns TIXMLA_SUCCESS. If it is not		an integer, it returns TIXMLA_WRONG_TYPE. If the attribute		does not exist, then TIXMLA_NO_ATTRIBUTE is returned.	*/		int QueryIntAttribute( const char* name, int* value ) const;	/// QueryDoubleAttribute examines the attribute - see QueryIntAttribute().	int QueryDoubleAttribute( const char* name, double* value ) const;	/** Sets an attribute of name to a given value. The attribute		will be created if it does not exist, or changed if it does.	*/	void SetAttribute( const char* name, const char * value );    #ifdef TIXMLA_USE_STL	const char* Attribute( const std::string& name ) const				{ return Attribute( name.c_str() ); }	const char* Attribute( const std::string& name, int* i ) const		{ return Attribute( name.c_str(), i ); }	/// STL std::string form.	void SetAttribute( const std::string& name, const std::string& _value )		{			StringToBuffer n( name );		StringToBuffer v( _value );		if ( n.buffer && v.buffer )			SetAttribute (n.buffer, v.buffer );		}		///< STL std::string form.	void SetAttribute( const std::string& name, int _value )		{			StringToBuffer n( name );		if ( n.buffer )			SetAttribute (n.buffer, _value);		}		#endif	/** Sets an attribute of name to a given value. The attribute		will be created if it does not exist, or changed if it does.	*/	void SetAttribute( const char * name, int value );	/** Deletes an attribute with the given name.	*/	void RemoveAttribute( const char * name );    #ifdef TIXMLA_USE_STL	void RemoveAttribute( const std::string& name )	{	RemoveAttribute (name.c_str ());	}	///< STL std::string form.	#endif	TiXmlAttributeA* FirstAttribute() const	{ return attributeSet.First(); }		///< Access the first attribute in this element.	TiXmlAttributeA* LastAttribute()	const 	{ return attributeSet.Last(); }		///< Access the last attribute in this element.	// [internal use] Creates a new Element and returs it.	virtual TiXmlNodeA* Clone() const;	// [internal use]	virtual void Print( FILE* cfile, int depth ) const;protected:	// Used to be public [internal use]	#ifdef TIXMLA_USE_STL	    virtual void StreamIn( TIXMLA_ISTREAM * in, TIXMLA_STRING * tag );	#endif	virtual void StreamOut( TIXMLA_OSTREAM * out ) const;	/*	[internal use]		Attribtue parsing starts: next char past '<'						 returns: next char past '>'	*/	virtual const char* Parse( const char* p, TiXmlParsingDataA* data );	/*	[internal use]		Reads the "value" of the element -- another element, or text.		This should terminate with the current end tag.	*/	const char* ReadValue( const char* in, TiXmlParsingDataA* prevData );private:	TiXmlAttributeSetA attributeSet;};/**	An XML comment.*/class TiXmlCommentA : public TiXmlNodeA{public:	/// Constructs an empty comment.	TiXmlCommentA() : TiXmlNodeA( TiXmlNodeA::COMMENT ) {}	virtual ~TiXmlCommentA()	{}	// [internal use] Creates a new Element and returs it.	virtual TiXmlNodeA* Clone() const;	// [internal use]	virtual void Print( FILE* cfile, int depth ) const;protected:	// used to be public	#ifdef TIXMLA_USE_STL	    virtual void StreamIn( TIXMLA_ISTREAM * in, TIXMLA_STRING * tag );	#endif	virtual void StreamOut( TIXMLA_OSTREAM * out ) const;	/*	[internal use]		Attribtue parsing starts: at the ! of the !--						 returns: next char past '>'	*/	virtual const char* Parse( const char* p, TiXmlParsingDataA* data );};/** XML text. Contained in an element.*/class TiXmlTextA : public TiXmlNodeA{

⌨️ 快捷键说明

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