1 // Boost.Signals library
3 // Copyright (C) 2001 Doug Gregor (gregod@cs.rpi.edu)
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.
11 // This software is provided "as is" without express or implied warranty,
12 // and with no claim as to its suitability for any purpose.
14 // For more information, see http://www.boost.org
16 #include <boost/signals/slot.hpp>
19 namespace BOOST_SIGNALS_NAMESPACE {
21 void slot_base::create_connection()
23 // Create a new connection object
24 basic_connection* con = new basic_connection();
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);
31 con->signal_disconnect = &bound_object_destructed;
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);
38 // We create a scoped connection, so that exceptions thrown while
39 // adding bound objects will cause a cleanup of the bound objects
41 scoped_connection safe_connection(watch_bound_objects);
43 // Now notify each of the bound objects that they are connected to this
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);
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);
56 // Add the binding to the list of bindings for the connection
57 con->bound_objects.push_back(binding);
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();
65 // No exceptions will be thrown past this point.
66 safe_connection.release();
68 } // end namespace detail
69 } // end namespace BOOST_SIGNALS_NAMESPACE
70 } // end namespace boost