summaryrefslogtreecommitdiff
path: root/louloulibs/xmpp/xmpp_stanza.hpp
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2015-09-01 14:47:57 +0200
committerFlorent Le Coz <louiz@louiz.org>2015-09-01 14:47:57 +0200
commitf3b3d937ae274d0eec4a737d11ba19a7f4ceef03 (patch)
treec8dbd17073d8247c1d292050c1fff2f12c2114b1 /louloulibs/xmpp/xmpp_stanza.hpp
parent38564d77c7679dd4de4562d321146322b6211d61 (diff)
downloadbiboumi-f3b3d937ae274d0eec4a737d11ba19a7f4ceef03.tar.gz
biboumi-f3b3d937ae274d0eec4a737d11ba19a7f4ceef03.tar.bz2
biboumi-f3b3d937ae274d0eec4a737d11ba19a7f4ceef03.tar.xz
biboumi-f3b3d937ae274d0eec4a737d11ba19a7f4ceef03.zip
Use unique_ptr to store the XmlNode’s children
Also fix some constness things
Diffstat (limited to 'louloulibs/xmpp/xmpp_stanza.hpp')
-rw-r--r--louloulibs/xmpp/xmpp_stanza.hpp18
1 files changed, 8 insertions, 10 deletions
diff --git a/louloulibs/xmpp/xmpp_stanza.hpp b/louloulibs/xmpp/xmpp_stanza.hpp
index ee6b25b..4a54379 100644
--- a/louloulibs/xmpp/xmpp_stanza.hpp
+++ b/louloulibs/xmpp/xmpp_stanza.hpp
@@ -4,6 +4,7 @@
#include <map>
#include <string>
#include <vector>
+#include <memory>
std::string xml_escape(const std::string& data);
std::string xml_unescape(const std::string& data);
@@ -37,14 +38,11 @@ public:
inner(node.inner),
tail(node.tail)
{
- for (XmlNode* child: node.children)
- {
- XmlNode* child_copy = new XmlNode(*child);
- this->add_child(child_copy);
- }
+ for (const auto& child: node.children)
+ this->add_child(std::make_unique<XmlNode>(*child));
}
- ~XmlNode();
+ ~XmlNode() = default;
void delete_all_children();
void set_attribute(const std::string& name, const std::string& value);
@@ -78,16 +76,16 @@ public:
/**
* Get a pointer to the first child element with that name and that xml namespace
*/
- XmlNode* get_child(const std::string& name, const std::string& xmlns) const;
+ const XmlNode* get_child(const std::string& name, const std::string& xmlns) const;
/**
* Get a vector of all the children that have that name and that xml namespace.
*/
- std::vector<XmlNode*> get_children(const std::string& name, const std::string& xmlns) const;
+ std::vector<const XmlNode*> get_children(const std::string& name, const std::string& xmlns) const;
/**
* 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(std::unique_ptr<XmlNode> child);
XmlNode* add_child(XmlNode&& child);
/**
* Returns the last of the children. If the node doesn't have any child,
@@ -126,7 +124,7 @@ private:
std::string name;
XmlNode* parent;
std::map<std::string, std::string> attributes;
- std::vector<XmlNode*> children;
+ std::vector<std::unique_ptr<XmlNode>> children;
std::string inner;
std::string tail;