summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Parser')
-rw-r--r--Swiften/Parser/BOSHBodyExtractor.cpp2
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h6
-rw-r--r--Swiften/Parser/PlatformXMLParserFactory.cpp6
-rw-r--r--Swiften/Parser/PlatformXMLParserFactory.h2
-rw-r--r--Swiften/Parser/UnitTest/ParserTester.h9
-rw-r--r--Swiften/Parser/XMLParserFactory.h4
-rw-r--r--Swiften/Parser/XMPPParser.cpp1
-rw-r--r--Swiften/Parser/XMPPParser.h2
8 files changed, 12 insertions, 20 deletions
diff --git a/Swiften/Parser/BOSHBodyExtractor.cpp b/Swiften/Parser/BOSHBodyExtractor.cpp
index c45d338..803f16a 100644
--- a/Swiften/Parser/BOSHBodyExtractor.cpp
+++ b/Swiften/Parser/BOSHBodyExtractor.cpp
@@ -126,7 +126,7 @@ BOSHBodyExtractor::BOSHBodyExtractor(XMLParserFactory* parserFactory, const Byte
// Parse the body element
BOSHBodyParserClient parserClient(this);
- std::shared_ptr<XMLParser> parser(parserFactory->createXMLParser(&parserClient));
+ std::shared_ptr<XMLParser> parser(std::move(parserFactory->createXMLParser(&parserClient)));
if (!parser->parse(std::string(
reinterpret_cast<const char*>(vecptr(data)),
boost::numeric_cast<size_t>(std::distance(data.begin(), i))))) {
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h b/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h
index 2c1ff8e..dcdbffa 100644
--- a/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h
+++ b/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h
@@ -22,10 +22,6 @@ namespace Swift {
xmlParser = PlatformXMLParserFactory().createXMLParser(this);
}
- ~PayloadsParserTester() {
- delete xmlParser;
- }
-
bool parse(const std::string& data) {
return xmlParser->parse(data);
}
@@ -60,7 +56,7 @@ namespace Swift {
}
private:
- XMLParser* xmlParser;
+ std::unique_ptr<XMLParser> xmlParser;
FullPayloadParserFactoryCollection factories;
std::shared_ptr<PayloadParser> payloadParser;
int level;
diff --git a/Swiften/Parser/PlatformXMLParserFactory.cpp b/Swiften/Parser/PlatformXMLParserFactory.cpp
index 87f70d1..97e1c9e 100644
--- a/Swiften/Parser/PlatformXMLParserFactory.cpp
+++ b/Swiften/Parser/PlatformXMLParserFactory.cpp
@@ -20,11 +20,11 @@ namespace Swift {
PlatformXMLParserFactory::PlatformXMLParserFactory() {
}
-XMLParser* PlatformXMLParserFactory::createXMLParser(XMLParserClient* client) {
+std::unique_ptr<XMLParser> PlatformXMLParserFactory::createXMLParser(XMLParserClient* client) {
#ifdef HAVE_LIBXML
- return new LibXMLParser(client);
+ return std::unique_ptr<XMLParser>(new LibXMLParser(client));
#else
- return new ExpatParser(client);
+ return std::unique_ptr<XMLParser>(new ExpatParser(client));
#endif
}
diff --git a/Swiften/Parser/PlatformXMLParserFactory.h b/Swiften/Parser/PlatformXMLParserFactory.h
index 82b8573..fa3ca19 100644
--- a/Swiften/Parser/PlatformXMLParserFactory.h
+++ b/Swiften/Parser/PlatformXMLParserFactory.h
@@ -14,6 +14,6 @@ namespace Swift {
public:
PlatformXMLParserFactory();
- virtual XMLParser* createXMLParser(XMLParserClient*);
+ virtual std::unique_ptr<XMLParser> createXMLParser(XMLParserClient*);
};
}
diff --git a/Swiften/Parser/UnitTest/ParserTester.h b/Swiften/Parser/UnitTest/ParserTester.h
index a98eb51..aa01d40 100644
--- a/Swiften/Parser/UnitTest/ParserTester.h
+++ b/Swiften/Parser/UnitTest/ParserTester.h
@@ -16,12 +16,7 @@ namespace Swift {
template<typename ParserType>
class ParserTester : public XMLParserClient {
public:
- ParserTester(ParserType* parser) : parser_(parser) {
- xmlParser_ = PlatformXMLParserFactory().createXMLParser(this);
- }
-
- ~ParserTester() {
- delete xmlParser_;
+ ParserTester(ParserType* parser) : xmlParser_(PlatformXMLParserFactory().createXMLParser(this)), parser_(parser) {
}
bool parse(const std::string& data) {
@@ -41,7 +36,7 @@ namespace Swift {
}
private:
- XMLParser* xmlParser_;
+ std::unique_ptr<XMLParser> xmlParser_;
ParserType* parser_;
};
}
diff --git a/Swiften/Parser/XMLParserFactory.h b/Swiften/Parser/XMLParserFactory.h
index 091f45b..595512b 100644
--- a/Swiften/Parser/XMLParserFactory.h
+++ b/Swiften/Parser/XMLParserFactory.h
@@ -6,6 +6,8 @@
#pragma once
+#include <memory>
+
#include <Swiften/Base/API.h>
namespace Swift {
@@ -16,6 +18,6 @@ namespace Swift {
public:
virtual ~XMLParserFactory();
- virtual XMLParser* createXMLParser(XMLParserClient*) = 0;
+ virtual std::unique_ptr<XMLParser> createXMLParser(XMLParserClient*) = 0;
};
}
diff --git a/Swiften/Parser/XMPPParser.cpp b/Swiften/Parser/XMPPParser.cpp
index 2b45a12..d2a5a98 100644
--- a/Swiften/Parser/XMPPParser.cpp
+++ b/Swiften/Parser/XMPPParser.cpp
@@ -60,7 +60,6 @@ XMPPParser::XMPPParser(
XMPPParser::~XMPPParser() {
delete currentElementParser_;
- delete xmlParser_;
}
bool XMPPParser::parse(const std::string& data) {
diff --git a/Swiften/Parser/XMPPParser.h b/Swiften/Parser/XMPPParser.h
index 09fae38..6595b94 100644
--- a/Swiften/Parser/XMPPParser.h
+++ b/Swiften/Parser/XMPPParser.h
@@ -42,7 +42,7 @@ namespace Swift {
ElementParser* createElementParser(const std::string& element, const std::string& xmlns);
private:
- XMLParser* xmlParser_;
+ std::unique_ptr<XMLParser> xmlParser_;
XMPPParserClient* client_;
PayloadParserFactoryCollection* payloadParserFactories_;
enum Level {