Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/signals2/slot_base.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children | c530137014c0 |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
1 // Boost.Signals2 library | |
2 | |
3 // Copyright Frank Mori Hess 2007-2008. | |
4 // Copyright Timmo Stange 2007. | |
5 // Copyright Douglas Gregor 2001-2004. Use, modification and | |
6 // distribution is subject to the Boost Software License, Version | |
7 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
8 // http://www.boost.org/LICENSE_1_0.txt) | |
9 | |
10 // For more information, see http://www.boost.org | |
11 | |
12 #ifndef BOOST_SIGNALS2_SLOT_BASE_HPP | |
13 #define BOOST_SIGNALS2_SLOT_BASE_HPP | |
14 | |
15 #include <boost/shared_ptr.hpp> | |
16 #include <boost/weak_ptr.hpp> | |
17 #include <boost/signals2/detail/foreign_ptr.hpp> | |
18 #include <boost/signals2/expired_slot.hpp> | |
19 #include <boost/signals2/signal_base.hpp> | |
20 #include <boost/throw_exception.hpp> | |
21 #include <boost/variant/apply_visitor.hpp> | |
22 #include <boost/variant/variant.hpp> | |
23 #include <vector> | |
24 | |
25 namespace boost | |
26 { | |
27 namespace signals2 | |
28 { | |
29 namespace detail | |
30 { | |
31 class tracked_objects_visitor; | |
32 | |
33 typedef boost::variant<boost::weak_ptr<void>, detail::foreign_void_weak_ptr > void_weak_ptr_variant; | |
34 typedef boost::variant<boost::shared_ptr<void>, detail::foreign_void_shared_ptr > void_shared_ptr_variant; | |
35 class lock_weak_ptr_visitor | |
36 { | |
37 public: | |
38 typedef void_shared_ptr_variant result_type; | |
39 template<typename WeakPtr> | |
40 result_type operator()(const WeakPtr &wp) const | |
41 { | |
42 return wp.lock(); | |
43 } | |
44 }; | |
45 class expired_weak_ptr_visitor | |
46 { | |
47 public: | |
48 typedef bool result_type; | |
49 template<typename WeakPtr> | |
50 bool operator()(const WeakPtr &wp) const | |
51 { | |
52 return wp.expired(); | |
53 } | |
54 }; | |
55 } | |
56 | |
57 class slot_base | |
58 { | |
59 public: | |
60 typedef std::vector<detail::void_weak_ptr_variant> tracked_container_type; | |
61 typedef std::vector<detail::void_shared_ptr_variant> locked_container_type; | |
62 | |
63 const tracked_container_type& tracked_objects() const {return _tracked_objects;} | |
64 locked_container_type lock() const | |
65 { | |
66 locked_container_type locked_objects; | |
67 tracked_container_type::const_iterator it; | |
68 for(it = tracked_objects().begin(); it != tracked_objects().end(); ++it) | |
69 { | |
70 locked_objects.push_back(apply_visitor(detail::lock_weak_ptr_visitor(), *it)); | |
71 if(apply_visitor(detail::expired_weak_ptr_visitor(), *it)) | |
72 { | |
73 boost::throw_exception(expired_slot()); | |
74 } | |
75 } | |
76 return locked_objects; | |
77 } | |
78 bool expired() const | |
79 { | |
80 tracked_container_type::const_iterator it; | |
81 for(it = tracked_objects().begin(); it != tracked_objects().end(); ++it) | |
82 { | |
83 if(apply_visitor(detail::expired_weak_ptr_visitor(), *it)) return true; | |
84 } | |
85 return false; | |
86 } | |
87 protected: | |
88 friend class detail::tracked_objects_visitor; | |
89 | |
90 void track_signal(const signal_base &signal) | |
91 { | |
92 _tracked_objects.push_back(signal.lock_pimpl()); | |
93 } | |
94 | |
95 tracked_container_type _tracked_objects; | |
96 }; | |
97 } | |
98 } // end namespace boost | |
99 | |
100 #endif // BOOST_SIGNALS2_SLOT_BASE_HPP |