1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/signals/trackable.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,195 @@
1.4 +// Boost.Signals library
1.5 +
1.6 +// Copyright Douglas Gregor 2001-2004. Use, modification and
1.7 +// distribution is subject to the Boost Software License, Version
1.8 +// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
1.9 +// http://www.boost.org/LICENSE_1_0.txt)
1.10 +
1.11 +// For more information, see http://www.boost.org
1.12 +
1.13 +#ifndef BOOST_SIGNALS_TRACKABLE_HPP
1.14 +#define BOOST_SIGNALS_TRACKABLE_HPP
1.15 +
1.16 +#include <boost/type_traits.hpp>
1.17 +#include <boost/signals/connection.hpp>
1.18 +#include <boost/pending/ct_if.hpp>
1.19 +#include <boost/ref.hpp>
1.20 +#include <boost/utility/addressof.hpp>
1.21 +#include <list>
1.22 +#include <vector>
1.23 +
1.24 +#ifdef BOOST_HAS_ABI_HEADERS
1.25 +# include BOOST_ABI_PREFIX
1.26 +#endif
1.27 +
1.28 +namespace boost {
1.29 +
1.30 +namespace BOOST_SIGNALS_NAMESPACE {
1.31 + // Base class for "trackable" objects that can be tracked when they are
1.32 + // bound in slot target functions. When a trackable object is destroyed,
1.33 + // the signal/slot connections are disconnected automatically.
1.34 + class BOOST_SIGNALS_DECL trackable {
1.35 + private:
1.36 + static void signal_disconnected(void* obj, void* data);
1.37 +
1.38 + friend class detail::signal_base_impl;
1.39 + friend class detail::slot_base;
1.40 + void signal_connected(connection, BOOST_SIGNALS_NAMESPACE::detail::bound_object&) const;
1.41 +
1.42 + protected:
1.43 + trackable() : connected_signals(), dying(false) {}
1.44 + trackable(const trackable&) : connected_signals(), dying(false) {}
1.45 + ~trackable();
1.46 +
1.47 + trackable& operator=(const trackable&)
1.48 + {
1.49 + connected_signals.clear();
1.50 + return *this;
1.51 + }
1.52 +
1.53 + private:
1.54 + typedef std::list<connection> connection_list;
1.55 + typedef connection_list::iterator connection_iterator;
1.56 +
1.57 + // List of connections that this object is part of
1.58 + mutable connection_list connected_signals;
1.59 +
1.60 + // True when the object is being destroyed
1.61 + mutable bool dying;
1.62 + };
1.63 +
1.64 + namespace detail {
1.65 + template<bool Cond> struct truth {};
1.66 +
1.67 + // A visitor that adds each trackable object to a vector
1.68 + class bound_objects_visitor {
1.69 + public:
1.70 + bound_objects_visitor(std::vector<const trackable*>& v) :
1.71 + bound_objects(v)
1.72 + {
1.73 + }
1.74 +
1.75 + template<typename T>
1.76 + void operator()(const T& t) const
1.77 + {
1.78 + decode(t, 0);
1.79 + }
1.80 +
1.81 + private:
1.82 + // decode() decides between a reference wrapper and anything else
1.83 + template<typename T>
1.84 + void decode(const reference_wrapper<T>& t, int) const
1.85 + {
1.86 + add_if_trackable(t.get_pointer());
1.87 + }
1.88 +
1.89 + template<typename T>
1.90 + void decode(const T& t, long) const
1.91 + {
1.92 + typedef truth<(is_pointer<T>::value)> is_a_pointer;
1.93 + maybe_get_pointer(t, is_a_pointer());
1.94 + }
1.95 +
1.96 + // maybe_get_pointer() decides between a pointer and a non-pointer
1.97 + template<typename T>
1.98 + void maybe_get_pointer(const T& t, truth<true>) const
1.99 + {
1.100 + add_if_trackable(t);
1.101 + }
1.102 +
1.103 + template<typename T>
1.104 + void maybe_get_pointer(const T& t, truth<false>) const
1.105 + {
1.106 + // Take the address of this object, because the object itself may be
1.107 + // trackable
1.108 + add_if_trackable(boost::addressof(t));
1.109 + }
1.110 +
1.111 + // add_if_trackable() adds trackable objects to the list of bound objects
1.112 + inline void add_if_trackable(const trackable* b) const
1.113 + {
1.114 + if (b) {
1.115 + bound_objects.push_back(b);
1.116 + }
1.117 + }
1.118 +
1.119 + inline void add_if_trackable(const void*) const
1.120 + {
1.121 + }
1.122 +
1.123 + template<typename R>
1.124 + inline void add_if_trackable(R (*)()) const
1.125 + {
1.126 + }
1.127 +
1.128 + template<typename R, typename T1>
1.129 + inline void add_if_trackable(R (*)(T1)) const
1.130 + {
1.131 + }
1.132 +
1.133 + template<typename R, typename T1, typename T2>
1.134 + inline void add_if_trackable(R (*)(T1, T2)) const
1.135 + {
1.136 + }
1.137 +
1.138 + template<typename R, typename T1, typename T2, typename T3>
1.139 + inline void add_if_trackable(R (*)(T1, T2, T3)) const
1.140 + {
1.141 + }
1.142 +
1.143 + template<typename R, typename T1, typename T2, typename T3, typename T4>
1.144 + inline void add_if_trackable(R (*)(T1, T2, T3, T4)) const
1.145 + {
1.146 + }
1.147 +
1.148 + template<typename R, typename T1, typename T2, typename T3, typename T4,
1.149 + typename T5>
1.150 + inline void add_if_trackable(R (*)(T1, T2, T3, T4, T5)) const
1.151 + {
1.152 + }
1.153 +
1.154 + template<typename R, typename T1, typename T2, typename T3, typename T4,
1.155 + typename T5, typename T6>
1.156 + inline void add_if_trackable(R (*)(T1, T2, T3, T4, T5, T6)) const
1.157 + {
1.158 + }
1.159 +
1.160 + template<typename R, typename T1, typename T2, typename T3, typename T4,
1.161 + typename T5, typename T6, typename T7>
1.162 + inline void add_if_trackable(R (*)(T1, T2, T3, T4, T5, T6, T7)) const
1.163 + {
1.164 + }
1.165 +
1.166 + template<typename R, typename T1, typename T2, typename T3, typename T4,
1.167 + typename T5, typename T6, typename T7, typename T8>
1.168 + inline void add_if_trackable(R (*)(T1, T2, T3, T4, T5, T6, T7, T8)) const
1.169 + {
1.170 + }
1.171 +
1.172 + template<typename R, typename T1, typename T2, typename T3, typename T4,
1.173 + typename T5, typename T6, typename T7, typename T8, typename T9>
1.174 + inline void
1.175 + add_if_trackable(R (*)(T1, T2, T3, T4, T5, T6, T7, T8, T9)) const
1.176 + {
1.177 + }
1.178 +
1.179 + template<typename R, typename T1, typename T2, typename T3, typename T4,
1.180 + typename T5, typename T6, typename T7, typename T8, typename T9,
1.181 + typename T10>
1.182 + inline void
1.183 + add_if_trackable(R (*)(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)) const
1.184 + {
1.185 + }
1.186 +
1.187 + std::vector<const trackable*>& bound_objects;
1.188 + };
1.189 + } // end namespace detail
1.190 +} // end namespace BOOST_SIGNALS_NAMESPACE
1.191 +
1.192 +} // end namespace boost
1.193 +
1.194 +#ifdef BOOST_HAS_ABI_HEADERS
1.195 +# include BOOST_ABI_SUFFIX
1.196 +#endif
1.197 +
1.198 +#endif // BOOST_SIGNALS_TRACKABLE_HPP