comparison DEPENDENCIES/generic/include/boost/graph/parallel/simple_trigger.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
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_GRAPH_PARALLEL_SIMPLE_TRIGGER_HPP
13 #define BOOST_GRAPH_PARALLEL_SIMPLE_TRIGGER_HPP
14
15 #ifndef BOOST_GRAPH_USE_MPI
16 #error "Parallel BGL files should not be included unless <boost/graph/use_mpi.hpp> has been included"
17 #endif
18
19 #include <boost/graph/parallel/process_group.hpp>
20
21 namespace boost { namespace graph { namespace parallel {
22
23 namespace detail {
24
25 /**
26 * INTERNAL ONLY
27 *
28 * The actual function object that bridges from the normal trigger
29 * interface to the simplified interface. This is the equivalent of
30 * bind(pmf, self, _1, _2, _3, _4), but without the compile-time
31 * overhead of bind.
32 */
33 template<typename Class, typename T, typename Result>
34 class simple_trigger_t
35 {
36 public:
37 simple_trigger_t(Class* self,
38 Result (Class::*pmf)(int, int, const T&,
39 trigger_receive_context))
40 : self(self), pmf(pmf) { }
41
42 Result
43 operator()(int source, int tag, const T& data,
44 trigger_receive_context context) const
45 {
46 return (self->*pmf)(source, tag, data, context);
47 }
48
49 private:
50 Class* self;
51 Result (Class::*pmf)(int, int, const T&, trigger_receive_context);
52 };
53
54 } // end namespace detail
55
56 /**
57 * Simplified trigger interface that reduces the amount of code
58 * required to connect a process group trigger to a handler that is
59 * just a bound member function.
60 *
61 * INTERNAL ONLY
62 */
63 template<typename ProcessGroup, typename Class, typename T>
64 inline void
65 simple_trigger(ProcessGroup& pg, int tag, Class* self,
66 void (Class::*pmf)(int source, int tag, const T& data,
67 trigger_receive_context context), int)
68 {
69 pg.template trigger<T>(tag,
70 detail::simple_trigger_t<Class, T, void>(self, pmf));
71 }
72
73 /**
74 * Simplified trigger interface that reduces the amount of code
75 * required to connect a process group trigger with a reply to a
76 * handler that is just a bound member function.
77 *
78 * INTERNAL ONLY
79 */
80 template<typename ProcessGroup, typename Class, typename T, typename Result>
81 inline void
82 simple_trigger(ProcessGroup& pg, int tag, Class* self,
83 Result (Class::*pmf)(int source, int tag, const T& data,
84 trigger_receive_context context), long)
85 {
86 pg.template trigger_with_reply<T>
87 (tag, detail::simple_trigger_t<Class, T, Result>(self, pmf));
88 }
89
90 /**
91 * Simplified trigger interface that reduces the amount of code
92 * required to connect a process group trigger to a handler that is
93 * just a bound member function.
94 */
95 template<typename ProcessGroup, typename Class, typename T, typename Result>
96 inline void
97 simple_trigger(ProcessGroup& pg, int tag, Class* self,
98 Result (Class::*pmf)(int source, int tag, const T& data,
99 trigger_receive_context context))
100 {
101 // We pass 0 (an int) to help VC++ disambiguate calls to simple_trigger
102 // with Result=void.
103 simple_trigger(pg, tag, self, pmf, 0);
104 }
105
106 } } } // end namespace boost::graph::parallel
107
108 #endif // BOOST_GRAPH_PARALLEL_SIMPLE_TRIGGER_HPP