Chris@102: // Copyright (C) 2007 Douglas Gregor Chris@102: Chris@102: // Use, modification and distribution is subject to the Boost Software Chris@102: // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@102: // http://www.boost.org/LICENSE_1_0.txt) Chris@102: Chris@102: // This file contains a simplification of the "trigger" method for Chris@102: // process groups. The simple trigger handles the common case where Chris@102: // the handler associated with a trigger is a member function bound to Chris@102: // a particular pointer. Chris@102: Chris@102: #ifndef BOOST_PROPERTY_MAP_PARALLEL_SIMPLE_TRIGGER_HPP Chris@102: #define BOOST_PROPERTY_MAP_PARALLEL_SIMPLE_TRIGGER_HPP Chris@102: Chris@102: #include Chris@102: Chris@102: namespace boost { namespace parallel { Chris@102: Chris@102: namespace detail { Chris@102: Chris@102: /** Chris@102: * INTERNAL ONLY Chris@102: * Chris@102: * The actual function object that bridges from the normal trigger Chris@102: * interface to the simplified interface. This is the equivalent of Chris@102: * bind(pmf, self, _1, _2, _3, _4), but without the compile-time Chris@102: * overhead of bind. Chris@102: */ Chris@102: template Chris@102: class simple_trigger_t Chris@102: { Chris@102: public: Chris@102: simple_trigger_t(Class* self, Chris@102: Result (Class::*pmf)(int, int, const T&, Chris@102: trigger_receive_context)) Chris@102: : self(self), pmf(pmf) { } Chris@102: Chris@102: Result Chris@102: operator()(int source, int tag, const T& data, Chris@102: trigger_receive_context context) const Chris@102: { Chris@102: return (self->*pmf)(source, tag, data, context); Chris@102: } Chris@102: Chris@102: private: Chris@102: Class* self; Chris@102: Result (Class::*pmf)(int, int, const T&, trigger_receive_context); Chris@102: }; Chris@102: Chris@102: } // end namespace detail Chris@102: Chris@102: /** Chris@102: * Simplified trigger interface that reduces the amount of code Chris@102: * required to connect a process group trigger to a handler that is Chris@102: * just a bound member function. Chris@102: * Chris@102: * INTERNAL ONLY Chris@102: */ Chris@102: template Chris@102: inline void Chris@102: simple_trigger(ProcessGroup& pg, int tag, Class* self, Chris@102: void (Class::*pmf)(int source, int tag, const T& data, Chris@102: trigger_receive_context context), int) Chris@102: { Chris@102: pg.template trigger(tag, Chris@102: detail::simple_trigger_t(self, pmf)); Chris@102: } Chris@102: Chris@102: /** Chris@102: * Simplified trigger interface that reduces the amount of code Chris@102: * required to connect a process group trigger with a reply to a Chris@102: * handler that is just a bound member function. Chris@102: * Chris@102: * INTERNAL ONLY Chris@102: */ Chris@102: template Chris@102: inline void Chris@102: simple_trigger(ProcessGroup& pg, int tag, Class* self, Chris@102: Result (Class::*pmf)(int source, int tag, const T& data, Chris@102: trigger_receive_context context), long) Chris@102: { Chris@102: pg.template trigger_with_reply Chris@102: (tag, detail::simple_trigger_t(self, pmf)); Chris@102: } Chris@102: Chris@102: /** Chris@102: * Simplified trigger interface that reduces the amount of code Chris@102: * required to connect a process group trigger to a handler that is Chris@102: * just a bound member function. Chris@102: */ Chris@102: template Chris@102: inline void Chris@102: simple_trigger(ProcessGroup& pg, int tag, Class* self, Chris@102: Result (Class::*pmf)(int source, int tag, const T& data, Chris@102: trigger_receive_context context)) Chris@102: { Chris@102: // We pass 0 (an int) to help VC++ disambiguate calls to simple_trigger Chris@102: // with Result=void. Chris@102: simple_trigger(pg, tag, self, pmf, 0); Chris@102: } Chris@102: Chris@102: } } // end namespace boost::parallel Chris@102: Chris@102: namespace boost { namespace graph { namespace parallel { using boost::parallel::simple_trigger; } } } Chris@102: Chris@102: #endif // BOOST_PROPERTY_MAP_PARALLEL_SIMPLE_TRIGGER_HPP