]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/spirit/include/boost/spirit/home/x3/numeric/bool.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / spirit / include / boost / spirit / home / x3 / numeric / bool.hpp
CommitLineData
7c673cae
FG
1/*=============================================================================
2 Copyright (c) 2009 Hartmut Kaiser
3 Copyright (c) 2014 Joel de Guzman
4
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7==============================================================================*/
8#if !defined(SPIRIT_X3_BOOL_SEP_29_2009_0709AM)
9#define SPIRIT_X3_BOOL_SEP_29_2009_0709AM
10
11#include <boost/spirit/home/x3/core/parser.hpp>
12#include <boost/spirit/home/x3/core/skip_over.hpp>
13#include <boost/spirit/home/x3/numeric/bool_policies.hpp>
14
15namespace boost { namespace spirit { namespace x3
16{
17 template <typename T, typename Encoding, typename BoolPolicies = bool_policies<T>>
18 struct bool_parser : parser<bool_parser<T, Encoding, BoolPolicies>>
19 {
20 typedef Encoding encoding;
21 typedef T attribute_type;
22 static bool const has_attribute = true;
23
24 bool_parser()
25 : policies() {}
26
27 bool_parser(BoolPolicies const& policies)
28 : policies(policies) {}
29
30 template <typename Iterator, typename Context>
31 bool parse(Iterator& first, Iterator const& last
32 , Context const& context, unused_type, T& attr) const
33 {
34 x3::skip_over(first, last, context);
35 return policies.parse_true(first, last, attr, get_case_compare<encoding>(context))
36 || policies.parse_false(first, last, attr, get_case_compare<encoding>(context));
37 }
38
39 template <typename Iterator, typename Context, typename Attribute>
40 bool parse(Iterator& first, Iterator const& last
41 , Context const& context, unused_type, Attribute& attr_param) const
42 {
43 // this case is called when Attribute is not T
44 T attr_;
45 if (parse(first, last, context, unused, attr_))
46 {
47 traits::move_to(attr_, attr_param);
48 return true;
49 }
50 return false;
51 }
52
53 BoolPolicies policies;
54 };
55
56 template <typename T, typename Encoding, typename BoolPolicies = bool_policies<T>>
57 struct literal_bool_parser : parser<bool_parser<T, Encoding, BoolPolicies>>
58 {
59 typedef Encoding encoding;
60 typedef T attribute_type;
61 static bool const has_attribute = true;
62
63 template <typename Value>
64 literal_bool_parser(Value const& n)
65 : policies(), n_(n) {}
66
67 template <typename Value>
68 literal_bool_parser(Value const& n, BoolPolicies const& policies)
69 : policies(policies), n_(n) {}
70
71 template <typename Iterator, typename Context>
72 bool parse_main(Iterator& first, Iterator const& last
73 , Context& context, T& attr) const
74 {
75 x3::skip_over(first, last, context);
76 return (n_ && policies.parse_true(first, last, attr, get_case_compare<encoding>(context)))
77 || (!n_ && policies.parse_false(first, last, attr, get_case_compare<encoding>(context)));
78 }
79
80 template <typename Iterator, typename Context>
81 bool parse(Iterator& first, Iterator const& last
82 , Context& context, unused_type, T& attr) const
83 {
84 return parse_main(first, last, context, attr);
85 }
86
87 template <typename Iterator, typename Context, typename Attribute>
88 bool parse(Iterator& first, Iterator const& last
89 , Context const& context, unused_type, Attribute& attr_param) const
90 {
91 // this case is called when Attribute is not T
92 T attr_;
93 if (parse_main(first, last, context, attr_))
94 {
95 traits::move_to(attr_, attr_param);
96 return true;
97 }
98 return false;
99 }
100
101 BoolPolicies policies;
102 T n_;
103 };
104
105 namespace standard
106 {
107 typedef bool_parser<bool, char_encoding::standard> bool_type;
108 bool_type const bool_ = {};
109
110 typedef literal_bool_parser<bool, char_encoding::standard> true_type;
111 true_type const true_ = { true };
112
113 typedef literal_bool_parser<bool, char_encoding::standard> false_type;
114 false_type const false_ = { false };
115 }
116
117 namespace standard_wide
118 {
119 typedef bool_parser<bool, char_encoding::standard_wide> bool_type;
120 bool_type const bool_ = {};
121
122 typedef literal_bool_parser<bool, char_encoding::standard_wide> true_type;
123 true_type const true_ = { true };
124
125 typedef literal_bool_parser<bool, char_encoding::standard_wide> false_type;
126 false_type const false_ = { false };
127 }
128
129 namespace ascii
130 {
131 typedef bool_parser<bool, char_encoding::ascii> bool_type;
132 bool_type const bool_ = {};
133
134 typedef literal_bool_parser<bool, char_encoding::ascii> true_type;
135 true_type const true_ = { true };
136
137 typedef literal_bool_parser<bool, char_encoding::ascii> false_type;
138 false_type const false_ = { false };
139 }
140
141 namespace iso8859_1
142 {
143 typedef bool_parser<bool, char_encoding::iso8859_1> bool_type;
144 bool_type const bool_ = {};
145
146 typedef literal_bool_parser<bool, char_encoding::iso8859_1> true_type;
147 true_type const true_ = { true };
148
149 typedef literal_bool_parser<bool, char_encoding::iso8859_1> false_type;
150 false_type const false_ = { false };
151 }
152
153 using standard::bool_;
154 using standard::true_;
155 using standard::false_;
156
157 }}}
158
159#endif