1 // Boost.Signals library
3 // Copyright Douglas Gregor 2001-2004. Use, modification and
4 // distribution is subject to the Boost Software License, Version
5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // For more information, see http://www.boost.org
10 #ifndef BOOST_SIGNALS_SLOT_CALL_ITERATOR
11 #define BOOST_SIGNALS_SLOT_CALL_ITERATOR
14 #include <boost/iterator/iterator_facade.hpp>
15 #include <boost/smart_ptr.hpp>
16 #include <boost/signals/detail/config.hpp>
17 #include <boost/signals/connection.hpp>
19 #ifdef BOOST_HAS_ABI_HEADERS
20 # include BOOST_ABI_PREFIX
24 namespace BOOST_SIGNALS_NAMESPACE {
26 // A cached return value from a slot
28 struct cached_return_value {
29 cached_return_value(const T& t) : value(t) {}
34 // Generates a slot call iterator. Essentially, this is an iterator that:
35 // - skips over disconnected slots in the underlying list
36 // - calls the connected slots when dereferenced
37 // - caches the result of calling the slots
38 template<typename Function, typename Iterator>
39 class slot_call_iterator
40 : public iterator_facade<slot_call_iterator<Function, Iterator>,
41 typename Function::result_type,
42 single_pass_traversal_tag,
43 typename Function::result_type const&>
45 typedef iterator_facade<slot_call_iterator<Function, Iterator>,
46 typename Function::result_type,
47 single_pass_traversal_tag,
48 typename Function::result_type const&>
51 typedef typename Function::result_type result_type;
53 friend class iterator_core_access;
56 slot_call_iterator() {}
58 slot_call_iterator(Iterator iter_in, Iterator end_in, Function f)
59 : iter(iter_in), end(end_in), f(f), cache()
61 iter = std::find_if(iter, end, std::not1(is_disconnected()));
64 typename inherited::reference
68 cache.reset(new cached_return_value<result_type>(f(*iter)));
76 iter = std::find_if(++iter, end, std::not1(is_disconnected()));
80 bool equal(const slot_call_iterator& other) const
82 iter = std::find_if(iter, end, std::not1(is_disconnected()));
83 other.iter = std::find_if(other.iter, other.end,
84 std::not1(is_disconnected()));
85 return iter == other.iter;
89 mutable Iterator iter;
92 mutable shared_ptr< cached_return_value<result_type> > cache;
94 } // end namespace detail
95 } // end namespace BOOST_SIGNALS_NAMESPACE
96 } // end namespace boost
98 #ifdef BOOST_HAS_ABI_HEADERS
99 # include BOOST_ABI_SUFFIX
102 #endif // BOOST_SIGNALS_SLOT_CALL_ITERATOR