1 | // TR2 <bool_set> support files -*- C++ -*-
|
---|
2 |
|
---|
3 | // Copyright (C) 2009-2021 Free Software Foundation, Inc.
|
---|
4 | //
|
---|
5 | // This file is part of the GNU ISO C++ Library. This library is free
|
---|
6 | // software; you can redistribute it and/or modify it under the
|
---|
7 | // terms of the GNU General Public License as published by the
|
---|
8 | // Free Software Foundation; either version 3, or (at your option)
|
---|
9 | // any later version.
|
---|
10 |
|
---|
11 | // This library is distributed in the hope that it will be useful,
|
---|
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | // GNU General Public License for more details.
|
---|
15 |
|
---|
16 | // Under Section 7 of GPL version 3, you are granted additional
|
---|
17 | // permissions described in the GCC Runtime Library Exception, version
|
---|
18 | // 3.1, as published by the Free Software Foundation.
|
---|
19 |
|
---|
20 | // You should have received a copy of the GNU General Public License and
|
---|
21 | // a copy of the GCC Runtime Library Exception along with this program;
|
---|
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
---|
23 | // <http://www.gnu.org/licenses/>.
|
---|
24 |
|
---|
25 | /** @file tr2/bool_set.tcc
|
---|
26 | * This is a TR2 C++ Library header.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #ifndef _GLIBCXX_TR2_BOOL_SET_TCC
|
---|
30 | #define _GLIBCXX_TR2_BOOL_SET_TCC 1
|
---|
31 |
|
---|
32 | #pragma GCC system_header
|
---|
33 |
|
---|
34 | namespace std _GLIBCXX_VISIBILITY(default)
|
---|
35 | {
|
---|
36 | _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
---|
37 |
|
---|
38 | namespace tr2
|
---|
39 | {
|
---|
40 | bool_set::_Bool_set_val
|
---|
41 | bool_set::_S_not[4] =
|
---|
42 | { _S_true_, _S_false, _S_indet, _S_empty };
|
---|
43 |
|
---|
44 | bool_set::_Bool_set_val
|
---|
45 | bool_set::_S_xor[4][4] =
|
---|
46 | { { _S_false, _S_true_, _S_indet, _S_empty },
|
---|
47 | { _S_true_, _S_false, _S_indet, _S_empty },
|
---|
48 | { _S_indet, _S_indet, _S_indet, _S_empty },
|
---|
49 | { _S_empty, _S_empty, _S_empty, _S_empty } };
|
---|
50 |
|
---|
51 | bool_set::_Bool_set_val
|
---|
52 | bool_set::_S_or[4][4] =
|
---|
53 | { { _S_false, _S_true_, _S_indet, _S_empty },
|
---|
54 | { _S_true_, _S_true_, _S_true_, _S_empty },
|
---|
55 | { _S_indet, _S_true_, _S_indet, _S_empty },
|
---|
56 | { _S_empty, _S_empty, _S_empty, _S_empty } };
|
---|
57 |
|
---|
58 | bool_set::_Bool_set_val
|
---|
59 | bool_set::_S_and[4][4] =
|
---|
60 | { { _S_false, _S_false, _S_false, _S_empty },
|
---|
61 | { _S_false, _S_true_, _S_indet, _S_empty },
|
---|
62 | { _S_false, _S_indet, _S_indet, _S_empty },
|
---|
63 | { _S_empty, _S_empty, _S_empty, _S_empty } };
|
---|
64 |
|
---|
65 | bool_set::_Bool_set_val
|
---|
66 | bool_set::_S_eq[4][4] =
|
---|
67 | { { _S_true_, _S_false, _S_indet, _S_empty },
|
---|
68 | { _S_false, _S_true_, _S_indet, _S_empty },
|
---|
69 | { _S_indet, _S_indet, _S_indet, _S_empty },
|
---|
70 | { _S_empty, _S_empty, _S_empty, _S_empty } };
|
---|
71 | }
|
---|
72 |
|
---|
73 | _GLIBCXX_END_NAMESPACE_VERSION
|
---|
74 | }
|
---|
75 |
|
---|
76 | // I object to these things.
|
---|
77 | // The stuff in locale facets are for basic types.
|
---|
78 | // I think we could hack operator<< and operator>>.
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * @brief Numeric parsing.
|
---|
82 | *
|
---|
83 | * Parses the input stream into the bool @a v. It does so by calling
|
---|
84 | * num_get::do_get().
|
---|
85 | *
|
---|
86 | * If ios_base::boolalpha is set, attempts to read
|
---|
87 | * ctype<CharT>::truename() or ctype<CharT>::falsename(). Sets
|
---|
88 | * @a v to true or false if successful. Sets err to
|
---|
89 | * ios_base::failbit if reading the string fails. Sets err to
|
---|
90 | * ios_base::eofbit if the stream is emptied.
|
---|
91 | *
|
---|
92 | * If ios_base::boolalpha is not set, proceeds as with reading a long,
|
---|
93 | * except if the value is 1, sets @a v to true, if the value is 0, sets
|
---|
94 | * @a v to false, and otherwise set err to ios_base::failbit.
|
---|
95 | *
|
---|
96 | * @param in Start of input stream.
|
---|
97 | * @param end End of input stream.
|
---|
98 | * @param io Source of locale and flags.
|
---|
99 | * @param err Error flags to set.
|
---|
100 | * @param v Value to format and insert.
|
---|
101 | * @return Iterator after reading.
|
---|
102 | iter_type
|
---|
103 | get(iter_type __in, iter_type __end, ios_base& __io,
|
---|
104 | ios_base::iostate& __err, bool& __v) const
|
---|
105 | { return this->do_get(__in, __end, __io, __err, __v); }
|
---|
106 | */
|
---|
107 | /*
|
---|
108 | template<typename _CharT, typename _InIter>
|
---|
109 | _InIter
|
---|
110 | num_get<_CharT, _InIter>::
|
---|
111 | do_get(iter_type __beg, iter_type __end, ios_base& __io,
|
---|
112 | ios_base::iostate& __err, bool_set& __v) const
|
---|
113 | {
|
---|
114 | if (!(__io.flags() & ios_base::boolalpha))
|
---|
115 | {
|
---|
116 | // Parse bool values as long.
|
---|
117 | // NB: We can't just call do_get(long) here, as it might
|
---|
118 | // refer to a derived class.
|
---|
119 | long __l = -1;
|
---|
120 | __beg = _M_extract_int(__beg, __end, __io, __err, __l);
|
---|
121 | if (__c >= _S_false && __c < _S_empty)
|
---|
122 | __b._M_b = static_cast<_Bool_set_val>(__c);
|
---|
123 | else
|
---|
124 | {
|
---|
125 | // What should we do here?
|
---|
126 | __v = true;
|
---|
127 | __err = ios_base::failbit;
|
---|
128 | if (__beg == __end)
|
---|
129 | __err |= ios_base::eofbit;
|
---|
130 | }
|
---|
131 | }
|
---|
132 | else
|
---|
133 | {
|
---|
134 | // Parse bool values as alphanumeric.
|
---|
135 | typedef __numpunct_cache<_CharT> __cache_type;
|
---|
136 | __use_cache<__cache_type> __uc;
|
---|
137 | const locale& __loc = __io._M_getloc();
|
---|
138 | const __cache_type* __lc = __uc(__loc);
|
---|
139 |
|
---|
140 | bool __testf = true;
|
---|
141 | bool __testt = true;
|
---|
142 | bool __donef = __lc->_M_falsename_size == 0;
|
---|
143 | bool __donet = __lc->_M_truename_size == 0;
|
---|
144 | bool __testeof = false;
|
---|
145 | size_t __n = 0;
|
---|
146 | while (!__donef || !__donet)
|
---|
147 | {
|
---|
148 | if (__beg == __end)
|
---|
149 | {
|
---|
150 | __testeof = true;
|
---|
151 | break;
|
---|
152 | }
|
---|
153 |
|
---|
154 | const char_type __c = *__beg;
|
---|
155 |
|
---|
156 | if (!__donef)
|
---|
157 | __testf = __c == __lc->_M_falsename[__n];
|
---|
158 |
|
---|
159 | if (!__testf && __donet)
|
---|
160 | break;
|
---|
161 |
|
---|
162 | if (!__donet)
|
---|
163 | __testt = __c == __lc->_M_truename[__n];
|
---|
164 |
|
---|
165 | if (!__testt && __donef)
|
---|
166 | break;
|
---|
167 |
|
---|
168 | if (!__testt && !__testf)
|
---|
169 | break;
|
---|
170 |
|
---|
171 | ++__n;
|
---|
172 | ++__beg;
|
---|
173 |
|
---|
174 | __donef = !__testf || __n >= __lc->_M_falsename_size;
|
---|
175 | __donet = !__testt || __n >= __lc->_M_truename_size;
|
---|
176 | }
|
---|
177 | if (__testf && __n == __lc->_M_falsename_size && __n)
|
---|
178 | {
|
---|
179 | __v = false;
|
---|
180 | if (__testt && __n == __lc->_M_truename_size)
|
---|
181 | __err = ios_base::failbit;
|
---|
182 | else
|
---|
183 | __err = __testeof ? ios_base::eofbit : ios_base::goodbit;
|
---|
184 | }
|
---|
185 | else if (__testt && __n == __lc->_M_truename_size && __n)
|
---|
186 | {
|
---|
187 | __v = true;
|
---|
188 | __err = __testeof ? ios_base::eofbit : ios_base::goodbit;
|
---|
189 | }
|
---|
190 | else
|
---|
191 | {
|
---|
192 | // _GLIBCXX_RESOLVE_LIB_DEFECTS
|
---|
193 | // 23. Num_get overflow result.
|
---|
194 | __v = false;
|
---|
195 | __err = ios_base::failbit;
|
---|
196 | if (__testeof)
|
---|
197 | __err |= ios_base::eofbit;
|
---|
198 | }
|
---|
199 | }
|
---|
200 | return __beg;
|
---|
201 | }
|
---|
202 | */
|
---|
203 |
|
---|
204 | /**
|
---|
205 | * @brief Numeric formatting.
|
---|
206 | *
|
---|
207 | * Formats the boolean @a v and inserts it into a stream. It does so
|
---|
208 | * by calling num_put::do_put().
|
---|
209 | *
|
---|
210 | * If ios_base::boolalpha is set, writes ctype<CharT>::truename() or
|
---|
211 | * ctype<CharT>::falsename(). Otherwise formats @a v as an int.
|
---|
212 | *
|
---|
213 | * @param s Stream to write to.
|
---|
214 | * @param io Source of locale and flags.
|
---|
215 | * @param fill Char_type to use for filling.
|
---|
216 | * @param v Value to format and insert.
|
---|
217 | * @return Iterator after writing.
|
---|
218 | iter_type
|
---|
219 | put(iter_type __s, ios_base& __f, char_type __fill, bool __v) const
|
---|
220 | { return this->do_put(__s, __f, __fill, __v); }
|
---|
221 | */
|
---|
222 |
|
---|
223 | /*
|
---|
224 | template<typename _CharT, typename _OutIter>
|
---|
225 | _OutIter
|
---|
226 | num_put<_CharT, _OutIter>::
|
---|
227 | do_put(iter_type __s, ios_base& __io, char_type __fill, bool_set __v) const
|
---|
228 | {
|
---|
229 | const ios_base::fmtflags __flags = __io.flags();
|
---|
230 | if ((__flags & ios_base::boolalpha) == 0)
|
---|
231 | {
|
---|
232 | const long __l = __v;
|
---|
233 | __s = _M_insert_int(__s, __io, __fill, __l);
|
---|
234 | }
|
---|
235 | else
|
---|
236 | {
|
---|
237 | typedef __numpunct_cache<_CharT> __cache_type;
|
---|
238 | __use_cache<__cache_type> __uc;
|
---|
239 | const locale& __loc = __io._M_getloc();
|
---|
240 | const __cache_type* __lc = __uc(__loc);
|
---|
241 |
|
---|
242 | const _CharT* __name = __v ? __lc->_M_truename
|
---|
243 | : __lc->_M_falsename;
|
---|
244 | int __len = __v ? __lc->_M_truename_size
|
---|
245 | : __lc->_M_falsename_size;
|
---|
246 |
|
---|
247 | const streamsize __w = __io.width();
|
---|
248 | if (__w > static_cast<streamsize>(__len))
|
---|
249 | {
|
---|
250 | const streamsize __plen = __w - __len;
|
---|
251 | _CharT* __ps
|
---|
252 | = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
|
---|
253 | * __plen));
|
---|
254 |
|
---|
255 | char_traits<_CharT>::assign(__ps, __plen, __fill);
|
---|
256 | __io.width(0);
|
---|
257 |
|
---|
258 | if ((__flags & ios_base::adjustfield) == ios_base::left)
|
---|
259 | {
|
---|
260 | __s = std::__write(__s, __name, __len);
|
---|
261 | __s = std::__write(__s, __ps, __plen);
|
---|
262 | }
|
---|
263 | else
|
---|
264 | {
|
---|
265 | __s = std::__write(__s, __ps, __plen);
|
---|
266 | __s = std::__write(__s, __name, __len);
|
---|
267 | }
|
---|
268 | return __s;
|
---|
269 | }
|
---|
270 | __io.width(0);
|
---|
271 | __s = std::__write(__s, __name, __len);
|
---|
272 | }
|
---|
273 | return __s;
|
---|
274 | }
|
---|
275 | */
|
---|
276 |
|
---|
277 | #endif // _GLIBCXX_TR2_BOOL_SET_TCC
|
---|