core: Use the Singleton mixin for the Core instance
authorManuel Nickschas <sputnick@quassel-irc.org>
Fri, 28 Sep 2018 20:28:33 +0000 (22:28 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Mon, 1 Oct 2018 17:06:49 +0000 (19:06 +0200)
Instead of implementing the instance pointer manually, use the
Singleton mixin.

src/core/core.cpp
src/core/core.h

index 9b7af58..7f69869 100644 (file)
@@ -67,22 +67,10 @@ public:
 // ==============================
 //  Core
 // ==============================
-Core *Core::_instance{nullptr};
-
-Core *Core::instance()
-{
-    return _instance;
-}
-
 
 Core::Core()
+    : Singleton<Core>{this}
 {
-    if (_instance) {
-        qWarning() << "Recreating core instance!";
-        delete _instance;
-    }
-    _instance = this;
-
     // Parent all QObject-derived attributes, so when the Core instance gets moved into another
     // thread, they get moved with it
     _server.setParent(this);
@@ -97,7 +85,6 @@ Core::~Core()
     qDeleteAll(_connectingClients);
     qDeleteAll(_sessions);
     syncStorage();
-    _instance = nullptr;
 }
 
 
index 8d02d9e..efbefa6 100644 (file)
@@ -44,6 +44,7 @@
 #include "message.h"
 #include "oidentdconfiggenerator.h"
 #include "sessionthread.h"
+#include "singleton.h"
 #include "storage.h"
 #include "types.h"
 
@@ -58,13 +59,11 @@ struct NetworkInfo;
 class AbstractSqlMigrationReader;
 class AbstractSqlMigrationWriter;
 
-class Core : public QObject
+class Core : public QObject, public Singleton<Core>
 {
     Q_OBJECT
 
 public:
-    static Core *instance();
-
     Core();
     ~Core() override;