one_of_c.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef BOOST_METAPARSE_V1_ONE_OF_C_HPP
  2. #define BOOST_METAPARSE_V1_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/preprocessor/arithmetic/sub.hpp>
  10. #include <boost/preprocessor/cat.hpp>
  11. #include <boost/preprocessor/punctuation/comma_if.hpp>
  12. #include <boost/preprocessor/repetition/enum.hpp>
  13. #include <boost/preprocessor/repetition/enum_params.hpp>
  14. #include <boost/preprocessor/repetition/enum_params_with_a_default.hpp>
  15. #include <boost/preprocessor/repetition/repeat.hpp>
  16. #include <boost/preprocessor/tuple/eat.hpp>
  17. #include <climits>
  18. namespace boost
  19. {
  20. namespace metaparse
  21. {
  22. namespace v1
  23. {
  24. #ifdef BOOST_NO_SCALAR_VALUE
  25. # error BOOST_NO_SCALAR_VALUE already defined
  26. #endif
  27. #define BOOST_NO_SCALAR_VALUE LONG_MAX
  28. template <
  29. BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(
  30. BOOST_METAPARSE_LIMIT_ONE_OF_SIZE,
  31. long C,
  32. BOOST_NO_SCALAR_VALUE
  33. )
  34. >
  35. struct one_of_c;
  36. #ifdef BOOST_METAPARSE_ONE_OF_C_LIT
  37. # error BOOST_METAPARSE_ONE_OF_C_LIT already defined
  38. #endif
  39. #define BOOST_METAPARSE_ONE_OF_C_LIT(z, n, unused) lit_c<BOOST_PP_CAT(C, n)>
  40. #ifdef BOOST_METAPARSE_ONE_OF_C_CASE
  41. # error BOOST_METAPARSE_ONE_OF_C_CASE already defined
  42. #endif
  43. #define BOOST_METAPARSE_ONE_OF_C_CASE(z, n, unused) \
  44. template <BOOST_PP_ENUM_PARAMS(n, long C)> \
  45. struct \
  46. one_of_c< \
  47. BOOST_PP_ENUM_PARAMS(n, C) \
  48. BOOST_PP_COMMA_IF(n) \
  49. BOOST_PP_ENUM( \
  50. BOOST_PP_SUB(BOOST_METAPARSE_LIMIT_ONE_OF_SIZE, n), \
  51. BOOST_NO_SCALAR_VALUE BOOST_PP_TUPLE_EAT(3), \
  52. ~ \
  53. ) \
  54. > : \
  55. one_of< BOOST_PP_ENUM(n, BOOST_METAPARSE_ONE_OF_C_LIT, ~) > \
  56. {};
  57. BOOST_PP_REPEAT(
  58. BOOST_METAPARSE_LIMIT_ONE_OF_SIZE,
  59. BOOST_METAPARSE_ONE_OF_C_CASE,
  60. ~
  61. )
  62. #undef BOOST_METAPARSE_ONE_OF_C_CASE
  63. #undef BOOST_METAPARSE_ONE_OF_C_LIT
  64. #undef BOOST_NO_SCALAR_VALUE
  65. }
  66. }
  67. }
  68. #endif