]> git.lyx.org Git - lyx.git/blob - boost/libs/signals/src/slot.cpp
update from Boost CVS
[lyx.git] / boost / libs / signals / src / slot.cpp
1 // Boost.Signals library
2 //
3 // Copyright (C) 2001 Doug Gregor (gregod@cs.rpi.edu)
4 //
5 // Permission to copy, use, sell and distribute this software is granted
6 // provided this copyright notice appears in all copies.
7 // Permission to modify the code and to distribute modified code is granted
8 // provided this copyright notice appears in all copies, and a notice
9 // that the code was modified is included with the copyright notice.
10 //
11 // This software is provided "as is" without express or implied warranty,
12 // and with no claim as to its suitability for any purpose.
13  
14 // For more information, see http://www.boost.org
15
16 #include <boost/signals/slot.hpp>
17
18 namespace boost {
19   namespace BOOST_SIGNALS_NAMESPACE {
20     namespace detail {
21       void slot_base::create_connection()
22       {
23         // Create a new connection object
24         basic_connection* con = new basic_connection();
25
26         /* nothrow */ {
27           // The signal portion isn't really necessary, except that we need a 
28           // signal for the connection to be connected.
29           con->signal = static_cast<void*>(this);
30           con->signal_data = 0;
31           con->signal_disconnect = &bound_object_destructed;
32         }
33
34         // This connection watches for destruction of bound objects. Note 
35         // that the reset routine will delete con if an allocation throws
36         watch_bound_objects.reset(con);
37
38         // We create a scoped connection, so that exceptions thrown while
39         // adding bound objects will cause a cleanup of the bound objects 
40         // already connected.
41         scoped_connection safe_connection(watch_bound_objects);
42
43         // Now notify each of the bound objects that they are connected to this
44         // slot.
45         for(std::vector<const trackable*>::iterator i = bound_objects.begin();
46             i != bound_objects.end(); ++i) {
47           // Notify the object that the slot is connecting to it
48           BOOST_SIGNALS_NAMESPACE::detail::bound_object binding;
49           (*i)->signal_connected(watch_bound_objects, binding);
50         
51           // This will notify the bound object that the connection just made
52           // should be disconnected if an exception is thrown before the
53           // end of this iteration
54           BOOST_SIGNALS_NAMESPACE::detail::auto_disconnect_bound_object disconnector(binding);
55
56           // Add the binding to the list of bindings for the connection
57           con->bound_objects.push_back(binding);
58
59           // The connection object now knows about the bound object, so if an
60           // exception is thrown later the connection object will notify the
61           // bound object of the disconnection automatically
62           disconnector.release();
63         }
64
65         // No exceptions will be thrown past this point.
66         safe_connection.release();
67       }
68     } // end namespace detail
69   } // end namespace BOOST_SIGNALS_NAMESPACE
70 } // end namespace boost