Chris@16: /* Chris@16: Helper class used by variadic implementation of variadic boost::signals2::signal. Chris@16: Chris@16: Author: Frank Mori Hess Chris@16: Begin: 2009-05-27 Chris@16: */ Chris@16: // Copyright Frank Mori Hess 2009 Chris@16: // 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_SIGNALS2_DETAIL_VARIADIC_SLOT_INVOKER_HPP Chris@16: #define BOOST_SIGNALS2_DETAIL_VARIADIC_SLOT_INVOKER_HPP Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: // if compiler has std::tuple use it instead of boost::tuple Chris@16: // because boost::tuple does not have variadic template support at present. Chris@16: #ifdef BOOST_NO_CXX11_HDR_TUPLE Chris@16: #include Chris@16: #define BOOST_SIGNALS2_TUPLE boost::tuple Chris@16: #define BOOST_SIGNALS2_GET boost::get Chris@16: #else Chris@16: #include Chris@16: #define BOOST_SIGNALS2_TUPLE std::tuple Chris@16: #define BOOST_SIGNALS2_GET std::get Chris@16: #endif Chris@16: Chris@16: namespace boost Chris@16: { Chris@16: namespace signals2 Chris@16: { Chris@16: namespace detail Chris@16: { Chris@16: template class unsigned_meta_array {}; Chris@16: Chris@16: template class unsigned_meta_array_appender; Chris@16: Chris@16: template Chris@16: class unsigned_meta_array_appender, n> Chris@16: { Chris@16: public: Chris@16: typedef unsigned_meta_array type; Chris@16: }; Chris@16: Chris@16: template class make_unsigned_meta_array; Chris@16: Chris@16: template<> class make_unsigned_meta_array<0> Chris@16: { Chris@16: public: Chris@16: typedef unsigned_meta_array<> type; Chris@16: }; Chris@16: Chris@16: template<> class make_unsigned_meta_array<1> Chris@16: { Chris@16: public: Chris@16: typedef unsigned_meta_array<0> type; Chris@16: }; Chris@16: Chris@16: template class make_unsigned_meta_array Chris@16: { Chris@16: public: Chris@16: typedef typename unsigned_meta_array_appender::type, n - 1>::type type; Chris@16: }; Chris@16: Chris@16: template Chris@16: class call_with_tuple_args Chris@16: { Chris@16: public: Chris@16: typedef R result_type; Chris@16: Chris@16: template Chris@16: R operator()(Func &func, BOOST_SIGNALS2_TUPLE args, mpl::size_t) const Chris@16: { Chris@16: typedef typename make_unsigned_meta_array::type indices_type; Chris@16: typename Func::result_type *resolver = 0; Chris@16: return m_invoke(resolver, func, indices_type(), args); Chris@16: } Chris@16: private: Chris@16: template Chris@16: R m_invoke(T *, Func &func, unsigned_meta_array, BOOST_SIGNALS2_TUPLE args) const Chris@16: { Chris@16: return func(BOOST_SIGNALS2_GET(args)...); Chris@16: } Chris@16: template Chris@16: R m_invoke(void *, Func &func, unsigned_meta_array, BOOST_SIGNALS2_TUPLE args) const Chris@16: { Chris@16: func(BOOST_SIGNALS2_GET(args)...); Chris@16: return R(); Chris@16: } Chris@101: // This overload is redundant, as it is the same as the previous variadic method when Chris@101: // it has zero "indices" or "Args" variadic template parameters. This overload Chris@101: // only exists to quiet some unused parameter warnings Chris@101: // on certain compilers (some versions of gcc and msvc) Chris@101: template Chris@101: R m_invoke(void *, Func &func, unsigned_meta_array<>, BOOST_SIGNALS2_TUPLE<>) const Chris@101: { Chris@101: func(); Chris@101: return R(); Chris@101: } Chris@16: }; Chris@16: Chris@16: template Chris@16: class variadic_slot_invoker Chris@16: { Chris@16: public: Chris@16: typedef R result_type; Chris@16: Chris@16: variadic_slot_invoker(Args & ... args): _args(args...) Chris@16: {} Chris@16: template Chris@16: result_type operator ()(const ConnectionBodyType &connectionBody) const Chris@16: { Chris@16: result_type *resolver = 0; Chris@16: return m_invoke(connectionBody, Chris@16: resolver); Chris@16: } Chris@16: private: Chris@16: template Chris@16: result_type m_invoke(const ConnectionBodyType &connectionBody, Chris@16: const void_type *) const Chris@16: { Chris@16: return call_with_tuple_args()(connectionBody->slot.slot_function(), _args, mpl::size_t()); Chris@16: } Chris@16: template Chris@16: result_type m_invoke(const ConnectionBodyType &connectionBody, ...) const Chris@16: { Chris@16: return call_with_tuple_args()(connectionBody->slot.slot_function(), _args, mpl::size_t()); Chris@16: } Chris@16: BOOST_SIGNALS2_TUPLE _args; Chris@16: }; Chris@16: } // namespace detail Chris@16: } // namespace signals2 Chris@16: } // namespace boost Chris@16: Chris@16: #endif // BOOST_SIGNALS2_DETAIL_VARIADIC_SLOT_INVOKER_HPP