1 // Copyright (C) 2007 Douglas Gregor
3 // Use, modification and distribution is subject to the Boost Software
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 // This file contains a simplification of the "trigger" method for
8 // process groups. The simple trigger handles the common case where
9 // the handler associated with a trigger is a member function bound to
10 // a particular pointer.
12 #ifndef BOOST_PROPERTY_MAP_PARALLEL_SIMPLE_TRIGGER_HPP
13 #define BOOST_PROPERTY_MAP_PARALLEL_SIMPLE_TRIGGER_HPP
15 #include <boost/property_map/parallel/process_group.hpp>
17 namespace boost { namespace parallel {
24 * The actual function object that bridges from the normal trigger
25 * interface to the simplified interface. This is the equivalent of
26 * bind(pmf, self, _1, _2, _3, _4), but without the compile-time
29 template<typename Class, typename T, typename Result>
30 class simple_trigger_t
33 simple_trigger_t(Class* self,
34 Result (Class::*pmf)(int, int, const T&,
35 trigger_receive_context))
36 : self(self), pmf(pmf) { }
39 operator()(int source, int tag, const T& data,
40 trigger_receive_context context) const
42 return (self->*pmf)(source, tag, data, context);
47 Result (Class::*pmf)(int, int, const T&, trigger_receive_context);
50 } // end namespace detail
53 * Simplified trigger interface that reduces the amount of code
54 * required to connect a process group trigger to a handler that is
55 * just a bound member function.
59 template<typename ProcessGroup, typename Class, typename T>
61 simple_trigger(ProcessGroup& pg, int tag, Class* self,
62 void (Class::*pmf)(int source, int tag, const T& data,
63 trigger_receive_context context), int)
65 pg.template trigger<T>(tag,
66 detail::simple_trigger_t<Class, T, void>(self, pmf));
70 * Simplified trigger interface that reduces the amount of code
71 * required to connect a process group trigger with a reply to a
72 * handler that is just a bound member function.
76 template<typename ProcessGroup, typename Class, typename T, typename Result>
78 simple_trigger(ProcessGroup& pg, int tag, Class* self,
79 Result (Class::*pmf)(int source, int tag, const T& data,
80 trigger_receive_context context), long)
82 pg.template trigger_with_reply<T>
83 (tag, detail::simple_trigger_t<Class, T, Result>(self, pmf));
87 * Simplified trigger interface that reduces the amount of code
88 * required to connect a process group trigger to a handler that is
89 * just a bound member function.
91 template<typename ProcessGroup, typename Class, typename T, typename Result>
93 simple_trigger(ProcessGroup& pg, int tag, Class* self,
94 Result (Class::*pmf)(int source, int tag, const T& data,
95 trigger_receive_context context))
97 // We pass 0 (an int) to help VC++ disambiguate calls to simple_trigger
99 simple_trigger(pg, tag, self, pmf, 0);
102 } } // end namespace boost::parallel
104 namespace boost { namespace graph { namespace parallel { using boost::parallel::simple_trigger; } } }
106 #endif // BOOST_PROPERTY_MAP_PARALLEL_SIMPLE_TRIGGER_HPP