comparison DEPENDENCIES/generic/include/boost/spirit/home/classic/utility/impl/chset.ipp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
1 /*=============================================================================
2 Copyright (c) 2001-2003 Joel de Guzman
3 Copyright (c) 2001-2003 Daniel Nuffer
4 http://spirit.sourceforge.net/
5
6 Use, modification and distribution is subject to the Boost Software
7 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 http://www.boost.org/LICENSE_1_0.txt)
9 =============================================================================*/
10 #ifndef BOOST_SPIRIT_CHSET_IPP
11 #define BOOST_SPIRIT_CHSET_IPP
12
13 ///////////////////////////////////////////////////////////////////////////////
14 #include <boost/limits.hpp>
15 #include <boost/spirit/home/classic/utility/chset.hpp>
16
17 ///////////////////////////////////////////////////////////////////////////////
18 namespace boost { namespace spirit {
19
20 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
21
22 ///////////////////////////////////////////////////////////////////////////////
23 //
24 // chset class
25 //
26 ///////////////////////////////////////////////////////////////////////////////
27 namespace utility { namespace impl {
28 template <typename CharT>
29 inline void
30 detach(boost::shared_ptr<basic_chset<CharT> >& ptr)
31 {
32 if (!ptr.unique())
33 ptr = boost::shared_ptr<basic_chset<CharT> >
34 (new basic_chset<CharT>(*ptr));
35 }
36
37 template <typename CharT>
38 inline void
39 detach_clear(boost::shared_ptr<basic_chset<CharT> >& ptr)
40 {
41 if (ptr.unique())
42 ptr->clear();
43 else
44 ptr.reset(new basic_chset<CharT>());
45 }
46
47 template <typename CharT, typename CharT2>
48 void construct_chset(boost::shared_ptr<basic_chset<CharT> >& ptr,
49 CharT2 const* definition)
50 {
51 CharT2 ch = *definition++;
52 while (ch)
53 {
54 CharT2 next = *definition++;
55 if (next == '-')
56 {
57 next = *definition++;
58 if (next == 0)
59 {
60 ptr->set(ch);
61 ptr->set('-');
62 break;
63 }
64 ptr->set(ch, next);
65 }
66 else
67 {
68 ptr->set(ch);
69 }
70 ch = next;
71 }
72 }
73
74 //////////////////////////////////
75
76 #if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
77
78 template <typename CharT, typename FakeT>
79 void chset_negated_set(boost::shared_ptr<basic_chset<CharT> > &ptr, chlit<CharT> const &ch,
80 FakeT)
81 {
82 if(ch.ch != (std::numeric_limits<CharT>::min)()) {
83 ptr->set((std::numeric_limits<CharT>::min)(), ch.ch - 1);
84 }
85 if(ch.ch != (std::numeric_limits<CharT>::max)()) {
86 ptr->set(ch.ch + 1, (std::numeric_limits<CharT>::max)());
87 }
88 }
89
90 template <typename CharT, typename FakeT>
91 void chset_negated_set(boost::shared_ptr<basic_chset<CharT> > &ptr,
92 spirit::range<CharT> const &rng, FakeT)
93 {
94 if(rng.first != (std::numeric_limits<CharT>::min)()) {
95 ptr->set((std::numeric_limits<CharT>::min)(), rng.first - 1);
96 }
97 if(rng.last != (std::numeric_limits<CharT>::max)()) {
98 ptr->set(rng.last + 1, (std::numeric_limits<CharT>::max)());
99 }
100 }
101
102 #endif // BOOST_WORKAROUND(BOOST_MSVC, < 1300)
103
104 //////////////////////////////////
105
106 }} // namespace utility::impl
107
108 template <typename CharT>
109 inline chset<CharT>::chset()
110 : ptr(new basic_chset<CharT>()) {}
111
112 template <typename CharT>
113 inline chset<CharT>::chset(chset const& arg_)
114 : ptr(new basic_chset<CharT>(*arg_.ptr)) {}
115
116 template <typename CharT>
117 inline chset<CharT>::chset(CharT arg_)
118 : ptr(new basic_chset<CharT>())
119 { ptr->set(arg_); }
120
121 template <typename CharT>
122 inline chset<CharT>::chset(anychar_parser /*arg*/)
123 : ptr(new basic_chset<CharT>())
124 {
125 ptr->set(
126 (std::numeric_limits<CharT>::min)(),
127 (std::numeric_limits<CharT>::max)()
128 );
129 }
130
131 template <typename CharT>
132 inline chset<CharT>::chset(nothing_parser arg_)
133 : ptr(new basic_chset<CharT>()) {}
134
135 template <typename CharT>
136 inline chset<CharT>::chset(chlit<CharT> const& arg_)
137 : ptr(new basic_chset<CharT>())
138 { ptr->set(arg_.ch); }
139
140 template <typename CharT>
141 inline chset<CharT>::chset(range<CharT> const& arg_)
142 : ptr(new basic_chset<CharT>())
143 { ptr->set(arg_.first, arg_.last); }
144
145 #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
146
147 template <typename CharT>
148 inline chset<CharT>::chset(negated_char_parser<chlit<CharT> > const& arg_)
149 : ptr(new basic_chset<CharT>())
150 {
151 set(arg_);
152 }
153
154 template <typename CharT>
155 inline chset<CharT>::chset(negated_char_parser<range<CharT> > const& arg_)
156 : ptr(new basic_chset<CharT>())
157 {
158 set(arg_);
159 }
160
161 #endif // !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
162
163 template <typename CharT>
164 inline chset<CharT>::~chset() {}
165
166 template <typename CharT>
167 inline chset<CharT>&
168 chset<CharT>::operator=(chset const& rhs)
169 {
170 ptr = rhs.ptr;
171 return *this;
172 }
173
174 template <typename CharT>
175 inline chset<CharT>&
176 chset<CharT>::operator=(CharT rhs)
177 {
178 utility::impl::detach_clear(ptr);
179 ptr->set(rhs);
180 return *this;
181 }
182
183 template <typename CharT>
184 inline chset<CharT>&
185 chset<CharT>::operator=(anychar_parser rhs)
186 {
187 utility::impl::detach_clear(ptr);
188 ptr->set(
189 (std::numeric_limits<CharT>::min)(),
190 (std::numeric_limits<CharT>::max)()
191 );
192 return *this;
193 }
194
195 template <typename CharT>
196 inline chset<CharT>&
197 chset<CharT>::operator=(nothing_parser rhs)
198 {
199 utility::impl::detach_clear(ptr);
200 return *this;
201 }
202
203 template <typename CharT>
204 inline chset<CharT>&
205 chset<CharT>::operator=(chlit<CharT> const& rhs)
206 {
207 utility::impl::detach_clear(ptr);
208 ptr->set(rhs.ch);
209 return *this;
210 }
211
212 template <typename CharT>
213 inline chset<CharT>&
214 chset<CharT>::operator=(range<CharT> const& rhs)
215 {
216 utility::impl::detach_clear(ptr);
217 ptr->set(rhs.first, rhs.last);
218 return *this;
219 }
220
221 #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
222
223 template <typename CharT>
224 inline chset<CharT>&
225 chset<CharT>::operator=(negated_char_parser<chlit<CharT> > const& rhs)
226 {
227 utility::impl::detach_clear(ptr);
228 set(rhs);
229 return *this;
230 }
231
232 template <typename CharT>
233 inline chset<CharT>&
234 chset<CharT>::operator=(negated_char_parser<range<CharT> > const& rhs)
235 {
236 utility::impl::detach_clear(ptr);
237 set(rhs);
238 return *this;
239 }
240
241 #endif // !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
242
243 template <typename CharT>
244 inline void
245 chset<CharT>::set(range<CharT> const& arg_)
246 {
247 utility::impl::detach(ptr);
248 ptr->set(arg_.first, arg_.last);
249 }
250
251 #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
252
253 template <typename CharT>
254 inline void
255 chset<CharT>::set(negated_char_parser<chlit<CharT> > const& arg_)
256 {
257 utility::impl::detach(ptr);
258
259 if(arg_.positive.ch != (std::numeric_limits<CharT>::min)()) {
260 ptr->set((std::numeric_limits<CharT>::min)(), arg_.positive.ch - 1);
261 }
262 if(arg_.positive.ch != (std::numeric_limits<CharT>::max)()) {
263 ptr->set(arg_.positive.ch + 1, (std::numeric_limits<CharT>::max)());
264 }
265 }
266
267 template <typename CharT>
268 inline void
269 chset<CharT>::set(negated_char_parser<range<CharT> > const& arg_)
270 {
271 utility::impl::detach(ptr);
272
273 if(arg_.positive.first != (std::numeric_limits<CharT>::min)()) {
274 ptr->set((std::numeric_limits<CharT>::min)(), arg_.positive.first - 1);
275 }
276 if(arg_.positive.last != (std::numeric_limits<CharT>::max)()) {
277 ptr->set(arg_.positive.last + 1, (std::numeric_limits<CharT>::max)());
278 }
279 }
280
281 #endif // !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
282
283 template <typename CharT>
284 inline void
285 chset<CharT>::clear(range<CharT> const& arg_)
286 {
287 utility::impl::detach(ptr);
288 ptr->clear(arg_.first, arg_.last);
289 }
290
291 template <typename CharT>
292 inline void
293 chset<CharT>::clear(negated_char_parser<range<CharT> > const& arg_)
294 {
295 utility::impl::detach(ptr);
296
297 if(arg_.positive.first != (std::numeric_limits<CharT>::min)()) {
298 ptr->clear((std::numeric_limits<CharT>::min)(), arg_.positive.first - 1);
299 }
300 if(arg_.positive.last != (std::numeric_limits<CharT>::max)()) {
301 ptr->clear(arg_.positive.last + 1, (std::numeric_limits<CharT>::max)());
302 }
303 }
304
305 template <typename CharT>
306 inline bool
307 chset<CharT>::test(CharT ch) const
308 { return ptr->test(ch); }
309
310 template <typename CharT>
311 inline chset<CharT>&
312 chset<CharT>::inverse()
313 {
314 utility::impl::detach(ptr);
315 ptr->inverse();
316 return *this;
317 }
318
319 template <typename CharT>
320 inline void
321 chset<CharT>::swap(chset& x)
322 { ptr.swap(x.ptr); }
323
324 template <typename CharT>
325 inline chset<CharT>&
326 chset<CharT>::operator|=(chset const& x)
327 {
328 utility::impl::detach(ptr);
329 *ptr |= *x.ptr;
330 return *this;
331 }
332
333 template <typename CharT>
334 inline chset<CharT>&
335 chset<CharT>::operator&=(chset const& x)
336 {
337 utility::impl::detach(ptr);
338 *ptr &= *x.ptr;
339 return *this;
340 }
341
342 template <typename CharT>
343 inline chset<CharT>&
344 chset<CharT>::operator-=(chset const& x)
345 {
346 utility::impl::detach(ptr);
347 *ptr -= *x.ptr;
348 return *this;
349 }
350
351 template <typename CharT>
352 inline chset<CharT>&
353 chset<CharT>::operator^=(chset const& x)
354 {
355 utility::impl::detach(ptr);
356 *ptr ^= *x.ptr;
357 return *this;
358 }
359
360 ///////////////////////////////////////////////////////////////////////////////
361 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
362
363 }} // namespace boost::spirit
364
365 #endif
366