summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMurray Cumming <murrayc@murrayc.com>2016-04-28 11:21:55 +0200
committerMurray Cumming <murrayc@murrayc.com>2016-05-02 10:19:54 +0200
commit846d1fe14af2551381bfe8c22ac9772664821b4b (patch)
tree5ee26d803f697be2b80c7472160e9d00153f1b34
parent57a20ea1f4b64c82e2c6c4711619393415e88af1 (diff)
downloadsigc++-846d1fe14af2551381bfe8c22ac9772664821b4b.tar.gz
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.
-rw-r--r--sigc++/connection.cc21
-rw-r--r--sigc++/connection.h12
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 */