Skip to content

Commit 846d1fe

Browse files
committed
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.
1 parent 57a20ea commit 846d1fe

File tree

2 files changed

+5
-28
lines changed

2 files changed

+5
-28
lines changed

sigc++/connection.cc

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,11 @@ connection::connection() noexcept : slot_(nullptr)
2929
connection::connection(slot_base& slot)
3030
: slot_(&slot)
3131
{
32-
if (slot_)
33-
slot_->add_destroy_notify_callback(this, &notify_slot_invalidated);
3432
}
3533

3634

3735
connection::connection(const connection& c) : slot_(c.slot_)
3836
{
39-
// Let the connection forget about the signal handler when the handler object dies:
40-
if (slot_)
41-
slot_->add_destroy_notify_callback(this, &notify_slot_invalidated);
4237
}
4338

4439
connection&
@@ -50,8 +45,6 @@ connection::operator=(const connection& src)
5045

5146
connection::~connection()
5247
{
53-
if (slot_)
54-
slot_->remove_destroy_notify_callback(this);
5548
}
5649

5750
bool
@@ -97,22 +90,10 @@ connection::operator bool() const noexcept
9790
}
9891

9992
void
100-
connection::set_slot(slot_base* sl)
93+
connection::set_slot(const sigc::internal::weak_raw_ptr<slot_base>& sl)
10194
{
102-
if (slot_)
103-
slot_->remove_destroy_notify_callback(this);
104-
10595
slot_ = sl;
106-
107-
if (slot_)
108-
slot_->add_destroy_notify_callback(this, &notify_slot_invalidated);
10996
}
11097

111-
void
112-
connection::notify_slot_invalidated(notifiable* data)
113-
{
114-
auto self = static_cast<connection*>(data);
115-
self->slot_ = nullptr;
116-
}
11798

11899
} /* namespace sigc */

sigc++/connection.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define SIGC_CONNECTION_HPP
2121
#include <sigc++config.h>
2222
#include <sigc++/functors/slot_base.h>
23+
#include <sigc++/weak_raw_ptr.h>
2324

2425
namespace sigc
2526
{
@@ -31,7 +32,7 @@ namespace sigc
3132
*
3233
* @ingroup signal
3334
*/
34-
struct SIGC_API connection : public notifiable
35+
struct SIGC_API connection
3536
{
3637
/** Constructs an empty connection object. */
3738
connection() noexcept;
@@ -89,17 +90,12 @@ struct SIGC_API connection : public notifiable
8990
explicit operator bool() const noexcept;
9091

9192
private:
92-
void set_slot(slot_base* sl);
93-
94-
/** Callback that is executed when the referred slot is destroyed.
95-
* @param data The connection object notified (@p this).
96-
*/
97-
static void notify_slot_invalidated(notifiable* data);
93+
void set_slot(const sigc::internal::weak_raw_ptr<slot_base>& sl);
9894

9995
/* Referred slot. Set to zero from notify().
10096
* A value of zero indicates an "empty" connection.
10197
*/
102-
slot_base* slot_;
98+
sigc::internal::weak_raw_ptr<slot_base> slot_;
10399
};
104100

105101
} /* namespace sigc */

0 commit comments

Comments
 (0)