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