Chris@16
|
1 // Boost.Signals library
|
Chris@16
|
2
|
Chris@16
|
3 // Copyright Douglas Gregor 2001-2004. Use, modification and
|
Chris@16
|
4 // distribution is subject to the Boost Software License, Version
|
Chris@16
|
5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
6 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
7
|
Chris@16
|
8 // For more information, see http://www.boost.org
|
Chris@16
|
9
|
Chris@16
|
10 #ifndef BOOST_SIGNALS_COMMON_HEADER
|
Chris@16
|
11 #define BOOST_SIGNALS_COMMON_HEADER
|
Chris@16
|
12
|
Chris@16
|
13 #ifndef BOOST_SIGNALS_NAMESPACE
|
Chris@16
|
14 # define BOOST_SIGNALS_NAMESPACE signals
|
Chris@16
|
15 #endif
|
Chris@16
|
16
|
Chris@16
|
17 #include <boost/type_traits/conversion_traits.hpp>
|
Chris@16
|
18 #include <boost/ref.hpp>
|
Chris@16
|
19 #include <boost/signals/detail/config.hpp>
|
Chris@16
|
20
|
Chris@16
|
21 #ifdef BOOST_HAS_ABI_HEADERS
|
Chris@16
|
22 # include BOOST_ABI_PREFIX
|
Chris@16
|
23 #endif
|
Chris@16
|
24
|
Chris@16
|
25 namespace boost {
|
Chris@16
|
26 namespace BOOST_SIGNALS_NAMESPACE {
|
Chris@16
|
27 namespace detail {
|
Chris@16
|
28 // The unusable class is a placeholder for unused function arguments
|
Chris@16
|
29 // It is also completely unusable except that it constructable from
|
Chris@16
|
30 // anything. This helps compilers without partial specialization
|
Chris@16
|
31 // handle slots returning void.
|
Chris@16
|
32 struct unusable {
|
Chris@16
|
33 unusable() {}
|
Chris@16
|
34 };
|
Chris@16
|
35
|
Chris@16
|
36 // Determine the result type of a slot call
|
Chris@16
|
37 template<typename R>
|
Chris@16
|
38 struct slot_result_type {
|
Chris@16
|
39 typedef R type;
|
Chris@16
|
40 };
|
Chris@16
|
41
|
Chris@16
|
42 template<>
|
Chris@16
|
43 struct slot_result_type<void> {
|
Chris@16
|
44 typedef unusable type;
|
Chris@16
|
45 };
|
Chris@16
|
46
|
Chris@16
|
47 // Determine if the given type T is a signal
|
Chris@16
|
48 class signal_base;
|
Chris@16
|
49
|
Chris@16
|
50 template<typename T>
|
Chris@16
|
51 struct is_signal {
|
Chris@16
|
52 BOOST_STATIC_CONSTANT(bool,
|
Chris@16
|
53 value = (is_convertible<T*, signal_base*>::value));
|
Chris@16
|
54 };
|
Chris@16
|
55
|
Chris@16
|
56 /*
|
Chris@16
|
57 * The IF implementation is temporary code. When a Boost metaprogramming
|
Chris@16
|
58 * library is introduced, Boost.Signals will use it instead.
|
Chris@16
|
59 */
|
Chris@16
|
60 namespace intimate {
|
Chris@16
|
61 struct SelectThen
|
Chris@16
|
62 {
|
Chris@16
|
63 template<typename Then, typename Else>
|
Chris@16
|
64 struct Result
|
Chris@16
|
65 {
|
Chris@16
|
66 typedef Then type;
|
Chris@16
|
67 };
|
Chris@16
|
68 };
|
Chris@16
|
69
|
Chris@16
|
70 struct SelectElse
|
Chris@16
|
71 {
|
Chris@16
|
72 template<typename Then, typename Else>
|
Chris@16
|
73 struct Result
|
Chris@16
|
74 {
|
Chris@16
|
75 typedef Else type;
|
Chris@16
|
76 };
|
Chris@16
|
77 };
|
Chris@16
|
78
|
Chris@16
|
79 template<bool Condition>
|
Chris@16
|
80 struct Selector
|
Chris@16
|
81 {
|
Chris@16
|
82 typedef SelectThen type;
|
Chris@16
|
83 };
|
Chris@16
|
84
|
Chris@16
|
85 template<>
|
Chris@16
|
86 struct Selector<false>
|
Chris@16
|
87 {
|
Chris@16
|
88 typedef SelectElse type;
|
Chris@16
|
89 };
|
Chris@16
|
90 } // end namespace intimate
|
Chris@16
|
91
|
Chris@16
|
92 template<bool Condition, typename Then, typename Else>
|
Chris@16
|
93 struct IF
|
Chris@16
|
94 {
|
Chris@16
|
95 typedef typename intimate::Selector<Condition>::type select;
|
Chris@16
|
96 typedef typename select::template Result<Then,Else>::type type;
|
Chris@16
|
97 };
|
Chris@16
|
98
|
Chris@16
|
99 // Determine if the incoming argument is a reference_wrapper
|
Chris@16
|
100 template<typename T>
|
Chris@16
|
101 struct is_ref
|
Chris@16
|
102 {
|
Chris@16
|
103 BOOST_STATIC_CONSTANT(bool, value = false);
|
Chris@16
|
104 };
|
Chris@16
|
105
|
Chris@16
|
106 template<typename T>
|
Chris@16
|
107 struct is_ref<reference_wrapper<T> >
|
Chris@16
|
108 {
|
Chris@16
|
109 BOOST_STATIC_CONSTANT(bool, value = true);
|
Chris@16
|
110 };
|
Chris@16
|
111
|
Chris@16
|
112 // A slot can be a signal, a reference to a function object, or a
|
Chris@16
|
113 // function object.
|
Chris@16
|
114 struct signal_tag {};
|
Chris@16
|
115 struct reference_tag {};
|
Chris@16
|
116 struct value_tag {};
|
Chris@16
|
117
|
Chris@16
|
118 // Classify the given slot as a signal, a reference-to-slot, or a
|
Chris@16
|
119 // standard slot
|
Chris@16
|
120 template<typename S>
|
Chris@16
|
121 class get_slot_tag {
|
Chris@16
|
122 typedef typename IF<(is_signal<S>::value),
|
Chris@16
|
123 signal_tag,
|
Chris@16
|
124 value_tag>::type signal_or_value;
|
Chris@16
|
125
|
Chris@16
|
126 public:
|
Chris@16
|
127 typedef typename IF<(is_ref<S>::value),
|
Chris@16
|
128 reference_tag,
|
Chris@16
|
129 signal_or_value>::type type;
|
Chris@16
|
130 };
|
Chris@16
|
131
|
Chris@16
|
132 // Forward declaration needed in lots of places
|
Chris@16
|
133 class signal_base_impl;
|
Chris@16
|
134 class bound_objects_visitor;
|
Chris@16
|
135 class slot_base;
|
Chris@16
|
136 } // end namespace detail
|
Chris@16
|
137 } // end namespace BOOST_SIGNALS_NAMESPACE
|
Chris@16
|
138 } // end namespace boost
|
Chris@16
|
139
|
Chris@16
|
140 #ifdef BOOST_HAS_ABI_HEADERS
|
Chris@16
|
141 # include BOOST_ABI_SUFFIX
|
Chris@16
|
142 #endif
|
Chris@16
|
143
|
Chris@16
|
144 #endif // BOOST_SIGNALS_COMMON_HEADER
|