vmd_modifiers_filter.qbk 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. [/
  2. (C) Copyright Edward Diener 2011-2015
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. ]
  7. [section:vmd_modifiers_filter Filtering modifiers]
  8. Filtering modifiers are optional modifiers which work
  9. with some generic macros to specify a type of
  10. data to apply to the macro's functionality. The filtering
  11. modifier itself is an optional parameter specified as a
  12. v-type. Any v-type, specified as an optional parameter,
  13. may be used as a filtering modifier.
  14. [heading Usage with equality macros]
  15. The equality macros, BOOST_VMD_EQUAL and BOOST_VMD_NOT_EQUAL, tests
  16. generically whether each of its two required inputs are equal or
  17. not equal to each other.
  18. Each of these macro takes a single optional parameter, a filtering
  19. modifier, to narrow the focus of its equality testing to a particular
  20. v-type.
  21. For the macro BOOST_VMD_EQUAL this optional parameter when specified means
  22. that equality is not only that the two required input parameters are equal
  23. but also that they are of the type or of a subtype of the third optional
  24. parameter. A number and a v-type are subtypes of identifiers
  25. while a non-empty list and an array are subtypes of tuples.
  26. Conversely BOOST_VMD_NOT_EQUAL, with the optional third v-type parameter,
  27. returns 1 if either the first two parameters are not equal or if the type of
  28. the first two parameters is not the type or a subtype of the third parameter.
  29. Otherwise it returns 0. It is implemented as the complement of BOOST_VMD_EQUAL
  30. so that whenever BOOST_VMD_EQUAL returns 1, BOOST_VMD_NOT_EQUAL returns 0
  31. and vice versa.
  32. Here is an example of using BOOST_VMD_EQUAL with a filtering modifier.
  33. BOOST_VMD_NOT_EQUAL is just the complement of the results in our example
  34. for each result, and would be redundant to be specified each time below.
  35. #include <boost/vmd/equal.hpp>
  36. #define BOOST_VMD_REGISTER_AN_ID1 (AN_ID1)
  37. #define BOOST_VMD_REGISTER_AN_ID2 (AN_ID2)
  38. #define BOOST_VMD_DETECT_AN_ID1_AN_ID1
  39. #define BOOST_VMD_DETECT_AN_ID2_AN_ID2
  40. #define AN_IDENTIFIER1 AN_ID1
  41. #define AN_IDENTIFIER2 AN_ID2
  42. #define AN_IDENTIFIER3 AN_ID1 // same as AN_IDENTIFIER1 = AN_ID1
  43. #define A_NUMBER1 33
  44. #define A_NUMBER2 145
  45. #define A_NUMBER3 33 // same as A_NUMBER1 = 33
  46. #define A_TUPLE1 (AN_IDENTIFIER1,A_NUMBER1)
  47. #define A_TUPLE2 (AN_IDENTIFIER1,A_NUMBER2)
  48. #define A_TUPLE3 (AN_IDENTIFIER3,A_NUMBER3) // same as A_TUPLE1 = (AN_ID1,33)
  49. #define A_LIST1 (A_NUMBER1,(A_NUMBER3,BOOST_PP_NIL))
  50. #define A_LIST2 (A_NUMBER1,(A_NUMBER2,BOOST_PP_NIL))
  51. #define A_LIST3 (A_NUMBER1,(A_NUMBER3,BOOST_PP_NIL))
  52. #define A_LIST4 BOOST_PP_NIL // empty list
  53. #define A_LIST5 BOOST_PP_NIL // empty list
  54. BOOST_VMD_EQUAL(AN_IDENTIFIER1,AN_IDENTIFIER2,BOOST_VMD_TYPE_IDENTIFIER) will return 0
  55. BOOST_VMD_EQUAL(AN_IDENTIFIER1,AN_IDENTIFIER3,BOOST_VMD_TYPE_IDENTIFIER) will return 1
  56. BOOST_VMD_EQUAL(AN_IDENTIFIER1,AN_IDENTIFIER3,BOOST_VMD_TYPE_TYPE) will return 0 because the type does not match
  57. BOOST_VMD_EQUAL(A_NUMBER1,A_NUMBER2,BOOST_VMD_TYPE_NUMBER) will return 0
  58. BOOST_VMD_EQUAL(A_NUMBER1,A_NUMBER3,BOOST_VMD_TYPE_NUMBER) will return 1
  59. BOOST_VMD_EQUAL(A_NUMBER1,A_NUMBER3,BOOST_VMD_TYPE_IDENTIFIER) will return 1 because a number is an identifier
  60. BOOST_VMD_EQUAL(A_NUMBER1,A_NUMBER3,BOOST_VMD_TYPE_EMPTY) will return 0 because the type does not match
  61. BOOST_VMD_EQUAL(A_TUPLE1,A_TUPLE2,BOOST_VMD_TYPE_TUPLE) will return 0
  62. BOOST_VMD_EQUAL(A_TUPLE1,A_TUPLE3,BOOST_VMD_TYPE_TUPLE) will return 1
  63. BOOST_VMD_EQUAL(A_TUPLE1,A_TUPLE3,BOOST_VMD_TYPE_ARRAY) will return 0 because the type does not match
  64. BOOST_VMD_EQUAL(A_LIST1,A_LIST2,BOOST_VMD_TYPE_LIST) will return 0
  65. BOOST_VMD_EQUAL(A_LIST1,A_LIST3,BOOST_VMD_TYPE_LIST) will return 1
  66. BOOST_VMD_EQUAL(A_LIST1,A_LIST3,BOOST_VMD_TYPE_IDENTIFIER) will return 0 because the type does not match
  67. BOOST_VMD_EQUAL(A_LIST1,A_LIST3,BOOST_VMD_TYPE_TUPLE) will return 1 because a non-empty list is also a tuple
  68. BOOST_VMD_EQUAL(A_LIST4,A_LIST5,BOOST_VMD_TYPE_LIST) will return 1
  69. BOOST_VMD_EQUAL(A_LIST4,A_LIST5,BOOST_VMD_TYPE_IDENTIFIER) will return 1 because an empty list is also an identifier
  70. BOOST_VMD_EQUAL(A_LIST4,A_LIST5,BOOST_VMD_TYPE_TUPLE) will return 0 because an empty list is not a tuple
  71. [heading Usage with BOOST_VMD_ELEM]
  72. As with the equality macros BOOST_VMD_ELEM allows one to perform
  73. filtering for the result. An optional parameter of a v-type can be
  74. used so that BOOST_VMD_ELEM returns its result only if the sequence
  75. element is of the v-type specified, else it fails to find the
  76. element in the same way that an element number which is outside
  77. the bounds of the sequence fails.
  78. #include <boost/vmd/elem.hpp>
  79. #define BOOST_VMD_REGISTER_ANAME (ANAME) // an identifier must always be registered to be found by VMD
  80. #define A_SEQUENCE (1,2,3) 46 (list_data1,(list_data2,BOOST_PP_NIL)) BOOST_VMD_TYPE_SEQ ANAME
  81. BOOST_VMD_ELEM(0,A_SEQUENCE) will return (1,2,3)
  82. BOOST_VMD_ELEM(0,A_SEQUENCE,BOOST_VMD_TYPE_TUPLE) will return (1,2,3)
  83. BOOST_VMD_ELEM(0,A_SEQUENCE,BOOST_VMD_TYPE_SEQ) will return emptiness
  84. BOOST_VMD_ELEM(1,A_SEQUENCE) will return 46
  85. BOOST_VMD_ELEM(1,A_SEQUENCE,BOOST_VMD_TYPE_NUMBER) will return 46
  86. BOOST_VMD_ELEM(1,A_SEQUENCE,BOOST_VMD_TYPE_IDENTIFIER) will return 46 since a number is also an identifier
  87. BOOST_VMD_ELEM(1,A_SEQUENCE,BOOST_VMD_TYPE_LIST) will return emptiness
  88. BOOST_VMD_ELEM(2,A_SEQUENCE) will return (list_data1,(list_data2,BOOST_PP_NIL))
  89. BOOST_VMD_ELEM(2,A_SEQUENCE,BOOST_VMD_TYPE_LIST) will return (list_data1,(list_data2,BOOST_PP_NIL))
  90. BOOST_VMD_ELEM(2,A_SEQUENCE,BOOST_VMD_TYPE_TUPLE) will return (list_data1,(list_data2,BOOST_PP_NIL)) since a list is also a tuple
  91. BOOST_VMD_ELEM(2,A_SEQUENCE,BOOST_VMD_TYPE_TYPE) will return emptiness
  92. BOOST_VMD_ELEM(3,A_SEQUENCE) will return BOOST_VMD_TYPE_SEQ
  93. BOOST_VMD_ELEM(3,A_SEQUENCE,BOOST_VMD_TYPE_TYPE) will return BOOST_VMD_TYPE_SEQ
  94. BOOST_VMD_ELEM(3,A_SEQUENCE,BOOST_VMD_TYPE_IDENTIFIER) will return BOOST_VMD_TYPE_SEQ since a type is also an identifier
  95. BOOST_VMD_ELEM(3,A_SEQUENCE,BOOST_VMD_TYPE_TUPLE) will return emptiness
  96. BOOST_VMD_ELEM(4,A_SEQUENCE) will return ANAME
  97. BOOST_VMD_ELEM(4,A_SEQUENCE,BOOST_VMD_TYPE_IDENTIFIER) will return ANAME
  98. BOOST_VMD_ELEM(4,A_SEQUENCE,BOOST_VMD_TYPE_NUMBER) will return emptiness
  99. BOOST_VMD_ELEM(0,BOOST_PP_NIL) will return BOOST_PP_NIL
  100. BOOST_VMD_ELEM(0,BOOST_PP_NIL,BOOST_VMD_TYPE_LIST) will return BOOST_PP_NIL since it is an empty list
  101. BOOST_VMD_ELEM(0,BOOST_PP_NIL,BOOST_VMD_TYPE_IDENTIFIER) will return BOOST_PP_NIL since it a registered identifier
  102. BOOST_VMD_ELEM(0,BOOST_PP_NIL,BOOST_VMD_TYPE_TUPLE) will return emptiness
  103. If you specify more than one v-type as a filtering modifier to BOOST_VMD_ELEM
  104. the last v-type becomes the filter.
  105. Filtering with BOOST_VMD_ELEM denotes the type of the data expected when
  106. the particular element is found. Because filtering represents the type of
  107. the data requested, filtering modifiers and return type modifiers are
  108. mutually exclusive and any filtering modifier means that return
  109. type modifiers specified are ignored.
  110. [endsect]