1 // Boost.Signals library
3 // Copyright (C) 2001-2002 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 #ifndef BOOST_SIGNALS_SLOT_HEADER
17 #define BOOST_SIGNALS_SLOT_HEADER
19 #include <boost/signals/detail/signals_common.hpp>
20 #include <boost/signals/connection.hpp>
21 #include <boost/signals/trackable.hpp>
22 #include <boost/visit_each.hpp>
26 namespace BOOST_SIGNALS_NAMESPACE {
29 // We would have to enumerate all of the signalN classes here as
30 // friends to make this private (as it otherwise should be). We can't
31 // name all of them because we don't know how many there are.
33 // Get the set of bound objects
34 std::vector<const trackable*>& get_bound_objects() const
35 { return bound_objects; }
37 // Determine if this slot is still "active", i.e., all of the bound
38 // objects still exist
39 bool is_active() const { return watch_bound_objects.connected(); }
42 // Create a connection for this slot
43 void create_connection();
45 // Get the slot so that it can be copied
47 reference_wrapper<const F>
48 get_invocable_slot(const F& f, BOOST_SIGNALS_NAMESPACE::detail::signal_tag)
49 { return reference_wrapper<const F>(f); }
52 const F& get_invocable_slot(const F& f, BOOST_SIGNALS_NAMESPACE::detail::reference_tag)
56 const F& get_invocable_slot(const F& f, BOOST_SIGNALS_NAMESPACE::detail::value_tag)
59 // Get the slot so that it can be inspected for trackable objects
61 const F& get_inspectable_slot(const F& f,
62 BOOST_SIGNALS_NAMESPACE::detail::signal_tag)
66 const F& get_inspectable_slot(const F& f,
67 BOOST_SIGNALS_NAMESPACE::detail::reference_tag)
71 const F& get_inspectable_slot(const F& f, BOOST_SIGNALS_NAMESPACE::detail::value_tag)
74 // Determines the type of the slot - is it a signal, a reference to a
75 // slot or just a normal slot.
77 typename BOOST_SIGNALS_NAMESPACE::detail::get_slot_tag<F>::type
80 typename BOOST_SIGNALS_NAMESPACE::detail::get_slot_tag<F>::type tag;
84 mutable std::vector<const trackable*> bound_objects;
85 connection watch_bound_objects;
88 static void bound_object_destructed(void*, void*) {}
90 } // end namespace detail
91 } // end namespace BOOST_SIGNALS_NAMESPACE
93 template<typename SlotFunction>
94 class slot : public BOOST_SIGNALS_NAMESPACE::detail::slot_base {
97 slot(const F& f) : slot_function(get_invocable_slot(f, tag_type(f)))
99 // Visit each of the bound objects and store them for later use
100 // An exception thrown here will allow the basic_connection to be
101 // destroyed when this goes out of scope, and no other connections
103 BOOST_SIGNALS_NAMESPACE::detail::bound_objects_visitor do_bind(bound_objects);
104 visit_each(do_bind, get_inspectable_slot(f, tag_type(f)));
111 slot(F* f) : slot_function(f)
115 #endif // __BORLANDC__
117 // We would have to enumerate all of the signalN classes here as friends
118 // to make this private (as it otherwise should be). We can't name all of
119 // them because we don't know how many there are.
121 // Get the slot function to call the actual slot
122 const SlotFunction& get_slot_function() const { return slot_function; }
125 slot(); // no default constructor
126 slot& operator=(const slot&); // no assignment operator
128 SlotFunction slot_function;
130 } // end namespace boost
132 #endif // BOOST_SIGNALS_SLOT_HEADER