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#include <__config> 215 216#if defined(_LIBCPP_HAS_NO_LOCALIZATION) 217# error "The iostreams library is not supported since libc++ has been configured without support for localization." 218#endif 219 220#include <__assert> // all public C++ headers provide the assertion handler 221#include <__fwd/ios.h> 222#include <__ios/fpos.h> 223#include <__locale> 224#include <__system_error/error_category.h> 225#include <__system_error/error_code.h> 226#include <__system_error/error_condition.h> 227#include <__system_error/system_error.h> 228#include <__utility/swap.h> 229#include <__verbose_abort> 230#include <version> 231 232// standard-mandated includes 233 234// [ios.syn] 235#include <iosfwd> 236 237#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) 238# include <__atomic/atomic.h> // for __xindex_ 239#endif 240 241#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 242# pragma GCC system_header 243#endif 244 245_LIBCPP_BEGIN_NAMESPACE_STD 246 247typedef ptrdiff_t streamsize; 248 249class _LIBCPP_EXPORTED_FROM_ABI ios_base 250{ 251public: 252 class _LIBCPP_EXPORTED_FROM_ABI failure; 253 254 typedef unsigned int fmtflags; 255 static const fmtflags boolalpha = 0x0001; 256 static const fmtflags dec = 0x0002; 257 static const fmtflags fixed = 0x0004; 258 static const fmtflags hex = 0x0008; 259 static const fmtflags internal = 0x0010; 260 static const fmtflags left = 0x0020; 261 static const fmtflags oct = 0x0040; 262 static const fmtflags right = 0x0080; 263 static const fmtflags scientific = 0x0100; 264 static const fmtflags showbase = 0x0200; 265 static const fmtflags showpoint = 0x0400; 266 static const fmtflags showpos = 0x0800; 267 static const fmtflags skipws = 0x1000; 268 static const fmtflags unitbuf = 0x2000; 269 static const fmtflags uppercase = 0x4000; 270 static const fmtflags adjustfield = left | right | internal; 271 static const fmtflags basefield = dec | oct | hex; 272 static const fmtflags floatfield = scientific | fixed; 273 274 typedef unsigned int iostate; 275 static const iostate badbit = 0x1; 276 static const iostate eofbit = 0x2; 277 static const iostate failbit = 0x4; 278 static const iostate goodbit = 0x0; 279 280 typedef unsigned int openmode; 281 static const openmode app = 0x01; 282 static const openmode ate = 0x02; 283 static const openmode binary = 0x04; 284 static const openmode in = 0x08; 285 static const openmode out = 0x10; 286 static const openmode trunc = 0x20; 287#if _LIBCPP_STD_VER >= 23 288 static const openmode noreplace = 0x40; 289#endif 290 291 enum seekdir {beg, cur, end}; 292 293#if _LIBCPP_STD_VER <= 14 294 typedef iostate io_state; 295 typedef openmode open_mode; 296 typedef seekdir seek_dir; 297 298 typedef std::streamoff streamoff; 299 typedef std::streampos streampos; 300#endif 301 302 class _LIBCPP_EXPORTED_FROM_ABI Init; 303 304 // 27.5.2.2 fmtflags state: 305 _LIBCPP_HIDE_FROM_ABI fmtflags flags() const; 306 _LIBCPP_HIDE_FROM_ABI fmtflags flags(fmtflags __fmtfl); 307 _LIBCPP_HIDE_FROM_ABI fmtflags setf(fmtflags __fmtfl); 308 _LIBCPP_HIDE_FROM_ABI fmtflags setf(fmtflags __fmtfl, fmtflags __mask); 309 _LIBCPP_HIDE_FROM_ABI void unsetf(fmtflags __mask); 310 311 _LIBCPP_HIDE_FROM_ABI streamsize precision() const; 312 _LIBCPP_HIDE_FROM_ABI streamsize precision(streamsize __prec); 313 _LIBCPP_HIDE_FROM_ABI streamsize width() const; 314 _LIBCPP_HIDE_FROM_ABI streamsize width(streamsize __wide); 315 316 // 27.5.2.3 locales: 317 locale imbue(const locale& __loc); 318 locale getloc() const; 319 320 // 27.5.2.5 storage: 321 static int xalloc(); 322 long& iword(int __index); 323 void*& pword(int __index); 324 325 // destructor 326 virtual ~ios_base(); 327 328 // 27.5.2.6 callbacks; 329 enum event { erase_event, imbue_event, copyfmt_event }; 330 typedef void (*event_callback)(event, ios_base&, int __index); 331 void register_callback(event_callback __fn, int __index); 332 333 ios_base(const ios_base&) = delete; 334 ios_base& operator=(const ios_base&) = delete; 335 336 static bool sync_with_stdio(bool __sync = true); 337 338 _LIBCPP_HIDE_FROM_ABI iostate rdstate() const; 339 void clear(iostate __state = goodbit); 340 _LIBCPP_HIDE_FROM_ABI void setstate(iostate __state); 341 342 _LIBCPP_HIDE_FROM_ABI bool good() const; 343 _LIBCPP_HIDE_FROM_ABI bool eof() const; 344 _LIBCPP_HIDE_FROM_ABI bool fail() const; 345 _LIBCPP_HIDE_FROM_ABI bool bad() const; 346 347 _LIBCPP_HIDE_FROM_ABI iostate exceptions() const; 348 _LIBCPP_HIDE_FROM_ABI void exceptions(iostate __iostate); 349 350 void __set_badbit_and_consider_rethrow(); 351 void __set_failbit_and_consider_rethrow(); 352 353 _LIBCPP_HIDE_FROM_ABI 354 void __setstate_nothrow(iostate __state) 355 { 356 if (__rdbuf_) 357 __rdstate_ |= __state; 358 else 359 __rdstate_ |= __state | ios_base::badbit; 360 } 361 362protected: 363 _LIBCPP_HIDE_FROM_ABI 364 ios_base() {// purposefully does no initialization 365 } 366 367 void init(void* __sb); 368 _LIBCPP_HIDE_FROM_ABI void* rdbuf() const {return __rdbuf_;} 369 370 _LIBCPP_HIDE_FROM_ABI 371 void rdbuf(void* __sb) 372 { 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 383 void set_rdbuf(void* __sb) 384 { 385 __rdbuf_ = __sb; 386 } 387 388private: 389 // All data members must be scalars 390 fmtflags __fmtflags_; 391 streamsize __precision_; 392 streamsize __width_; 393 iostate __rdstate_; 394 iostate __exceptions_; 395 void* __rdbuf_; 396 void* __loc_; 397 event_callback* __fn_; 398 int* __index_; 399 size_t __event_size_; 400 size_t __event_cap_; 401// TODO(EricWF): Enable this for both Clang and GCC. Currently it is only 402// enabled with clang. 403#if defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS) 404 static atomic<int> __xindex_; 405#else 406 static int __xindex_; 407#endif 408 long* __iarray_; 409 size_t __iarray_size_; 410 size_t __iarray_cap_; 411 void** __parray_; 412 size_t __parray_size_; 413 size_t __parray_cap_; 414}; 415 416//enum class io_errc 417_LIBCPP_DECLARE_STRONG_ENUM(io_errc) 418{ 419 stream = 1 420}; 421_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(io_errc) 422 423template <> 424struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc> : public true_type { }; 425 426#ifdef _LIBCPP_CXX03_LANG 427template <> 428struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc::__lx> : public true_type { }; 429#endif 430 431_LIBCPP_EXPORTED_FROM_ABI const error_category& iostream_category() _NOEXCEPT; 432 433inline _LIBCPP_HIDE_FROM_ABI 434error_code 435make_error_code(io_errc __e) _NOEXCEPT 436{ 437 return error_code(static_cast<int>(__e), iostream_category()); 438} 439 440inline _LIBCPP_HIDE_FROM_ABI 441error_condition 442make_error_condition(io_errc __e) _NOEXCEPT 443{ 444 return error_condition(static_cast<int>(__e), iostream_category()); 445} 446 447class _LIBCPP_EXPORTED_FROM_ABI ios_base::failure 448 : public system_error 449{ 450public: 451 explicit failure(const string& __msg, const error_code& __ec = io_errc::stream); 452 explicit failure(const char* __msg, const error_code& __ec = io_errc::stream); 453 _LIBCPP_HIDE_FROM_ABI failure(const failure&) _NOEXCEPT = default; 454 ~failure() _NOEXCEPT override; 455}; 456 457_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI 458void __throw_failure(char const* __msg) { 459#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 460 throw ios_base::failure(__msg); 461#else 462 _LIBCPP_VERBOSE_ABORT("ios_base::failure was thrown in -fno-exceptions mode with message \"%s\"", __msg); 463#endif 464} 465 466class _LIBCPP_EXPORTED_FROM_ABI ios_base::Init 467{ 468public: 469 Init(); 470 ~Init(); 471}; 472 473// fmtflags 474 475inline _LIBCPP_HIDE_FROM_ABI 476ios_base::fmtflags 477ios_base::flags() const 478{ 479 return __fmtflags_; 480} 481 482inline _LIBCPP_HIDE_FROM_ABI 483ios_base::fmtflags 484ios_base::flags(fmtflags __fmtfl) 485{ 486 fmtflags __r = __fmtflags_; 487 __fmtflags_ = __fmtfl; 488 return __r; 489} 490 491inline _LIBCPP_HIDE_FROM_ABI 492ios_base::fmtflags 493ios_base::setf(fmtflags __fmtfl) 494{ 495 fmtflags __r = __fmtflags_; 496 __fmtflags_ |= __fmtfl; 497 return __r; 498} 499 500inline _LIBCPP_HIDE_FROM_ABI 501void 502ios_base::unsetf(fmtflags __mask) 503{ 504 __fmtflags_ &= ~__mask; 505} 506 507inline _LIBCPP_HIDE_FROM_ABI 508ios_base::fmtflags 509ios_base::setf(fmtflags __fmtfl, fmtflags __mask) 510{ 511 fmtflags __r = __fmtflags_; 512 unsetf(__mask); 513 __fmtflags_ |= __fmtfl & __mask; 514 return __r; 515} 516 517// precision 518 519inline _LIBCPP_HIDE_FROM_ABI 520streamsize 521ios_base::precision() const 522{ 523 return __precision_; 524} 525 526inline _LIBCPP_HIDE_FROM_ABI 527streamsize 528ios_base::precision(streamsize __prec) 529{ 530 streamsize __r = __precision_; 531 __precision_ = __prec; 532 return __r; 533} 534 535// width 536 537inline _LIBCPP_HIDE_FROM_ABI 538streamsize 539ios_base::width() const 540{ 541 return __width_; 542} 543 544inline _LIBCPP_HIDE_FROM_ABI 545streamsize 546ios_base::width(streamsize __wide) 547{ 548 streamsize __r = __width_; 549 __width_ = __wide; 550 return __r; 551} 552 553// iostate 554 555inline _LIBCPP_HIDE_FROM_ABI 556ios_base::iostate 557ios_base::rdstate() const 558{ 559 return __rdstate_; 560} 561 562inline _LIBCPP_HIDE_FROM_ABI 563void 564ios_base::setstate(iostate __state) 565{ 566 clear(__rdstate_ | __state); 567} 568 569inline _LIBCPP_HIDE_FROM_ABI 570bool 571ios_base::good() const 572{ 573 return __rdstate_ == 0; 574} 575 576inline _LIBCPP_HIDE_FROM_ABI 577bool 578ios_base::eof() const 579{ 580 return (__rdstate_ & eofbit) != 0; 581} 582 583inline _LIBCPP_HIDE_FROM_ABI 584bool 585ios_base::fail() const 586{ 587 return (__rdstate_ & (failbit | badbit)) != 0; 588} 589 590inline _LIBCPP_HIDE_FROM_ABI 591bool 592ios_base::bad() const 593{ 594 return (__rdstate_ & badbit) != 0; 595} 596 597inline _LIBCPP_HIDE_FROM_ABI 598ios_base::iostate 599ios_base::exceptions() const 600{ 601 return __exceptions_; 602} 603 604inline _LIBCPP_HIDE_FROM_ABI 605void 606ios_base::exceptions(iostate __iostate) 607{ 608 __exceptions_ = __iostate; 609 clear(__rdstate_); 610} 611 612template <class _CharT, class _Traits> 613class _LIBCPP_TEMPLATE_VIS basic_ios 614 : public ios_base 615{ 616public: 617 // types: 618 typedef _CharT char_type; 619 typedef _Traits traits_type; 620 621 typedef typename traits_type::int_type int_type; 622 typedef typename traits_type::pos_type pos_type; 623 typedef typename traits_type::off_type off_type; 624 625 static_assert((is_same<_CharT, typename traits_type::char_type>::value), 626 "traits_type::char_type must be the same type as CharT"); 627 628#ifdef _LIBCPP_CXX03_LANG 629 // Preserve the ability to compare with literal 0, 630 // and implicitly convert to bool, but not implicitly convert to int. 631 _LIBCPP_HIDE_FROM_ABI 632 operator void*() const {return fail() ? nullptr : (void*)this;} 633#else 634 _LIBCPP_HIDE_FROM_ABI 635 explicit operator bool() const {return !fail();} 636#endif 637 638 _LIBCPP_HIDE_FROM_ABI bool operator!() const {return fail();} 639 _LIBCPP_HIDE_FROM_ABI iostate rdstate() const {return ios_base::rdstate();} 640 _LIBCPP_HIDE_FROM_ABI void clear(iostate __state = goodbit) {ios_base::clear(__state);} 641 _LIBCPP_HIDE_FROM_ABI void setstate(iostate __state) {ios_base::setstate(__state);} 642 _LIBCPP_HIDE_FROM_ABI bool good() const {return ios_base::good();} 643 _LIBCPP_HIDE_FROM_ABI bool eof() const {return ios_base::eof();} 644 _LIBCPP_HIDE_FROM_ABI bool fail() const {return ios_base::fail();} 645 _LIBCPP_HIDE_FROM_ABI bool bad() const {return ios_base::bad();} 646 647 _LIBCPP_HIDE_FROM_ABI iostate exceptions() const {return ios_base::exceptions();} 648 _LIBCPP_HIDE_FROM_ABI void exceptions(iostate __iostate) {ios_base::exceptions(__iostate);} 649 650 // 27.5.4.1 Constructor/destructor: 651 _LIBCPP_HIDE_FROM_ABI 652 explicit basic_ios(basic_streambuf<char_type,traits_type>* __sb); 653 ~basic_ios() override; 654 655 // 27.5.4.2 Members: 656 _LIBCPP_HIDE_FROM_ABI 657 basic_ostream<char_type, traits_type>* tie() const; 658 _LIBCPP_HIDE_FROM_ABI 659 basic_ostream<char_type, traits_type>* tie(basic_ostream<char_type, traits_type>* __tiestr); 660 661 _LIBCPP_HIDE_FROM_ABI 662 basic_streambuf<char_type, traits_type>* rdbuf() const; 663 _LIBCPP_HIDE_FROM_ABI 664 basic_streambuf<char_type, traits_type>* rdbuf(basic_streambuf<char_type, traits_type>* __sb); 665 666 basic_ios& copyfmt(const basic_ios& __rhs); 667 668 _LIBCPP_HIDE_FROM_ABI 669 char_type fill() const; 670 _LIBCPP_HIDE_FROM_ABI 671 char_type fill(char_type __ch); 672 673 _LIBCPP_HIDE_FROM_ABI 674 locale imbue(const locale& __loc); 675 676 _LIBCPP_HIDE_FROM_ABI 677 char narrow(char_type __c, char __dfault) const; 678 _LIBCPP_HIDE_FROM_ABI 679 char_type widen(char __c) const; 680 681protected: 682 _LIBCPP_HIDE_FROM_ABI 683 basic_ios() {// purposefully does no initialization 684 } 685 _LIBCPP_HIDE_FROM_ABI 686 void init(basic_streambuf<char_type, traits_type>* __sb); 687 688 _LIBCPP_HIDE_FROM_ABI 689 void move(basic_ios& __rhs); 690 _LIBCPP_HIDE_FROM_ABI 691 void move(basic_ios&& __rhs) {move(__rhs);} 692 _LIBCPP_HIDE_FROM_ABI 693 void swap(basic_ios& __rhs) _NOEXCEPT; 694 _LIBCPP_HIDE_FROM_ABI 695 void set_rdbuf(basic_streambuf<char_type, traits_type>* __sb); 696private: 697 basic_ostream<char_type, traits_type>* __tie_; 698 mutable int_type __fill_; 699}; 700 701template <class _CharT, class _Traits> 702inline _LIBCPP_HIDE_FROM_ABI 703basic_ios<_CharT, _Traits>::basic_ios(basic_streambuf<char_type,traits_type>* __sb) 704{ 705 init(__sb); 706} 707 708template <class _CharT, class _Traits> 709basic_ios<_CharT, _Traits>::~basic_ios() 710{ 711} 712 713template <class _CharT, class _Traits> 714inline _LIBCPP_HIDE_FROM_ABI 715void 716basic_ios<_CharT, _Traits>::init(basic_streambuf<char_type, traits_type>* __sb) 717{ 718 ios_base::init(__sb); 719 __tie_ = nullptr; 720 __fill_ = traits_type::eof(); 721} 722 723template <class _CharT, class _Traits> 724inline _LIBCPP_HIDE_FROM_ABI 725basic_ostream<_CharT, _Traits>* 726basic_ios<_CharT, _Traits>::tie() const 727{ 728 return __tie_; 729} 730 731template <class _CharT, class _Traits> 732inline _LIBCPP_HIDE_FROM_ABI 733basic_ostream<_CharT, _Traits>* 734basic_ios<_CharT, _Traits>::tie(basic_ostream<char_type, traits_type>* __tiestr) 735{ 736 basic_ostream<char_type, traits_type>* __r = __tie_; 737 __tie_ = __tiestr; 738 return __r; 739} 740 741template <class _CharT, class _Traits> 742inline _LIBCPP_HIDE_FROM_ABI 743basic_streambuf<_CharT, _Traits>* 744basic_ios<_CharT, _Traits>::rdbuf() const 745{ 746 return static_cast<basic_streambuf<char_type, traits_type>*>(ios_base::rdbuf()); 747} 748 749template <class _CharT, class _Traits> 750inline _LIBCPP_HIDE_FROM_ABI 751basic_streambuf<_CharT, _Traits>* 752basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<char_type, traits_type>* __sb) 753{ 754 basic_streambuf<char_type, traits_type>* __r = rdbuf(); 755 ios_base::rdbuf(__sb); 756 return __r; 757} 758 759template <class _CharT, class _Traits> 760inline _LIBCPP_HIDE_FROM_ABI 761locale 762basic_ios<_CharT, _Traits>::imbue(const locale& __loc) 763{ 764 locale __r = getloc(); 765 ios_base::imbue(__loc); 766 if (rdbuf()) 767 rdbuf()->pubimbue(__loc); 768 return __r; 769} 770 771template <class _CharT, class _Traits> 772inline _LIBCPP_HIDE_FROM_ABI 773char 774basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const 775{ 776 return std::use_facet<ctype<char_type> >(getloc()).narrow(__c, __dfault); 777} 778 779template <class _CharT, class _Traits> 780inline _LIBCPP_HIDE_FROM_ABI 781_CharT 782basic_ios<_CharT, _Traits>::widen(char __c) const 783{ 784 return std::use_facet<ctype<char_type> >(getloc()).widen(__c); 785} 786 787template <class _CharT, class _Traits> 788inline _LIBCPP_HIDE_FROM_ABI 789_CharT 790basic_ios<_CharT, _Traits>::fill() const 791{ 792 if (traits_type::eq_int_type(traits_type::eof(), __fill_)) 793 __fill_ = widen(' '); 794 return __fill_; 795} 796 797template <class _CharT, class _Traits> 798inline _LIBCPP_HIDE_FROM_ABI 799_CharT 800basic_ios<_CharT, _Traits>::fill(char_type __ch) 801{ 802 if (traits_type::eq_int_type(traits_type::eof(), __fill_)) 803 __fill_ = widen(' '); 804 char_type __r = __fill_; 805 __fill_ = __ch; 806 return __r; 807} 808 809template <class _CharT, class _Traits> 810basic_ios<_CharT, _Traits>& 811basic_ios<_CharT, _Traits>::copyfmt(const basic_ios& __rhs) 812{ 813 if (this != &__rhs) 814 { 815 __call_callbacks(erase_event); 816 ios_base::copyfmt(__rhs); 817 __tie_ = __rhs.__tie_; 818 __fill_ = __rhs.__fill_; 819 __call_callbacks(copyfmt_event); 820 exceptions(__rhs.exceptions()); 821 } 822 return *this; 823} 824 825template <class _CharT, class _Traits> 826inline _LIBCPP_HIDE_FROM_ABI 827void 828basic_ios<_CharT, _Traits>::move(basic_ios& __rhs) 829{ 830 ios_base::move(__rhs); 831 __tie_ = __rhs.__tie_; 832 __rhs.__tie_ = nullptr; 833 __fill_ = __rhs.__fill_; 834} 835 836template <class _CharT, class _Traits> 837inline _LIBCPP_HIDE_FROM_ABI 838void 839basic_ios<_CharT, _Traits>::swap(basic_ios& __rhs) _NOEXCEPT 840{ 841 ios_base::swap(__rhs); 842 std::swap(__tie_, __rhs.__tie_); 843 std::swap(__fill_, __rhs.__fill_); 844} 845 846template <class _CharT, class _Traits> 847inline _LIBCPP_HIDE_FROM_ABI 848void 849basic_ios<_CharT, _Traits>::set_rdbuf(basic_streambuf<char_type, traits_type>* __sb) 850{ 851 ios_base::set_rdbuf(__sb); 852} 853 854extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios<char>; 855 856#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 857extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios<wchar_t>; 858#endif 859 860_LIBCPP_HIDE_FROM_ABI inline 861ios_base& 862boolalpha(ios_base& __str) 863{ 864 __str.setf(ios_base::boolalpha); 865 return __str; 866} 867 868_LIBCPP_HIDE_FROM_ABI inline 869ios_base& 870noboolalpha(ios_base& __str) 871{ 872 __str.unsetf(ios_base::boolalpha); 873 return __str; 874} 875 876_LIBCPP_HIDE_FROM_ABI inline 877ios_base& 878showbase(ios_base& __str) 879{ 880 __str.setf(ios_base::showbase); 881 return __str; 882} 883 884_LIBCPP_HIDE_FROM_ABI inline 885ios_base& 886noshowbase(ios_base& __str) 887{ 888 __str.unsetf(ios_base::showbase); 889 return __str; 890} 891 892_LIBCPP_HIDE_FROM_ABI inline 893ios_base& 894showpoint(ios_base& __str) 895{ 896 __str.setf(ios_base::showpoint); 897 return __str; 898} 899 900_LIBCPP_HIDE_FROM_ABI inline 901ios_base& 902noshowpoint(ios_base& __str) 903{ 904 __str.unsetf(ios_base::showpoint); 905 return __str; 906} 907 908_LIBCPP_HIDE_FROM_ABI inline 909ios_base& 910showpos(ios_base& __str) 911{ 912 __str.setf(ios_base::showpos); 913 return __str; 914} 915 916_LIBCPP_HIDE_FROM_ABI inline 917ios_base& 918noshowpos(ios_base& __str) 919{ 920 __str.unsetf(ios_base::showpos); 921 return __str; 922} 923 924_LIBCPP_HIDE_FROM_ABI inline 925ios_base& 926skipws(ios_base& __str) 927{ 928 __str.setf(ios_base::skipws); 929 return __str; 930} 931 932_LIBCPP_HIDE_FROM_ABI inline 933ios_base& 934noskipws(ios_base& __str) 935{ 936 __str.unsetf(ios_base::skipws); 937 return __str; 938} 939 940_LIBCPP_HIDE_FROM_ABI inline 941ios_base& 942uppercase(ios_base& __str) 943{ 944 __str.setf(ios_base::uppercase); 945 return __str; 946} 947 948_LIBCPP_HIDE_FROM_ABI inline 949ios_base& 950nouppercase(ios_base& __str) 951{ 952 __str.unsetf(ios_base::uppercase); 953 return __str; 954} 955 956_LIBCPP_HIDE_FROM_ABI inline 957ios_base& 958unitbuf(ios_base& __str) 959{ 960 __str.setf(ios_base::unitbuf); 961 return __str; 962} 963 964_LIBCPP_HIDE_FROM_ABI inline 965ios_base& 966nounitbuf(ios_base& __str) 967{ 968 __str.unsetf(ios_base::unitbuf); 969 return __str; 970} 971 972_LIBCPP_HIDE_FROM_ABI inline 973ios_base& 974internal(ios_base& __str) 975{ 976 __str.setf(ios_base::internal, ios_base::adjustfield); 977 return __str; 978} 979 980_LIBCPP_HIDE_FROM_ABI inline 981ios_base& 982left(ios_base& __str) 983{ 984 __str.setf(ios_base::left, ios_base::adjustfield); 985 return __str; 986} 987 988_LIBCPP_HIDE_FROM_ABI inline 989ios_base& 990right(ios_base& __str) 991{ 992 __str.setf(ios_base::right, ios_base::adjustfield); 993 return __str; 994} 995 996_LIBCPP_HIDE_FROM_ABI inline 997ios_base& 998dec(ios_base& __str) 999{ 1000 __str.setf(ios_base::dec, ios_base::basefield); 1001 return __str; 1002} 1003 1004_LIBCPP_HIDE_FROM_ABI inline 1005ios_base& 1006hex(ios_base& __str) 1007{ 1008 __str.setf(ios_base::hex, ios_base::basefield); 1009 return __str; 1010} 1011 1012_LIBCPP_HIDE_FROM_ABI inline 1013ios_base& 1014oct(ios_base& __str) 1015{ 1016 __str.setf(ios_base::oct, ios_base::basefield); 1017 return __str; 1018} 1019 1020_LIBCPP_HIDE_FROM_ABI inline 1021ios_base& 1022fixed(ios_base& __str) 1023{ 1024 __str.setf(ios_base::fixed, ios_base::floatfield); 1025 return __str; 1026} 1027 1028_LIBCPP_HIDE_FROM_ABI inline 1029ios_base& 1030scientific(ios_base& __str) 1031{ 1032 __str.setf(ios_base::scientific, ios_base::floatfield); 1033 return __str; 1034} 1035 1036_LIBCPP_HIDE_FROM_ABI inline 1037ios_base& 1038hexfloat(ios_base& __str) 1039{ 1040 __str.setf(ios_base::fixed | ios_base::scientific, ios_base::floatfield); 1041 return __str; 1042} 1043 1044_LIBCPP_HIDE_FROM_ABI inline 1045ios_base& 1046defaultfloat(ios_base& __str) 1047{ 1048 __str.unsetf(ios_base::floatfield); 1049 return __str; 1050} 1051 1052_LIBCPP_END_NAMESPACE_STD 1053 1054#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 1055# include <atomic> 1056# include <concepts> 1057# include <cstddef> 1058# include <cstdlib> 1059# include <cstring> 1060# include <initializer_list> 1061# include <limits> 1062# include <mutex> 1063# include <new> 1064# include <stdexcept> 1065# include <system_error> 1066# include <type_traits> 1067# include <typeinfo> 1068#endif 1069 1070#endif // _LIBCPP_IOS 1071