args.hpp 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2008 Christophe Henry
  2. // henry UNDERSCORE christophe AT hotmail DOT com
  3. // This is an extended version of the state machine available in the boost::mpl library
  4. // Distributed under the same license as the original.
  5. // Copyright for the original version:
  6. // Copyright 2005 David Abrahams and Aleksey Gurtovoy. Distributed
  7. // under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #ifndef BOOST_MSM_BACK_ARGS_H
  11. #define BOOST_MSM_BACK_ARGS_H
  12. #include <boost/preprocessor/repetition/enum_params.hpp>
  13. #include <boost/preprocessor/arithmetic/sub.hpp>
  14. #include <boost/preprocessor/punctuation/comma_if.hpp>
  15. #include <boost/preprocessor/control/expr_if.hpp>
  16. #include <boost/preprocessor/punctuation/comma.hpp>
  17. #include <boost/preprocessor/arithmetic/add.hpp>
  18. #include <boost/preprocessor/cat.hpp>
  19. #include <boost/preprocessor/comparison/less.hpp>
  20. #include <boost/preprocessor/arithmetic/dec.hpp>
  21. #include <boost/function.hpp>
  22. #ifndef BOOST_MSM_VISITOR_ARG_SIZE
  23. #define BOOST_MSM_VISITOR_ARG_SIZE 2 // default max number of arguments
  24. #endif
  25. namespace boost { namespace msm { namespace back
  26. {
  27. struct no_args {};
  28. #define MSM_ARGS_TYPEDEF_SUB(z, n, unused) typedef ARG ## n argument ## n ;
  29. #define MSM_ARGS_PRINT(z, n, data) data
  30. #define MSM_ARGS_NONE_PRINT(z, n, data) class data ## n = no_args \
  31. BOOST_PP_COMMA_IF( BOOST_PP_LESS(n, BOOST_PP_DEC(BOOST_MSM_VISITOR_ARG_SIZE) ) )
  32. #define MSM_VISITOR_MAIN_ARGS(n) \
  33. template <class RES, \
  34. BOOST_PP_REPEAT(BOOST_MSM_VISITOR_ARG_SIZE, MSM_ARGS_NONE_PRINT, ARG)> \
  35. struct args \
  36. { \
  37. typedef ::boost::function<RES(BOOST_PP_ENUM_PARAMS(n, ARG))> type; \
  38. enum {args_number=n}; \
  39. BOOST_PP_REPEAT(n, MSM_ARGS_TYPEDEF_SUB, ~ ) \
  40. };
  41. #define MSM_VISITOR_ARGS(z, n, unused) \
  42. template <class RES BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, class ARG)> \
  43. struct args<RES, \
  44. BOOST_PP_ENUM_PARAMS(n,ARG) \
  45. BOOST_PP_COMMA_IF(n) \
  46. BOOST_PP_ENUM(BOOST_PP_SUB(BOOST_MSM_VISITOR_ARG_SIZE,n), MSM_ARGS_PRINT, no_args) \
  47. > \
  48. { \
  49. typedef ::boost::function<RES(BOOST_PP_ENUM_PARAMS(n, ARG))> type; \
  50. enum {args_number=n}; \
  51. BOOST_PP_REPEAT(n, MSM_ARGS_TYPEDEF_SUB, ~ ) \
  52. };
  53. MSM_VISITOR_MAIN_ARGS(BOOST_MSM_VISITOR_ARG_SIZE)
  54. BOOST_PP_REPEAT(BOOST_MSM_VISITOR_ARG_SIZE, MSM_VISITOR_ARGS, ~)
  55. #undef MSM_VISITOR_ARGS
  56. #undef MSM_ARGS_PRINT
  57. }}}
  58. #endif //BOOST_MSM_BACK_ARGS_H