core: Don't store a reference in CoreCertManager
authorManuel Nickschas <sputnick@quassel-irc.org>
Fri, 30 Aug 2019 19:48:32 +0000 (21:48 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Fri, 30 Aug 2019 22:34:29 +0000 (00:34 +0200)
Storing references violates all sorts of Best Practices, and also
prevents the compiler from implicitly declaring a copy assignment
operator. Store a pointer instead, and clean up the API a bit.

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

index 5cdd3ca..5671ae8 100644 (file)
@@ -25,7 +25,7 @@
 CoreIdentity::CoreIdentity(IdentityId id, QObject* parent)
     : Identity(id, parent)
 #ifdef HAVE_SSL
-    , _certManager(*this)
+    , _certManager(this)
 #endif
 {
 #ifdef HAVE_SSL
@@ -37,7 +37,7 @@ CoreIdentity::CoreIdentity(IdentityId id, QObject* parent)
 CoreIdentity::CoreIdentity(const Identity& other, QObject* parent)
     : Identity(other, parent)
 #ifdef HAVE_SSL
-    , _certManager(*this)
+    , _certManager(this)
 #endif
 {
 #ifdef HAVE_SSL
@@ -51,7 +51,7 @@ CoreIdentity::CoreIdentity(const CoreIdentity& other, QObject* parent)
 #ifdef HAVE_SSL
     , _sslKey(other._sslKey)
     , _sslCert(other._sslCert)
-    , _certManager(*this)
+    , _certManager(this)
 #endif
 {
 #ifdef HAVE_SSL
@@ -91,9 +91,9 @@ void CoreIdentity::setSslCert(const QByteArray& encoded)
 //  CoreCertManager
 // ========================================
 
-CoreCertManager::CoreCertManager(CoreIdentity& identity)
-    : CertManager(identity.id())
-    , identity(identity)
+CoreCertManager::CoreCertManager(CoreIdentity* identity)
+    : CertManager(identity->id())
+    , _identity(identity)
 {
     setAllowClientUpdates(true);
 }
@@ -105,13 +105,13 @@ void CoreCertManager::setId(IdentityId id)
 
 void CoreCertManager::setSslKey(const QByteArray& encoded)
 {
-    identity.setSslKey(encoded);
+    _identity->setSslKey(encoded);
     CertManager::setSslKey(encoded);
 }
 
 void CoreCertManager::setSslCert(const QByteArray& encoded)
 {
-    identity.setSslCert(encoded);
+    _identity->setSslCert(encoded);
     CertManager::setSslCert(encoded);
 }
 
index bb11ff5..573f9c5 100644 (file)
@@ -20,6 +20,8 @@
 
 #pragma once
 
+#include "core-export.h"
+
 #include "identity.h"
 
 #ifdef HAVE_SSL
@@ -34,12 +36,12 @@ class SignalProxy;
 // ========================================
 #ifdef HAVE_SSL
 class CoreIdentity;
-class CoreCertManager : public CertManager
+class CORE_EXPORT CoreCertManager : public CertManager
 {
     Q_OBJECT
 
 public:
-    CoreCertManager(CoreIdentity& identity);
+    CoreCertManager(CoreIdentity* identity);
 
 #    ifdef HAVE_SSL
     const QSslKey& sslKey() const override;
@@ -53,7 +55,7 @@ public slots:
     void setId(IdentityId id);
 
 private:
-    CoreIdentity& identity;
+    CoreIdentity* _identity{nullptr};
 };
 
 #endif  // HAVE_SSL
@@ -61,7 +63,7 @@ private:
 // =========================================
 //  CoreIdentity
 // =========================================
-class CoreIdentity : public Identity
+class CORE_EXPORT CoreIdentity : public Identity
 {
     Q_OBJECT
 
@@ -93,12 +95,12 @@ private:
 #ifdef HAVE_SSL
 inline const QSslKey& CoreCertManager::sslKey() const
 {
-    return identity.sslKey();
+    return _identity->sslKey();
 }
 
 inline const QSslCertificate& CoreCertManager::sslCert() const
 {
-    return identity.sslCert();
+    return _identity->sslCert();
 }
 
 #endif