summaryrefslogtreecommitdiff
path: root/louloulibs/xmpp/xmpp_parser.cpp
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_parser.cpp
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_parser.cpp')
-rw-r--r--louloulibs/xmpp/xmpp_parser.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/louloulibs/xmpp/xmpp_parser.cpp b/louloulibs/xmpp/xmpp_parser.cpp
index 3903b73..c1fd63a 100644
--- a/louloulibs/xmpp/xmpp_parser.cpp
+++ b/louloulibs/xmpp/xmpp_parser.cpp
@@ -29,7 +29,8 @@ static void character_data_handler(void *user_data, const XML_Char *s, int len)
XmppParser::XmppParser():
level(0),
- current_node(nullptr)
+ current_node(nullptr),
+ root(nullptr)
{
this->init_xml_parser();
}
@@ -47,8 +48,6 @@ void XmppParser::init_xml_parser()
XmppParser::~XmppParser()
{
- if (this->current_node)
- delete this->current_node;
XML_ParserFree(this->parser);
}
@@ -75,9 +74,8 @@ void XmppParser::reset()
{
XML_ParserFree(this->parser);
this->init_xml_parser();
- if (this->current_node)
- delete this->current_node;
this->current_node = nullptr;
+ this->root.reset(nullptr);
this->level = 0;
}
@@ -90,10 +88,13 @@ void XmppParser::start_element(const XML_Char* name, const XML_Char** attribute)
{
level++;
- XmlNode* new_node = new XmlNode(name, this->current_node);
+ auto new_node = std::make_unique<XmlNode>(name, this->current_node);
+ auto new_node_ptr = new_node.get();
if (this->current_node)
- this->current_node->add_child(new_node);
- this->current_node = new_node;
+ this->current_node->add_child(std::move(new_node));
+ else
+ this->root = std::move(new_node);
+ this->current_node = new_node_ptr;
for (size_t i = 0; attribute[i]; i += 2)
this->current_node->set_attribute(attribute[i], attribute[i+1]);
if (this->level == 1)
@@ -111,8 +112,8 @@ void XmppParser::end_element(const XML_Char* name)
if (level == 0)
{
this->stream_close_event(*this->current_node);
- delete this->current_node;
this->current_node = nullptr;
+ this->root.reset();
}
else
this->current_node = this->current_node->get_parent();