[libsigcplusplus] connection: Use weak_raw_ptr for slot_base.



commit 846d1fe14af2551381bfe8c22ac9772664821b4b
Author: Murray Cumming <murrayc murrayc com>
Date:   Thu Apr 28 11:21:55 2016 +0200

    connection: Use weak_raw_ptr for slot_base.
    
    Instead of connection deriving from notifiable and setting/unsetting
    its own notification callbacks. This simplifies the code.

 sigc++/connection.cc |   21 +--------------------
 sigc++/connection.h  |   12 ++++--------
 2 files changed, 5 insertions(+), 28 deletions(-)
---
diff --git a/sigc++/connection.cc b/sigc++/connection.cc
index 10549b3..f70a9ba 100644
--- a/sigc++/connection.cc
+++ b/sigc++/connection.cc
@@ -29,16 +29,11 @@ connection::connection() noexcept : slot_(nullptr)
 connection::connection(slot_base& slot)
 : slot_(&slot)
 {
-  if (slot_)
-    slot_->add_destroy_notify_callback(this, &notify_slot_invalidated);
 }
 
 
 connection::connection(const connection& c) : slot_(c.slot_)
 {
-  // Let the connection forget about the signal handler when the handler object dies:
-  if (slot_)
-    slot_->add_destroy_notify_callback(this, &notify_slot_invalidated);
 }
 
 connection&
@@ -50,8 +45,6 @@ connection::operator=(const connection& src)
 
 connection::~connection()
 {
-  if (slot_)
-    slot_->remove_destroy_notify_callback(this);
 }
 
 bool
@@ -97,22 +90,10 @@ connection::operator bool() const noexcept
 }
 
 void
-connection::set_slot(slot_base* sl)
+connection::set_slot(const sigc::internal::weak_raw_ptr<slot_base>& sl)
 {
-  if (slot_)
-    slot_->remove_destroy_notify_callback(this);
-
   slot_ = sl;
-
-  if (slot_)
-    slot_->add_destroy_notify_callback(this, &notify_slot_invalidated);
 }
 
-void
-connection::notify_slot_invalidated(notifiable* data)
-{
-  auto self = static_cast<connection*>(data);
-  self->slot_ = nullptr;
-}
 
 } /* namespace sigc */
diff --git a/sigc++/connection.h b/sigc++/connection.h
index 04aa74a..b00f818 100644
--- a/sigc++/connection.h
+++ b/sigc++/connection.h
@@ -20,6 +20,7 @@
 #define SIGC_CONNECTION_HPP
 #include <sigc++config.h>
 #include <sigc++/functors/slot_base.h>
+#include <sigc++/weak_raw_ptr.h>
 
 namespace sigc
 {
@@ -31,7 +32,7 @@ namespace sigc
  *
  * @ingroup signal
  */
-struct SIGC_API connection : public notifiable
+struct SIGC_API connection
 {
   /** Constructs an empty connection object. */
   connection() noexcept;
@@ -89,17 +90,12 @@ struct SIGC_API connection : public notifiable
   explicit operator bool() const noexcept;
 
 private:
-  void set_slot(slot_base* sl);
-
-  /** Callback that is executed when the referred slot is destroyed.
-   * @param data The connection object notified (@p this).
-   */
-  static void notify_slot_invalidated(notifiable* data);
+  void set_slot(const sigc::internal::weak_raw_ptr<slot_base>& sl);
 
   /* Referred slot. Set to zero from notify().
    * A value of zero indicates an "empty" connection.
    */
-  slot_base* slot_;
+  sigc::internal::weak_raw_ptr<slot_base> slot_;
 };
 
 } /* namespace sigc */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]