]> git.lyx.org Git - lyx.git/blob - boost/boost/signals/detail/signal_base.hpp
update to boost 1.32.0
[lyx.git] / boost / boost / signals / detail / signal_base.hpp
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 #ifndef BOOST_SIGNALS_SIGNAL_BASE_HEADER
11 #define BOOST_SIGNALS_SIGNAL_BASE_HEADER
12
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>
23 #include <utility>
24 #include <vector>
25
26 #ifdef BOOST_HAS_ABI_HEADERS
27 #  include BOOST_ABI_PREFIX
28 #endif
29
30 namespace boost {
31   namespace BOOST_SIGNALS_NAMESPACE {
32     namespace detail {
33       // Must be constructed before calling the slots, because it safely
34       // manages call depth
35       class BOOST_SIGNALS_DECL call_notification {
36       public:
37         call_notification(const shared_ptr<signal_base_impl>&);
38         ~call_notification();
39
40         shared_ptr<signal_base_impl> impl;
41       };
42
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 {
46       public:
47         friend class call_notification;
48
49         typedef function2<bool, any, any> compare_type;
50
51         // Make sure that an exception does not cause the "clearing" flag to
52         // remain set
53         class temporarily_set_clearing {
54         public:
55           temporarily_set_clearing(signal_base_impl* b) : base(b)
56           {
57             base->flags.clearing = true;
58           }
59
60           ~temporarily_set_clearing()
61           {
62             base->flags.clearing = false;
63           }
64
65         private:
66           signal_base_impl* base;
67         };
68
69         friend class temporarily_set_clearing;
70
71         signal_base_impl(const compare_type&, const any&);
72         ~signal_base_impl();
73
74         // Disconnect all slots connected to this signal
75         void disconnect_all_slots();
76
77         // Are there any connected slots?
78         bool empty() const;
79
80         // The number of connected slots
81         std::size_t num_slots() const;
82
83         // Disconnect all slots in the given group
84         void disconnect(const any&);
85
86         // We're being notified that a slot has disconnected
87         static void slot_disconnected(void* obj, void* data);
88
89         connection connect_slot(const any& slot,
90                                 const any& name,
91                                 shared_ptr<slot_base::data_t> data,
92                                 connect_position at);
93
94       private:
95         // Remove all of the slots that have been marked "disconnected"
96         void remove_disconnected_slots() const;
97
98       public:
99         // Our call depth when invoking slots (> 1 when we have a loop)
100         mutable int call_depth;
101
102         struct {
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;
107
108           // True if we are disconnecting all disconnected slots
109           bool clearing:1;
110         } flags;
111
112         // Slots
113         mutable named_slot_map slots_;
114         any combiner_;
115
116         // Types
117         typedef named_slot_map::iterator iterator;
118       };
119
120       class BOOST_SIGNALS_DECL signal_base : public noncopyable {
121       public:
122         typedef signal_base_impl::compare_type compare_type;
123
124         friend class call_notification;
125
126         signal_base(const compare_type& comp, const any& combiner);
127         ~signal_base();
128
129       public:
130         // Disconnect all slots connected to this signal
131         void disconnect_all_slots() { impl->disconnect_all_slots(); }
132
133         // Are there any connected slots?
134         bool empty() const { return impl->empty(); }
135
136         // How many slots are connected?
137         std::size_t num_slots() const { return impl->num_slots(); }
138
139       protected:
140         connection connect_slot(const any& slot,
141                                 const any& name,
142                                 shared_ptr<slot_base::data_t> data,
143                                 connect_position at)
144         {
145           return impl->connect_slot(slot, name, data, at);
146         }
147
148         typedef named_slot_map::iterator iterator;
149
150         shared_ptr<signal_base_impl> impl;
151       };
152     } // end namespace detail
153   } // end namespace BOOST_SIGNALS_NAMESPACE
154 } // end namespace boost
155
156 #ifdef BOOST_HAS_ABI_HEADERS
157 #  include BOOST_ABI_SUFFIX
158 #endif
159
160 #endif // BOOST_SIGNALS_SIGNAL_BASE_HEADER