Chris@16: // Boost.Signals library Chris@16: Chris@16: // Copyright Douglas Gregor 2001-2004. Use, modification and Chris@16: // distribution is subject to the Boost Software License, Version Chris@16: // 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: // For more information, see http://www.boost.org Chris@16: Chris@16: #ifndef BOOST_SIGNALS_SLOT_CALL_ITERATOR Chris@16: #define BOOST_SIGNALS_SLOT_CALL_ITERATOR Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #ifdef BOOST_HAS_ABI_HEADERS Chris@16: # include BOOST_ABI_PREFIX Chris@16: #endif Chris@16: Chris@16: namespace boost { Chris@16: namespace BOOST_SIGNALS_NAMESPACE { Chris@16: namespace detail { Chris@16: Chris@16: // Generates a slot call iterator. Essentially, this is an iterator that: Chris@16: // - skips over disconnected slots in the underlying list Chris@16: // - calls the connected slots when dereferenced Chris@16: // - caches the result of calling the slots Chris@16: template Chris@16: class slot_call_iterator Chris@16: : public iterator_facade, Chris@16: typename Function::result_type, Chris@16: single_pass_traversal_tag, Chris@16: typename Function::result_type const&> Chris@16: { Chris@16: typedef iterator_facade, Chris@16: typename Function::result_type, Chris@16: single_pass_traversal_tag, Chris@16: typename Function::result_type const&> Chris@16: inherited; Chris@16: Chris@16: typedef typename Function::result_type result_type; Chris@16: Chris@16: friend class iterator_core_access; Chris@16: Chris@16: public: Chris@16: slot_call_iterator(Iterator iter_in, Iterator end_in, Function func, Chris@16: optional &c) Chris@16: : iter(iter_in), end(end_in), f(func), cache(&c) Chris@16: { Chris@16: iter = std::find_if(iter, end, is_callable()); Chris@16: } Chris@16: Chris@16: typename inherited::reference Chris@16: dereference() const Chris@16: { Chris@16: if (!cache->is_initialized()) { Chris@16: cache->reset(f(*iter)); Chris@16: } Chris@16: Chris@16: return cache->get(); Chris@16: } Chris@16: Chris@16: void increment() Chris@16: { Chris@16: iter = std::find_if(++iter, end, is_callable()); Chris@16: cache->reset(); Chris@16: } Chris@16: Chris@16: bool equal(const slot_call_iterator& other) const Chris@16: { Chris@16: iter = std::find_if(iter, end, is_callable()); Chris@16: other.iter = std::find_if(other.iter, other.end, Chris@16: is_callable()); Chris@16: return iter == other.iter; Chris@16: } Chris@16: Chris@16: private: Chris@16: mutable Iterator iter; Chris@16: Iterator end; Chris@16: Function f; Chris@16: optional* cache; Chris@16: }; Chris@16: } // end namespace detail Chris@16: } // end namespace BOOST_SIGNALS_NAMESPACE Chris@16: } // end namespace boost Chris@16: Chris@16: #ifdef BOOST_HAS_ABI_HEADERS Chris@16: # include BOOST_ABI_SUFFIX Chris@16: #endif Chris@16: Chris@16: #endif // BOOST_SIGNALS_SLOT_CALL_ITERATOR