1 // Boost.Signals library
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)
8 // For more information, see http://www.boost.org
10 #define BOOST_SIGNALS_SOURCE
12 #include <boost/signals/connection.hpp>
16 namespace BOOST_SIGNALS_NAMESPACE {
18 connection::connection(const connection& other) :
19 con(other.con), controlling_connection(other.controlling_connection)
23 connection::~connection()
25 if (controlling_connection) {
31 connection::reset(BOOST_SIGNALS_NAMESPACE::detail::basic_connection* new_con)
36 bool connection::operator==(const connection& other) const
38 return con.get() == other.con.get();
41 bool connection::operator<(const connection& other) const
43 return con.get() < other.con.get();
46 connection& connection::operator=(const connection& other)
48 connection(other).swap(*this);
52 void connection::swap(connection& other)
54 this->con.swap(other.con);
55 std::swap(this->controlling_connection, other.controlling_connection);
58 void swap(connection& c1, connection& c2)
63 scoped_connection::scoped_connection(const connection& other) :
69 scoped_connection::scoped_connection(const scoped_connection& other) :
71 released(other.released)
75 scoped_connection::~scoped_connection()
82 connection scoped_connection::release()
88 void scoped_connection::swap(scoped_connection& other)
90 this->connection::swap(other);
91 bool other_released = other.released;
92 other.released = this->released;
93 this->released = other_released;
96 void swap(scoped_connection& c1, scoped_connection& c2)
102 scoped_connection::operator=(const connection& other)
104 scoped_connection(other).swap(*this);
109 scoped_connection::operator=(const scoped_connection& other)
111 scoped_connection(other).swap(*this);
116 connection::add_bound_object(const BOOST_SIGNALS_NAMESPACE::detail::bound_object& b)
118 assert(con.get() != 0);
119 con->bound_objects.push_back(b);
123 void connection::disconnect() const
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;
130 void (*signal_disconnect)(void*, void*) = local_con->signal_disconnect;
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;
138 signal_disconnect(local_con->signal, local_con->signal_data);
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);
149 } // end namespace boost
150 } // end namespace boost
153 // Explicit instantiations to keep everything in the library
154 template class std::list<boost::BOOST_SIGNALS_NAMESPACE::detail::bound_object>;