File indexing completed on 2025-01-18 09:51:41
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef BOOST_SIGNALS2_TRACKED_OBJECTS_VISITOR_HPP
0013 #define BOOST_SIGNALS2_TRACKED_OBJECTS_VISITOR_HPP
0014
0015 #include <boost/core/ref.hpp>
0016 #include <boost/mpl/bool.hpp>
0017 #include <boost/signals2/detail/signals_common.hpp>
0018 #include <boost/signals2/slot_base.hpp>
0019 #include <boost/signals2/trackable.hpp>
0020 #include <boost/type_traits/is_function.hpp>
0021 #include <boost/type_traits/is_pointer.hpp>
0022 #include <boost/type_traits/remove_pointer.hpp>
0023 #include <boost/core/addressof.hpp>
0024
0025 namespace boost
0026 {
0027 namespace signals2
0028 {
0029 namespace detail
0030 {
0031
0032 class tracked_objects_visitor
0033 {
0034 public:
0035 tracked_objects_visitor(slot_base *slot) : slot_(slot)
0036 {}
0037 template<typename T>
0038 void operator()(const T& t) const
0039 {
0040 m_visit_reference_wrapper(t, mpl::bool_<is_reference_wrapper<T>::value>());
0041 }
0042 private:
0043 template<typename T>
0044 void m_visit_reference_wrapper(const reference_wrapper<T> &t, const mpl::bool_<true> &) const
0045 {
0046 m_visit_pointer(t.get_pointer(), mpl::bool_<true>());
0047 }
0048 template<typename T>
0049 void m_visit_reference_wrapper(const T &t, const mpl::bool_<false> &) const
0050 {
0051 m_visit_pointer(t, mpl::bool_<is_pointer<T>::value>());
0052 }
0053 template<typename T>
0054 void m_visit_pointer(const T &t, const mpl::bool_<true> &) const
0055 {
0056 m_visit_not_function_pointer(t, mpl::bool_<!is_function<typename remove_pointer<T>::type>::value>());
0057 }
0058 template<typename T>
0059 void m_visit_pointer(const T &t, const mpl::bool_<false> &) const
0060 {
0061 m_visit_pointer(boost::addressof(t), mpl::bool_<true>());
0062 }
0063 template<typename T>
0064 void m_visit_not_function_pointer(const T *t, const mpl::bool_<true> &) const
0065 {
0066 m_visit_signal(t, mpl::bool_<is_signal<T>::value>());
0067 }
0068 template<typename T>
0069 void m_visit_not_function_pointer(const T &, const mpl::bool_<false> &) const
0070 {}
0071 template<typename T>
0072 void m_visit_signal(const T *signal, const mpl::bool_<true> &) const
0073 {
0074 if(signal)
0075 slot_->track_signal(*signal);
0076 }
0077 template<typename T>
0078 void m_visit_signal(const T &t, const mpl::bool_<false> &) const
0079 {
0080 add_if_trackable(t);
0081 }
0082 void add_if_trackable(const trackable *trackable) const
0083 {
0084 if(trackable)
0085 slot_->_tracked_objects.push_back(trackable->get_weak_ptr());
0086 }
0087 void add_if_trackable(const void *) const {}
0088
0089 mutable slot_base * slot_;
0090 };
0091
0092
0093 }
0094 }
0095 }
0096
0097 #endif
0098