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