summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2013-11-22 20:44:27 +0100
committerFlorent Le Coz <louiz@louiz.org>2013-11-27 00:37:23 +0100
commit959291afe69de05aaa7ceeb61b3b0ede7a54bfea (patch)
tree3f069d2b79432050a1c904fc6f5ca7cce86dd8a9 /src
parent12a18ca748a27111bb24a7f6518f831494e5ca47 (diff)
downloadbiboumi-959291afe69de05aaa7ceeb61b3b0ede7a54bfea.tar.gz
biboumi-959291afe69de05aaa7ceeb61b3b0ede7a54bfea.tar.bz2
biboumi-959291afe69de05aaa7ceeb61b3b0ede7a54bfea.tar.xz
biboumi-959291afe69de05aaa7ceeb61b3b0ede7a54bfea.zip
Set the parent of a node passed to add_child, and return it for conveniance
Diffstat (limited to 'src')
-rw-r--r--src/xmpp/xmpp_stanza.cpp8
-rw-r--r--src/xmpp/xmpp_stanza.hpp11
2 files changed, 14 insertions, 5 deletions
diff --git a/src/xmpp/xmpp_stanza.cpp b/src/xmpp/xmpp_stanza.cpp
index 348d73c..85bd6b5 100644
--- a/src/xmpp/xmpp_stanza.cpp
+++ b/src/xmpp/xmpp_stanza.cpp
@@ -152,15 +152,17 @@ XmlNode* XmlNode::get_child(const std::string& name) const
return nullptr;
}
-void XmlNode::add_child(XmlNode* child)
+XmlNode* XmlNode::add_child(XmlNode* child)
{
+ child->parent = this;
this->children.push_back(child);
+ return child;
}
-void XmlNode::add_child(XmlNode&& child)
+XmlNode* XmlNode::add_child(XmlNode&& child)
{
XmlNode* new_node = new XmlNode(std::move(child));
- this->add_child(new_node);
+ return this->add_child(new_node);
}
XmlNode* XmlNode::get_last_child() const
diff --git a/src/xmpp/xmpp_stanza.hpp b/src/xmpp/xmpp_stanza.hpp
index 2ce8ce2..ca21ab4 100644
--- a/src/xmpp/xmpp_stanza.hpp
+++ b/src/xmpp/xmpp_stanza.hpp
@@ -77,8 +77,15 @@ public:
* Get a pointer to the first child element with that name
*/
XmlNode* get_child(const std::string& name) const;
- void add_child(XmlNode* child);
- void add_child(XmlNode&& child);
+ /**
+ * Add a node child to this node. Assign this node to the child’s parent.
+ * Returns a pointer to the newly added child.
+ */
+ XmlNode* add_child(XmlNode* child);
+ XmlNode* add_child(XmlNode&& child);
+ /**
+ * Returns the last of the children
+ */
XmlNode* get_last_child() const;
/**
* Mark this node as closed, nothing else