1 | // -*- C++ -*- |
2 | //===----------------------------------------------------------------------===// |
3 | // |
4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
5 | // See https://llvm.org/LICENSE.txt for license information. |
6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
7 | // |
8 | //===----------------------------------------------------------------------===// |
9 | |
10 | #ifndef _LIBCPP_IOS |
11 | #define _LIBCPP_IOS |
12 | |
13 | /* |
14 | ios synopsis |
15 | |
16 | #include <iosfwd> |
17 | |
18 | namespace std |
19 | { |
20 | |
21 | typedef OFF_T streamoff; |
22 | typedef SZ_T streamsize; |
23 | template <class stateT> class fpos; |
24 | |
25 | class ios_base |
26 | { |
27 | public: |
28 | class failure; |
29 | |
30 | typedef T1 fmtflags; |
31 | static constexpr fmtflags boolalpha; |
32 | static constexpr fmtflags dec; |
33 | static constexpr fmtflags fixed; |
34 | static constexpr fmtflags hex; |
35 | static constexpr fmtflags internal; |
36 | static constexpr fmtflags left; |
37 | static constexpr fmtflags oct; |
38 | static constexpr fmtflags right; |
39 | static constexpr fmtflags scientific; |
40 | static constexpr fmtflags showbase; |
41 | static constexpr fmtflags showpoint; |
42 | static constexpr fmtflags showpos; |
43 | static constexpr fmtflags skipws; |
44 | static constexpr fmtflags unitbuf; |
45 | static constexpr fmtflags uppercase; |
46 | static constexpr fmtflags adjustfield; |
47 | static constexpr fmtflags basefield; |
48 | static constexpr fmtflags floatfield; |
49 | |
50 | typedef T2 iostate; |
51 | static constexpr iostate badbit; |
52 | static constexpr iostate eofbit; |
53 | static constexpr iostate failbit; |
54 | static constexpr iostate goodbit; |
55 | |
56 | typedef T3 openmode; |
57 | static constexpr openmode app; |
58 | static constexpr openmode ate; |
59 | static constexpr openmode binary; |
60 | static constexpr openmode in; |
61 | static constexpr openmode noreplace; // since C++23 |
62 | static constexpr openmode out; |
63 | static constexpr openmode trunc; |
64 | |
65 | typedef T4 seekdir; |
66 | static constexpr seekdir beg; |
67 | static constexpr seekdir cur; |
68 | static constexpr seekdir end; |
69 | |
70 | class Init; |
71 | |
72 | // 27.5.2.2 fmtflags state: |
73 | fmtflags flags() const; |
74 | fmtflags flags(fmtflags fmtfl); |
75 | fmtflags setf(fmtflags fmtfl); |
76 | fmtflags setf(fmtflags fmtfl, fmtflags mask); |
77 | void unsetf(fmtflags mask); |
78 | |
79 | streamsize precision() const; |
80 | streamsize precision(streamsize prec); |
81 | streamsize width() const; |
82 | streamsize width(streamsize wide); |
83 | |
84 | // 27.5.2.3 locales: |
85 | locale imbue(const locale& loc); |
86 | locale getloc() const; |
87 | |
88 | // 27.5.2.5 storage: |
89 | static int xalloc(); |
90 | long& iword(int index); |
91 | void*& pword(int index); |
92 | |
93 | // destructor |
94 | virtual ~ios_base(); |
95 | |
96 | // 27.5.2.6 callbacks; |
97 | enum event { erase_event, imbue_event, copyfmt_event }; |
98 | typedef void (*event_callback)(event, ios_base&, int index); |
99 | void register_callback(event_callback fn, int index); |
100 | |
101 | ios_base(const ios_base&) = delete; |
102 | ios_base& operator=(const ios_base&) = delete; |
103 | |
104 | static bool sync_with_stdio(bool sync = true); |
105 | |
106 | protected: |
107 | ios_base(); |
108 | }; |
109 | |
110 | template <class charT, class traits = char_traits<charT> > |
111 | class basic_ios |
112 | : public ios_base |
113 | { |
114 | public: |
115 | // types: |
116 | typedef charT char_type; |
117 | typedef typename traits::int_type int_type; // removed in C++17 |
118 | typedef typename traits::pos_type pos_type; // removed in C++17 |
119 | typedef typename traits::off_type off_type; // removed in C++17 |
120 | typedef traits traits_type; |
121 | |
122 | operator unspecified-bool-type() const; |
123 | bool operator!() const; |
124 | iostate rdstate() const; |
125 | void clear(iostate state = goodbit); |
126 | void setstate(iostate state); |
127 | bool good() const; |
128 | bool eof() const; |
129 | bool fail() const; |
130 | bool bad() const; |
131 | |
132 | iostate exceptions() const; |
133 | void exceptions(iostate except); |
134 | |
135 | // 27.5.4.1 Constructor/destructor: |
136 | explicit basic_ios(basic_streambuf<charT,traits>* sb); |
137 | virtual ~basic_ios(); |
138 | |
139 | // 27.5.4.2 Members: |
140 | basic_ostream<charT,traits>* tie() const; |
141 | basic_ostream<charT,traits>* tie(basic_ostream<charT,traits>* tiestr); |
142 | |
143 | basic_streambuf<charT,traits>* rdbuf() const; |
144 | basic_streambuf<charT,traits>* rdbuf(basic_streambuf<charT,traits>* sb); |
145 | |
146 | basic_ios& copyfmt(const basic_ios& rhs); |
147 | |
148 | char_type fill() const; |
149 | char_type fill(char_type ch); |
150 | |
151 | locale imbue(const locale& loc); |
152 | |
153 | char narrow(char_type c, char dfault) const; |
154 | char_type widen(char c) const; |
155 | |
156 | basic_ios(const basic_ios& ) = delete; |
157 | basic_ios& operator=(const basic_ios&) = delete; |
158 | |
159 | protected: |
160 | basic_ios(); |
161 | void init(basic_streambuf<charT,traits>* sb); |
162 | void move(basic_ios& rhs); |
163 | void swap(basic_ios& rhs) noexcept; |
164 | void set_rdbuf(basic_streambuf<charT, traits>* sb); |
165 | }; |
166 | |
167 | // 27.5.5, manipulators: |
168 | ios_base& boolalpha (ios_base& str); |
169 | ios_base& noboolalpha(ios_base& str); |
170 | ios_base& showbase (ios_base& str); |
171 | ios_base& noshowbase (ios_base& str); |
172 | ios_base& showpoint (ios_base& str); |
173 | ios_base& noshowpoint(ios_base& str); |
174 | ios_base& showpos (ios_base& str); |
175 | ios_base& noshowpos (ios_base& str); |
176 | ios_base& skipws (ios_base& str); |
177 | ios_base& noskipws (ios_base& str); |
178 | ios_base& uppercase (ios_base& str); |
179 | ios_base& nouppercase(ios_base& str); |
180 | ios_base& unitbuf (ios_base& str); |
181 | ios_base& nounitbuf (ios_base& str); |
182 | |
183 | // 27.5.5.2 adjustfield: |
184 | ios_base& internal (ios_base& str); |
185 | ios_base& left (ios_base& str); |
186 | ios_base& right (ios_base& str); |
187 | |
188 | // 27.5.5.3 basefield: |
189 | ios_base& dec (ios_base& str); |
190 | ios_base& hex (ios_base& str); |
191 | ios_base& oct (ios_base& str); |
192 | |
193 | // 27.5.5.4 floatfield: |
194 | ios_base& fixed (ios_base& str); |
195 | ios_base& scientific (ios_base& str); |
196 | ios_base& hexfloat (ios_base& str); |
197 | ios_base& defaultfloat(ios_base& str); |
198 | |
199 | // 27.5.5.5 error reporting: |
200 | enum class io_errc |
201 | { |
202 | stream = 1 |
203 | }; |
204 | |
205 | concept_map ErrorCodeEnum<io_errc> { }; |
206 | error_code make_error_code(io_errc e) noexcept; |
207 | error_condition make_error_condition(io_errc e) noexcept; |
208 | storage-class-specifier const error_category& iostream_category() noexcept; |
209 | |
210 | } // std |
211 | |
212 | */ |
213 | |
214 | #include <__config> |
215 | |
216 | #if !defined(_LIBCPP_HAS_NO_LOCALIZATION) |
217 | |
218 | # include <__fwd/ios.h> |
219 | # include <__ios/fpos.h> |
220 | # include <__locale> |
221 | # include <__system_error/error_category.h> |
222 | # include <__system_error/error_code.h> |
223 | # include <__system_error/error_condition.h> |
224 | # include <__system_error/system_error.h> |
225 | # include <__utility/swap.h> |
226 | # include <__verbose_abort> |
227 | # include <version> |
228 | |
229 | // standard-mandated includes |
230 | |
231 | // [ios.syn] |
232 | # include <iosfwd> |
233 | |
234 | # if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) |
235 | # include <__atomic/atomic.h> // for __xindex_ |
236 | # endif |
237 | |
238 | # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
239 | # pragma GCC system_header |
240 | # endif |
241 | |
242 | _LIBCPP_PUSH_MACROS |
243 | # include <__undef_macros> |
244 | |
245 | _LIBCPP_BEGIN_NAMESPACE_STD |
246 | |
247 | typedef ptrdiff_t streamsize; |
248 | |
249 | class _LIBCPP_EXPORTED_FROM_ABI ios_base { |
250 | public: |
251 | class _LIBCPP_EXPORTED_FROM_ABI failure; |
252 | |
253 | typedef unsigned int fmtflags; |
254 | static const fmtflags boolalpha = 0x0001; |
255 | static const fmtflags dec = 0x0002; |
256 | static const fmtflags fixed = 0x0004; |
257 | static const fmtflags hex = 0x0008; |
258 | static const fmtflags internal = 0x0010; |
259 | static const fmtflags left = 0x0020; |
260 | static const fmtflags oct = 0x0040; |
261 | static const fmtflags right = 0x0080; |
262 | static const fmtflags scientific = 0x0100; |
263 | static const fmtflags showbase = 0x0200; |
264 | static const fmtflags showpoint = 0x0400; |
265 | static const fmtflags showpos = 0x0800; |
266 | static const fmtflags skipws = 0x1000; |
267 | static const fmtflags unitbuf = 0x2000; |
268 | static const fmtflags uppercase = 0x4000; |
269 | static const fmtflags adjustfield = left | right | internal; |
270 | static const fmtflags basefield = dec | oct | hex; |
271 | static const fmtflags floatfield = scientific | fixed; |
272 | |
273 | typedef unsigned int iostate; |
274 | static const iostate badbit = 0x1; |
275 | static const iostate eofbit = 0x2; |
276 | static const iostate failbit = 0x4; |
277 | static const iostate goodbit = 0x0; |
278 | |
279 | typedef unsigned int openmode; |
280 | static const openmode app = 0x01; |
281 | static const openmode ate = 0x02; |
282 | static const openmode binary = 0x04; |
283 | static const openmode in = 0x08; |
284 | static const openmode out = 0x10; |
285 | static const openmode trunc = 0x20; |
286 | # if _LIBCPP_STD_VER >= 23 |
287 | static const openmode noreplace = 0x40; |
288 | # endif |
289 | |
290 | enum seekdir { beg, cur, end }; |
291 | |
292 | # if _LIBCPP_STD_VER <= 14 |
293 | typedef iostate io_state; |
294 | typedef openmode open_mode; |
295 | typedef seekdir seek_dir; |
296 | |
297 | typedef std::streamoff streamoff; |
298 | typedef std::streampos streampos; |
299 | # endif |
300 | |
301 | class _LIBCPP_EXPORTED_FROM_ABI Init; |
302 | |
303 | // 27.5.2.2 fmtflags state: |
304 | _LIBCPP_HIDE_FROM_ABI fmtflags flags() const; |
305 | _LIBCPP_HIDE_FROM_ABI fmtflags flags(fmtflags __fmtfl); |
306 | _LIBCPP_HIDE_FROM_ABI fmtflags setf(fmtflags __fmtfl); |
307 | _LIBCPP_HIDE_FROM_ABI fmtflags setf(fmtflags __fmtfl, fmtflags __mask); |
308 | _LIBCPP_HIDE_FROM_ABI void unsetf(fmtflags __mask); |
309 | |
310 | _LIBCPP_HIDE_FROM_ABI streamsize precision() const; |
311 | _LIBCPP_HIDE_FROM_ABI streamsize precision(streamsize __prec); |
312 | _LIBCPP_HIDE_FROM_ABI streamsize width() const; |
313 | _LIBCPP_HIDE_FROM_ABI streamsize width(streamsize __wide); |
314 | |
315 | // 27.5.2.3 locales: |
316 | locale imbue(const locale& __loc); |
317 | locale getloc() const; |
318 | |
319 | // 27.5.2.5 storage: |
320 | static int xalloc(); |
321 | long& iword(int __index); |
322 | void*& pword(int __index); |
323 | |
324 | // destructor |
325 | virtual ~ios_base(); |
326 | |
327 | // 27.5.2.6 callbacks; |
328 | enum event { erase_event, imbue_event, copyfmt_event }; |
329 | typedef void (*event_callback)(event, ios_base&, int __index); |
330 | void register_callback(event_callback __fn, int __index); |
331 | |
332 | ios_base(const ios_base&) = delete; |
333 | ios_base& operator=(const ios_base&) = delete; |
334 | |
335 | static bool sync_with_stdio(bool __sync = true); |
336 | |
337 | _LIBCPP_HIDE_FROM_ABI iostate rdstate() const; |
338 | void clear(iostate __state = goodbit); |
339 | _LIBCPP_HIDE_FROM_ABI void setstate(iostate __state); |
340 | |
341 | _LIBCPP_HIDE_FROM_ABI bool good() const; |
342 | _LIBCPP_HIDE_FROM_ABI bool eof() const; |
343 | _LIBCPP_HIDE_FROM_ABI bool fail() const; |
344 | _LIBCPP_HIDE_FROM_ABI bool bad() const; |
345 | |
346 | _LIBCPP_HIDE_FROM_ABI iostate exceptions() const; |
347 | _LIBCPP_HIDE_FROM_ABI void exceptions(iostate __iostate); |
348 | |
349 | void __set_badbit_and_consider_rethrow(); |
350 | void __set_failbit_and_consider_rethrow(); |
351 | |
352 | _LIBCPP_HIDE_FROM_ABI void __setstate_nothrow(iostate __state) { |
353 | if (__rdbuf_) |
354 | __rdstate_ |= __state; |
355 | else |
356 | __rdstate_ |= __state | ios_base::badbit; |
357 | } |
358 | |
359 | protected: |
360 | _LIBCPP_HIDE_FROM_ABI ios_base() : __loc_(nullptr) { |
361 | // Purposefully does no initialization |
362 | // |
363 | // Except for the locale, this is a sentinel to avoid destroying |
364 | // an uninitialized object. See |
365 | // test/libcxx/input.output/iostreams.base/ios.base/ios.base.cons/dtor.uninitialized.pass.cpp |
366 | // for the details. |
367 | } |
368 | |
369 | void init(void* __sb); |
370 | _LIBCPP_HIDE_FROM_ABI void* rdbuf() const { return __rdbuf_; } |
371 | |
372 | _LIBCPP_HIDE_FROM_ABI void rdbuf(void* __sb) { |
373 | __rdbuf_ = __sb; |
374 | clear(); |
375 | } |
376 | |
377 | void __call_callbacks(event); |
378 | void copyfmt(const ios_base&); |
379 | void move(ios_base&); |
380 | void swap(ios_base&) _NOEXCEPT; |
381 | |
382 | _LIBCPP_HIDE_FROM_ABI void set_rdbuf(void* __sb) { __rdbuf_ = __sb; } |
383 | |
384 | private: |
385 | // All data members must be scalars |
386 | fmtflags __fmtflags_; |
387 | streamsize __precision_; |
388 | streamsize __width_; |
389 | iostate __rdstate_; |
390 | iostate __exceptions_; |
391 | void* __rdbuf_; |
392 | void* __loc_; |
393 | event_callback* __fn_; |
394 | int* __index_; |
395 | size_t __event_size_; |
396 | size_t __event_cap_; |
397 | // TODO(EricWF): Enable this for both Clang and GCC. Currently it is only |
398 | // enabled with clang. |
399 | # if defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS) |
400 | static atomic<int> __xindex_; |
401 | # else |
402 | static int __xindex_; |
403 | # endif |
404 | long* __iarray_; |
405 | size_t __iarray_size_; |
406 | size_t __iarray_cap_; |
407 | void** __parray_; |
408 | size_t __parray_size_; |
409 | size_t __parray_cap_; |
410 | }; |
411 | |
412 | // enum class io_errc |
413 | _LIBCPP_DECLARE_STRONG_ENUM(io_errc){stream = 1}; |
414 | _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(io_errc) |
415 | |
416 | template <> |
417 | struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc> : public true_type {}; |
418 | |
419 | # ifdef _LIBCPP_CXX03_LANG |
420 | template <> |
421 | struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc::__lx> : public true_type {}; |
422 | # endif |
423 | |
424 | _LIBCPP_EXPORTED_FROM_ABI const error_category& iostream_category() _NOEXCEPT; |
425 | |
426 | inline _LIBCPP_HIDE_FROM_ABI error_code make_error_code(io_errc __e) _NOEXCEPT { |
427 | return error_code(static_cast<int>(__e), iostream_category()); |
428 | } |
429 | |
430 | inline _LIBCPP_HIDE_FROM_ABI error_condition make_error_condition(io_errc __e) _NOEXCEPT { |
431 | return error_condition(static_cast<int>(__e), iostream_category()); |
432 | } |
433 | |
434 | class _LIBCPP_EXPORTED_FROM_ABI ios_base::failure : public system_error { |
435 | public: |
436 | explicit failure(const string& __msg, const error_code& __ec = io_errc::stream); |
437 | explicit failure(const char* __msg, const error_code& __ec = io_errc::stream); |
438 | _LIBCPP_HIDE_FROM_ABI failure(const failure&) _NOEXCEPT = default; |
439 | ~failure() _NOEXCEPT override; |
440 | }; |
441 | |
442 | _LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_failure(char const* __msg) { |
443 | # ifndef _LIBCPP_HAS_NO_EXCEPTIONS |
444 | throw ios_base::failure(__msg); |
445 | # else |
446 | _LIBCPP_VERBOSE_ABORT("ios_base::failure was thrown in -fno-exceptions mode with message \"%s\"" , __msg); |
447 | # endif |
448 | } |
449 | |
450 | class _LIBCPP_EXPORTED_FROM_ABI ios_base::Init { |
451 | public: |
452 | Init(); |
453 | ~Init(); |
454 | }; |
455 | |
456 | // fmtflags |
457 | |
458 | inline _LIBCPP_HIDE_FROM_ABI ios_base::fmtflags ios_base::flags() const { return __fmtflags_; } |
459 | |
460 | inline _LIBCPP_HIDE_FROM_ABI ios_base::fmtflags ios_base::flags(fmtflags __fmtfl) { |
461 | fmtflags __r = __fmtflags_; |
462 | __fmtflags_ = __fmtfl; |
463 | return __r; |
464 | } |
465 | |
466 | inline _LIBCPP_HIDE_FROM_ABI ios_base::fmtflags ios_base::setf(fmtflags __fmtfl) { |
467 | fmtflags __r = __fmtflags_; |
468 | __fmtflags_ |= __fmtfl; |
469 | return __r; |
470 | } |
471 | |
472 | inline _LIBCPP_HIDE_FROM_ABI void ios_base::unsetf(fmtflags __mask) { __fmtflags_ &= ~__mask; } |
473 | |
474 | inline _LIBCPP_HIDE_FROM_ABI ios_base::fmtflags ios_base::setf(fmtflags __fmtfl, fmtflags __mask) { |
475 | fmtflags __r = __fmtflags_; |
476 | unsetf(__mask); |
477 | __fmtflags_ |= __fmtfl & __mask; |
478 | return __r; |
479 | } |
480 | |
481 | // precision |
482 | |
483 | inline _LIBCPP_HIDE_FROM_ABI streamsize ios_base::precision() const { return __precision_; } |
484 | |
485 | inline _LIBCPP_HIDE_FROM_ABI streamsize ios_base::precision(streamsize __prec) { |
486 | streamsize __r = __precision_; |
487 | __precision_ = __prec; |
488 | return __r; |
489 | } |
490 | |
491 | // width |
492 | |
493 | inline _LIBCPP_HIDE_FROM_ABI streamsize ios_base::width() const { return __width_; } |
494 | |
495 | inline _LIBCPP_HIDE_FROM_ABI streamsize ios_base::width(streamsize __wide) { |
496 | streamsize __r = __width_; |
497 | __width_ = __wide; |
498 | return __r; |
499 | } |
500 | |
501 | // iostate |
502 | |
503 | inline _LIBCPP_HIDE_FROM_ABI ios_base::iostate ios_base::rdstate() const { return __rdstate_; } |
504 | |
505 | inline _LIBCPP_HIDE_FROM_ABI void ios_base::setstate(iostate __state) { clear(__rdstate_ | __state); } |
506 | |
507 | inline _LIBCPP_HIDE_FROM_ABI bool ios_base::good() const { return __rdstate_ == 0; } |
508 | |
509 | inline _LIBCPP_HIDE_FROM_ABI bool ios_base::eof() const { return (__rdstate_ & eofbit) != 0; } |
510 | |
511 | inline _LIBCPP_HIDE_FROM_ABI bool ios_base::fail() const { return (__rdstate_ & (failbit | badbit)) != 0; } |
512 | |
513 | inline _LIBCPP_HIDE_FROM_ABI bool ios_base::bad() const { return (__rdstate_ & badbit) != 0; } |
514 | |
515 | inline _LIBCPP_HIDE_FROM_ABI ios_base::iostate ios_base::exceptions() const { return __exceptions_; } |
516 | |
517 | inline _LIBCPP_HIDE_FROM_ABI void ios_base::exceptions(iostate __iostate) { |
518 | __exceptions_ = __iostate; |
519 | clear(__rdstate_); |
520 | } |
521 | |
522 | template <class _Traits> |
523 | // Attribute 'packed' is used to keep the layout compatible with the previous |
524 | // definition of the '__fill_' and '_set_' pair in basic_ios on AIX & z/OS. |
525 | struct _LIBCPP_PACKED _FillHelper { |
526 | _LIBCPP_HIDE_FROM_ABI void __init() { __set_ = false; } |
527 | _LIBCPP_HIDE_FROM_ABI _FillHelper& operator=(typename _Traits::int_type __x) { |
528 | __set_ = true; |
529 | __fill_val_ = __x; |
530 | return *this; |
531 | } |
532 | _LIBCPP_HIDE_FROM_ABI bool __is_set() const { return __set_; } |
533 | _LIBCPP_HIDE_FROM_ABI typename _Traits::int_type __get() const { return __fill_val_; } |
534 | |
535 | private: |
536 | typename _Traits::int_type __fill_val_; |
537 | bool __set_; |
538 | }; |
539 | |
540 | template <class _Traits> |
541 | struct _LIBCPP_PACKED _SentinelValueFill { |
542 | _LIBCPP_HIDE_FROM_ABI void __init() { __fill_val_ = _Traits::eof(); } |
543 | _LIBCPP_HIDE_FROM_ABI _SentinelValueFill& operator=(typename _Traits::int_type __x) { |
544 | __fill_val_ = __x; |
545 | return *this; |
546 | } |
547 | _LIBCPP_HIDE_FROM_ABI bool __is_set() const { return __fill_val_ != _Traits::eof(); } |
548 | _LIBCPP_HIDE_FROM_ABI typename _Traits::int_type __get() const { return __fill_val_; } |
549 | |
550 | private: |
551 | typename _Traits::int_type __fill_val_; |
552 | }; |
553 | |
554 | template <class _CharT, class _Traits> |
555 | class _LIBCPP_TEMPLATE_VIS basic_ios : public ios_base { |
556 | public: |
557 | // types: |
558 | typedef _CharT char_type; |
559 | typedef _Traits traits_type; |
560 | |
561 | typedef typename traits_type::int_type int_type; |
562 | typedef typename traits_type::pos_type pos_type; |
563 | typedef typename traits_type::off_type off_type; |
564 | |
565 | static_assert(is_same<_CharT, typename traits_type::char_type>::value, |
566 | "traits_type::char_type must be the same type as CharT" ); |
567 | |
568 | # ifdef _LIBCPP_CXX03_LANG |
569 | // Preserve the ability to compare with literal 0, |
570 | // and implicitly convert to bool, but not implicitly convert to int. |
571 | _LIBCPP_HIDE_FROM_ABI operator void*() const { return fail() ? nullptr : (void*)this; } |
572 | # else |
573 | _LIBCPP_HIDE_FROM_ABI explicit operator bool() const { return !fail(); } |
574 | # endif |
575 | |
576 | _LIBCPP_HIDE_FROM_ABI bool operator!() const { return fail(); } |
577 | _LIBCPP_HIDE_FROM_ABI iostate rdstate() const { return ios_base::rdstate(); } |
578 | _LIBCPP_HIDE_FROM_ABI void clear(iostate __state = goodbit) { ios_base::clear(__state); } |
579 | _LIBCPP_HIDE_FROM_ABI void setstate(iostate __state) { ios_base::setstate(__state); } |
580 | _LIBCPP_HIDE_FROM_ABI bool good() const { return ios_base::good(); } |
581 | _LIBCPP_HIDE_FROM_ABI bool eof() const { return ios_base::eof(); } |
582 | _LIBCPP_HIDE_FROM_ABI bool fail() const { return ios_base::fail(); } |
583 | _LIBCPP_HIDE_FROM_ABI bool bad() const { return ios_base::bad(); } |
584 | |
585 | _LIBCPP_HIDE_FROM_ABI iostate exceptions() const { return ios_base::exceptions(); } |
586 | _LIBCPP_HIDE_FROM_ABI void exceptions(iostate __iostate) { ios_base::exceptions(__iostate); } |
587 | |
588 | // 27.5.4.1 Constructor/destructor: |
589 | _LIBCPP_HIDE_FROM_ABI explicit basic_ios(basic_streambuf<char_type, traits_type>* __sb); |
590 | ~basic_ios() override; |
591 | |
592 | // 27.5.4.2 Members: |
593 | _LIBCPP_HIDE_FROM_ABI basic_ostream<char_type, traits_type>* tie() const; |
594 | _LIBCPP_HIDE_FROM_ABI basic_ostream<char_type, traits_type>* tie(basic_ostream<char_type, traits_type>* __tiestr); |
595 | |
596 | _LIBCPP_HIDE_FROM_ABI basic_streambuf<char_type, traits_type>* rdbuf() const; |
597 | _LIBCPP_HIDE_FROM_ABI basic_streambuf<char_type, traits_type>* rdbuf(basic_streambuf<char_type, traits_type>* __sb); |
598 | |
599 | basic_ios& copyfmt(const basic_ios& __rhs); |
600 | |
601 | _LIBCPP_HIDE_FROM_ABI char_type fill() const; |
602 | _LIBCPP_HIDE_FROM_ABI char_type fill(char_type __ch); |
603 | |
604 | _LIBCPP_HIDE_FROM_ABI locale imbue(const locale& __loc); |
605 | |
606 | _LIBCPP_HIDE_FROM_ABI char narrow(char_type __c, char __dfault) const; |
607 | _LIBCPP_HIDE_FROM_ABI char_type widen(char __c) const; |
608 | |
609 | protected: |
610 | _LIBCPP_HIDE_FROM_ABI basic_ios() { |
611 | // purposefully does no initialization |
612 | // since the destructor does nothing this does not have ios_base issues. |
613 | } |
614 | _LIBCPP_HIDE_FROM_ABI void init(basic_streambuf<char_type, traits_type>* __sb); |
615 | |
616 | _LIBCPP_HIDE_FROM_ABI void move(basic_ios& __rhs); |
617 | _LIBCPP_HIDE_FROM_ABI void move(basic_ios&& __rhs) { move(__rhs); } |
618 | _LIBCPP_HIDE_FROM_ABI void swap(basic_ios& __rhs) _NOEXCEPT; |
619 | _LIBCPP_HIDE_FROM_ABI void set_rdbuf(basic_streambuf<char_type, traits_type>* __sb); |
620 | |
621 | private: |
622 | basic_ostream<char_type, traits_type>* __tie_; |
623 | |
624 | #if defined(_LIBCPP_ABI_IOS_ALLOW_ARBITRARY_FILL_VALUE) |
625 | using _FillType = _FillHelper<traits_type>; |
626 | #else |
627 | using _FillType = _SentinelValueFill<traits_type>; |
628 | #endif |
629 | mutable _FillType __fill_; |
630 | }; |
631 | |
632 | template <class _CharT, class _Traits> |
633 | inline _LIBCPP_HIDE_FROM_ABI basic_ios<_CharT, _Traits>::basic_ios(basic_streambuf<char_type, traits_type>* __sb) { |
634 | init(__sb); |
635 | } |
636 | |
637 | template <class _CharT, class _Traits> |
638 | basic_ios<_CharT, _Traits>::~basic_ios() {} |
639 | |
640 | template <class _CharT, class _Traits> |
641 | inline _LIBCPP_HIDE_FROM_ABI void basic_ios<_CharT, _Traits>::init(basic_streambuf<char_type, traits_type>* __sb) { |
642 | ios_base::init(__sb); |
643 | __tie_ = nullptr; |
644 | __fill_.__init(); |
645 | } |
646 | |
647 | template <class _CharT, class _Traits> |
648 | inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>* basic_ios<_CharT, _Traits>::tie() const { |
649 | return __tie_; |
650 | } |
651 | |
652 | template <class _CharT, class _Traits> |
653 | inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>* |
654 | basic_ios<_CharT, _Traits>::tie(basic_ostream<char_type, traits_type>* __tiestr) { |
655 | basic_ostream<char_type, traits_type>* __r = __tie_; |
656 | __tie_ = __tiestr; |
657 | return __r; |
658 | } |
659 | |
660 | template <class _CharT, class _Traits> |
661 | inline _LIBCPP_HIDE_FROM_ABI basic_streambuf<_CharT, _Traits>* basic_ios<_CharT, _Traits>::rdbuf() const { |
662 | return static_cast<basic_streambuf<char_type, traits_type>*>(ios_base::rdbuf()); |
663 | } |
664 | |
665 | template <class _CharT, class _Traits> |
666 | inline _LIBCPP_HIDE_FROM_ABI basic_streambuf<_CharT, _Traits>* |
667 | basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<char_type, traits_type>* __sb) { |
668 | basic_streambuf<char_type, traits_type>* __r = rdbuf(); |
669 | ios_base::rdbuf(__sb); |
670 | return __r; |
671 | } |
672 | |
673 | template <class _CharT, class _Traits> |
674 | inline _LIBCPP_HIDE_FROM_ABI locale basic_ios<_CharT, _Traits>::imbue(const locale& __loc) { |
675 | locale __r = getloc(); |
676 | ios_base::imbue(__loc); |
677 | if (rdbuf()) |
678 | rdbuf()->pubimbue(__loc); |
679 | return __r; |
680 | } |
681 | |
682 | template <class _CharT, class _Traits> |
683 | inline _LIBCPP_HIDE_FROM_ABI char basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const { |
684 | return std::use_facet<ctype<char_type> >(getloc()).narrow(__c, __dfault); |
685 | } |
686 | |
687 | template <class _CharT, class _Traits> |
688 | inline _LIBCPP_HIDE_FROM_ABI _CharT basic_ios<_CharT, _Traits>::widen(char __c) const { |
689 | return std::use_facet<ctype<char_type> >(getloc()).widen(__c); |
690 | } |
691 | |
692 | template <class _CharT, class _Traits> |
693 | inline _LIBCPP_HIDE_FROM_ABI _CharT basic_ios<_CharT, _Traits>::fill() const { |
694 | if (!__fill_.__is_set()) |
695 | __fill_ = widen(' '); |
696 | return __fill_.__get(); |
697 | } |
698 | |
699 | template <class _CharT, class _Traits> |
700 | inline _LIBCPP_HIDE_FROM_ABI _CharT basic_ios<_CharT, _Traits>::fill(char_type __ch) { |
701 | if (!__fill_.__is_set()) |
702 | __fill_ = widen(' '); |
703 | char_type __r = __fill_.__get(); |
704 | __fill_ = __ch; |
705 | return __r; |
706 | } |
707 | |
708 | template <class _CharT, class _Traits> |
709 | basic_ios<_CharT, _Traits>& basic_ios<_CharT, _Traits>::copyfmt(const basic_ios& __rhs) { |
710 | if (this != &__rhs) { |
711 | __call_callbacks(erase_event); |
712 | ios_base::copyfmt(__rhs); |
713 | __tie_ = __rhs.__tie_; |
714 | __fill_ = __rhs.__fill_; |
715 | __call_callbacks(copyfmt_event); |
716 | exceptions(__rhs.exceptions()); |
717 | } |
718 | return *this; |
719 | } |
720 | |
721 | template <class _CharT, class _Traits> |
722 | inline _LIBCPP_HIDE_FROM_ABI void basic_ios<_CharT, _Traits>::move(basic_ios& __rhs) { |
723 | ios_base::move(__rhs); |
724 | __tie_ = __rhs.__tie_; |
725 | __rhs.__tie_ = nullptr; |
726 | __fill_ = __rhs.__fill_; |
727 | } |
728 | |
729 | template <class _CharT, class _Traits> |
730 | inline _LIBCPP_HIDE_FROM_ABI void basic_ios<_CharT, _Traits>::swap(basic_ios& __rhs) _NOEXCEPT { |
731 | ios_base::swap(__rhs); |
732 | std::swap(__tie_, __rhs.__tie_); |
733 | std::swap(__fill_, __rhs.__fill_); |
734 | } |
735 | |
736 | template <class _CharT, class _Traits> |
737 | inline _LIBCPP_HIDE_FROM_ABI void basic_ios<_CharT, _Traits>::set_rdbuf(basic_streambuf<char_type, traits_type>* __sb) { |
738 | ios_base::set_rdbuf(__sb); |
739 | } |
740 | |
741 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios<char>; |
742 | |
743 | # ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
744 | extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios<wchar_t>; |
745 | # endif |
746 | |
747 | _LIBCPP_HIDE_FROM_ABI inline ios_base& boolalpha(ios_base& __str) { |
748 | __str.setf(ios_base::boolalpha); |
749 | return __str; |
750 | } |
751 | |
752 | _LIBCPP_HIDE_FROM_ABI inline ios_base& noboolalpha(ios_base& __str) { |
753 | __str.unsetf(ios_base::boolalpha); |
754 | return __str; |
755 | } |
756 | |
757 | _LIBCPP_HIDE_FROM_ABI inline ios_base& showbase(ios_base& __str) { |
758 | __str.setf(ios_base::showbase); |
759 | return __str; |
760 | } |
761 | |
762 | _LIBCPP_HIDE_FROM_ABI inline ios_base& noshowbase(ios_base& __str) { |
763 | __str.unsetf(ios_base::showbase); |
764 | return __str; |
765 | } |
766 | |
767 | _LIBCPP_HIDE_FROM_ABI inline ios_base& showpoint(ios_base& __str) { |
768 | __str.setf(ios_base::showpoint); |
769 | return __str; |
770 | } |
771 | |
772 | _LIBCPP_HIDE_FROM_ABI inline ios_base& noshowpoint(ios_base& __str) { |
773 | __str.unsetf(ios_base::showpoint); |
774 | return __str; |
775 | } |
776 | |
777 | _LIBCPP_HIDE_FROM_ABI inline ios_base& showpos(ios_base& __str) { |
778 | __str.setf(ios_base::showpos); |
779 | return __str; |
780 | } |
781 | |
782 | _LIBCPP_HIDE_FROM_ABI inline ios_base& noshowpos(ios_base& __str) { |
783 | __str.unsetf(ios_base::showpos); |
784 | return __str; |
785 | } |
786 | |
787 | _LIBCPP_HIDE_FROM_ABI inline ios_base& skipws(ios_base& __str) { |
788 | __str.setf(ios_base::skipws); |
789 | return __str; |
790 | } |
791 | |
792 | _LIBCPP_HIDE_FROM_ABI inline ios_base& noskipws(ios_base& __str) { |
793 | __str.unsetf(ios_base::skipws); |
794 | return __str; |
795 | } |
796 | |
797 | _LIBCPP_HIDE_FROM_ABI inline ios_base& uppercase(ios_base& __str) { |
798 | __str.setf(ios_base::uppercase); |
799 | return __str; |
800 | } |
801 | |
802 | _LIBCPP_HIDE_FROM_ABI inline ios_base& nouppercase(ios_base& __str) { |
803 | __str.unsetf(ios_base::uppercase); |
804 | return __str; |
805 | } |
806 | |
807 | _LIBCPP_HIDE_FROM_ABI inline ios_base& unitbuf(ios_base& __str) { |
808 | __str.setf(ios_base::unitbuf); |
809 | return __str; |
810 | } |
811 | |
812 | _LIBCPP_HIDE_FROM_ABI inline ios_base& nounitbuf(ios_base& __str) { |
813 | __str.unsetf(ios_base::unitbuf); |
814 | return __str; |
815 | } |
816 | |
817 | _LIBCPP_HIDE_FROM_ABI inline ios_base& internal(ios_base& __str) { |
818 | __str.setf(ios_base::internal, ios_base::adjustfield); |
819 | return __str; |
820 | } |
821 | |
822 | _LIBCPP_HIDE_FROM_ABI inline ios_base& left(ios_base& __str) { |
823 | __str.setf(ios_base::left, ios_base::adjustfield); |
824 | return __str; |
825 | } |
826 | |
827 | _LIBCPP_HIDE_FROM_ABI inline ios_base& right(ios_base& __str) { |
828 | __str.setf(ios_base::right, ios_base::adjustfield); |
829 | return __str; |
830 | } |
831 | |
832 | _LIBCPP_HIDE_FROM_ABI inline ios_base& dec(ios_base& __str) { |
833 | __str.setf(ios_base::dec, ios_base::basefield); |
834 | return __str; |
835 | } |
836 | |
837 | _LIBCPP_HIDE_FROM_ABI inline ios_base& hex(ios_base& __str) { |
838 | __str.setf(ios_base::hex, ios_base::basefield); |
839 | return __str; |
840 | } |
841 | |
842 | _LIBCPP_HIDE_FROM_ABI inline ios_base& oct(ios_base& __str) { |
843 | __str.setf(ios_base::oct, ios_base::basefield); |
844 | return __str; |
845 | } |
846 | |
847 | _LIBCPP_HIDE_FROM_ABI inline ios_base& fixed(ios_base& __str) { |
848 | __str.setf(ios_base::fixed, ios_base::floatfield); |
849 | return __str; |
850 | } |
851 | |
852 | _LIBCPP_HIDE_FROM_ABI inline ios_base& scientific(ios_base& __str) { |
853 | __str.setf(ios_base::scientific, ios_base::floatfield); |
854 | return __str; |
855 | } |
856 | |
857 | _LIBCPP_HIDE_FROM_ABI inline ios_base& hexfloat(ios_base& __str) { |
858 | __str.setf(ios_base::fixed | ios_base::scientific, ios_base::floatfield); |
859 | return __str; |
860 | } |
861 | |
862 | _LIBCPP_HIDE_FROM_ABI inline ios_base& defaultfloat(ios_base& __str) { |
863 | __str.unsetf(ios_base::floatfield); |
864 | return __str; |
865 | } |
866 | |
867 | _LIBCPP_END_NAMESPACE_STD |
868 | |
869 | _LIBCPP_POP_MACROS |
870 | |
871 | #endif // !defined(_LIBCPP_HAS_NO_LOCALIZATION) |
872 | |
873 | #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 |
874 | # include <atomic> |
875 | # include <concepts> |
876 | # include <cstddef> |
877 | # include <cstdlib> |
878 | # include <cstring> |
879 | # include <initializer_list> |
880 | # include <limits> |
881 | # include <mutex> |
882 | # include <new> |
883 | # include <stdexcept> |
884 | # include <system_error> |
885 | # include <type_traits> |
886 | # include <typeinfo> |
887 | #endif |
888 | |
889 | #endif // _LIBCPP_IOS |
890 | |