/src/contrib/boost/spirit/home/support/action_dispatch.hpp

http://pythonocc.googlecode.com/ · C++ Header · 84 lines · 58 code · 11 blank · 15 comment · 0 complexity · d67ef71083b715e2f6e846a4a120aa62 MD5 · raw file

  1. /*=============================================================================
  2. Copyright (c) 2001-2010 Joel de Guzman
  3. Copyright (c) 2001-2010 Hartmut Kaiser
  4. http://spirit.sourceforge.net/
  5. Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. =============================================================================*/
  8. #if !defined(BOOST_SPIRIT_ACTION_DISPATCH_APRIL_18_2008_0720AM)
  9. #define BOOST_SPIRIT_ACTION_DISPATCH_APRIL_18_2008_0720AM
  10. #if defined(_MSC_VER)
  11. #pragma once
  12. #endif
  13. #include <boost/spirit/home/phoenix/core/actor.hpp>
  14. #include <boost/spirit/home/support/attributes.hpp>
  15. namespace boost { namespace spirit { namespace traits
  16. {
  17. template <typename Component>
  18. struct action_dispatch
  19. {
  20. // general handler for everything not explicitly specialized below
  21. template <typename F, typename Attribute, typename Context>
  22. bool operator()(F const& f, Attribute& attr, Context& context)
  23. {
  24. bool pass = true;
  25. f(attr, context, pass);
  26. return pass;
  27. }
  28. // handler for phoenix actors
  29. // If the component this action has to be invoked for is a tuple, we
  30. // wrap any non-fusion tuple into a fusion tuple (done by pass_attribute)
  31. // and pass through any fusion tuple.
  32. template <typename Eval, typename Attribute, typename Context>
  33. bool operator()(phoenix::actor<Eval> const& f
  34. , Attribute& attr, Context& context)
  35. {
  36. bool pass = true;
  37. typename pass_attribute<Component, Attribute>::type attr_wrap(attr);
  38. f(attr_wrap, context, pass);
  39. return pass;
  40. }
  41. // specializations for plain function pointers taking different number of
  42. // arguments
  43. template <typename RT, typename A0, typename A1, typename A2
  44. , typename Attribute, typename Context>
  45. bool operator()(RT(*f)(A0, A1, A2), Attribute& attr, Context& context)
  46. {
  47. bool pass = true;
  48. f(attr, context, pass);
  49. return pass;
  50. }
  51. template <typename RT, typename A0, typename A1
  52. , typename Attribute, typename Context>
  53. bool operator()(RT(*f)(A0, A1), Attribute& attr, Context& context)
  54. {
  55. f(attr, context);
  56. return true;
  57. }
  58. template <typename RT, typename A0, typename Attribute, typename Context>
  59. bool operator()(RT(*f)(A0), Attribute& attr, Context&)
  60. {
  61. f(attr);
  62. return true;
  63. }
  64. template <typename RT, typename Attribute, typename Context>
  65. bool operator()(RT(*f)(), Attribute&, Context&)
  66. {
  67. f();
  68. return true;
  69. }
  70. };
  71. }}}
  72. #endif