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

📄 tinyxml.h

📁 一个帮助你学习英语的软件~~很不错的咯~~ 对功能又做了改进~大家支持下哈~
💻 H
📖 第 1 页 / 共 5 页
字号:
	/** If an error occurs, Error will be set to true. Also,		- The ErrorId() will contain the integer identifier of the error (not generally useful)		- The ErrorDesc() method will return the name of the error. (very useful)		- The ErrorRow() and ErrorCol() will return the location of the error (if known)	*/		bool Error() const						{ return error; }	/// Contains a textual (english) description of the error if one occurs.	const char * ErrorDesc() const	{ return errorDesc.c_str (); }	/** Generally, you probably want the error string ( ErrorDesc() ). But if you		prefer the ErrorId, this function will fetch it.	*/	int ErrorId()	const				{ return errorId; }	/** Returns the location (if known) of the error. The first column is column 1, 		and the first row is row 1. A value of 0 means the row and column wasn't applicable		(memory errors, for example, have no row/column) or the parser lost the error. (An		error in the error reporting, in that case.)		@sa SetTabSize, Row, Column	*/	int ErrorRow() const	{ return errorLocation.row+1; }	int ErrorCol() const	{ return errorLocation.col+1; }	///< The column where the error occured. See ErrorRow()	/** SetTabSize() allows the error reporting functions (ErrorRow() and ErrorCol())		to report the correct values for row and column. It does not change the output		or input in any way.				By calling this method, with a tab size		greater than 0, the row and column of each node and attribute is stored		when the file is loaded. Very useful for tracking the DOM back in to		the source file.		The tab size is required for calculating the location of nodes. If not		set, the default of 4 is used. The tabsize is set per document. Setting		the tabsize to 0 disables row/column tracking.		Note that row and column tracking is not supported when using operator>>.		The tab size needs to be enabled before the parse or load. Correct usage:		@verbatim		TiXmlDocument doc;		doc.SetTabSize( 8 );		doc.Load( "myfile.xml" );		@endverbatim		@sa Row, Column	*/	void SetTabSize( int _tabsize )		{ tabsize = _tabsize; }	int TabSize() const	{ return tabsize; }	/** If you have handled the error, it can be reset with this call. The error		state is automatically cleared if you Parse a new XML block.	*/	void ClearError()						{	error = false; 												errorId = 0; 												errorDesc = ""; 												errorLocation.row = errorLocation.col = 0; 												//errorLocation.last = 0; 											}	/** Write the document to standard out using formatted printing ("pretty print"). */	void Print() const						{ Print( stdout, 0 ); }	/* Write the document to a string using formatted printing ("pretty print"). This		will allocate a character array (new char[]) and return it as a pointer. The		calling code pust call delete[] on the return char* to avoid a memory leak.	*/	//char* PrintToMemory() const; 	/// Print this Document to a FILE stream.	virtual void Print( FILE* cfile, int depth = 0 ) const;	// [internal use]	void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding );	virtual const TiXmlDocument*    ToDocument()    const { return this; } ///< Cast to a more defined type. Will return null not of the requested type.	virtual TiXmlDocument*          ToDocument()          { return this; } ///< Cast to a more defined type. Will return null not of the requested type.	/** Walk the XML tree visiting this node and all of its children. 	*/	virtual bool Accept( TiXmlVisitor* content ) const;protected :	// [internal use]	virtual TiXmlNode* Clone() const;	#ifdef TIXML_USE_STL	virtual void StreamIn( std::istream * in, TIXML_STRING * tag );	#endifprivate:	void CopyTo( TiXmlDocument* target ) const;	bool error;	int  errorId;	TIXML_STRING errorDesc;	int tabsize;	TiXmlCursor errorLocation;	bool useMicrosoftBOM;		// the UTF-8 BOM were found when read. Note this, and try to write.};/**	A TiXmlHandle is a class that wraps a node pointer with null checks; this is	an incredibly useful thing. Note that TiXmlHandle is not part of the TinyXml	DOM structure. It is a separate utility class.	Take an example:	@verbatim	<Document>		<Element attributeA = "valueA">			<Child attributeB = "value1" />			<Child attributeB = "value2" />		</Element>	<Document>	@endverbatim	Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very 	easy to write a *lot* of code that looks like:	@verbatim	TiXmlElement* root = document.FirstChildElement( "Document" );	if ( root )	{		TiXmlElement* element = root->FirstChildElement( "Element" );		if ( element )		{			TiXmlElement* child = element->FirstChildElement( "Child" );			if ( child )			{				TiXmlElement* child2 = child->NextSiblingElement( "Child" );				if ( child2 )				{					// Finally do something useful.	@endverbatim	And that doesn't even cover "else" cases. TiXmlHandle addresses the verbosity	of such code. A TiXmlHandle checks for null	pointers so it is perfectly safe 	and correct to use:	@verbatim	TiXmlHandle docHandle( &document );	TiXmlElement* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", 1 ).ToElement();	if ( child2 )	{		// do something useful	@endverbatim	Which is MUCH more concise and useful.	It is also safe to copy handles - internally they are nothing more than node pointers.	@verbatim	TiXmlHandle handleCopy = handle;	@endverbatim	What they should not be used for is iteration:	@verbatim	int i=0; 	while ( true )	{		TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", i ).ToElement();		if ( !child )			break;		// do something		++i;	}	@endverbatim	It seems reasonable, but it is in fact two embedded while loops. The Child method is 	a linear walk to find the element, so this code would iterate much more than it needs 	to. Instead, prefer:	@verbatim	TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild( "Child" ).ToElement();	for( child; child; child=child->NextSiblingElement() )	{		// do something	}	@endverbatim*/class TiXmlHandle{public:	/// Create a handle from any node (at any depth of the tree.) This can be a null pointer.	TiXmlHandle( TiXmlNode* _node )					{ this->node = _node; }	/// Copy constructor	TiXmlHandle( const TiXmlHandle& ref )			{ this->node = ref.node; }	TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.node; return *this; }	/// Return a handle to the first child node.	TiXmlHandle FirstChild() const;	/// Return a handle to the first child node with the given name.	TiXmlHandle FirstChild( const char * value ) const;	/// Return a handle to the first child element.	TiXmlHandle FirstChildElement() const;	/// Return a handle to the first child element with the given name.	TiXmlHandle FirstChildElement( const char * value ) const;	/** Return a handle to the "index" child with the given name. 		The first child is 0, the second 1, etc.	*/	TiXmlHandle Child( const char* value, int index ) const;	/** Return a handle to the "index" child. 		The first child is 0, the second 1, etc.	*/	TiXmlHandle Child( int index ) const;	/** Return a handle to the "index" child element with the given name. 		The first child element is 0, the second 1, etc. Note that only TiXmlElements		are indexed: other types are not counted.	*/	TiXmlHandle ChildElement( const char* value, int index ) const;	/** Return a handle to the "index" child element. 		The first child element is 0, the second 1, etc. Note that only TiXmlElements		are indexed: other types are not counted.	*/	TiXmlHandle ChildElement( int index ) const;	#ifdef TIXML_USE_STL	TiXmlHandle FirstChild( const std::string& _value ) const				{ return FirstChild( _value.c_str() ); }	TiXmlHandle FirstChildElement( const std::string& _value ) const		{ return FirstChildElement( _value.c_str() ); }	TiXmlHandle Child( const std::string& _value, int index ) const			{ return Child( _value.c_str(), index ); }	TiXmlHandle ChildElement( const std::string& _value, int index ) const	{ return ChildElement( _value.c_str(), index ); }	#endif	/** Return the handle as a TiXmlNode. This may return null.	*/	TiXmlNode* ToNode() const			{ return node; } 	/** Return the handle as a TiXmlElement. This may return null.	*/	TiXmlElement* ToElement() const		{ return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); }	/**	Return the handle as a TiXmlText. This may return null.	*/	TiXmlText* ToText() const			{ return ( ( node && node->ToText() ) ? node->ToText() : 0 ); }	/** Return the handle as a TiXmlUnknown. This may return null.	*/	TiXmlUnknown* ToUnknown() const		{ return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); }	/** @deprecated use ToNode. 		Return the handle as a TiXmlNode. This may return null.	*/	TiXmlNode* Node() const			{ return ToNode(); } 	/** @deprecated use ToElement. 		Return the handle as a TiXmlElement. This may return null.	*/	TiXmlElement* Element() const	{ return ToElement(); }	/**	@deprecated use ToText()		Return the handle as a TiXmlText. This may return null.	*/	TiXmlText* Text() const			{ return ToText(); }	/** @deprecated use ToUnknown()		Return the handle as a TiXmlUnknown. This may return null.	*/	TiXmlUnknown* Unknown() const	{ return ToUnknown(); }private:	TiXmlNode* node;};/** Print to memory functionality. The TiXmlPrinter is useful when you need to:	-# Print to memory (especially in non-STL mode)	-# Control formatting (line endings, etc.)	When constructed, the TiXmlPrinter is in its default "pretty printing" mode.	Before calling Accept() you can call methods to control the printing	of the XML document. After TiXmlNode::Accept() is called, the printed document can	be accessed via the CStr(), Str(), and Size() methods.	TiXmlPrinter uses the Visitor API.	@verbatim	TiXmlPrinter printer;	printer.SetIndent( "\t" );	doc.Accept( &printer );	fprintf( stdout, "%s", printer.CStr() );	@endverbatim*/class TiXmlPrinter : public TiXmlVisitor{public:	TiXmlPrinter() : depth( 0 ), simpleTextPrint( false ),					 buffer(), indent( "    " ), lineBreak( "\n" ) {}	virtual bool VisitEnter( const TiXmlDocument& doc );	virtual bool VisitExit( const TiXmlDocument& doc );	virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute );	virtual bool VisitExit( const TiXmlElement& element );	virtual bool Visit( const TiXmlDeclaration& declaration );	virtual bool Visit( const TiXmlText& text );	virtual bool Visit( const TiXmlComment& comment );	virtual bool Visit( const TiXmlUnknown& unknown );	/** Set the indent characters for printing. By default 4 spaces		but tab (\t) is also useful, or null/empty string for no indentation.	*/	void SetIndent( const char* _indent )			{ indent = _indent ? _indent : "" ; }	/// Query the indention string.	const char* Indent()							{ return indent.c_str(); }	/** Set the line breaking string. By default set to newline (\n). 		Some operating systems prefer other characters, or can be		set to the null/empty string for no indenation.	*/	void SetLineBreak( const char* _lineBreak )		{ lineBreak = _lineBreak ? _lineBreak : ""; }	/// Query the current line breaking string.	const char* LineBreak()							{ return lineBreak.c_str(); }	/** Switch over to "stream printing" which is the most dense formatting without 		linebreaks. Common when the XML is needed for network transmission.	*/	void SetStreamPrinting()						{ indent = "";													  lineBreak = "";													}		/// Return the result.	const char* CStr()								{ return buffer.c_str(); }	/// Return the length of the result string.	size_t Size()									{ return buffer.size(); }	#ifdef TIXML_USE_STL	/// Return the result.	const std::string& Str()						{ return buffer; }	#endifprivate:	void DoIndent()	{		for( int i=0; i<depth; ++i )			buffer += indent;	}	void DoLineBreak() {		buffer += lineBreak;	}	int depth;	bool simpleTextPrint;	TIXML_STRING buffer;	TIXML_STRING indent;	TIXML_STRING lineBreak;};#ifdef _MSC_VER#pragma warning( pop )#endif#endif

⌨️ 快捷键说明

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