1 // Boost.Signals library
3 // Copyright Doug Gregor 2001-2003. 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)
8 // For more information, see http://www.boost.org
10 #ifndef BOOST_SIGNALS_SLOT_HEADER
11 #define BOOST_SIGNALS_SLOT_HEADER
13 #include <boost/signals/detail/signals_common.hpp>
14 #include <boost/signals/connection.hpp>
15 #include <boost/signals/trackable.hpp>
16 #include <boost/visit_each.hpp>
19 #ifdef BOOST_HAS_ABI_HEADERS
20 # include BOOST_ABI_PREFIX
24 namespace BOOST_SIGNALS_NAMESPACE {
26 class BOOST_SIGNALS_DECL slot_base {
27 // We would have to enumerate all of the signalN classes here as
28 // friends to make this private (as it otherwise should be). We can't
29 // name all of them because we don't know how many there are.
31 // Get the set of bound objects
32 std::vector<const trackable*>& get_bound_objects() const
33 { return bound_objects; }
35 // Determine if this slot is still "active", i.e., all of the bound
36 // objects still exist
37 bool is_active() const { return watch_bound_objects.connected(); }
40 // Create a connection for this slot
41 void create_connection();
43 mutable std::vector<const trackable*> bound_objects;
44 connection watch_bound_objects;
47 static void bound_object_destructed(void*, void*) {}
49 } // end namespace detail
51 // Get the slot so that it can be copied
53 reference_wrapper<const F>
54 get_invocable_slot(const F& f, BOOST_SIGNALS_NAMESPACE::detail::signal_tag)
55 { return reference_wrapper<const F>(f); }
59 get_invocable_slot(const F& f, BOOST_SIGNALS_NAMESPACE::detail::reference_tag)
64 get_invocable_slot(const F& f, BOOST_SIGNALS_NAMESPACE::detail::value_tag)
67 // Get the slot so that it can be inspected for trackable objects
70 get_inspectable_slot(const F& f, BOOST_SIGNALS_NAMESPACE::detail::signal_tag)
75 get_inspectable_slot(const reference_wrapper<F>& f, BOOST_SIGNALS_NAMESPACE::detail::reference_tag)
80 get_inspectable_slot(const F& f, BOOST_SIGNALS_NAMESPACE::detail::value_tag)
83 // Determines the type of the slot - is it a signal, a reference to a
84 // slot or just a normal slot.
86 typename BOOST_SIGNALS_NAMESPACE::detail::get_slot_tag<F>::type
89 typedef typename BOOST_SIGNALS_NAMESPACE::detail::get_slot_tag<F>::type
91 the_tag_type tag = the_tag_type();
95 } // end namespace BOOST_SIGNALS_NAMESPACE
97 template<typename SlotFunction>
98 class slot : public BOOST_SIGNALS_NAMESPACE::detail::slot_base {
101 slot(const F& f) : slot_function(BOOST_SIGNALS_NAMESPACE::get_invocable_slot(f, BOOST_SIGNALS_NAMESPACE::tag_type(f)))
103 // Visit each of the bound objects and store them for later use
104 // An exception thrown here will allow the basic_connection to be
105 // destroyed when this goes out of scope, and no other connections
107 BOOST_SIGNALS_NAMESPACE::detail::bound_objects_visitor do_bind(bound_objects);
108 visit_each(do_bind, BOOST_SIGNALS_NAMESPACE::get_inspectable_slot(f, BOOST_SIGNALS_NAMESPACE::tag_type(f)));
115 slot(F* f) : slot_function(f)
119 #endif // __BORLANDC__
121 // We would have to enumerate all of the signalN classes here as friends
122 // to make this private (as it otherwise should be). We can't name all of
123 // them because we don't know how many there are.
125 // Get the slot function to call the actual slot
126 const SlotFunction& get_slot_function() const { return slot_function; }
129 slot(); // no default constructor
130 slot& operator=(const slot&); // no assignment operator
132 SlotFunction slot_function;
134 } // end namespace boost
136 #ifdef BOOST_HAS_ABI_HEADERS
137 # include BOOST_ABI_SUFFIX
140 #endif // BOOST_SIGNALS_SLOT_HEADER