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_COMMON_HEADER
17 #define BOOST_SIGNALS_COMMON_HEADER
19 #ifndef BOOST_SIGNALS_NAMESPACE
20 # define BOOST_SIGNALS_NAMESPACE signals
23 /*****************************************************************************
25 * Set up dll import/export options:
27 ****************************************************************************/
28 #if defined(_MSC_VER) && defined(_DLL)
29 # define BOOST_SIGNALS_HAS_DLL_RUNTIME
32 #if defined(BOOST_SIGNALS_HAS_DLL_RUNTIME) && !defined(BOOST_SIGNALS_STATIC_LINK)
33 # if defined(BOOST_SIGNALS_IN_LIBRARY_SOURCE)
34 # define BOOST_SIGNALS_DECL __declspec(dllexport)
35 # define BOOST_SIGNALS_BUILD_DLL
37 # define BOOST_SIGNALS_DECL __declspec(dllimport)
41 #ifndef BOOST_SIGNALS_DECL
42 # define BOOST_SIGNALS_DECL
45 /*****************************************************************************
46 ****************************************************************************/
48 #include <boost/type_traits/conversion_traits.hpp>
49 #include <boost/ref.hpp>
52 namespace BOOST_SIGNALS_NAMESPACE {
54 // The unusable class is a placeholder for unused function arguments
55 // It is also completely unusable except that it constructable from
56 // anything. This helps compilers without partial specialization
57 // handle slots returning void.
62 // Determine the result type of a slot call
64 struct slot_result_type {
69 struct slot_result_type<void> {
70 typedef unusable type;
73 // Determine if the given type T is a signal
78 BOOST_STATIC_CONSTANT(bool,
79 value = (is_convertible<T*, signal_base*>::value));
83 * The IF implementation is temporary code. When a Boost metaprogramming
84 * library is introduced, Boost.Signals will use it instead.
89 template<typename Then, typename Else>
98 template<typename Then, typename Else>
105 template<bool Condition>
108 typedef SelectThen type;
112 struct Selector<false>
114 typedef SelectElse type;
116 } // end namespace intimate
118 template<bool Condition, typename Then, typename Else>
121 typedef typename intimate::Selector<Condition>::type select;
122 typedef typename select::template Result<Then,Else>::type type;
125 // Determine if the incoming argument is a reference_wrapper
126 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
130 BOOST_STATIC_CONSTANT(bool, value = false);
134 struct is_ref<reference_wrapper<T> >
136 BOOST_STATIC_CONSTANT(bool, value = true);
138 #else // no partial specialization
139 typedef char yes_type;
140 typedef double no_type;
142 no_type is_ref_tester(...);
145 yes_type is_ref_tester(reference_wrapper<T>*);
151 BOOST_STATIC_CONSTANT(bool,
152 value = (sizeof(is_ref_tester(t)) == sizeof(yes_type)));
154 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
156 // A slot can be a signal, a reference to a function object, or a
158 struct signal_tag {};
159 struct reference_tag {};
162 // Classify the given slot as a signal, a reference-to-slot, or a
166 typedef typename IF<(is_signal<S>::value),
168 value_tag>::type signal_or_value;
171 typedef typename IF<(is_ref<S>::value),
173 signal_or_value>::type type;
176 // Forward declaration needed in lots of places
177 class signal_base_impl;
178 class bound_objects_visitor;
180 } // end namespace detail
181 } // end namespace BOOST_SIGNALS_NAMESPACE
182 } // end namespace boost
184 #endif // BOOST_SIGNALS_COMMON_HEADER