one_of_c.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef BOOST_METAPARSE_V1_CPP98_ONE_OF_C_HPP
  2. #define BOOST_METAPARSE_V1_CPP98_ONE_OF_C_HPP
  3. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2013.
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #include <boost/metaparse/v1/one_of.hpp>
  8. #include <boost/metaparse/v1/lit_c.hpp>
  9. #include <boost/metaparse/limit_one_of_size.hpp>
  10. #include <boost/preprocessor/arithmetic/sub.hpp>
  11. #include <boost/preprocessor/cat.hpp>
  12. #include <boost/preprocessor/punctuation/comma_if.hpp>
  13. #include <boost/preprocessor/repetition/enum.hpp>
  14. #include <boost/preprocessor/repetition/enum_params.hpp>
  15. #include <boost/preprocessor/repetition/enum_params_with_a_default.hpp>
  16. #include <boost/preprocessor/repetition/repeat.hpp>
  17. #include <boost/preprocessor/tuple/eat.hpp>
  18. #include <climits>
  19. namespace boost
  20. {
  21. namespace metaparse
  22. {
  23. namespace v1
  24. {
  25. #ifdef BOOST_NO_SCALAR_VALUE
  26. # error BOOST_NO_SCALAR_VALUE already defined
  27. #endif
  28. #define BOOST_NO_SCALAR_VALUE LONG_MAX
  29. template <
  30. BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(
  31. BOOST_METAPARSE_LIMIT_ONE_OF_SIZE,
  32. long C,
  33. BOOST_NO_SCALAR_VALUE
  34. )
  35. >
  36. struct one_of_c;
  37. #ifdef BOOST_METAPARSE_ONE_OF_C_LIT
  38. # error BOOST_METAPARSE_ONE_OF_C_LIT already defined
  39. #endif
  40. #define BOOST_METAPARSE_ONE_OF_C_LIT(z, n, unused) lit_c<BOOST_PP_CAT(C, n)>
  41. #ifdef BOOST_METAPARSE_ONE_OF_C_CASE
  42. # error BOOST_METAPARSE_ONE_OF_C_CASE already defined
  43. #endif
  44. #define BOOST_METAPARSE_ONE_OF_C_CASE(z, n, unused) \
  45. template <BOOST_PP_ENUM_PARAMS(n, long C)> \
  46. struct \
  47. one_of_c< \
  48. BOOST_PP_ENUM_PARAMS(n, C) \
  49. BOOST_PP_COMMA_IF(n) \
  50. BOOST_PP_ENUM( \
  51. BOOST_PP_SUB(BOOST_METAPARSE_LIMIT_ONE_OF_SIZE, n), \
  52. BOOST_NO_SCALAR_VALUE BOOST_PP_TUPLE_EAT(3), \
  53. ~ \
  54. ) \
  55. > : \
  56. one_of< BOOST_PP_ENUM(n, BOOST_METAPARSE_ONE_OF_C_LIT, ~) > \
  57. {};
  58. BOOST_PP_REPEAT(
  59. BOOST_METAPARSE_LIMIT_ONE_OF_SIZE,
  60. BOOST_METAPARSE_ONE_OF_C_CASE,
  61. ~
  62. )
  63. #undef BOOST_METAPARSE_ONE_OF_C_CASE
  64. #undef BOOST_METAPARSE_ONE_OF_C_LIT
  65. #undef BOOST_NO_SCALAR_VALUE
  66. }
  67. }
  68. }
  69. #endif