This commit is contained in:
Lee Thomason 2012-02-13 15:07:09 -08:00
parent 50f97b2d06
commit 50adb4ca8e
3 changed files with 53 additions and 31 deletions

View File

@ -275,7 +275,7 @@ bool XMLDocument::Accept( XMLVisitor* visitor ) const
XMLNode::XMLNode( XMLDocument* doc ) : XMLNode::XMLNode( XMLDocument* doc ) :
document( doc ), document( doc ),
parent( 0 ), parent( 0 ),
isTextParent( false ), // isTextParent( false ),
firstChild( 0 ), lastChild( 0 ), firstChild( 0 ), lastChild( 0 ),
prev( 0 ), next( 0 ) prev( 0 ), next( 0 )
{ {
@ -342,9 +342,9 @@ XMLNode* XMLNode::InsertEndChild( XMLNode* addThis )
addThis->prev = 0; addThis->prev = 0;
addThis->next = 0; addThis->next = 0;
} }
if ( addThis->ToText() ) { // if ( addThis->ToText() ) {
SetTextParent(); // SetTextParent();
} // }
return addThis; return addThis;
} }

View File

@ -3,16 +3,19 @@
/* /*
TODO TODO
- const and non-const versions of API X const and non-const versions of API
X memory pool the class construction X memory pool the class construction
- attribute accessors X attribute accessors
- node navigation X node navigation
- handles - handles
- visit pattern - change streamer? X visit pattern - change streamer?
- make constructors protected X make constructors protected
- hide copy constructor X hide copy constructor
- hide = operator X hide = operator
X UTF8 support: isAlpha, etc. X UTF8 support: isAlpha, etc.
- tests from xml1
- perf test: xml1
- perf test: xenowar
*/ */
#include <limits.h> #include <limits.h>
@ -156,6 +159,7 @@ private:
int size; // number objects in use int size; // number objects in use
}; };
class MemPool class MemPool
{ {
public: public:
@ -167,6 +171,7 @@ public:
virtual void Free( void* ) = 0; virtual void Free( void* ) = 0;
}; };
template< int SIZE > template< int SIZE >
class MemPoolT : public MemPool class MemPoolT : public MemPool
{ {
@ -371,18 +376,17 @@ public:
//virtual void Print( XMLStreamer* streamer ); //virtual void Print( XMLStreamer* streamer );
virtual char* ParseDeep( char* ); virtual char* ParseDeep( char* );
void SetTextParent() { isTextParent = true; }
bool IsTextParent() const { return isTextParent; }
virtual bool IsClosingElement() const { return false; } virtual bool IsClosingElement() const { return false; }
protected: protected:
XMLNode( XMLDocument* ); XMLNode( XMLDocument* );
virtual ~XMLNode(); virtual ~XMLNode();
XMLNode( const XMLNode& ); // not supported
void operator=( const XMLNode& ); // not supported
XMLDocument* document; XMLDocument* document;
XMLNode* parent; XMLNode* parent;
bool isTextParent; mutable StrPair value;
mutable StrPair value;
XMLNode* firstChild; XMLNode* firstChild;
XMLNode* lastChild; XMLNode* lastChild;
@ -402,6 +406,7 @@ class XMLText : public XMLNode
friend class XMLDocument; friend class XMLDocument;
public: public:
virtual bool Accept( XMLVisitor* visitor ) const; virtual bool Accept( XMLVisitor* visitor ) const;
virtual XMLText* ToText() { return this; } virtual XMLText* ToText() { return this; }
virtual const XMLText* ToText() const { return this; } virtual const XMLText* ToText() const { return this; }
@ -413,6 +418,8 @@ public:
protected: protected:
XMLText( XMLDocument* doc ) : XMLNode( doc ), isCData( false ) {} XMLText( XMLDocument* doc ) : XMLNode( doc ), isCData( false ) {}
virtual ~XMLText() {} virtual ~XMLText() {}
XMLText( const XMLText& ); // not supported
void operator=( const XMLText& ); // not supported
private: private:
bool isCData; bool isCData;
@ -433,6 +440,8 @@ public:
protected: protected:
XMLComment( XMLDocument* doc ); XMLComment( XMLDocument* doc );
virtual ~XMLComment(); virtual ~XMLComment();
XMLComment( const XMLComment& ); // not supported
void operator=( const XMLComment& ); // not supported
private: private:
}; };
@ -452,6 +461,8 @@ public:
protected: protected:
XMLDeclaration( XMLDocument* doc ); XMLDeclaration( XMLDocument* doc );
virtual ~XMLDeclaration(); virtual ~XMLDeclaration();
XMLDeclaration( const XMLDeclaration& ); // not supported
void operator=( const XMLDeclaration& ); // not supported
}; };
@ -469,6 +480,8 @@ public:
protected: protected:
XMLUnknown( XMLDocument* doc ); XMLUnknown( XMLDocument* doc );
virtual ~XMLUnknown(); virtual ~XMLUnknown();
XMLUnknown( const XMLUnknown& ); // not supported
void operator=( const XMLUnknown& ); // not supported
}; };
@ -476,15 +489,28 @@ class XMLAttribute
{ {
friend class XMLElement; friend class XMLElement;
public: public:
//virtual void Print( XMLStreamer* streamer );
const char* Name() const { return name.GetStr(); } const char* Name() const { return name.GetStr(); }
const char* Value() const { return value.GetStr(); } const char* Value() const { return value.GetStr(); }
const XMLAttribute* Next() const { return next; } const XMLAttribute* Next() const { return next; }
int QueryIntAttribute( const char* name, int* value ) const;
int QueryUnsignedAttribute( const char* name, unsigned int* value ) const;
int QueryBoolAttribute( const char* name, bool* value ) const;
int QueryDoubleAttribute( const char* name, double* _value ) const;
int QueryFloatAttribute( const char* name, float* _value ) const;
void SetAttribute( const char* name, const char* value );
void SetAttribute( const char* name, int value );
void SetAttribute( const char* name, unsigned value );
void SetAttribute( const char* name, bool value );
void SetAttribute( const char* name, double value );
private: private:
XMLAttribute( XMLElement* element ) : next( 0 ) {} XMLAttribute( XMLElement* element ) : next( 0 ) {}
virtual ~XMLAttribute() {} virtual ~XMLAttribute() {}
XMLAttribute( const XMLAttribute& ); // not supported
void operator=( const XMLAttribute& ); // not supported
char* ParseDeep( char* p ); char* ParseDeep( char* p );
mutable StrPair name; mutable StrPair name;
@ -530,11 +556,12 @@ public:
virtual bool IsClosingElement() const { return closing; } virtual bool IsClosingElement() const { return closing; }
char* ParseDeep( char* p ); char* ParseDeep( char* p );
protected: private:
XMLElement( XMLDocument* doc ); XMLElement( XMLDocument* doc );
virtual ~XMLElement(); virtual ~XMLElement();
XMLElement( const XMLElement& ); // not supported
void operator=( const XMLElement& ); // not supported
private:
char* ParseAttributes( char* p, bool *closedElement ); char* ParseAttributes( char* p, bool *closedElement );
bool closing; bool closing;
@ -579,8 +606,8 @@ public:
char* Identify( char* p, XMLNode** node ); char* Identify( char* p, XMLNode** node );
private: private:
XMLDocument( const XMLDocument& ); // not supported
XMLDocument( const XMLDocument& ); // intentionally not implemented void operator=( const XMLDocument& ); // not supported
void InitDocument(); void InitDocument();
int errorID; int errorID;

View File

@ -7,14 +7,7 @@ using namespace tinyxml2;
int main( int argc, const char* argv ) int main( int argc, const char* argv )
{ {
#if 0 #if 1
{
static const char* test = "<!--hello world-->";
XMLDocument doc;
doc.Parse( test );
doc.Print( stdout );
}
{ {
static const char* test = "<!--hello world\n" static const char* test = "<!--hello world\n"
" line 2\r" " line 2\r"
@ -24,9 +17,10 @@ int main( int argc, const char* argv )
XMLDocument doc; XMLDocument doc;
doc.Parse( test ); doc.Parse( test );
doc.Print( stdout ); doc.Print();
} }
#endif #endif
#if 0
{ {
static const char* test[] = { "<element />", static const char* test[] = { "<element />",
"<element></element>", "<element></element>",
@ -52,7 +46,8 @@ int main( int argc, const char* argv )
printf( "----------------------------------------------\n" ); printf( "----------------------------------------------\n" );
} }
} }
#if 0 #endif
#if 1
{ {
static const char* test = "<element>Text before.</element>"; static const char* test = "<element>Text before.</element>";
XMLDocument doc; XMLDocument doc;