]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/include/boost/spirit/home/classic/utility/impl/chset_operators.ipp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / spirit / include / boost / spirit / home / classic / utility / impl / chset_operators.ipp
1 /*=============================================================================
2 Copyright (c) 2001-2003 Joel de Guzman
3 http://spirit.sourceforge.net/
4
5 Use, modification and distribution is subject to the Boost Software
6 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 http://www.boost.org/LICENSE_1_0.txt)
8 =============================================================================*/
9 #ifndef BOOST_SPIRIT_CHSET_OPERATORS_IPP
10 #define BOOST_SPIRIT_CHSET_OPERATORS_IPP
11
12 ///////////////////////////////////////////////////////////////////////////////
13 #include <boost/limits.hpp>
14
15 ///////////////////////////////////////////////////////////////////////////////
16 namespace boost { namespace spirit {
17
18 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
19
20 ///////////////////////////////////////////////////////////////////////////////
21 //
22 // chset free operators implementation
23 //
24 ///////////////////////////////////////////////////////////////////////////////
25 template <typename CharT>
26 inline chset<CharT>
27 operator|(chset<CharT> const& a, chset<CharT> const& b)
28 {
29 return chset<CharT>(a) |= b;
30 }
31
32 //////////////////////////////////
33 template <typename CharT>
34 inline chset<CharT>
35 operator-(chset<CharT> const& a, chset<CharT> const& b)
36 {
37 return chset<CharT>(a) -= b;
38 }
39
40 //////////////////////////////////
41 template <typename CharT>
42 inline chset<CharT>
43 operator~(chset<CharT> const& a)
44 {
45 return chset<CharT>(a).inverse();
46 }
47
48 //////////////////////////////////
49 template <typename CharT>
50 inline chset<CharT>
51 operator&(chset<CharT> const& a, chset<CharT> const& b)
52 {
53 return chset<CharT>(a) &= b;
54 }
55
56 //////////////////////////////////
57 template <typename CharT>
58 inline chset<CharT>
59 operator^(chset<CharT> const& a, chset<CharT> const& b)
60 {
61 return chset<CharT>(a) ^= b;
62 }
63
64 ///////////////////////////////////////////////////////////////////////////////
65 //
66 // range <--> chset free operators implementation
67 //
68 ///////////////////////////////////////////////////////////////////////////////
69 template <typename CharT>
70 inline chset<CharT>
71 operator|(chset<CharT> const& a, range<CharT> const& b)
72 {
73 chset<CharT> a_(a);
74 a_.set(b);
75 return a_;
76 }
77
78 //////////////////////////////////
79 template <typename CharT>
80 inline chset<CharT>
81 operator&(chset<CharT> const& a, range<CharT> const& b)
82 {
83 chset<CharT> a_(a);
84 if(b.first != (std::numeric_limits<CharT>::min)()) {
85 a_.clear(range<CharT>((std::numeric_limits<CharT>::min)(), b.first - 1));
86 }
87 if(b.last != (std::numeric_limits<CharT>::max)()) {
88 a_.clear(range<CharT>(b.last + 1, (std::numeric_limits<CharT>::max)()));
89 }
90 return a_;
91 }
92
93 //////////////////////////////////
94 template <typename CharT>
95 inline chset<CharT>
96 operator-(chset<CharT> const& a, range<CharT> const& b)
97 {
98 chset<CharT> a_(a);
99 a_.clear(b);
100 return a_;
101 }
102
103 //////////////////////////////////
104 template <typename CharT>
105 inline chset<CharT>
106 operator^(chset<CharT> const& a, range<CharT> const& b)
107 {
108 return a ^ chset<CharT>(b);
109 }
110
111 //////////////////////////////////
112 template <typename CharT>
113 inline chset<CharT>
114 operator|(range<CharT> const& a, chset<CharT> const& b)
115 {
116 chset<CharT> b_(b);
117 b_.set(a);
118 return b_;
119 }
120
121 //////////////////////////////////
122 template <typename CharT>
123 inline chset<CharT>
124 operator&(range<CharT> const& a, chset<CharT> const& b)
125 {
126 chset<CharT> b_(b);
127 if(a.first != (std::numeric_limits<CharT>::min)()) {
128 b_.clear(range<CharT>((std::numeric_limits<CharT>::min)(), a.first - 1));
129 }
130 if(a.last != (std::numeric_limits<CharT>::max)()) {
131 b_.clear(range<CharT>(a.last + 1, (std::numeric_limits<CharT>::max)()));
132 }
133 return b_;
134 }
135
136 //////////////////////////////////
137 template <typename CharT>
138 inline chset<CharT>
139 operator-(range<CharT> const& a, chset<CharT> const& b)
140 {
141 return chset<CharT>(a) - b;
142 }
143
144 //////////////////////////////////
145 template <typename CharT>
146 inline chset<CharT>
147 operator^(range<CharT> const& a, chset<CharT> const& b)
148 {
149 return chset<CharT>(a) ^ b;
150 }
151
152 ///////////////////////////////////////////////////////////////////////////////
153 //
154 // literal primitives <--> chset free operators implementation
155 //
156 ///////////////////////////////////////////////////////////////////////////////
157 template <typename CharT>
158 inline chset<CharT>
159 operator|(chset<CharT> const& a, CharT b)
160 {
161 return a | chset<CharT>(b);
162 }
163
164 //////////////////////////////////
165 template <typename CharT>
166 inline chset<CharT>
167 operator&(chset<CharT> const& a, CharT b)
168 {
169 return a & chset<CharT>(b);
170 }
171
172 //////////////////////////////////
173 template <typename CharT>
174 inline chset<CharT>
175 operator-(chset<CharT> const& a, CharT b)
176 {
177 return a - chset<CharT>(b);
178 }
179
180 //////////////////////////////////
181 template <typename CharT>
182 inline chset<CharT>
183 operator^(chset<CharT> const& a, CharT b)
184 {
185 return a ^ chset<CharT>(b);
186 }
187
188 //////////////////////////////////
189 template <typename CharT>
190 inline chset<CharT>
191 operator|(CharT a, chset<CharT> const& b)
192 {
193 return chset<CharT>(a) | b;
194 }
195
196 //////////////////////////////////
197 template <typename CharT>
198 inline chset<CharT>
199 operator&(CharT a, chset<CharT> const& b)
200 {
201 return chset<CharT>(a) & b;
202 }
203
204 //////////////////////////////////
205 template <typename CharT>
206 inline chset<CharT>
207 operator-(CharT a, chset<CharT> const& b)
208 {
209 return chset<CharT>(a) - b;
210 }
211
212 //////////////////////////////////
213 template <typename CharT>
214 inline chset<CharT>
215 operator^(CharT a, chset<CharT> const& b)
216 {
217 return chset<CharT>(a) ^ b;
218 }
219
220 ///////////////////////////////////////////////////////////////////////////////
221 //
222 // chlit <--> chset free operators implementation
223 //
224 ///////////////////////////////////////////////////////////////////////////////
225 template <typename CharT>
226 inline chset<CharT>
227 operator|(chset<CharT> const& a, chlit<CharT> const& b)
228 {
229 return a | chset<CharT>(b.ch);
230 }
231
232 //////////////////////////////////
233 template <typename CharT>
234 inline chset<CharT>
235 operator&(chset<CharT> const& a, chlit<CharT> const& b)
236 {
237 return a & chset<CharT>(b.ch);
238 }
239
240 //////////////////////////////////
241 template <typename CharT>
242 inline chset<CharT>
243 operator-(chset<CharT> const& a, chlit<CharT> const& b)
244 {
245 return a - chset<CharT>(b.ch);
246 }
247
248 //////////////////////////////////
249 template <typename CharT>
250 inline chset<CharT>
251 operator^(chset<CharT> const& a, chlit<CharT> const& b)
252 {
253 return a ^ chset<CharT>(b.ch);
254 }
255
256 //////////////////////////////////
257 template <typename CharT>
258 inline chset<CharT>
259 operator|(chlit<CharT> const& a, chset<CharT> const& b)
260 {
261 return chset<CharT>(a.ch) | b;
262 }
263
264 //////////////////////////////////
265 template <typename CharT>
266 inline chset<CharT>
267 operator&(chlit<CharT> const& a, chset<CharT> const& b)
268 {
269 return chset<CharT>(a.ch) & b;
270 }
271
272 //////////////////////////////////
273 template <typename CharT>
274 inline chset<CharT>
275 operator-(chlit<CharT> const& a, chset<CharT> const& b)
276 {
277 return chset<CharT>(a.ch) - b;
278 }
279
280 //////////////////////////////////
281 template <typename CharT>
282 inline chset<CharT>
283 operator^(chlit<CharT> const& a, chset<CharT> const& b)
284 {
285 return chset<CharT>(a.ch) ^ b;
286 }
287
288 ///////////////////////////////////////////////////////////////////////////////
289 //
290 // negated_char_parser<range> <--> chset free operators implementation
291 //
292 ///////////////////////////////////////////////////////////////////////////////
293 template <typename CharT>
294 inline chset<CharT>
295 operator|(chset<CharT> const& a, negated_char_parser<range<CharT> > const& b)
296 {
297 return a | chset<CharT>(b);
298 }
299
300 //////////////////////////////////
301 template <typename CharT>
302 inline chset<CharT>
303 operator&(chset<CharT> const& a, negated_char_parser<range<CharT> > const& b)
304 {
305 return a & chset<CharT>(b);
306 }
307
308 //////////////////////////////////
309 template <typename CharT>
310 inline chset<CharT>
311 operator-(chset<CharT> const& a, negated_char_parser<range<CharT> > const& b)
312 {
313 return a - chset<CharT>(b);
314 }
315
316 //////////////////////////////////
317 template <typename CharT>
318 inline chset<CharT>
319 operator^(chset<CharT> const& a, negated_char_parser<range<CharT> > const& b)
320 {
321 return a ^ chset<CharT>(b);
322 }
323
324 //////////////////////////////////
325 template <typename CharT>
326 inline chset<CharT>
327 operator|(negated_char_parser<range<CharT> > const& a, chset<CharT> const& b)
328 {
329 return chset<CharT>(a) | b;
330 }
331
332 //////////////////////////////////
333 template <typename CharT>
334 inline chset<CharT>
335 operator&(negated_char_parser<range<CharT> > const& a, chset<CharT> const& b)
336 {
337 return chset<CharT>(a) & b;
338 }
339
340 //////////////////////////////////
341 template <typename CharT>
342 inline chset<CharT>
343 operator-(negated_char_parser<range<CharT> > const& a, chset<CharT> const& b)
344 {
345 return chset<CharT>(a) - b;
346 }
347
348 //////////////////////////////////
349 template <typename CharT>
350 inline chset<CharT>
351 operator^(negated_char_parser<range<CharT> > const& a, chset<CharT> const& b)
352 {
353 return chset<CharT>(a) ^ b;
354 }
355
356 ///////////////////////////////////////////////////////////////////////////////
357 //
358 // negated_char_parser<chlit> <--> chset free operators implementation
359 //
360 ///////////////////////////////////////////////////////////////////////////////
361 template <typename CharT>
362 inline chset<CharT>
363 operator|(chset<CharT> const& a, negated_char_parser<chlit<CharT> > const& b)
364 {
365 return a | chset<CharT>(b);
366 }
367
368 //////////////////////////////////
369 template <typename CharT>
370 inline chset<CharT>
371 operator&(chset<CharT> const& a, negated_char_parser<chlit<CharT> > const& b)
372 {
373 return a & chset<CharT>(b);
374 }
375
376 //////////////////////////////////
377 template <typename CharT>
378 inline chset<CharT>
379 operator-(chset<CharT> const& a, negated_char_parser<chlit<CharT> > const& b)
380 {
381 return a - chset<CharT>(b);
382 }
383
384 //////////////////////////////////
385 template <typename CharT>
386 inline chset<CharT>
387 operator^(chset<CharT> const& a, negated_char_parser<chlit<CharT> > const& b)
388 {
389 return a ^ chset<CharT>(b);
390 }
391
392 //////////////////////////////////
393 template <typename CharT>
394 inline chset<CharT>
395 operator|(negated_char_parser<chlit<CharT> > const& a, chset<CharT> const& b)
396 {
397 return chset<CharT>(a) | b;
398 }
399
400 //////////////////////////////////
401 template <typename CharT>
402 inline chset<CharT>
403 operator&(negated_char_parser<chlit<CharT> > const& a, chset<CharT> const& b)
404 {
405 return chset<CharT>(a) & b;
406 }
407
408 //////////////////////////////////
409 template <typename CharT>
410 inline chset<CharT>
411 operator-(negated_char_parser<chlit<CharT> > const& a, chset<CharT> const& b)
412 {
413 return chset<CharT>(a) - b;
414 }
415
416 //////////////////////////////////
417 template <typename CharT>
418 inline chset<CharT>
419 operator^(negated_char_parser<chlit<CharT> > const& a, chset<CharT> const& b)
420 {
421 return chset<CharT>(a) ^ b;
422 }
423
424 ///////////////////////////////////////////////////////////////////////////////
425 //
426 // anychar_parser <--> chset free operators
427 //
428 // Where a is chset and b is a anychar_parser, and vice-versa, implements:
429 //
430 // a | b, a & b, a - b, a ^ b
431 //
432 ///////////////////////////////////////////////////////////////////////////////
433 namespace impl {
434
435 template <typename CharT>
436 inline BOOST_SPIRIT_CLASSIC_NS::range<CharT> const&
437 full()
438 {
439 static BOOST_SPIRIT_CLASSIC_NS::range<CharT> full_(
440 (std::numeric_limits<CharT>::min)(),
441 (std::numeric_limits<CharT>::max)());
442 return full_;
443 }
444
445 template <typename CharT>
446 inline BOOST_SPIRIT_CLASSIC_NS::range<CharT> const&
447 empty()
448 {
449 static BOOST_SPIRIT_CLASSIC_NS::range<CharT> empty_;
450 return empty_;
451 }
452 }
453
454 //////////////////////////////////
455 template <typename CharT>
456 inline chset<CharT>
457 operator|(chset<CharT> const&, anychar_parser)
458 {
459 return chset<CharT>(impl::full<CharT>());
460 }
461
462 //////////////////////////////////
463 template <typename CharT>
464 inline chset<CharT>
465 operator&(chset<CharT> const& a, anychar_parser)
466 {
467 return a;
468 }
469
470 //////////////////////////////////
471 template <typename CharT>
472 inline chset<CharT>
473 operator-(chset<CharT> const&, anychar_parser)
474 {
475 return chset<CharT>();
476 }
477
478 //////////////////////////////////
479 template <typename CharT>
480 inline chset<CharT>
481 operator^(chset<CharT> const& a, anychar_parser)
482 {
483 return ~a;
484 }
485
486 //////////////////////////////////
487 template <typename CharT>
488 inline chset<CharT>
489 operator|(anychar_parser, chset<CharT> const& /*b*/)
490 {
491 return chset<CharT>(impl::full<CharT>());
492 }
493
494 //////////////////////////////////
495 template <typename CharT>
496 inline chset<CharT>
497 operator&(anychar_parser, chset<CharT> const& b)
498 {
499 return b;
500 }
501
502 //////////////////////////////////
503 template <typename CharT>
504 inline chset<CharT>
505 operator-(anychar_parser, chset<CharT> const& b)
506 {
507 return ~b;
508 }
509
510 //////////////////////////////////
511 template <typename CharT>
512 inline chset<CharT>
513 operator^(anychar_parser, chset<CharT> const& b)
514 {
515 return ~b;
516 }
517
518 ///////////////////////////////////////////////////////////////////////////////
519 //
520 // nothing_parser <--> chset free operators implementation
521 //
522 ///////////////////////////////////////////////////////////////////////////////
523 template <typename CharT>
524 inline chset<CharT>
525 operator|(chset<CharT> const& a, nothing_parser)
526 {
527 return a;
528 }
529
530 //////////////////////////////////
531 template <typename CharT>
532 inline chset<CharT>
533 operator&(chset<CharT> const& /*a*/, nothing_parser)
534 {
535 return impl::empty<CharT>();
536 }
537
538 //////////////////////////////////
539 template <typename CharT>
540 inline chset<CharT>
541 operator-(chset<CharT> const& a, nothing_parser)
542 {
543 return a;
544 }
545
546 //////////////////////////////////
547 template <typename CharT>
548 inline chset<CharT>
549 operator^(chset<CharT> const& a, nothing_parser)
550 {
551 return a;
552 }
553
554 //////////////////////////////////
555 template <typename CharT>
556 inline chset<CharT>
557 operator|(nothing_parser, chset<CharT> const& b)
558 {
559 return b;
560 }
561
562 //////////////////////////////////
563 template <typename CharT>
564 inline chset<CharT>
565 operator&(nothing_parser, chset<CharT> const& /*b*/)
566 {
567 return impl::empty<CharT>();
568 }
569
570 //////////////////////////////////
571 template <typename CharT>
572 inline chset<CharT>
573 operator-(nothing_parser, chset<CharT> const& /*b*/)
574 {
575 return impl::empty<CharT>();
576 }
577
578 //////////////////////////////////
579 template <typename CharT>
580 inline chset<CharT>
581 operator^(nothing_parser, chset<CharT> const& b)
582 {
583 return b;
584 }
585
586 ///////////////////////////////////////////////////////////////////////////////
587 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
588
589 }} // namespace boost::spirit
590
591 #endif
592