Procházet zdrojové kódy

add convenience methods

Lee Thomason před 6 roky
rodič
revize
e444268103
2 změnil soubory, kde provedl 24 přidání a 31 odebrání
  1. 15 22
      tinyxml2.cpp
  2. 9 9
      tinyxml2.h

+ 15 - 22
tinyxml2.cpp

@@ -1962,41 +1962,34 @@ XMLAttribute* XMLElement::CreateAttribute()
 }
 
 
-XMLElement* XMLElement::PushNewChildElement(const char* name)
+XMLElement* XMLElement::InsertNewChildElement(const char* name)
 {
-    XMLElement* element = _document->NewElement(name);
-    // by construction, the new element has the same Document, so this
-    // call will always succeed
-    InsertEndChild(element);
-    return element;
+    XMLElement* node = _document->NewElement(name);
+    return InsertEndChild(node) ? node : 0;
 }
 
-XMLComment* XMLElement::PushNewChildComment(const char* comment)
+XMLComment* XMLElement::InsertNewComment(const char* comment)
 {
-    XMLComment* element = _document->NewComment(comment);
-    InsertEndChild(element);
-    return element;
+    XMLComment* node = _document->NewComment(comment);
+    return InsertEndChild(node) ? node : 0;
 }
 
-XMLText* XMLElement::PushNewChildText(const char* text)
+XMLText* XMLElement::InsertNewText(const char* text)
 {
-    XMLText* element = _document->NewText(text);
-    InsertEndChild(element);
-    return element;
+    XMLText* node = _document->NewText(text);
+    return InsertEndChild(node) ? node : 0;
 }
 
-XMLDeclaration* XMLElement::PushNewChildDeclaration(const char* text)
+XMLDeclaration* XMLElement::InsertNewDeclaration(const char* text)
 {
-    XMLDeclaration* element = _document->NewDeclaration(text);
-    InsertEndChild(element);
-    return element;
+    XMLDeclaration* node = _document->NewDeclaration(text);
+    return InsertEndChild(node) ? node : 0;
 }
 
-XMLUnknown* XMLElement::PushNewUnknown(const char* text)
+XMLUnknown* XMLElement::InsertNewUnknown(const char* text)
 {
-    XMLUnknown* element = _document->NewUnknown(text);
-    InsertEndChild(element);
-    return element;
+    XMLUnknown* node = _document->NewUnknown(text);
+    return InsertEndChild(node) ? node : 0;
 }
 
 

+ 9 - 9
tinyxml2.h

@@ -1646,15 +1646,15 @@ public:
         Convenience method to create a new XMLElement and add it as last (right)
         child of this node. Returns the created and inserted element.
     */
-    XMLElement* PushNewChildElement(const char* name);
-    /// See PushNewChildElement()
-    XMLComment* PushNewChildComment(const char* comment);
-    /// See PushNewChildElement()
-    XMLText* PushNewChildText(const char* text);
-    /// See PushNewChildElement()
-    XMLDeclaration* PushNewChildDeclaration(const char* text);
-    /// See PushNewChildElement()
-    XMLUnknown* PushNewUnknown(const char* text);
+    XMLElement* InsertNewChildElement(const char* name);
+    /// See InsertNewChildElement()
+    XMLComment* InsertNewComment(const char* comment);
+    /// See InsertNewChildElement()
+    XMLText* InsertNewText(const char* text);
+    /// See InsertNewChildElement()
+    XMLDeclaration* InsertNewDeclaration(const char* text);
+    /// See InsertNewChildElement()
+    XMLUnknown* InsertNewUnknown(const char* text);
 
 
     // internal: