• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef BOOST_METAPARSE_V1_SOURCE_POSITION_HPP
2 #define BOOST_METAPARSE_V1_SOURCE_POSITION_HPP
3 
4 //    Copyright Abel Sinkovics (abel@sinkovics.hu) 2011.
5 // Distributed under the Boost Software License, Version 1.0.
6 //    (See accompanying file LICENSE_1_0.txt or copy at
7 //          http://www.boost.org/LICENSE_1_0.txt)
8 
9 #include <boost/metaparse/v1/fwd/source_position.hpp>
10 #include <boost/metaparse/v1/source_position_tag.hpp>
11 
12 
13 #include <boost/mpl/bool.hpp>
14 #include <boost/mpl/equal_to.hpp>
15 #include <boost/mpl/less.hpp>
16 
17 namespace boost
18 {
19   namespace metaparse
20   {
21     namespace v1
22     {
23       template <class Line, class Col, class PrevChar>
24       struct source_position
25       {
26         typedef source_position_tag tag;
27         typedef source_position type;
28 
29         typedef Line line;
30         typedef Col col;
31         typedef PrevChar prev_char;
32       };
33     }
34   }
35 }
36 
37 namespace boost
38 {
39   namespace mpl
40   {
41     template <class TagA, class TagB>
42     struct equal_to_impl;
43 
44     template <>
45     struct equal_to_impl<
46       boost::metaparse::v1::source_position_tag,
47       boost::metaparse::v1::source_position_tag
48     >
49     {
50       typedef equal_to_impl type;
51 
52       template <class A, class B>
53       struct apply :
54         bool_<
55           A::type::line::value == B::type::line::value
56           && A::type::col::value == B::type::col::value
57           && A::type::prev_char::value == B::type::prev_char::value
58         >
59       {};
60     };
61 
62     template <class TagA, class TagB>
63     struct not_equal_to_impl;
64 
65     template <>
66     struct not_equal_to_impl<
67       boost::metaparse::v1::source_position_tag,
68       boost::metaparse::v1::source_position_tag
69     >
70     {
71       typedef not_equal_to_impl type;
72 
73       template <class A, class B>
74       struct apply : bool_<!equal_to<A, B>::type::value> {};
75     };
76 
77     template <class TagA, class TagB>
78     struct less_impl;
79 
80     template <>
81     struct less_impl<
82       boost::metaparse::v1::source_position_tag,
83       boost::metaparse::v1::source_position_tag
84     >
85     {
86       typedef less_impl type;
87 
88       template <class A, class B>
89       struct apply :
90         bool_<(
91           (A::type::line::value) < (B::type::line::value) || (
92             (A::type::line::value) == (B::type::line::value) && (
93               (A::type::col::value) < (B::type::col::value) || (
94                 (A::type::col::value) == (B::type::col::value) &&
95                 (A::type::prev_char::value) < (B::type::prev_char::value)
96               )
97             )
98           )
99         )>
100       {};
101     };
102 
103     template <class TagA, class TagB>
104     struct greater_impl;
105 
106     template <>
107     struct greater_impl<
108       boost::metaparse::v1::source_position_tag,
109       boost::metaparse::v1::source_position_tag
110     >
111     {
112       typedef greater_impl type;
113 
114       template <class A, class B>
115       struct apply :
116         bool_<!(less<A, B>::type::value || equal_to<A, B>::type::value)>
117       {};
118     };
119 
120     template <class TagA, class TagB>
121     struct greater_equal_impl;
122 
123     template <>
124     struct greater_equal_impl<
125       boost::metaparse::v1::source_position_tag,
126       boost::metaparse::v1::source_position_tag
127     >
128     {
129       typedef greater_equal_impl type;
130 
131       template <class A, class B>
132       struct apply : bool_<!less<A, B>::type::value> {};
133     };
134 
135     template <class TagA, class TagB>
136     struct less_equal_impl;
137 
138     template <>
139     struct less_equal_impl<
140       boost::metaparse::v1::source_position_tag,
141       boost::metaparse::v1::source_position_tag
142     >
143     {
144       typedef less_equal_impl type;
145 
146       template <class A, class B>
147       struct apply :
148         bool_<less<A, B>::type::value || equal_to<A, B>::type::value>
149       {};
150     };
151 
152   }
153 }
154 
155 #endif
156 
157