Chris@16: // Copyright (C) 2007 Douglas Gregor Chris@16: Chris@16: // Use, modification and distribution is subject to the Boost Software Chris@16: // License, Version 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: // This file contains a simplification of the "trigger" method for Chris@16: // process groups. The simple trigger handles the common case where Chris@16: // the handler associated with a trigger is a member function bound to Chris@16: // a particular pointer. Chris@16: Chris@16: #ifndef BOOST_GRAPH_PARALLEL_SIMPLE_TRIGGER_HPP Chris@16: #define BOOST_GRAPH_PARALLEL_SIMPLE_TRIGGER_HPP Chris@16: Chris@16: #ifndef BOOST_GRAPH_USE_MPI Chris@16: #error "Parallel BGL files should not be included unless has been included" Chris@16: #endif Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { namespace graph { namespace parallel { Chris@16: Chris@16: namespace detail { Chris@16: Chris@16: /** Chris@16: * INTERNAL ONLY Chris@16: * Chris@16: * The actual function object that bridges from the normal trigger Chris@16: * interface to the simplified interface. This is the equivalent of Chris@16: * bind(pmf, self, _1, _2, _3, _4), but without the compile-time Chris@16: * overhead of bind. Chris@16: */ Chris@16: template Chris@16: class simple_trigger_t Chris@16: { Chris@16: public: Chris@16: simple_trigger_t(Class* self, Chris@16: Result (Class::*pmf)(int, int, const T&, Chris@16: trigger_receive_context)) Chris@16: : self(self), pmf(pmf) { } Chris@16: Chris@16: Result Chris@16: operator()(int source, int tag, const T& data, Chris@16: trigger_receive_context context) const Chris@16: { Chris@16: return (self->*pmf)(source, tag, data, context); Chris@16: } Chris@16: Chris@16: private: Chris@16: Class* self; Chris@16: Result (Class::*pmf)(int, int, const T&, trigger_receive_context); Chris@16: }; Chris@16: Chris@16: } // end namespace detail Chris@16: Chris@16: /** Chris@16: * Simplified trigger interface that reduces the amount of code Chris@16: * required to connect a process group trigger to a handler that is Chris@16: * just a bound member function. Chris@16: * Chris@16: * INTERNAL ONLY Chris@16: */ Chris@16: template Chris@16: inline void Chris@16: simple_trigger(ProcessGroup& pg, int tag, Class* self, Chris@16: void (Class::*pmf)(int source, int tag, const T& data, Chris@16: trigger_receive_context context), int) Chris@16: { Chris@16: pg.template trigger(tag, Chris@16: detail::simple_trigger_t(self, pmf)); Chris@16: } Chris@16: Chris@16: /** Chris@16: * Simplified trigger interface that reduces the amount of code Chris@16: * required to connect a process group trigger with a reply to a Chris@16: * handler that is just a bound member function. Chris@16: * Chris@16: * INTERNAL ONLY Chris@16: */ Chris@16: template Chris@16: inline void Chris@16: simple_trigger(ProcessGroup& pg, int tag, Class* self, Chris@16: Result (Class::*pmf)(int source, int tag, const T& data, Chris@16: trigger_receive_context context), long) Chris@16: { Chris@16: pg.template trigger_with_reply Chris@16: (tag, detail::simple_trigger_t(self, pmf)); Chris@16: } Chris@16: Chris@16: /** Chris@16: * Simplified trigger interface that reduces the amount of code Chris@16: * required to connect a process group trigger to a handler that is Chris@16: * just a bound member function. Chris@16: */ Chris@16: template Chris@16: inline void Chris@16: simple_trigger(ProcessGroup& pg, int tag, Class* self, Chris@16: Result (Class::*pmf)(int source, int tag, const T& data, Chris@16: trigger_receive_context context)) Chris@16: { Chris@16: // We pass 0 (an int) to help VC++ disambiguate calls to simple_trigger Chris@16: // with Result=void. Chris@16: simple_trigger(pg, tag, self, pmf, 0); Chris@16: } Chris@16: Chris@16: } } } // end namespace boost::graph::parallel Chris@16: Chris@16: #endif // BOOST_GRAPH_PARALLEL_SIMPLE_TRIGGER_HPP