[Pkg-owncloud-commits] [owncloud-client] 232/498: Do not use std::unique_ptr

Sandro Knauß hefee-guest at moszumanska.debian.org
Tue Aug 11 14:48:53 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 2db7ab5c46ee9ff192aaad38b89e50bd445b6961
Author: Olivier Goffart <ogoffart at woboq.com>
Date:   Thu Jul 2 12:44:03 2015 +0200

    Do not use std::unique_ptr
    
    The class is not existing on all platform we support
    (namely macos 10.7)
---
 src/gui/accountstate.cpp |  2 +-
 src/gui/accountstate.h   |  2 +-
 src/libsync/account.cpp  |  4 ++--
 src/libsync/account.h    |  2 +-
 src/libsync/utility.h    | 35 +++++++++++++++++++++++++++++++++++
 5 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/src/gui/accountstate.cpp b/src/gui/accountstate.cpp
index 57c658d..0cb37bd 100644
--- a/src/gui/accountstate.cpp
+++ b/src/gui/accountstate.cpp
@@ -246,7 +246,7 @@ void AccountState::slotCredentialsFetched(AbstractCredentials* credentials)
     checkConnectivity();
 }
 
-std::unique_ptr<QSettings> AccountState::settings()
+UniquePointer<QSettings> AccountState::settings()
 {
     auto s = _account->settingsWithGroup(QLatin1String("Accounts"));
     s->beginGroup(_account->id());
diff --git a/src/gui/accountstate.h b/src/gui/accountstate.h
index d7eaf4f..8478963 100644
--- a/src/gui/accountstate.h
+++ b/src/gui/accountstate.h
@@ -87,7 +87,7 @@ public:
     void checkConnectivity();
 
     /** Returns a new settings object for this account, already in the right groups. */
-    std::unique_ptr<QSettings> settings();
+    UniquePointer<QSettings> settings();
 
 private:
     void setState(State state);
diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp
index 2b789e5..779169a 100644
--- a/src/libsync/account.cpp
+++ b/src/libsync/account.cpp
@@ -335,14 +335,14 @@ QUrl Account::concatUrlPath(const QUrl &url, const QString &concatPath,
 
 QString Account::_configFileName;
 
-std::unique_ptr<QSettings> Account::settingsWithGroup(const QString& group, QObject *parent)
+UniquePointer<QSettings> Account::settingsWithGroup(const QString& group, QObject *parent)
 {
     if (_configFileName.isEmpty()) {
         // cache file name
         ConfigFile cfg;
         _configFileName = cfg.configFile();
     }
-    std::unique_ptr<QSettings> settings(new QSettings(_configFileName, QSettings::IniFormat, parent));
+    UniquePointer<QSettings> settings(new QSettings(_configFileName, QSettings::IniFormat, parent));
     settings->beginGroup(group);
     return settings;
 }
diff --git a/src/libsync/account.h b/src/libsync/account.h
index e19795b..bb3b229 100644
--- a/src/libsync/account.h
+++ b/src/libsync/account.h
@@ -130,7 +130,7 @@ public:
 
     /**  Returns a new settings pre-set in a specific group.  The Settings will be created
          with the given parent. If no parents is specified, the caller must destroy the settings */
-    static std::unique_ptr<QSettings> settingsWithGroup(const QString& group, QObject* parent = 0);
+    static UniquePointer<QSettings> settingsWithGroup(const QString& group, QObject* parent = 0);
 
     // to be called by credentials only
     QVariant credentialSetting(const QString& key) const;
diff --git a/src/libsync/utility.h b/src/libsync/utility.h
index 957f5e2..10ad803 100644
--- a/src/libsync/utility.h
+++ b/src/libsync/utility.h
@@ -118,5 +118,40 @@ namespace Utility
 }
 /** @} */ // \addtogroup
 
+
+/**
+ * @brief a replacement for std::unique_ptr which is not available on all the platform we support
+ *
+ * Only implement the most basic features
+ */
+template<class T>
+class UniquePointer {
+    T *d;
+    Q_DISABLE_COPY(UniquePointer)
+public:
+    explicit UniquePointer(T * p = 0) : d(p) {};
+    UniquePointer( UniquePointer && u ) : d(u.d) { u.d = 0; }
+    ~UniquePointer() { delete d; }
+
+    UniquePointer& operator=( UniquePointer&& r ) {
+        delete d;
+        d = r.d;
+        r.d = 0;
+        return *this;
+    }
+
+    T *release() {
+        T *r = d;
+        d = 0;
+        return r;
+    }
+
+    void reset(T *u) { delete d; d = u; }
+    T *operator->() const { return d; }
+    T *data() const { return d; }
+    T &operator*() const { return *d; }
+    operator bool() const { return d; }
+};
+
 }
 #endif // UTILITY_H

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list