match_identifier.hpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // (C) Copyright Edward Diener 2011-2015
  2. // Use, modification and distribution are subject to the Boost Software License,
  3. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt).
  5. #if !defined(BOOST_VMD_DETAIL_MATCH_IDENTIFIER_HPP)
  6. #define BOOST_VMD_DETAIL_MATCH_IDENTIFIER_HPP
  7. #include <boost/preprocessor/arithmetic/inc.hpp>
  8. #include <boost/preprocessor/cat.hpp>
  9. #include <boost/preprocessor/comparison/equal.hpp>
  10. #include <boost/preprocessor/comparison/not_equal.hpp>
  11. #include <boost/preprocessor/control/iif.hpp>
  12. #include <boost/preprocessor/control/while.hpp>
  13. #include <boost/preprocessor/logical/bitand.hpp>
  14. #include <boost/preprocessor/tuple/elem.hpp>
  15. #include <boost/preprocessor/tuple/replace.hpp>
  16. #include <boost/preprocessor/tuple/size.hpp>
  17. #include <boost/vmd/is_empty.hpp>
  18. #include <boost/vmd/detail/idprefix.hpp>
  19. #include <boost/vmd/detail/match_identifier_common.hpp>
  20. #define BOOST_VMD_DETAIL_MATCH_IDENTIFIER_STATE_ID(state) \
  21. BOOST_PP_TUPLE_ELEM(0,state) \
  22. /**/
  23. #define BOOST_VMD_DETAIL_MATCH_IDENTIFIER_STATE_KEY_TUPLE(state) \
  24. BOOST_PP_TUPLE_ELEM(1,state) \
  25. /**/
  26. #define BOOST_VMD_DETAIL_MATCH_IDENTIFIER_STATE_KEY_TUPLE_SIZE(state) \
  27. BOOST_PP_TUPLE_ELEM(2,state) \
  28. /**/
  29. #define BOOST_VMD_DETAIL_MATCH_IDENTIFIER_STATE_KEY_CURRENT(state) \
  30. BOOST_PP_TUPLE_ELEM \
  31. ( \
  32. BOOST_VMD_DETAIL_MATCH_IDENTIFIER_STATE_INDEX(state), \
  33. BOOST_VMD_DETAIL_MATCH_IDENTIFIER_STATE_KEY_TUPLE(state) \
  34. ) \
  35. /**/
  36. #define BOOST_VMD_DETAIL_MATCH_IDENTIFIER_STATE_INDEX(state) \
  37. BOOST_PP_TUPLE_ELEM(3,state) \
  38. /**/
  39. #define BOOST_VMD_DETAIL_MATCH_IDENTIFIER_STATE_RESULT(state) \
  40. BOOST_PP_TUPLE_ELEM(4,state) \
  41. /**/
  42. #define BOOST_VMD_DETAIL_MATCH_IDENTIFIER_PRED(d,state) \
  43. BOOST_PP_BITAND \
  44. ( \
  45. BOOST_PP_EQUAL_D \
  46. ( \
  47. d, \
  48. BOOST_VMD_DETAIL_MATCH_IDENTIFIER_STATE_RESULT(state), \
  49. 0 \
  50. ), \
  51. BOOST_PP_NOT_EQUAL_D \
  52. ( \
  53. d, \
  54. BOOST_VMD_DETAIL_MATCH_IDENTIFIER_STATE_INDEX(state), \
  55. BOOST_VMD_DETAIL_MATCH_IDENTIFIER_STATE_KEY_TUPLE_SIZE(state) \
  56. ) \
  57. ) \
  58. /**/
  59. #define BOOST_VMD_DETAIL_MATCH_IDENTIFIER_OP_FOUND(d,state) \
  60. BOOST_PP_TUPLE_REPLACE_D \
  61. ( \
  62. d, \
  63. state, \
  64. 4, \
  65. BOOST_PP_INC \
  66. ( \
  67. BOOST_VMD_DETAIL_MATCH_IDENTIFIER_STATE_INDEX(state) \
  68. ) \
  69. ) \
  70. /**/
  71. #define BOOST_VMD_DETAIL_MATCH_IDENTIFIER_OP_CONTINUE(d,state) \
  72. BOOST_PP_TUPLE_REPLACE_D \
  73. ( \
  74. d, \
  75. state, \
  76. 3, \
  77. BOOST_PP_INC \
  78. ( \
  79. BOOST_VMD_DETAIL_MATCH_IDENTIFIER_STATE_INDEX(state) \
  80. ) \
  81. ) \
  82. /**/
  83. #define BOOST_VMD_DETAIL_MATCH_IDENTIFIER_OP(d,state) \
  84. BOOST_PP_IIF \
  85. ( \
  86. BOOST_VMD_DETAIL_MATCH_IDENTIFIER_OP_CMP_IDS \
  87. ( \
  88. BOOST_VMD_DETAIL_MATCH_IDENTIFIER_STATE_ID(state), \
  89. BOOST_VMD_DETAIL_MATCH_IDENTIFIER_STATE_KEY_CURRENT(state) \
  90. ), \
  91. BOOST_VMD_DETAIL_MATCH_IDENTIFIER_OP_FOUND, \
  92. BOOST_VMD_DETAIL_MATCH_IDENTIFIER_OP_CONTINUE \
  93. ) \
  94. (d,state) \
  95. /**/
  96. /*
  97. Return index starting with 1 of the tuple id the identifier matches, or 0 if there are no matches.
  98. */
  99. #define BOOST_VMD_DETAIL_MATCH_IDENTIFIER(id,keytuple) \
  100. BOOST_PP_TUPLE_ELEM \
  101. ( \
  102. 4, \
  103. BOOST_PP_WHILE \
  104. ( \
  105. BOOST_VMD_DETAIL_MATCH_IDENTIFIER_PRED, \
  106. BOOST_VMD_DETAIL_MATCH_IDENTIFIER_OP, \
  107. ( \
  108. id, \
  109. keytuple, \
  110. BOOST_PP_TUPLE_SIZE(keytuple), \
  111. 0, \
  112. 0 \
  113. ) \
  114. ) \
  115. ) \
  116. /**/
  117. /*
  118. Return index starting with 1 of the tuple id the identifier matches, or 0 if there are no matches.
  119. */
  120. #define BOOST_VMD_DETAIL_MATCH_IDENTIFIER_D(d,id,keytuple) \
  121. BOOST_PP_TUPLE_ELEM \
  122. ( \
  123. 4, \
  124. BOOST_PP_WHILE_ ## d \
  125. ( \
  126. BOOST_VMD_DETAIL_MATCH_IDENTIFIER_PRED, \
  127. BOOST_VMD_DETAIL_MATCH_IDENTIFIER_OP, \
  128. ( \
  129. id, \
  130. keytuple, \
  131. BOOST_PP_TUPLE_SIZE(keytuple), \
  132. 0, \
  133. 0 \
  134. ) \
  135. ) \
  136. ) \
  137. /**/
  138. #endif /* BOOST_VMD_DETAIL_MATCH_IDENTIFIER_HPP */