simple_trigger.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Copyright (C) 2007 Douglas Gregor
  2. // Use, modification and distribution is subject to the Boost Software
  3. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // This file contains a simplification of the "trigger" method for
  6. // process groups. The simple trigger handles the common case where
  7. // the handler associated with a trigger is a member function bound to
  8. // a particular pointer.
  9. #ifndef BOOST_GRAPH_PARALLEL_SIMPLE_TRIGGER_HPP
  10. #define BOOST_GRAPH_PARALLEL_SIMPLE_TRIGGER_HPP
  11. #ifndef BOOST_GRAPH_USE_MPI
  12. #error "Parallel BGL files should not be included unless <boost/graph/use_mpi.hpp> has been included"
  13. #endif
  14. #include <boost/graph/parallel/process_group.hpp>
  15. namespace boost { namespace graph { namespace parallel {
  16. namespace detail {
  17. /**
  18. * INTERNAL ONLY
  19. *
  20. * The actual function object that bridges from the normal trigger
  21. * interface to the simplified interface. This is the equivalent of
  22. * bind(pmf, self, _1, _2, _3, _4), but without the compile-time
  23. * overhead of bind.
  24. */
  25. template<typename Class, typename T, typename Result>
  26. class simple_trigger_t
  27. {
  28. public:
  29. simple_trigger_t(Class* self,
  30. Result (Class::*pmf)(int, int, const T&,
  31. trigger_receive_context))
  32. : self(self), pmf(pmf) { }
  33. Result
  34. operator()(int source, int tag, const T& data,
  35. trigger_receive_context context) const
  36. {
  37. return (self->*pmf)(source, tag, data, context);
  38. }
  39. private:
  40. Class* self;
  41. Result (Class::*pmf)(int, int, const T&, trigger_receive_context);
  42. };
  43. } // end namespace detail
  44. /**
  45. * Simplified trigger interface that reduces the amount of code
  46. * required to connect a process group trigger to a handler that is
  47. * just a bound member function.
  48. *
  49. * INTERNAL ONLY
  50. */
  51. template<typename ProcessGroup, typename Class, typename T>
  52. inline void
  53. simple_trigger(ProcessGroup& pg, int tag, Class* self,
  54. void (Class::*pmf)(int source, int tag, const T& data,
  55. trigger_receive_context context), int)
  56. {
  57. pg.template trigger<T>(tag,
  58. detail::simple_trigger_t<Class, T, void>(self, pmf));
  59. }
  60. /**
  61. * Simplified trigger interface that reduces the amount of code
  62. * required to connect a process group trigger with a reply to a
  63. * handler that is just a bound member function.
  64. *
  65. * INTERNAL ONLY
  66. */
  67. template<typename ProcessGroup, typename Class, typename T, typename Result>
  68. inline void
  69. simple_trigger(ProcessGroup& pg, int tag, Class* self,
  70. Result (Class::*pmf)(int source, int tag, const T& data,
  71. trigger_receive_context context), long)
  72. {
  73. pg.template trigger_with_reply<T>
  74. (tag, detail::simple_trigger_t<Class, T, Result>(self, pmf));
  75. }
  76. /**
  77. * Simplified trigger interface that reduces the amount of code
  78. * required to connect a process group trigger to a handler that is
  79. * just a bound member function.
  80. */
  81. template<typename ProcessGroup, typename Class, typename T, typename Result>
  82. inline void
  83. simple_trigger(ProcessGroup& pg, int tag, Class* self,
  84. Result (Class::*pmf)(int source, int tag, const T& data,
  85. trigger_receive_context context))
  86. {
  87. // We pass 0 (an int) to help VC++ disambiguate calls to simple_trigger
  88. // with Result=void.
  89. simple_trigger(pg, tag, self, pmf, 0);
  90. }
  91. } } } // end namespace boost::graph::parallel
  92. #endif // BOOST_GRAPH_PARALLEL_SIMPLE_TRIGGER_HPP