Patch to allow temporary variable arguments for Node::Insert*() operations

24 views
Skip to first unread message

Samuel Watters

unread,
Dec 18, 2009, 2:13:40 PM12/18/09
to ti...@googlegroups.com
The attached patch modifies TinyXML++, allowing the use of a temporary variable as an argument for the node to insert via the Node::InsertEndChild(), Node::InsertBeforeChild(), and Node::InsertAfterChild() operations.

Since these operations perform a copy of the node to insert, it is reasonable to use a temporary variable. This change allows the Node::Insert*() to show similar behavior to the STL operations such as vector<T>::push_back().


---cut here ---
diff --git a/ticpp.cpp b/ticpp.cpp
index 5965a51..7bacbfa 100644
--- a/ticpp.cpp
+++ b/ticpp.cpp
@@ -369,7 +369,7 @@ Node* Node::IterateChildren( const std::string& value, Node* previous ) const
return NodeFactory( pointer, false );
}

-Node* Node::InsertEndChild( Node& addThis )
+Node* Node::InsertEndChild( const Node& addThis )
{
if ( addThis.Type() == TiXmlNode::DOCUMENT )
{
@@ -403,7 +403,7 @@ Node* Node::LinkEndChild( Node* childNode )
return childNode;
}

-Node* Node::InsertBeforeChild( Node* beforeThis, Node& addThis )
+Node* Node::InsertBeforeChild( Node* beforeThis, const Node& addThis )
{
if ( addThis.Type() == TiXmlNode::DOCUMENT )
{
@@ -422,7 +422,7 @@ Node* Node::InsertBeforeChild( Node* beforeThis, Node& addThis )
return NodeFactory( pointer );
}

-Node* Node::InsertAfterChild( Node* afterThis, Node& addThis )
+Node* Node::InsertAfterChild( Node* afterThis, const Node& addThis )
{
if ( addThis.Type() == TiXmlNode::DOCUMENT )
{
diff --git a/ticpp.h b/ticpp.h
index ec0e729..f88ba1f 100644
--- a/ticpp.h
+++ b/ticpp.h
@@ -616,7 +616,7 @@ namespace ticpp
@see LinkEndChild
@see TiXmlNode::InsertEndChild
*/
- Node* InsertEndChild( Node& addThis );
+ Node* InsertEndChild( const Node& addThis );

/**
Adds a child past the LastChild.
@@ -641,7 +641,7 @@ namespace ticpp
@see InsertAfterChild
@see TiXmlNode::InsertBeforeChild
*/
- Node* InsertBeforeChild( Node* beforeThis, Node& addThis );
+ Node* InsertBeforeChild( Node* beforeThis, const Node& addThis );

/**
Adds a child after the specified child.
@@ -654,7 +654,7 @@ namespace ticpp
@see InsertBeforeChild
@see TiXmlNode::InsertAfterChild
*/
- Node* InsertAfterChild( Node* afterThis, Node& addThis );
+ Node* InsertAfterChild( Node* afterThis, const Node& addThis );

/**
Replace a child of this node.

Reply all
Reply to author
Forward
0 new messages