1
0
Lee Thomason 14 жил өмнө
parent
commit
ce0763e34b
3 өөрчлөгдсөн 43 нэмэгдсэн , 24 устгасан
  1. 30 13
      tinyxml2.cpp
  2. 13 11
      tinyxml2.h
  3. BIN
      tinyxml2.suo

+ 30 - 13
tinyxml2.cpp

@@ -58,7 +58,7 @@ XMLNode* XMLNode::InsertEndChild( XMLNode* addThis )
 		lastChild = addThis;
 		lastChild = addThis;
 
 
 		addThis->parent = this;
 		addThis->parent = this;
-		addThis->next = null;
+		addThis->next = 0;
 	}
 	}
 	else {
 	else {
 		TIXMLASSERT( firstChild == 0 );
 		TIXMLASSERT( firstChild == 0 );
@@ -66,7 +66,16 @@ XMLNode* XMLNode::InsertEndChild( XMLNode* addThis )
 
 
 		addThis->parent = this;
 		addThis->parent = this;
 		addThis->prev = 0;
 		addThis->prev = 0;
-		addThis->next = null;
+		addThis->next = 0;
+	}
+	return addThis;
+}
+
+
+void XMLNode::Print( FILE* fp, int depth )
+{
+	for( int i=0; i<depth; ++i ) {
+		fprintf( fp, "    " );
 	}
 	}
 }
 }
 
 
@@ -77,7 +86,7 @@ const char* XMLNode::ParseText( char* p, const char* endTag, char** next )
 
 
 	char* start = SkipWhiteSpace( p );
 	char* start = SkipWhiteSpace( p );
 	if ( !start )
 	if ( !start )
-		return;
+		return 0;
 
 
 	char endChar = *endTag;
 	char endChar = *endTag;
 	p = start;
 	p = start;
@@ -104,13 +113,20 @@ XMLComment::XMLComment( XMLDocument* doc ) : XMLNode( doc )
 }
 }
 
 
 
 
-virtual XMLComment::~XMLComment()
+XMLComment::~XMLComment()
 {
 {
 
 
 }
 }
 
 
 
 
-virtual char* XMLComment::ParseDeep( char* p )
+void XMLComment::Print( FILE* fp, int depth )
+{
+	XMLNode::Print( fp, depth );
+	fprintf( fp, "<!-- %s -->\n", value );
+}
+
+
+char* XMLComment::ParseDeep( char* p )
 {
 {
 	// Comment parses as text.
 	// Comment parses as text.
 	value = ParseText( p, "-->", &p );
 	value = ParseText( p, "-->", &p );
@@ -135,21 +151,22 @@ XMLDocument::~XMLDocument()
 
 
 bool XMLDocument::Parse( const char* p )
 bool XMLDocument::Parse( const char* p )
 {
 {
-	charBuffer = CharBuffer.Construct( p );
+	charBuffer = CharBuffer::Construct( p );
 	XMLNode* node = 0;
 	XMLNode* node = 0;
-	Identify( charBuffer., node );
-	node->Parse( p );
+	char* q = Identify( charBuffer->mem, &node );
+	node->ParseDeep( q );
+	return true;
 }
 }
 
 
 
 
-XMLComment* XMLDocument::newComment( XMLNode* parent )
+void XMLDocument::Print( FILE* fp, int depth ) 
 {
 {
-	
+	for( XMLNode* node = root->firstChild; node; node=node->next ) {
+		node->Print( fp, depth );
+	}
 }
 }
 
 
 
 
-
-
 char* XMLDocument::Identify( char* p, XMLNode** node ) 
 char* XMLDocument::Identify( char* p, XMLNode** node ) 
 {
 {
 	XMLNode* returnNode = 0;
 	XMLNode* returnNode = 0;
@@ -173,7 +190,7 @@ char* XMLDocument::Identify( char* p, XMLNode** node )
 	const char* cdataHeader = { "<![CDATA[" };
 	const char* cdataHeader = { "<![CDATA[" };
 
 
 	if ( XMLNode::StringEqual( p, xmlHeader, 5 ) ) {
 	if ( XMLNode::StringEqual( p, xmlHeader, 5 ) ) {
-		returnNode = new XMLComment();
+		returnNode = new XMLComment( this );
 	}
 	}
 	else {
 	else {
 		TIXMLASSERT( 0 );
 		TIXMLASSERT( 0 );

+ 13 - 11
tinyxml2.h

@@ -2,6 +2,8 @@
 #define TINYXML2_INCLUDED
 #define TINYXML2_INCLUDED
 
 
 #include <limits.h>
 #include <limits.h>
+#include <ctype.h>
+#include <stdio.h>
 
 
 #if defined( _DEBUG ) || defined( DEBUG ) || defined (__DEBUG__)
 #if defined( _DEBUG ) || defined( DEBUG ) || defined (__DEBUG__)
 	#ifndef DEBUG
 	#ifndef DEBUG
@@ -27,7 +29,7 @@
 
 
 namespace tinyxml2
 namespace tinyxml2
 {
 {
-class XMLDocument*;
+class XMLDocument;
 
 
 // internal - move to separate namespace
 // internal - move to separate namespace
 struct CharBuffer
 struct CharBuffer
@@ -45,7 +47,8 @@ class XMLNode
 	friend class XMLDocument;
 	friend class XMLDocument;
 public:
 public:
 
 
-	static XMLNode* Identify( const char* p );
+	XMLNode* InsertEndChild( XMLNode* addThis );
+	void Print( FILE* cfile, int depth );			// prints leading spaces.
 
 
 protected:
 protected:
 	XMLNode( XMLDocument* );
 	XMLNode( XMLDocument* );
@@ -97,8 +100,13 @@ public:
 	XMLComment( XMLDocument* doc );
 	XMLComment( XMLDocument* doc );
 	virtual ~XMLComment();
 	virtual ~XMLComment();
 
 
+	void Print( FILE* cfile, int depth );
+
+protected:
+	char* ParseDeep( char* );
+
 private:
 private:
-	char* value;
+	const char* value;
 };
 };
 
 
 
 
@@ -109,26 +117,20 @@ public:
 	~XMLDocument();
 	~XMLDocument();
 
 
 	bool Parse( const char* );
 	bool Parse( const char* );
+	void Print( FILE* cfile=stdout, int depth=0 );
 
 
 	XMLNode* Root()				{ return root; }
 	XMLNode* Root()				{ return root; }
 	XMLNode* RootElement();
 	XMLNode* RootElement();
 
 
-	XMLNode* InsertEndChild( XMLNode* addThis );
-
 private:
 private:
 	XMLDocument( const XMLDocument& );	// intentionally not implemented
 	XMLDocument( const XMLDocument& );	// intentionally not implemented
-
-	virtual char* ParseDeep( char* );
+	char* Identify( char* p, XMLNode** node );
 
 
 	XMLNode*	root;
 	XMLNode*	root;
 	CharBuffer* charBuffer;
 	CharBuffer* charBuffer;
 };
 };
 
 
 
 
-
-
-
-
 };	// tinyxml2
 };	// tinyxml2
 
 
 
 

BIN
tinyxml2.suo