summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2012-03-20 00:05:55 (GMT)
committerRemko Tronçon <git@el-tramo.be>2012-03-20 19:13:43 (GMT)
commit3d6694b0c698fff63d11f8bb4aa995c1df882315 (patch)
treea46ccace647f23a65100cf69c951345aa6dea7ab /Swiften/Queries
parent3d27d98ccc232ae7bfacfd5a3f85f44b6c2e9cc9 (diff)
downloadswift-contrib-3d6694b0c698fff63d11f8bb4aa995c1df882315.zip
swift-contrib-3d6694b0c698fff63d11f8bb4aa995c1df882315.tar.bz2
boost::shared_ptr<?>(new ?(...)) -> boost::make_shared<?>(...) transformation where possible.
License: This patch is BSD-licensed, see http://www.opensource.org/licenses/bsd-license.php
Diffstat (limited to 'Swiften/Queries')
-rw-r--r--Swiften/Queries/Requests/GetPrivateStorageRequest.h3
-rw-r--r--Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h4
-rw-r--r--Swiften/Queries/Requests/SetPrivateStorageRequest.h3
-rw-r--r--Swiften/Queries/Responders/SoftwareVersionResponder.cpp4
-rw-r--r--Swiften/Queries/UnitTest/IQRouterTest.cpp23
-rw-r--r--Swiften/Queries/UnitTest/RequestTest.cpp2
-rw-r--r--Swiften/Queries/UnitTest/ResponderTest.cpp5
7 files changed, 26 insertions, 18 deletions
diff --git a/Swiften/Queries/Requests/GetPrivateStorageRequest.h b/Swiften/Queries/Requests/GetPrivateStorageRequest.h
index b0eefb2..b5fd97f 100644
--- a/Swiften/Queries/Requests/GetPrivateStorageRequest.h
+++ b/Swiften/Queries/Requests/GetPrivateStorageRequest.h
@@ -2,35 +2,36 @@
* Copyright (c) 2010 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#pragma once
#include <Swiften/Base/boost_bsignals.h>
#include <boost/shared_ptr.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
#include <Swiften/Queries/Request.h>
#include <Swiften/Elements/PrivateStorage.h>
#include <Swiften/Elements/ErrorPayload.h>
namespace Swift {
template<typename PAYLOAD_TYPE>
class GetPrivateStorageRequest : public Request {
public:
typedef boost::shared_ptr<GetPrivateStorageRequest<PAYLOAD_TYPE> > ref;
static ref create(IQRouter* router) {
return ref(new GetPrivateStorageRequest(router));
}
private:
- GetPrivateStorageRequest(IQRouter* router) : Request(IQ::Get, JID(), boost::shared_ptr<PrivateStorage>(new PrivateStorage(boost::shared_ptr<Payload>(new PAYLOAD_TYPE()))), router) {
+ GetPrivateStorageRequest(IQRouter* router) : Request(IQ::Get, JID(), boost::make_shared<PrivateStorage>(boost::shared_ptr<Payload>(new PAYLOAD_TYPE())), router) {
}
virtual void handleResponse(boost::shared_ptr<Payload> payload, ErrorPayload::ref error) {
boost::shared_ptr<PrivateStorage> storage = boost::dynamic_pointer_cast<PrivateStorage>(payload);
if (storage) {
onResponse(boost::dynamic_pointer_cast<PAYLOAD_TYPE>(storage->getPayload()), error);
}
else {
onResponse(boost::shared_ptr<PAYLOAD_TYPE>(), error);
diff --git a/Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h b/Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h
index a6f782b..943adef 100644
--- a/Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h
+++ b/Swiften/Queries/Requests/GetSecurityLabelsCatalogRequest.h
@@ -1,30 +1,32 @@
/*
* Copyright (c) 2010 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#pragma once
+#include <boost/smart_ptr/make_shared.hpp>
+
#include <Swiften/Queries/GenericRequest.h>
#include <Swiften/Elements/SecurityLabelsCatalog.h>
namespace Swift {
class GetSecurityLabelsCatalogRequest : public GenericRequest<SecurityLabelsCatalog> {
public:
typedef boost::shared_ptr<GetSecurityLabelsCatalogRequest> ref;
static ref create(const JID& recipient, IQRouter* router) {
return ref(new GetSecurityLabelsCatalogRequest(recipient, router));
}
private:
GetSecurityLabelsCatalogRequest(
const JID& recipient,
IQRouter* router) :
GenericRequest<SecurityLabelsCatalog>(
- IQ::Get, JID(), boost::shared_ptr<SecurityLabelsCatalog>(new SecurityLabelsCatalog(recipient)), router) {
+ IQ::Get, JID(), boost::make_shared<SecurityLabelsCatalog>(recipient), router) {
}
};
}
diff --git a/Swiften/Queries/Requests/SetPrivateStorageRequest.h b/Swiften/Queries/Requests/SetPrivateStorageRequest.h
index f795742..f65f819 100644
--- a/Swiften/Queries/Requests/SetPrivateStorageRequest.h
+++ b/Swiften/Queries/Requests/SetPrivateStorageRequest.h
@@ -2,35 +2,36 @@
* Copyright (c) 2010 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#pragma once
#include <Swiften/Base/boost_bsignals.h>
#include <boost/shared_ptr.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
#include <Swiften/Queries/Request.h>
#include <Swiften/Elements/PrivateStorage.h>
#include <Swiften/Elements/ErrorPayload.h>
namespace Swift {
template<typename PAYLOAD_TYPE>
class SetPrivateStorageRequest : public Request {
public:
typedef boost::shared_ptr<SetPrivateStorageRequest<PAYLOAD_TYPE> > ref;
static ref create(boost::shared_ptr<PAYLOAD_TYPE> payload, IQRouter* router) {
return ref(new SetPrivateStorageRequest<PAYLOAD_TYPE>(payload, router));
}
private:
- SetPrivateStorageRequest(boost::shared_ptr<PAYLOAD_TYPE> payload, IQRouter* router) : Request(IQ::Set, JID(), boost::shared_ptr<PrivateStorage>(new PrivateStorage(payload)), router) {
+ SetPrivateStorageRequest(boost::shared_ptr<PAYLOAD_TYPE> payload, IQRouter* router) : Request(IQ::Set, JID(), boost::make_shared<PrivateStorage>(payload), router) {
}
virtual void handleResponse(boost::shared_ptr<Payload>, ErrorPayload::ref error) {
onResponse(error);
}
public:
boost::signal<void (ErrorPayload::ref)> onResponse;
};
diff --git a/Swiften/Queries/Responders/SoftwareVersionResponder.cpp b/Swiften/Queries/Responders/SoftwareVersionResponder.cpp
index 3f9616a..55328fb 100644
--- a/Swiften/Queries/Responders/SoftwareVersionResponder.cpp
+++ b/Swiften/Queries/Responders/SoftwareVersionResponder.cpp
@@ -1,26 +1,28 @@
/*
* Copyright (c) 2010 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
+#include <boost/smart_ptr/make_shared.hpp>
+
#include <Swiften/Queries/Responders/SoftwareVersionResponder.h>
#include <Swiften/Queries/IQRouter.h>
namespace Swift {
SoftwareVersionResponder::SoftwareVersionResponder(IQRouter* router) : GetResponder<SoftwareVersion>(router) {
}
void SoftwareVersionResponder::setVersion(const std::string& client, const std::string& version, const std::string& os) {
this->client = client;
this->version = version;
this->os = os;
}
bool SoftwareVersionResponder::handleGetRequest(const JID& from, const JID&, const std::string& id, boost::shared_ptr<SoftwareVersion>) {
- sendResponse(from, id, boost::shared_ptr<SoftwareVersion>(new SoftwareVersion(client, version, os)));
+ sendResponse(from, id, boost::make_shared<SoftwareVersion>(client, version, os));
return true;
}
}
diff --git a/Swiften/Queries/UnitTest/IQRouterTest.cpp b/Swiften/Queries/UnitTest/IQRouterTest.cpp
index f06b967..ee27a67 100644
--- a/Swiften/Queries/UnitTest/IQRouterTest.cpp
+++ b/Swiften/Queries/UnitTest/IQRouterTest.cpp
@@ -1,18 +1,19 @@
/*
* Copyright (c) 2010 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <boost/shared_ptr.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
#include <boost/bind.hpp>
#include <Swiften/Queries/IQHandler.h>
#include <Swiften/Queries/IQRouter.h>
#include <Swiften/Queries/DummyIQChannel.h>
using namespace Swift;
class IQRouterTest : public CppUnit::TestFixture {
@@ -37,107 +38,107 @@ class IQRouterTest : public CppUnit::TestFixture {
delete channel_;
}
void testRemoveHandler() {
IQRouter testling(channel_);
DummyIQHandler handler1(true, &testling);
DummyIQHandler handler2(true, &testling);
testling.removeHandler(&handler1);
- channel_->onIQReceived(boost::shared_ptr<IQ>(new IQ()));
+ channel_->onIQReceived(boost::make_shared<IQ>());
CPPUNIT_ASSERT_EQUAL(0, handler1.called);
CPPUNIT_ASSERT_EQUAL(1, handler2.called);
}
void testRemoveHandler_AfterHandleIQ() {
IQRouter testling(channel_);
DummyIQHandler handler2(true, &testling);
DummyIQHandler handler1(true, &testling);
- channel_->onIQReceived(boost::shared_ptr<IQ>(new IQ()));
+ channel_->onIQReceived(boost::make_shared<IQ>());
testling.removeHandler(&handler1);
- channel_->onIQReceived(boost::shared_ptr<IQ>(new IQ()));
+ channel_->onIQReceived(boost::make_shared<IQ>());
CPPUNIT_ASSERT_EQUAL(1, handler1.called);
CPPUNIT_ASSERT_EQUAL(1, handler2.called);
}
void testHandleIQ_SuccesfulHandlerFirst() {
IQRouter testling(channel_);
DummyIQHandler handler2(false, &testling);
DummyIQHandler handler1(true, &testling);
- channel_->onIQReceived(boost::shared_ptr<IQ>(new IQ()));
+ channel_->onIQReceived(boost::make_shared<IQ>());
CPPUNIT_ASSERT_EQUAL(1, handler1.called);
CPPUNIT_ASSERT_EQUAL(0, handler2.called);
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(channel_->iqs_.size()));
}
void testHandleIQ_SuccesfulHandlerLast() {
IQRouter testling(channel_);
DummyIQHandler handler2(true, &testling);
DummyIQHandler handler1(false, &testling);
- channel_->onIQReceived(boost::shared_ptr<IQ>(new IQ()));
+ channel_->onIQReceived(boost::make_shared<IQ>());
CPPUNIT_ASSERT_EQUAL(1, handler1.called);
CPPUNIT_ASSERT_EQUAL(1, handler2.called);
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(channel_->iqs_.size()));
}
void testHandleIQ_NoSuccesfulHandler() {
IQRouter testling(channel_);
DummyIQHandler handler(false, &testling);
- channel_->onIQReceived(boost::shared_ptr<IQ>(new IQ()));
+ channel_->onIQReceived(boost::make_shared<IQ>());
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
CPPUNIT_ASSERT(channel_->iqs_[0]->getPayload<ErrorPayload>());
}
void testHandleIQ_HandlerRemovedDuringHandle() {
IQRouter testling(channel_);
DummyIQHandler handler2(true, &testling);
RemovingIQHandler handler1(&testling);
- channel_->onIQReceived(boost::shared_ptr<IQ>(new IQ()));
- channel_->onIQReceived(boost::shared_ptr<IQ>(new IQ()));
+ channel_->onIQReceived(boost::make_shared<IQ>());
+ channel_->onIQReceived(boost::make_shared<IQ>());
CPPUNIT_ASSERT_EQUAL(1, handler1.called);
CPPUNIT_ASSERT_EQUAL(2, handler2.called);
}
void testSendIQ_WithFrom() {
IQRouter testling(channel_);
testling.setFrom(JID("foo@bar.com/baz"));
- testling.sendIQ(boost::shared_ptr<IQ>(new IQ()));
+ testling.sendIQ(boost::make_shared<IQ>());
CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com/baz"), channel_->iqs_[0]->getFrom());
}
void testSendIQ_WithoutFrom() {
IQRouter testling(channel_);
- testling.sendIQ(boost::shared_ptr<IQ>(new IQ()));
+ testling.sendIQ(boost::make_shared<IQ>());
CPPUNIT_ASSERT_EQUAL(JID(), channel_->iqs_[0]->getFrom());
}
void testHandleIQ_WithFrom() {
IQRouter testling(channel_);
testling.setFrom(JID("foo@bar.com/baz"));
DummyIQHandler handler(false, &testling);
- channel_->onIQReceived(boost::shared_ptr<IQ>(new IQ()));
+ channel_->onIQReceived(boost::make_shared<IQ>());
CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com/baz"), channel_->iqs_[0]->getFrom());
}
private:
struct DummyIQHandler : public IQHandler {
DummyIQHandler(bool handle, IQRouter* router) : handle(handle), router(router), called(0) {
router->addHandler(this);
}
diff --git a/Swiften/Queries/UnitTest/RequestTest.cpp b/Swiften/Queries/UnitTest/RequestTest.cpp
index 52d62fb..cf9b381 100644
--- a/Swiften/Queries/UnitTest/RequestTest.cpp
+++ b/Swiften/Queries/UnitTest/RequestTest.cpp
@@ -124,19 +124,19 @@ class RequestTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
}
void testHandleIQ_Error() {
MyRequest testling(IQ::Get, JID("foo@bar.com/baz"), payload_, router_);
testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
testling.send();
boost::shared_ptr<IQ> error = createError(JID("foo@bar.com/baz"),"test-id");
- boost::shared_ptr<Payload> errorPayload = boost::shared_ptr<ErrorPayload>(new ErrorPayload(ErrorPayload::InternalServerError));
+ boost::shared_ptr<Payload> errorPayload = boost::make_shared<ErrorPayload>(ErrorPayload::InternalServerError);
error->addPayload(errorPayload);
channel_->onIQReceived(error);
CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(receivedErrors.size()));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
CPPUNIT_ASSERT_EQUAL(ErrorPayload::InternalServerError, receivedErrors[0].getCondition());
}
diff --git a/Swiften/Queries/UnitTest/ResponderTest.cpp b/Swiften/Queries/UnitTest/ResponderTest.cpp
index a256346..6d40b6c 100644
--- a/Swiften/Queries/UnitTest/ResponderTest.cpp
+++ b/Swiften/Queries/UnitTest/ResponderTest.cpp
@@ -1,18 +1,19 @@
/*
* Copyright (c) 2010 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <boost/shared_ptr.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
#include <boost/bind.hpp>
#include <Swiften/Queries/Responder.h>
#include <Swiften/Queries/IQRouter.h>
#include <Swiften/Queries/DummyIQChannel.h>
#include <Swiften/Elements/SoftwareVersion.h>
using namespace Swift;
@@ -26,19 +27,19 @@ class ResponderTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testHandleIQ_Error);
CPPUNIT_TEST(testHandleIQ_Result);
CPPUNIT_TEST(testHandleIQ_NoPayload);
CPPUNIT_TEST_SUITE_END();
public:
void setUp() {
channel_ = new DummyIQChannel();
router_ = new IQRouter(channel_);
- payload_ = boost::shared_ptr<SoftwareVersion>(new SoftwareVersion("foo"));
+ payload_ = boost::make_shared<SoftwareVersion>("foo");
}
void tearDown() {
delete router_;
delete channel_;
}
void testConstructor() {
MyResponder testling(router_);
@@ -102,19 +103,19 @@ class ResponderTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT(!dynamic_cast<IQHandler*>(&testling)->handleIQ(createRequest(IQ::Result)));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling.getPayloads_.size()));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling.setPayloads_.size()));
}
void testHandleIQ_NoPayload() {
MyResponder testling(router_);
- CPPUNIT_ASSERT(!dynamic_cast<IQHandler*>(&testling)->handleIQ(boost::shared_ptr<IQ>(new IQ(IQ::Get))));
+ CPPUNIT_ASSERT(!dynamic_cast<IQHandler*>(&testling)->handleIQ(boost::make_shared<IQ>(IQ::Get)));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling.getPayloads_.size()));
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(testling.setPayloads_.size()));
}
private:
boost::shared_ptr<IQ> createRequest(IQ::Type type) {
boost::shared_ptr<IQ> iq(new IQ(type));
iq->addPayload(payload_);