simple_trigger.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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_PROPERTY_MAP_PARALLEL_SIMPLE_TRIGGER_HPP
  10. #define BOOST_PROPERTY_MAP_PARALLEL_SIMPLE_TRIGGER_HPP
  11. #include <boost/property_map/parallel/process_group.hpp>
  12. namespace boost { namespace parallel {
  13. namespace detail {
  14. /**
  15. * INTERNAL ONLY
  16. *
  17. * The actual function object that bridges from the normal trigger
  18. * interface to the simplified interface. This is the equivalent of
  19. * bind(pmf, self, _1, _2, _3, _4), but without the compile-time
  20. * overhead of bind.
  21. */
  22. template<typename Class, typename T, typename Result>
  23. class simple_trigger_t
  24. {
  25. public:
  26. simple_trigger_t(Class* self,
  27. Result (Class::*pmf)(int, int, const T&,
  28. trigger_receive_context))
  29. : self(self), pmf(pmf) { }
  30. Result
  31. operator()(int source, int tag, const T& data,
  32. trigger_receive_context context) const
  33. {
  34. return (self->*pmf)(source, tag, data, context);
  35. }
  36. private:
  37. Class* self;
  38. Result (Class::*pmf)(int, int, const T&, trigger_receive_context);
  39. };
  40. } // end namespace detail
  41. /**
  42. * Simplified trigger interface that reduces the amount of code
  43. * required to connect a process group trigger to a handler that is
  44. * just a bound member function.
  45. *
  46. * INTERNAL ONLY
  47. */
  48. template<typename ProcessGroup, typename Class, typename T>
  49. inline void
  50. simple_trigger(ProcessGroup& pg, int tag, Class* self,
  51. void (Class::*pmf)(int source, int tag, const T& data,
  52. trigger_receive_context context), int)
  53. {
  54. pg.template trigger<T>(tag,
  55. detail::simple_trigger_t<Class, T, void>(self, pmf));
  56. }
  57. /**
  58. * Simplified trigger interface that reduces the amount of code
  59. * required to connect a process group trigger with a reply to a
  60. * handler that is just a bound member function.
  61. *
  62. * INTERNAL ONLY
  63. */
  64. template<typename ProcessGroup, typename Class, typename T, typename Result>
  65. inline void
  66. simple_trigger(ProcessGroup& pg, int tag, Class* self,
  67. Result (Class::*pmf)(int source, int tag, const T& data,
  68. trigger_receive_context context), long)
  69. {
  70. pg.template trigger_with_reply<T>
  71. (tag, detail::simple_trigger_t<Class, T, Result>(self, pmf));
  72. }
  73. /**
  74. * Simplified trigger interface that reduces the amount of code
  75. * required to connect a process group trigger to a handler that is
  76. * just a bound member function.
  77. */
  78. template<typename ProcessGroup, typename Class, typename T, typename Result>
  79. inline void
  80. simple_trigger(ProcessGroup& pg, int tag, Class* self,
  81. Result (Class::*pmf)(int source, int tag, const T& data,
  82. trigger_receive_context context))
  83. {
  84. // We pass 0 (an int) to help VC++ disambiguate calls to simple_trigger
  85. // with Result=void.
  86. simple_trigger(pg, tag, self, pmf, 0);
  87. }
  88. } } // end namespace boost::parallel
  89. namespace boost { namespace graph { namespace parallel { using boost::parallel::simple_trigger; } } }
  90. #endif // BOOST_PROPERTY_MAP_PARALLEL_SIMPLE_TRIGGER_HPP