1 // Boost.Signals library
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)
8 // For more information, see http://www.boost.org
10 #ifndef BOOST_SIGNALS_SIGNAL_BASE_HEADER
11 #define BOOST_SIGNALS_SIGNAL_BASE_HEADER
13 #include <boost/signals/detail/config.hpp>
14 #include <boost/signals/detail/signals_common.hpp>
15 #include <boost/signals/detail/named_slot_map.hpp>
16 #include <boost/signals/connection.hpp>
17 #include <boost/signals/trackable.hpp>
18 #include <boost/signals/slot.hpp>
19 #include <boost/smart_ptr.hpp>
20 #include <boost/any.hpp>
21 #include <boost/utility.hpp>
22 #include <boost/function/function2.hpp>
26 #ifdef BOOST_HAS_ABI_HEADERS
27 # include BOOST_ABI_PREFIX
31 namespace BOOST_SIGNALS_NAMESPACE {
33 // Must be constructed before calling the slots, because it safely
35 class BOOST_SIGNALS_DECL call_notification {
37 call_notification(const shared_ptr<signal_base_impl>&);
40 shared_ptr<signal_base_impl> impl;
43 // Implementation of base class for all signals. It handles the
44 // management of the underlying slot lists.
45 class BOOST_SIGNALS_DECL signal_base_impl {
47 friend class call_notification;
49 typedef function2<bool, any, any> compare_type;
51 // Make sure that an exception does not cause the "clearing" flag to
53 class temporarily_set_clearing {
55 temporarily_set_clearing(signal_base_impl* b) : base(b)
57 base->flags.clearing = true;
60 ~temporarily_set_clearing()
62 base->flags.clearing = false;
66 signal_base_impl* base;
69 friend class temporarily_set_clearing;
71 signal_base_impl(const compare_type&, const any&);
74 // Disconnect all slots connected to this signal
75 void disconnect_all_slots();
77 // Are there any connected slots?
80 // The number of connected slots
81 std::size_t num_slots() const;
83 // Disconnect all slots in the given group
84 void disconnect(const any&);
86 // We're being notified that a slot has disconnected
87 static void slot_disconnected(void* obj, void* data);
89 connection connect_slot(const any& slot,
91 shared_ptr<slot_base::data_t> data,
95 // Remove all of the slots that have been marked "disconnected"
96 void remove_disconnected_slots() const;
99 // Our call depth when invoking slots (> 1 when we have a loop)
100 mutable int call_depth;
103 // True if some slots have disconnected, but we were not able to
104 // remove them from the list of slots because there are valid
105 // iterators into the slot list
106 mutable bool delayed_disconnect:1;
108 // True if we are disconnecting all disconnected slots
113 mutable named_slot_map slots_;
117 typedef named_slot_map::iterator iterator;
120 class BOOST_SIGNALS_DECL signal_base : public noncopyable {
122 typedef signal_base_impl::compare_type compare_type;
124 friend class call_notification;
126 signal_base(const compare_type& comp, const any& combiner);
130 // Disconnect all slots connected to this signal
131 void disconnect_all_slots() { impl->disconnect_all_slots(); }
133 // Are there any connected slots?
134 bool empty() const { return impl->empty(); }
136 // How many slots are connected?
137 std::size_t num_slots() const { return impl->num_slots(); }
140 connection connect_slot(const any& slot,
142 shared_ptr<slot_base::data_t> data,
145 return impl->connect_slot(slot, name, data, at);
148 typedef named_slot_map::iterator iterator;
150 shared_ptr<signal_base_impl> impl;
152 } // end namespace detail
153 } // end namespace BOOST_SIGNALS_NAMESPACE
154 } // end namespace boost
156 #ifdef BOOST_HAS_ABI_HEADERS
157 # include BOOST_ABI_SUFFIX
160 #endif // BOOST_SIGNALS_SIGNAL_BASE_HEADER