]> git.lyx.org Git - lyx.git/blob - boost/libs/signals/src/slot.cpp
update to boost 1.41.0
[lyx.git] / boost / libs / signals / src / slot.cpp
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/slot.hpp>
13
14 namespace boost {
15   namespace BOOST_SIGNALS_NAMESPACE {
16     namespace detail {
17       void slot_base::create_connection()
18       {
19         // Create a new connection object
20         basic_connection* con = new basic_connection();
21
22         /* nothrow */ {
23           // The signal portion isn't really necessary, except that we need a
24           // signal for the connection to be connected.
25           con->signal = static_cast<void*>(this);
26           con->signal_data = 0;
27           con->blocked_ = false ;
28           con->signal_disconnect = &bound_object_destructed;
29         }
30
31         // This connection watches for destruction of bound objects. Note
32         // that the reset routine will delete con if an allocation throws
33         data->watch_bound_objects.reset(con);
34
35         // We create a scoped connection, so that exceptions thrown while
36         // adding bound objects will cause a cleanup of the bound objects
37         // already connected.
38         scoped_connection safe_connection(data->watch_bound_objects);
39
40         // Now notify each of the bound objects that they are connected to this
41         // slot.
42         for(std::vector<const trackable*>::iterator i =
43               data->bound_objects.begin();
44             i != data->bound_objects.end(); ++i) {
45           // Notify the object that the slot is connecting to it
46           BOOST_SIGNALS_NAMESPACE::detail::bound_object binding;
47           (*i)->signal_connected(data->watch_bound_objects, binding);
48
49           // This will notify the bound object that the connection just made
50           // should be disconnected if an exception is thrown before the
51           // end of this iteration
52           BOOST_SIGNALS_NAMESPACE::detail::auto_disconnect_bound_object
53             disconnector(binding);
54
55           // Add the binding to the list of bindings for the connection
56           con->bound_objects.push_back(binding);
57
58           // The connection object now knows about the bound object, so if an
59           // exception is thrown later the connection object will notify the
60           // bound object of the disconnection automatically
61           disconnector.release();
62         }
63
64         // No exceptions will be thrown past this point.
65         safe_connection.release();
66
67         data->watch_bound_objects.set_controlling(true);
68       }
69     } // end namespace detail
70   } // end namespace BOOST_SIGNALS_NAMESPACE
71 } // end namespace boost