diff options
author | Tobias Markmann <tm@ayena.de> | 2016-09-26 12:49:48 (GMT) |
---|---|---|
committer | Kevin Smith <kevin.smith@isode.com> | 2016-09-26 22:04:37 (GMT) |
commit | 65596031acaf7d4f277bd75758bb1c551501ce86 (patch) | |
tree | aac3a8bf6dbdccc1d476225b50ba25decf1a46cc | |
parent | 05fbe78f5c3b30517f7152b37c157a99120682dc (diff) | |
download | swift-65596031acaf7d4f277bd75758bb1c551501ce86.zip swift-65596031acaf7d4f277bd75758bb1c551501ce86.tar.bz2 |
Use const std::unique_ptr for pimpl idiom usage
All our pimpl idiom usage used std::shared_ptr due to being
written in C++03. Now we use C++11 and const std::unique_ptr
is more sensible.
Test-Information:
Builds on macOS 10.12 and unit tests pass.
Change-Id: I1b9b3fbb22e337d53ae71e5a5e03118998cc3376
26 files changed, 50 insertions, 41 deletions
diff --git a/Sluift/ITunesInterface.h b/Sluift/ITunesInterface.h index a2cd06a..d09982b 100644 --- a/Sluift/ITunesInterface.h +++ b/Sluift/ITunesInterface.h @@ -35,6 +35,6 @@ namespace Swift { private: struct Private; - std::shared_ptr<Private> p; + const std::unique_ptr<Private> p; }; } diff --git a/Sluift/ITunesInterface.mm b/Sluift/ITunesInterface.mm index 7493d10..33cf1ca 100644 --- a/Sluift/ITunesInterface.mm +++ b/Sluift/ITunesInterface.mm @@ -25,7 +25,7 @@ struct ITunesInterface::Private { iTunesApplication* iTunes; }; -ITunesInterface::ITunesInterface() : p(std::make_shared<Private>()) { +ITunesInterface::ITunesInterface() : p(new Private()) { } ITunesInterface::~ITunesInterface() { diff --git a/SwifTools/Application/CocoaApplication.h b/SwifTools/Application/CocoaApplication.h index a3e281c..4b366c6 100644 --- a/SwifTools/Application/CocoaApplication.h +++ b/SwifTools/Application/CocoaApplication.h @@ -1,11 +1,13 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once +#include <memory> + namespace Swift { class CocoaApplication { public: @@ -14,6 +16,6 @@ namespace Swift { private: class Private; - Private* d; + const std::unique_ptr<Private> d; }; } diff --git a/SwifTools/Application/CocoaApplication.mm b/SwifTools/Application/CocoaApplication.mm index f879014..f058ed4 100644 --- a/SwifTools/Application/CocoaApplication.mm +++ b/SwifTools/Application/CocoaApplication.mm @@ -1,3 +1,9 @@ +/* + * Copyright (c) 2010-2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + #include <SwifTools/Application/CocoaApplication.h> #include <AppKit/AppKit.h> @@ -10,15 +16,13 @@ class CocoaApplication::Private { NSAutoreleasePool* autoReleasePool_; }; -CocoaApplication::CocoaApplication() { - d = new CocoaApplication::Private(); +CocoaApplication::CocoaApplication() : d(new Private()) { NSApplicationLoad(); d->autoReleasePool_ = [[NSAutoreleasePool alloc] init]; } CocoaApplication::~CocoaApplication() { [d->autoReleasePool_ release]; - delete d; } } diff --git a/SwifTools/AutoUpdater/SparkleAutoUpdater.h b/SwifTools/AutoUpdater/SparkleAutoUpdater.h index c3394f7..1242128 100644 --- a/SwifTools/AutoUpdater/SparkleAutoUpdater.h +++ b/SwifTools/AutoUpdater/SparkleAutoUpdater.h @@ -6,6 +6,7 @@ #pragma once +#include <memory> #include <string> #include <SwifTools/AutoUpdater/AutoUpdater.h> @@ -27,6 +28,6 @@ namespace Swift { private: class Private; - Private* d; + const unique_ptr<Private> d; }; } diff --git a/SwifTools/AutoUpdater/SparkleAutoUpdater.mm b/SwifTools/AutoUpdater/SparkleAutoUpdater.mm index 7e06b2f..76de34b 100644 --- a/SwifTools/AutoUpdater/SparkleAutoUpdater.mm +++ b/SwifTools/AutoUpdater/SparkleAutoUpdater.mm @@ -21,9 +21,7 @@ class SparkleAutoUpdater::Private { bool restartToUpdate = false; }; -SparkleAutoUpdater::SparkleAutoUpdater(const std::string& url) { - d = new Private; - +SparkleAutoUpdater::SparkleAutoUpdater(const std::string& url) : d(new Private()) { d->updater = [SUUpdater sharedUpdater]; [d->updater retain]; @@ -45,7 +43,6 @@ SparkleAutoUpdater::SparkleAutoUpdater(const std::string& url) { SparkleAutoUpdater::~SparkleAutoUpdater() { [d->updater release]; - delete d; SWIFT_LOG(warning) << std::endl; } diff --git a/SwifTools/Notifier/GrowlNotifier.h b/SwifTools/Notifier/GrowlNotifier.h index cbfe3e9..1b5f191 100644 --- a/SwifTools/Notifier/GrowlNotifier.h +++ b/SwifTools/Notifier/GrowlNotifier.h @@ -6,6 +6,8 @@ #pragma once +#include <memory> + #include <boost/filesystem/fstream.hpp> #include <SwifTools/Notifier/Notifier.h> @@ -36,6 +38,6 @@ namespace Swift { private: class Private; - std::shared_ptr<Private> p; + const std::unique_ptr<Private> p; }; } diff --git a/SwifTools/Notifier/GrowlNotifier.mm b/SwifTools/Notifier/GrowlNotifier.mm index 1356805..4ca53f7 100644 --- a/SwifTools/Notifier/GrowlNotifier.mm +++ b/SwifTools/Notifier/GrowlNotifier.mm @@ -32,8 +32,7 @@ class GrowlNotifier::Private { boost::intrusive_ptr<GrowlNotifierDelegate> delegate; }; -GrowlNotifier::GrowlNotifier(const std::string& name) { - p = std::make_shared<Private>(); +GrowlNotifier::GrowlNotifier(const std::string& name) : p(new Private()){ p->delegate = boost::intrusive_ptr<GrowlNotifierDelegate>([[GrowlNotifierDelegate alloc] init], false); p->delegate.get().notifier = this; p->delegate.get().name = std2NSString(name); diff --git a/SwifTools/Notifier/NotificationCenterNotifier.h b/SwifTools/Notifier/NotificationCenterNotifier.h index 19eb944..838971c 100644 --- a/SwifTools/Notifier/NotificationCenterNotifier.h +++ b/SwifTools/Notifier/NotificationCenterNotifier.h @@ -6,6 +6,7 @@ #pragma once +#include <memory> #include <string> #include <SwifTools/Notifier/Notifier.h> @@ -32,7 +33,7 @@ public: private: class Private; - std::shared_ptr<Private> p; + const std::unique_ptr<Private> p; }; } diff --git a/SwifTools/Notifier/NotificationCenterNotifier.mm b/SwifTools/Notifier/NotificationCenterNotifier.mm index 35c740a..1538186 100644 --- a/SwifTools/Notifier/NotificationCenterNotifier.mm +++ b/SwifTools/Notifier/NotificationCenterNotifier.mm @@ -39,8 +39,7 @@ class NotificationCenterNotifier::Private { boost::intrusive_ptr<NotificationCenterNotifierDelegate> delegate; }; -NotificationCenterNotifier::NotificationCenterNotifier() { - p = std::make_shared<Private>(); +NotificationCenterNotifier::NotificationCenterNotifier() : p(new Private()) { p->delegate = boost::intrusive_ptr<NotificationCenterNotifierDelegate>([[NotificationCenterNotifierDelegate alloc] init], false); [p->delegate.get() setNotifier: this]; diff --git a/SwifTools/URIHandler/MacOSXURIHandler.h b/SwifTools/URIHandler/MacOSXURIHandler.h index afa4c6c..8136fa7 100644 --- a/SwifTools/URIHandler/MacOSXURIHandler.h +++ b/SwifTools/URIHandler/MacOSXURIHandler.h @@ -1,11 +1,13 @@ /* - * Copyright (c) 2011 Isode Limited. + * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once +#include <memory> + #include <SwifTools/URIHandler/URIHandler.h> namespace Swift { @@ -19,6 +21,6 @@ namespace Swift { private: class Private; - Private* p; + const std::unique_ptr<Private> p; }; } diff --git a/SwifTools/URIHandler/MacOSXURIHandler.mm b/SwifTools/URIHandler/MacOSXURIHandler.mm index 6285e12..ae7dc44 100644 --- a/SwifTools/URIHandler/MacOSXURIHandler.mm +++ b/SwifTools/URIHandler/MacOSXURIHandler.mm @@ -44,14 +44,12 @@ class MacOSXURIHandler::Private { MacOSXURIEventHandler* eventHandler; }; -MacOSXURIHandler::MacOSXURIHandler() { - p = new Private(); +MacOSXURIHandler::MacOSXURIHandler() : p(new Private()) { p->eventHandler = [[MacOSXURIEventHandler alloc] initWithHandler: this]; } MacOSXURIHandler::~MacOSXURIHandler() { [p->eventHandler release]; - delete p; } void MacOSXURIHandler::start() { diff --git a/Swift/QtUI/CocoaApplicationActivateHelper.h b/Swift/QtUI/CocoaApplicationActivateHelper.h index c7aa5b3..83fa886 100644 --- a/Swift/QtUI/CocoaApplicationActivateHelper.h +++ b/Swift/QtUI/CocoaApplicationActivateHelper.h @@ -1,11 +1,13 @@ /* - * Copyright (c) 2012 Isode Limited. + * Copyright (c) 2012-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once +#include <memory> + #include <QObject> namespace Swift { @@ -23,6 +25,6 @@ namespace Swift { private: struct Private; - Private* p; + const std::unique_ptr<Private> p; }; } diff --git a/Swift/QtUI/CocoaApplicationActivateHelper.mm b/Swift/QtUI/CocoaApplicationActivateHelper.mm index 4d4409d..2bd985a 100644 --- a/Swift/QtUI/CocoaApplicationActivateHelper.mm +++ b/Swift/QtUI/CocoaApplicationActivateHelper.mm @@ -6,6 +6,8 @@ #include <Swift/QtUI/CocoaApplicationActivateHelper.h> +#include <memory> + #include <boost/function.hpp> #include <QApplication> @@ -31,8 +33,7 @@ struct CocoaApplicationActivateHelper::Private { bool initialized; }; -CocoaApplicationActivateHelper::CocoaApplicationActivateHelper() { - p = new Private(); +CocoaApplicationActivateHelper::CocoaApplicationActivateHelper() : p(new Private()) { p->delegate = [[CocoaApplicationActivateHelperDelegate alloc] init]; p->initialized = false; qApp->installEventFilter(this); @@ -41,7 +42,6 @@ CocoaApplicationActivateHelper::CocoaApplicationActivateHelper() { CocoaApplicationActivateHelper::~CocoaApplicationActivateHelper() { [[NSAppleEventManager sharedAppleEventManager] removeEventHandlerForEventClass:kCoreEventClass andEventID:kAEReopenApplication]; [p->delegate release]; - delete p; } bool CocoaApplicationActivateHelper::eventFilter(QObject* object, QEvent* event) { diff --git a/Swiften/Compress/ZLibCodecompressor.cpp b/Swiften/Compress/ZLibCodecompressor.cpp index a9929a8..344e6b7 100644 --- a/Swiften/Compress/ZLibCodecompressor.cpp +++ b/Swiften/Compress/ZLibCodecompressor.cpp @@ -22,7 +22,7 @@ namespace Swift { static const size_t CHUNK_SIZE = 1024; // If you change this, also change the unittest -ZLibCodecompressor::ZLibCodecompressor() : p(std::make_shared<Private>()) { +ZLibCodecompressor::ZLibCodecompressor() : p(new Private()) { memset(&p->stream, 0, sizeof(z_stream)); p->stream.zalloc = Z_NULL; p->stream.zfree = Z_NULL; diff --git a/Swiften/Compress/ZLibCodecompressor.h b/Swiften/Compress/ZLibCodecompressor.h index 641b7a3..8bc5d88 100644 --- a/Swiften/Compress/ZLibCodecompressor.h +++ b/Swiften/Compress/ZLibCodecompressor.h @@ -6,6 +6,8 @@ #pragma once +#include <memory> + #include <Swiften/Base/API.h> #include <Swiften/Base/SafeByteArray.h> @@ -20,6 +22,6 @@ namespace Swift { protected: struct Private; - std::shared_ptr<Private> p; + const std::unique_ptr<Private> p; }; } diff --git a/Swiften/Crypto/WindowsCryptoProvider.cpp b/Swiften/Crypto/WindowsCryptoProvider.cpp index 61ac03e..513941f 100644 --- a/Swiften/Crypto/WindowsCryptoProvider.cpp +++ b/Swiften/Crypto/WindowsCryptoProvider.cpp @@ -190,8 +190,7 @@ namespace { } } -WindowsCryptoProvider::WindowsCryptoProvider() { - p = std::make_shared<Private>(); +WindowsCryptoProvider::WindowsCryptoProvider() : p(new Private()){ if (!CryptAcquireContext(&p->context, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { assert(false); } diff --git a/Swiften/Crypto/WindowsCryptoProvider.h b/Swiften/Crypto/WindowsCryptoProvider.h index ddf7ffa..f446027 100644 --- a/Swiften/Crypto/WindowsCryptoProvider.h +++ b/Swiften/Crypto/WindowsCryptoProvider.h @@ -27,6 +27,6 @@ namespace Swift { private: struct Private; - std::shared_ptr<Private> p; + const std::unique_ptr<Private> p; }; } diff --git a/Swiften/Network/MiniUPnPInterface.cpp b/Swiften/Network/MiniUPnPInterface.cpp index 94305b9..9006ceb 100644 --- a/Swiften/Network/MiniUPnPInterface.cpp +++ b/Swiften/Network/MiniUPnPInterface.cpp @@ -32,7 +32,7 @@ struct MiniUPnPInterface::Private { IGDdatas data; }; -MiniUPnPInterface::MiniUPnPInterface() : p(std::make_shared<Private>()) { +MiniUPnPInterface::MiniUPnPInterface() : p(new Private()) { p->isValid = false; int error = 0; #if MINIUPNPC_API_VERSION > 14 diff --git a/Swiften/Network/MiniUPnPInterface.h b/Swiften/Network/MiniUPnPInterface.h index ea956d9..89457b8 100644 --- a/Swiften/Network/MiniUPnPInterface.h +++ b/Swiften/Network/MiniUPnPInterface.h @@ -28,6 +28,6 @@ namespace Swift { private: struct Private; - std::shared_ptr<Private> p; + const std::unique_ptr<Private> p; }; } diff --git a/Swiften/Network/NATPMPInterface.cpp b/Swiften/Network/NATPMPInterface.cpp index c811212..5e0b3b3 100644 --- a/Swiften/Network/NATPMPInterface.cpp +++ b/Swiften/Network/NATPMPInterface.cpp @@ -30,7 +30,7 @@ struct NATPMPInterface::Private { natpmp_t natpmp; }; -NATPMPInterface::NATPMPInterface() : p(std::make_shared<Private>()) { +NATPMPInterface::NATPMPInterface() : p(new Private()) { initnatpmp(&p->natpmp, 0, 0); } diff --git a/Swiften/Network/NATPMPInterface.h b/Swiften/Network/NATPMPInterface.h index 80f619c..e1666c8 100644 --- a/Swiften/Network/NATPMPInterface.h +++ b/Swiften/Network/NATPMPInterface.h @@ -28,6 +28,6 @@ namespace Swift { private: struct Private; - std::shared_ptr<Private> p; + const std::unique_ptr<Private> p; }; } diff --git a/Swiften/Parser/ExpatParser.cpp b/Swiften/Parser/ExpatParser.cpp index 80cfe76..77d959c 100644 --- a/Swiften/Parser/ExpatParser.cpp +++ b/Swiften/Parser/ExpatParser.cpp @@ -6,9 +6,9 @@ #include <Swiften/Parser/ExpatParser.h> -#include <string> - #include <cassert> +#include <memory> +#include <string> #include <expat.h> diff --git a/Swiften/Parser/ExpatParser.h b/Swiften/Parser/ExpatParser.h index 6580a7a..12df463 100644 --- a/Swiften/Parser/ExpatParser.h +++ b/Swiften/Parser/ExpatParser.h @@ -25,6 +25,6 @@ namespace Swift { private: struct Private; - std::shared_ptr<Private> p; + const std::unique_ptr<Private> p; }; } diff --git a/Swiften/Parser/LibXMLParser.cpp b/Swiften/Parser/LibXMLParser.cpp index a880141..be0a92d 100644 --- a/Swiften/Parser/LibXMLParser.cpp +++ b/Swiften/Parser/LibXMLParser.cpp @@ -8,6 +8,7 @@ #include <cassert> #include <cstring> +#include <memory> #include <string> #include <boost/numeric/conversion/cast.hpp> diff --git a/Swiften/Parser/LibXMLParser.h b/Swiften/Parser/LibXMLParser.h index e63a628..9f752ce 100644 --- a/Swiften/Parser/LibXMLParser.h +++ b/Swiften/Parser/LibXMLParser.h @@ -28,6 +28,6 @@ namespace Swift { static bool initialized; struct Private; - std::shared_ptr<Private> p; + const std::unique_ptr<Private> p; }; } |