Skip to content

Commit e427dee

Browse files
committed
signal::connect(): Return a sigc::connection.
Instead of an iterator aliases to a signal<>::connection.
1 parent fb57d3f commit e427dee

File tree

6 files changed

+21
-14
lines changed

6 files changed

+21
-14
lines changed

examples/member_method.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ class Something : public sigc::trackable
2323

2424
Something::Something()
2525
{
26-
auto iter = signal_print.connect(sigc::mem_fun(*this, &Something::on_print));
26+
auto connection = signal_print.connect(sigc::mem_fun(*this, &Something::on_print));
2727

2828
signal_print.emit(2);
2929

3030
// This isn't necessary - it's just to demonstrate how to disconnect:
31-
iter->disconnect();
31+
connection.disconnect();
3232
signal_print.emit(3); // Prove that it is no longer connected.
3333
}
3434

sigc++/connection.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@
1919
#ifndef SIGC_CONNECTION_HPP
2020
#define SIGC_CONNECTION_HPP
2121
#include <sigc++config.h>
22-
#include <sigc++/signal.h>
22+
#include <sigc++/functors/slot_base.h>
2323

2424
namespace sigc
2525
{
2626

27+
template <typename T_slot>
28+
struct slot_iterator;
29+
2730
/** Convinience class for safe disconnection.
2831
* Iterators must not be used beyond the lifetime of the list
2932
* they work on. A connection object can be created from a

sigc++/signal.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define SIGC_SIGNAL_H
2222

2323
#include <list>
24+
#include <sigc++/connection.h>
2425
#include <sigc++/signal_base.h>
2526
#include <sigc++/type_traits.h>
2627
#include <sigc++/trackable.h>
@@ -469,7 +470,12 @@ class signal_with_accumulator : public signal_base
469470
{
470471
public:
471472
using slot_type = slot<T_return(T_arg...)>;
472-
using connection = slot_iterator<slot_type>;
473+
474+
private:
475+
using iterator = slot_iterator<slot_type>;
476+
477+
public:
478+
473479

474480
/** Add a slot to the list of slots.
475481
* Any functor or slot may be passed into connect().
@@ -494,7 +500,7 @@ class signal_with_accumulator : public signal_base
494500
*/
495501
connection connect(const slot_type& slot_)
496502
{
497-
return connection(signal_base::connect(slot_));
503+
return connection(iterator(signal_base::connect(slot_)));
498504
}
499505

500506
/** Add a slot to the list of slots.
@@ -504,7 +510,7 @@ class signal_with_accumulator : public signal_base
504510
*/
505511
connection connect(slot_type&& slot_)
506512
{
507-
return connection(signal_base::connect(std::move(slot_)));
513+
return connection(iterator(signal_base::connect(std::move(slot_))));
508514
}
509515

510516
/** Triggers the emission of the signal.

tests/benchmark.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ void test_connect_disconnect()
8282
{
8383
foo foobar1;
8484
sigc::signal<int(int)> emitter;
85-
sigc::signal<int(int)>::connection conn;
85+
sigc::connection conn;
8686

8787
std::cout << "elapsed time for " << COUNT << " connections/disconnections:" << std::endl;
8888
boost::timer::auto_cpu_timer timer;
8989

9090
for (int i=0; i < COUNT; ++i)
9191
{
9292
conn = emitter.connect(mem_fun(foobar1, &foo::bar));
93-
conn->disconnect();
93+
conn.disconnect();
9494
}
9595
}
9696

tests/test_disconnect.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ main(int argc, char* argv[])
8181
return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
8282

8383
sigc::signal<int(int)> sig;
84-
sigc::signal<int(int)>::connection confoo;
85-
sigc::signal<int(int)>::connection conbar;
84+
sigc::connection confoo;
85+
sigc::connection conbar;
8686
sigc::connection cona; // connection objects are safe to use beyond the life time of a signal.
8787

8888
{
@@ -107,12 +107,12 @@ main(int argc, char* argv[])
107107
util->check_result(
108108
result_stream, "sig is connected to foo, A::foo, bar (size=3): foo(3) bar(3) A::foo(3) ");
109109

110-
conbar->disconnect(); // manual disconnection
110+
conbar.disconnect(); // manual disconnection
111111
result_stream << "sig is connected to foo, A::foo (size=" << sig.size() << "): ";
112112
sig(4);
113113
util->check_result(result_stream, "sig is connected to foo, A::foo (size=2): foo(4) A::foo(4) ");
114114

115-
confoo->disconnect(); // manual disconnection
115+
confoo.disconnect(); // manual disconnection
116116
result_stream << "sig is connected to A::foo (size=" << sig.size() << "): ";
117117
sig(5);
118118
util->check_result(result_stream, "sig is connected to A::foo (size=1): A::foo(5) ");

tests/test_size.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ main(int argc, char* argv[])
3535
std::cout << " trackable: " << sizeof(sigc::trackable) << std::endl;
3636
std::cout << " slot<void()>: " << sizeof(sigc::slot<void()>) << std::endl;
3737
std::cout << " signal<void()>: " << sizeof(sigc::signal<void()>) << std::endl;
38-
std::cout << " signal<void()>::connection: " << sizeof(sigc::signal<void()>::connection)
39-
<< std::endl;
4038
std::cout << " connection: " << sizeof(sigc::connection) << std::endl;
4139

4240
std::cout << std::endl << "sizes of internal classes:" << std::endl;

0 commit comments

Comments
 (0)