• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2007 Douglas Gregor
2 
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)
6 
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.
11 
12 #ifndef BOOST_PROPERTY_MAP_PARALLEL_SIMPLE_TRIGGER_HPP
13 #define BOOST_PROPERTY_MAP_PARALLEL_SIMPLE_TRIGGER_HPP
14 
15 #include <boost/property_map/parallel/process_group.hpp>
16 
17 namespace boost { namespace parallel {
18 
19 namespace detail {
20 
21 /**
22  * INTERNAL ONLY
23  *
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
27  * overhead of bind.
28  */
29 template<typename Class, typename T, typename Result>
30 class simple_trigger_t
31 {
32 public:
simple_trigger_t(Class * self,Result (Class::* pmf)(int,int,const T &,trigger_receive_context))33   simple_trigger_t(Class* self,
34                    Result (Class::*pmf)(int, int, const T&,
35                                         trigger_receive_context))
36     : self(self), pmf(pmf) { }
37 
38   Result
operator ()(int source,int tag,const T & data,trigger_receive_context context) const39   operator()(int source, int tag, const T& data,
40              trigger_receive_context context) const
41   {
42     return (self->*pmf)(source, tag, data, context);
43   }
44 
45 private:
46   Class* self;
47   Result (Class::*pmf)(int, int, const T&, trigger_receive_context);
48 };
49 
50 } // end namespace detail
51 
52 /**
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.
56  *
57  * INTERNAL ONLY
58  */
59 template<typename ProcessGroup, typename Class, typename T>
60 inline void
simple_trigger(ProcessGroup & pg,int tag,Class * self,void (Class::* pmf)(int source,int tag,const T & data,trigger_receive_context context),int)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)
64 {
65   pg.template trigger<T>(tag,
66                          detail::simple_trigger_t<Class, T, void>(self, pmf));
67 }
68 
69 /**
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.
73  *
74  * INTERNAL ONLY
75  */
76 template<typename ProcessGroup, typename Class, typename T, typename Result>
77 inline void
simple_trigger(ProcessGroup & pg,int tag,Class * self,Result (Class::* pmf)(int source,int tag,const T & data,trigger_receive_context context),long)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)
81 {
82   pg.template trigger_with_reply<T>
83     (tag, detail::simple_trigger_t<Class, T, Result>(self, pmf));
84 }
85 
86 /**
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.
90  */
91 template<typename ProcessGroup, typename Class, typename T, typename Result>
92 inline void
simple_trigger(ProcessGroup & pg,int tag,Class * self,Result (Class::* pmf)(int source,int tag,const T & data,trigger_receive_context context))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))
96 {
97         // We pass 0 (an int) to help VC++ disambiguate calls to simple_trigger
98         // with Result=void.
99         simple_trigger(pg, tag, self, pmf, 0);
100 }
101 
102 } } // end namespace boost::parallel
103 
104 namespace boost { namespace graph { namespace parallel { using boost::parallel::simple_trigger; } } }
105 
106 #endif // BOOST_PROPERTY_MAP_PARALLEL_SIMPLE_TRIGGER_HPP
107