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