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_SLOT_CALL_ITERATOR
|
Chris@16
|
11 #define BOOST_SIGNALS_SLOT_CALL_ITERATOR
|
Chris@16
|
12
|
Chris@16
|
13 #include <memory>
|
Chris@16
|
14 #include <boost/iterator/iterator_facade.hpp>
|
Chris@16
|
15 #include <boost/smart_ptr.hpp>
|
Chris@16
|
16 #include <boost/signals/detail/config.hpp>
|
Chris@16
|
17 #include <boost/signals/connection.hpp>
|
Chris@16
|
18 #include <boost/optional.hpp>
|
Chris@16
|
19
|
Chris@16
|
20 #ifdef BOOST_HAS_ABI_HEADERS
|
Chris@16
|
21 # include BOOST_ABI_PREFIX
|
Chris@16
|
22 #endif
|
Chris@16
|
23
|
Chris@16
|
24 namespace boost {
|
Chris@16
|
25 namespace BOOST_SIGNALS_NAMESPACE {
|
Chris@16
|
26 namespace detail {
|
Chris@16
|
27
|
Chris@16
|
28 // Generates a slot call iterator. Essentially, this is an iterator that:
|
Chris@16
|
29 // - skips over disconnected slots in the underlying list
|
Chris@16
|
30 // - calls the connected slots when dereferenced
|
Chris@16
|
31 // - caches the result of calling the slots
|
Chris@16
|
32 template<typename Function, typename Iterator>
|
Chris@16
|
33 class slot_call_iterator
|
Chris@16
|
34 : public iterator_facade<slot_call_iterator<Function, Iterator>,
|
Chris@16
|
35 typename Function::result_type,
|
Chris@16
|
36 single_pass_traversal_tag,
|
Chris@16
|
37 typename Function::result_type const&>
|
Chris@16
|
38 {
|
Chris@16
|
39 typedef iterator_facade<slot_call_iterator<Function, Iterator>,
|
Chris@16
|
40 typename Function::result_type,
|
Chris@16
|
41 single_pass_traversal_tag,
|
Chris@16
|
42 typename Function::result_type const&>
|
Chris@16
|
43 inherited;
|
Chris@16
|
44
|
Chris@16
|
45 typedef typename Function::result_type result_type;
|
Chris@16
|
46
|
Chris@16
|
47 friend class iterator_core_access;
|
Chris@16
|
48
|
Chris@16
|
49 public:
|
Chris@16
|
50 slot_call_iterator(Iterator iter_in, Iterator end_in, Function func,
|
Chris@16
|
51 optional<result_type> &c)
|
Chris@16
|
52 : iter(iter_in), end(end_in), f(func), cache(&c)
|
Chris@16
|
53 {
|
Chris@16
|
54 iter = std::find_if(iter, end, is_callable());
|
Chris@16
|
55 }
|
Chris@16
|
56
|
Chris@16
|
57 typename inherited::reference
|
Chris@16
|
58 dereference() const
|
Chris@16
|
59 {
|
Chris@16
|
60 if (!cache->is_initialized()) {
|
Chris@16
|
61 cache->reset(f(*iter));
|
Chris@16
|
62 }
|
Chris@16
|
63
|
Chris@16
|
64 return cache->get();
|
Chris@16
|
65 }
|
Chris@16
|
66
|
Chris@16
|
67 void increment()
|
Chris@16
|
68 {
|
Chris@16
|
69 iter = std::find_if(++iter, end, is_callable());
|
Chris@16
|
70 cache->reset();
|
Chris@16
|
71 }
|
Chris@16
|
72
|
Chris@16
|
73 bool equal(const slot_call_iterator& other) const
|
Chris@16
|
74 {
|
Chris@16
|
75 iter = std::find_if(iter, end, is_callable());
|
Chris@16
|
76 other.iter = std::find_if(other.iter, other.end,
|
Chris@16
|
77 is_callable());
|
Chris@16
|
78 return iter == other.iter;
|
Chris@16
|
79 }
|
Chris@16
|
80
|
Chris@16
|
81 private:
|
Chris@16
|
82 mutable Iterator iter;
|
Chris@16
|
83 Iterator end;
|
Chris@16
|
84 Function f;
|
Chris@16
|
85 optional<result_type>* cache;
|
Chris@16
|
86 };
|
Chris@16
|
87 } // end namespace detail
|
Chris@16
|
88 } // end namespace BOOST_SIGNALS_NAMESPACE
|
Chris@16
|
89 } // end namespace boost
|
Chris@16
|
90
|
Chris@16
|
91 #ifdef BOOST_HAS_ABI_HEADERS
|
Chris@16
|
92 # include BOOST_ABI_SUFFIX
|
Chris@16
|
93 #endif
|
Chris@16
|
94
|
Chris@16
|
95 #endif // BOOST_SIGNALS_SLOT_CALL_ITERATOR
|