]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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/trackable.hpp> | |
13 | #include <algorithm> | |
14 | ||
15 | namespace boost { | |
16 | namespace BOOST_SIGNALS_NAMESPACE { | |
17 | void trackable::signal_disconnected(void* obj, void* data) | |
18 | { | |
19 | trackable* self = reinterpret_cast<trackable*>(obj); | |
20 | connection_iterator* signal = | |
21 | reinterpret_cast<connection_iterator*>(data); | |
22 | ||
23 | // If we're dying, don't bother erasing the connection from the list; | |
24 | // it'll be gone anyway | |
25 | if (!self->dying) { | |
26 | self->connected_signals.erase(*signal); | |
27 | } | |
28 | ||
29 | // This iterator pointer won't ever be used again | |
30 | delete signal; | |
31 | } | |
32 | ||
33 | void | |
34 | trackable::signal_connected(connection c, | |
35 | BOOST_SIGNALS_NAMESPACE::detail::bound_object& binding) const | |
36 | { | |
37 | // Insert the connection | |
38 | connection_iterator pos = | |
39 | connected_signals.insert(connected_signals.end(), c); | |
40 | ||
41 | // Make this copy of the object disconnect when destroyed | |
42 | pos->set_controlling(); | |
43 | ||
44 | binding.obj = const_cast<void*>(reinterpret_cast<const void*>(this)); | |
45 | binding.data = reinterpret_cast<void*>(new connection_iterator(pos)); | |
46 | binding.disconnect = &signal_disconnected; | |
47 | } | |
48 | ||
49 | trackable::~trackable() | |
50 | { | |
51 | dying = true; | |
52 | } | |
53 | } // end namespace BOOST_SIGNALS_NAMESPACE | |
54 | } | |
55 | ||
56 | #ifndef BOOST_MSVC | |
57 | // Explicit instantiations to keep in the library | |
58 | template class std::list<boost::BOOST_SIGNALS_NAMESPACE::connection>; | |
59 | #endif |