2002-05-26 13:02:17 +00:00
|
|
|
// Boost.Signals library
|
2004-02-05 09:14:22 +00:00
|
|
|
|
2004-11-20 09:08:45 +00:00
|
|
|
// Copyright Douglas Gregor 2001-2004. Use, modification and
|
2004-02-05 09:14:22 +00:00
|
|
|
// distribution is subject to the Boost Software License, Version
|
|
|
|
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
|
|
|
// http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
|
2002-05-26 13:02:17 +00:00
|
|
|
// For more information, see http://www.boost.org
|
|
|
|
|
2004-02-05 09:14:22 +00:00
|
|
|
#define BOOST_SIGNALS_SOURCE
|
2002-08-20 21:50:08 +00:00
|
|
|
|
2002-05-26 13:02:17 +00:00
|
|
|
#include <boost/signals/slot.hpp>
|
|
|
|
|
|
|
|
namespace boost {
|
2002-06-18 15:39:27 +00:00
|
|
|
namespace BOOST_SIGNALS_NAMESPACE {
|
2002-05-26 13:02:17 +00:00
|
|
|
namespace detail {
|
|
|
|
void slot_base::create_connection()
|
|
|
|
{
|
|
|
|
// Create a new connection object
|
|
|
|
basic_connection* con = new basic_connection();
|
|
|
|
|
|
|
|
/* nothrow */ {
|
2004-02-05 09:14:22 +00:00
|
|
|
// The signal portion isn't really necessary, except that we need a
|
2002-05-26 13:02:17 +00:00
|
|
|
// signal for the connection to be connected.
|
|
|
|
con->signal = static_cast<void*>(this);
|
|
|
|
con->signal_data = 0;
|
2006-03-05 18:22:35 +00:00
|
|
|
con->blocked_ = false ;
|
2002-05-26 13:02:17 +00:00
|
|
|
con->signal_disconnect = &bound_object_destructed;
|
|
|
|
}
|
|
|
|
|
2004-02-05 09:14:22 +00:00
|
|
|
// This connection watches for destruction of bound objects. Note
|
2002-05-26 13:02:17 +00:00
|
|
|
// that the reset routine will delete con if an allocation throws
|
2004-11-20 09:08:45 +00:00
|
|
|
data->watch_bound_objects.reset(con);
|
2002-05-26 13:02:17 +00:00
|
|
|
|
|
|
|
// We create a scoped connection, so that exceptions thrown while
|
2004-02-05 09:14:22 +00:00
|
|
|
// adding bound objects will cause a cleanup of the bound objects
|
2002-05-26 13:02:17 +00:00
|
|
|
// already connected.
|
2004-11-20 09:08:45 +00:00
|
|
|
scoped_connection safe_connection(data->watch_bound_objects);
|
2002-05-26 13:02:17 +00:00
|
|
|
|
|
|
|
// Now notify each of the bound objects that they are connected to this
|
|
|
|
// slot.
|
2006-03-05 18:22:35 +00:00
|
|
|
for(std::vector<const trackable*>::iterator i =
|
|
|
|
data->bound_objects.begin();
|
2004-11-20 09:08:45 +00:00
|
|
|
i != data->bound_objects.end(); ++i) {
|
2002-05-26 13:02:17 +00:00
|
|
|
// Notify the object that the slot is connecting to it
|
2002-06-18 15:39:27 +00:00
|
|
|
BOOST_SIGNALS_NAMESPACE::detail::bound_object binding;
|
2004-11-20 09:08:45 +00:00
|
|
|
(*i)->signal_connected(data->watch_bound_objects, binding);
|
2004-02-05 09:14:22 +00:00
|
|
|
|
2002-05-26 13:02:17 +00:00
|
|
|
// This will notify the bound object that the connection just made
|
|
|
|
// should be disconnected if an exception is thrown before the
|
|
|
|
// end of this iteration
|
2004-11-20 09:08:45 +00:00
|
|
|
BOOST_SIGNALS_NAMESPACE::detail::auto_disconnect_bound_object
|
|
|
|
disconnector(binding);
|
2002-05-26 13:02:17 +00:00
|
|
|
|
|
|
|
// Add the binding to the list of bindings for the connection
|
|
|
|
con->bound_objects.push_back(binding);
|
|
|
|
|
|
|
|
// The connection object now knows about the bound object, so if an
|
|
|
|
// exception is thrown later the connection object will notify the
|
|
|
|
// bound object of the disconnection automatically
|
|
|
|
disconnector.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
// No exceptions will be thrown past this point.
|
|
|
|
safe_connection.release();
|
2004-11-20 09:08:45 +00:00
|
|
|
|
|
|
|
data->watch_bound_objects.set_controlling(true);
|
2002-05-26 13:02:17 +00:00
|
|
|
}
|
|
|
|
} // end namespace detail
|
2002-06-18 15:39:27 +00:00
|
|
|
} // end namespace BOOST_SIGNALS_NAMESPACE
|
2002-05-26 13:02:17 +00:00
|
|
|
} // end namespace boost
|