1// Boost.Signals library
2
3// Copyright Douglas Gregor 2001-2004. Use, modification and
4// distribution is subject to the Boost Software License, Version
5// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6// http://www.boost.org/LICENSE_1_0.txt)
7
8// For more information, see http://www.boost.org
9
10#define BOOST_SIGNALS_SOURCE
11
12#include <boost/signals/connection.hpp>
13#include <cassert>
14
15namespace boost {
16 namespace BOOST_SIGNALS_NAMESPACE {
17
18 connection::connection(const connection& other) :
19 con(other.con), controlling_connection(other.controlling_connection)
20 {
21 }
22
23 connection::~connection()
24 {
25 if (controlling_connection) {
26 disconnect();
27 }
28 }
29
30 void
31 connection::reset(BOOST_SIGNALS_NAMESPACE::detail::basic_connection* new_con)
32 {
33 con.reset(p: new_con);
34 }
35
36 bool connection::operator==(const connection& other) const
37 {
38 return con.get() == other.con.get();
39 }
40
41 bool connection::operator<(const connection& other) const
42 {
43 return con.get() < other.con.get();
44 }
45
46 connection& connection::operator=(const connection& other)
47 {
48 connection(other).swap(other&: *this);
49 return *this;
50 }
51
52 void connection::swap(connection& other)
53 {
54 this->con.swap(other&: other.con);
55 std::swap(a&: this->controlling_connection, b&: other.controlling_connection);
56 }
57
58 void swap(connection& c1, connection& c2)
59 {
60 c1.swap(other&: c2);
61 }
62
63 scoped_connection::scoped_connection(const connection& other) :
64 connection(other),
65 released(false)
66 {
67 }
68
69 scoped_connection::scoped_connection(const scoped_connection& other) :
70 connection(other),
71 released(other.released)
72 {
73 }
74
75 scoped_connection::~scoped_connection()
76 {
77 if (!released) {
78 this->disconnect();
79 }
80 }
81
82 connection scoped_connection::release()
83 {
84 released = true;
85 return *this;
86 }
87
88 void scoped_connection::swap(scoped_connection& other)
89 {
90 this->connection::swap(other);
91 bool other_released = other.released;
92 other.released = this->released;
93 this->released = other_released;
94 }
95
96 void swap(scoped_connection& c1, scoped_connection& c2)
97 {
98 c1.swap(other&: c2);
99 }
100
101 scoped_connection&
102 scoped_connection::operator=(const connection& other)
103 {
104 scoped_connection(other).swap(other&: *this);
105 return *this;
106 }
107
108 scoped_connection&
109 scoped_connection::operator=(const scoped_connection& other)
110 {
111 scoped_connection(other).swap(other&: *this);
112 return *this;
113 }
114
115 void
116 connection::add_bound_object(const BOOST_SIGNALS_NAMESPACE::detail::bound_object& b)
117 {
118 assert(con.get() != 0);
119 con->bound_objects.push_back(x: b);
120 }
121
122
123 void connection::disconnect() const
124 {
125 if (this->connected()) {
126 // Make sure we have a reference to the basic_connection object,
127 // because 'this' may disappear
128 shared_ptr<detail::basic_connection> local_con = con;
129
130 void (*signal_disconnect)(void*, void*) = local_con->signal_disconnect;
131
132 // Note that this connection no longer exists
133 // Order is important here: we could get into an infinite loop if this
134 // isn't cleared before we try the disconnect.
135 local_con->signal_disconnect = 0;
136
137 // Disconnect signal
138 signal_disconnect(local_con->signal, local_con->signal_data);
139
140 // Disconnect all bound objects
141 typedef std::list<BOOST_SIGNALS_NAMESPACE::detail::bound_object>::iterator iterator;
142 for (iterator i = local_con->bound_objects.begin();
143 i != local_con->bound_objects.end(); ++i) {
144 assert(i->disconnect != 0);
145 i->disconnect(i->obj, i->data);
146 }
147 }
148 }
149 } // end namespace boost
150} // end namespace boost
151
152#ifndef BOOST_MSVC
153// Explicit instantiations to keep everything in the library
154template class std::list<boost::BOOST_SIGNALS_NAMESPACE::detail::bound_object>;
155#endif
156

source code of boost/libs/signals/src/connection.cpp