source_position.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #ifndef BOOST_METAPARSE_V1_SOURCE_POSITION_HPP
  2. #define BOOST_METAPARSE_V1_SOURCE_POSITION_HPP
  3. // Copyright Abel Sinkovics ([email protected]) 2011.
  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/fwd/source_position.hpp>
  8. #include <boost/metaparse/v1/source_position_tag.hpp>
  9. #include <boost/mpl/bool.hpp>
  10. #include <boost/mpl/equal_to.hpp>
  11. #include <boost/mpl/less.hpp>
  12. namespace boost
  13. {
  14. namespace metaparse
  15. {
  16. namespace v1
  17. {
  18. template <class Line, class Col, class PrevChar>
  19. struct source_position
  20. {
  21. typedef source_position_tag tag;
  22. typedef source_position type;
  23. typedef Line line;
  24. typedef Col col;
  25. typedef PrevChar prev_char;
  26. };
  27. }
  28. }
  29. }
  30. namespace boost
  31. {
  32. namespace mpl
  33. {
  34. template <class TagA, class TagB>
  35. struct equal_to_impl;
  36. template <>
  37. struct equal_to_impl<
  38. boost::metaparse::v1::source_position_tag,
  39. boost::metaparse::v1::source_position_tag
  40. >
  41. {
  42. typedef equal_to_impl type;
  43. template <class A, class B>
  44. struct apply :
  45. bool_<
  46. A::type::line::value == B::type::line::value
  47. && A::type::col::value == B::type::col::value
  48. && A::type::prev_char::value == B::type::prev_char::value
  49. >
  50. {};
  51. };
  52. template <class TagA, class TagB>
  53. struct not_equal_to_impl;
  54. template <>
  55. struct not_equal_to_impl<
  56. boost::metaparse::v1::source_position_tag,
  57. boost::metaparse::v1::source_position_tag
  58. >
  59. {
  60. typedef not_equal_to_impl type;
  61. template <class A, class B>
  62. struct apply : bool_<!equal_to<A, B>::type::value> {};
  63. };
  64. template <class TagA, class TagB>
  65. struct less_impl;
  66. template <>
  67. struct less_impl<
  68. boost::metaparse::v1::source_position_tag,
  69. boost::metaparse::v1::source_position_tag
  70. >
  71. {
  72. typedef less_impl type;
  73. template <class A, class B>
  74. struct apply :
  75. bool_<(
  76. (A::type::line::value) < (B::type::line::value) || (
  77. (A::type::line::value) == (B::type::line::value) && (
  78. (A::type::col::value) < (B::type::col::value) || (
  79. (A::type::col::value) == (B::type::col::value) &&
  80. (A::type::prev_char::value) < (B::type::prev_char::value)
  81. )
  82. )
  83. )
  84. )>
  85. {};
  86. };
  87. template <class TagA, class TagB>
  88. struct greater_impl;
  89. template <>
  90. struct greater_impl<
  91. boost::metaparse::v1::source_position_tag,
  92. boost::metaparse::v1::source_position_tag
  93. >
  94. {
  95. typedef greater_impl type;
  96. template <class A, class B>
  97. struct apply :
  98. bool_<!(less<A, B>::type::value || equal_to<A, B>::type::value)>
  99. {};
  100. };
  101. template <class TagA, class TagB>
  102. struct greater_equal_impl;
  103. template <>
  104. struct greater_equal_impl<
  105. boost::metaparse::v1::source_position_tag,
  106. boost::metaparse::v1::source_position_tag
  107. >
  108. {
  109. typedef greater_equal_impl type;
  110. template <class A, class B>
  111. struct apply : bool_<!less<A, B>::type::value> {};
  112. };
  113. template <class TagA, class TagB>
  114. struct less_equal_impl;
  115. template <>
  116. struct less_equal_impl<
  117. boost::metaparse::v1::source_position_tag,
  118. boost::metaparse::v1::source_position_tag
  119. >
  120. {
  121. typedef less_equal_impl type;
  122. template <class A, class B>
  123. struct apply :
  124. bool_<less<A, B>::type::value || equal_to<A, B>::type::value>
  125. {};
  126. };
  127. }
  128. }
  129. #endif