Lee Thomason 9 лет назад
Родитель
Сommit
af9bce1762
3 измененных файлов с 19 добавлено и 0 удалено
  1. 1 0
      tinyxml2.cpp
  2. 16 0
      tinyxml2.h
  3. 2 0
      xmltest.cpp

+ 1 - 0
tinyxml2.cpp

@@ -719,6 +719,7 @@ XMLNode::XMLNode( XMLDocument* doc ) :
     _parent( 0 ),
     _firstChild( 0 ), _lastChild( 0 ),
     _prev( 0 ), _next( 0 ),
+	_userData( 0 ),
     _memPool( 0 )
 {
 }

+ 16 - 0
tinyxml2.h

@@ -857,6 +857,20 @@ public:
     */
     virtual bool Accept( XMLVisitor* visitor ) const = 0;
 
+	/** 
+		Set user data into the XMLNode. TinyXML-2 in 
+		no way processes or interprets user data.
+		It is initially 0.
+	*/
+	void SetUserData(void* userData)	{ _userData = userData; }
+
+	/**
+		Get user data set into the XMLNode. TinyXML-2 in
+		no way processes or interprets user data.
+		It is initially 0.
+	*/
+	void* GetUserData() const			{ return _userData; }
+
 protected:
     XMLNode( XMLDocument* );
     virtual ~XMLNode();
@@ -873,6 +887,8 @@ protected:
     XMLNode*		_prev;
     XMLNode*		_next;
 
+	void*			_userData;
+
 private:
     MemPool*		_memPool;
     void Unlink( XMLNode* child );

+ 2 - 0
xmltest.cpp

@@ -416,6 +416,7 @@ int main( int argc, const char ** argv )
 		}
 		element->InsertEndChild( sub[2] );
 		XMLNode* comment = element->InsertFirstChild( doc->NewComment( "comment" ) );
+		comment->SetUserData((void*)2);
 		element->InsertAfterChild( comment, sub[0] );
 		element->InsertAfterChild( sub[0], sub[1] );
 		sub[2]->InsertFirstChild( doc->NewText( "& Text!" ));
@@ -425,6 +426,7 @@ int main( int argc, const char ** argv )
 		XMLTest( "Programmatic DOM", 2, doc->FirstChildElement()->LastChildElement( "sub" )->IntAttribute( "attrib" ) );
 		XMLTest( "Programmatic DOM", "& Text!",
 				 doc->FirstChildElement()->LastChildElement( "sub" )->FirstChild()->ToText()->Value() );
+		XMLTest("User data", 2, (int)comment->GetUserData());
 
 		// And now deletion:
 		element->DeleteChild( sub[2] );