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>
18 #include <boost/optional.hpp>
20 #ifdef BOOST_HAS_ABI_HEADERS
21 # include BOOST_ABI_PREFIX
25 namespace BOOST_SIGNALS_NAMESPACE {
28 // Generates a slot call iterator. Essentially, this is an iterator that:
29 // - skips over disconnected slots in the underlying list
30 // - calls the connected slots when dereferenced
31 // - caches the result of calling the slots
32 template<typename Function, typename Iterator>
33 class slot_call_iterator
34 : public iterator_facade<slot_call_iterator<Function, Iterator>,
35 typename Function::result_type,
36 single_pass_traversal_tag,
37 typename Function::result_type const&>
39 typedef iterator_facade<slot_call_iterator<Function, Iterator>,
40 typename Function::result_type,
41 single_pass_traversal_tag,
42 typename Function::result_type const&>
45 typedef typename Function::result_type result_type;
47 friend class iterator_core_access;
50 slot_call_iterator(Iterator iter_in, Iterator end_in, Function func,
51 optional<result_type> &c)
52 : iter(iter_in), end(end_in), f(func), cache(&c)
54 iter = std::find_if(iter, end, is_callable());
57 typename inherited::reference
60 if (!cache->is_initialized()) {
61 cache->reset(f(*iter));
69 iter = std::find_if(++iter, end, is_callable());
73 bool equal(const slot_call_iterator& other) const
75 iter = std::find_if(iter, end, is_callable());
76 other.iter = std::find_if(other.iter, other.end,
78 return iter == other.iter;
82 mutable Iterator iter;
85 optional<result_type>* cache;
87 } // end namespace detail
88 } // end namespace BOOST_SIGNALS_NAMESPACE
89 } // end namespace boost
91 #ifdef BOOST_HAS_ABI_HEADERS
92 # include BOOST_ABI_SUFFIX
95 #endif // BOOST_SIGNALS_SLOT_CALL_ITERATOR