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 out; 62 static constexpr openmode trunc; 63 64 typedef T4 seekdir; 65 static constexpr seekdir beg; 66 static constexpr seekdir cur; 67 static constexpr seekdir end; 68 69 class Init; 70 71 // 27.5.2.2 fmtflags state: 72 fmtflags flags() const; 73 fmtflags flags(fmtflags fmtfl); 74 fmtflags setf(fmtflags fmtfl); 75 fmtflags setf(fmtflags fmtfl, fmtflags mask); 76 void unsetf(fmtflags mask); 77 78 streamsize precision() const; 79 streamsize precision(streamsize prec); 80 streamsize width() const; 81 streamsize width(streamsize wide); 82 83 // 27.5.2.3 locales: 84 locale imbue(const locale& loc); 85 locale getloc() const; 86 87 // 27.5.2.5 storage: 88 static int xalloc(); 89 long& iword(int index); 90 void*& pword(int index); 91 92 // destructor 93 virtual ~ios_base(); 94 95 // 27.5.2.6 callbacks; 96 enum event { erase_event, imbue_event, copyfmt_event }; 97 typedef void (*event_callback)(event, ios_base&, int index); 98 void register_callback(event_callback fn, int index); 99 100 ios_base(const ios_base&) = delete; 101 ios_base& operator=(const ios_base&) = delete; 102 103 static bool sync_with_stdio(bool sync = true); 104 105protected: 106 ios_base(); 107}; 108 109template <class charT, class traits = char_traits<charT> > 110class basic_ios 111 : public ios_base 112{ 113public: 114 // types: 115 typedef charT char_type; 116 typedef typename traits::int_type int_type; // removed in C++17 117 typedef typename traits::pos_type pos_type; // removed in C++17 118 typedef typename traits::off_type off_type; // removed in C++17 119 typedef traits traits_type; 120 121 operator unspecified-bool-type() const; 122 bool operator!() const; 123 iostate rdstate() const; 124 void clear(iostate state = goodbit); 125 void setstate(iostate state); 126 bool good() const; 127 bool eof() const; 128 bool fail() const; 129 bool bad() const; 130 131 iostate exceptions() const; 132 void exceptions(iostate except); 133 134 // 27.5.4.1 Constructor/destructor: 135 explicit basic_ios(basic_streambuf<charT,traits>* sb); 136 virtual ~basic_ios(); 137 138 // 27.5.4.2 Members: 139 basic_ostream<charT,traits>* tie() const; 140 basic_ostream<charT,traits>* tie(basic_ostream<charT,traits>* tiestr); 141 142 basic_streambuf<charT,traits>* rdbuf() const; 143 basic_streambuf<charT,traits>* rdbuf(basic_streambuf<charT,traits>* sb); 144 145 basic_ios& copyfmt(const basic_ios& rhs); 146 147 char_type fill() const; 148 char_type fill(char_type ch); 149 150 locale imbue(const locale& loc); 151 152 char narrow(char_type c, char dfault) const; 153 char_type widen(char c) const; 154 155 basic_ios(const basic_ios& ) = delete; 156 basic_ios& operator=(const basic_ios&) = delete; 157 158protected: 159 basic_ios(); 160 void init(basic_streambuf<charT,traits>* sb); 161 void move(basic_ios& rhs); 162 void swap(basic_ios& rhs) noexcept; 163 void set_rdbuf(basic_streambuf<charT, traits>* sb); 164}; 165 166// 27.5.5, manipulators: 167ios_base& boolalpha (ios_base& str); 168ios_base& noboolalpha(ios_base& str); 169ios_base& showbase (ios_base& str); 170ios_base& noshowbase (ios_base& str); 171ios_base& showpoint (ios_base& str); 172ios_base& noshowpoint(ios_base& str); 173ios_base& showpos (ios_base& str); 174ios_base& noshowpos (ios_base& str); 175ios_base& skipws (ios_base& str); 176ios_base& noskipws (ios_base& str); 177ios_base& uppercase (ios_base& str); 178ios_base& nouppercase(ios_base& str); 179ios_base& unitbuf (ios_base& str); 180ios_base& nounitbuf (ios_base& str); 181 182// 27.5.5.2 adjustfield: 183ios_base& internal (ios_base& str); 184ios_base& left (ios_base& str); 185ios_base& right (ios_base& str); 186 187// 27.5.5.3 basefield: 188ios_base& dec (ios_base& str); 189ios_base& hex (ios_base& str); 190ios_base& oct (ios_base& str); 191 192// 27.5.5.4 floatfield: 193ios_base& fixed (ios_base& str); 194ios_base& scientific (ios_base& str); 195ios_base& hexfloat (ios_base& str); 196ios_base& defaultfloat(ios_base& str); 197 198// 27.5.5.5 error reporting: 199enum class io_errc 200{ 201 stream = 1 202}; 203 204concept_map ErrorCodeEnum<io_errc> { }; 205error_code make_error_code(io_errc e) noexcept; 206error_condition make_error_condition(io_errc e) noexcept; 207storage-class-specifier const error_category& iostream_category() noexcept; 208 209} // std 210 211*/ 212 213#include <__assert> // all public C++ headers provide the assertion handler 214#include <__config> 215#include <__ios/fpos.h> 216#include <__locale> 217#include <__utility/swap.h> 218#include <iosfwd> 219#include <system_error> 220#include <version> 221 222#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) 223#include <atomic> // for __xindex_ 224#endif 225 226#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 227# pragma GCC system_header 228#endif 229 230_LIBCPP_BEGIN_NAMESPACE_STD 231 232typedef ptrdiff_t streamsize; 233 234class _LIBCPP_TYPE_VIS ios_base 235{ 236public: 237 class _LIBCPP_EXCEPTION_ABI failure; 238 239 typedef unsigned int fmtflags; 240 static const fmtflags boolalpha = 0x0001; 241 static const fmtflags dec = 0x0002; 242 static const fmtflags fixed = 0x0004; 243 static const fmtflags hex = 0x0008; 244 static const fmtflags internal = 0x0010; 245 static const fmtflags left = 0x0020; 246 static const fmtflags oct = 0x0040; 247 static const fmtflags right = 0x0080; 248 static const fmtflags scientific = 0x0100; 249 static const fmtflags showbase = 0x0200; 250 static const fmtflags showpoint = 0x0400; 251 static const fmtflags showpos = 0x0800; 252 static const fmtflags skipws = 0x1000; 253 static const fmtflags unitbuf = 0x2000; 254 static const fmtflags uppercase = 0x4000; 255 static const fmtflags adjustfield = left | right | internal; 256 static const fmtflags basefield = dec | oct | hex; 257 static const fmtflags floatfield = scientific | fixed; 258 259 typedef unsigned int iostate; 260 static const iostate badbit = 0x1; 261 static const iostate eofbit = 0x2; 262 static const iostate failbit = 0x4; 263 static const iostate goodbit = 0x0; 264 265 typedef unsigned int openmode; 266 static const openmode app = 0x01; 267 static const openmode ate = 0x02; 268 static const openmode binary = 0x04; 269 static const openmode in = 0x08; 270 static const openmode out = 0x10; 271 static const openmode trunc = 0x20; 272 273 enum seekdir {beg, cur, end}; 274 275#if _LIBCPP_STD_VER <= 14 276 typedef iostate io_state; 277 typedef openmode open_mode; 278 typedef seekdir seek_dir; 279 280 typedef _VSTD::streamoff streamoff; 281 typedef _VSTD::streampos streampos; 282#endif 283 284 class _LIBCPP_TYPE_VIS Init; 285 286 // 27.5.2.2 fmtflags state: 287 _LIBCPP_INLINE_VISIBILITY fmtflags flags() const; 288 _LIBCPP_INLINE_VISIBILITY fmtflags flags(fmtflags __fmtfl); 289 _LIBCPP_INLINE_VISIBILITY fmtflags setf(fmtflags __fmtfl); 290 _LIBCPP_INLINE_VISIBILITY fmtflags setf(fmtflags __fmtfl, fmtflags __mask); 291 _LIBCPP_INLINE_VISIBILITY void unsetf(fmtflags __mask); 292 293 _LIBCPP_INLINE_VISIBILITY streamsize precision() const; 294 _LIBCPP_INLINE_VISIBILITY streamsize precision(streamsize __prec); 295 _LIBCPP_INLINE_VISIBILITY streamsize width() const; 296 _LIBCPP_INLINE_VISIBILITY streamsize width(streamsize __wide); 297 298 // 27.5.2.3 locales: 299 locale imbue(const locale& __loc); 300 locale getloc() const; 301 302 // 27.5.2.5 storage: 303 static int xalloc(); 304 long& iword(int __index); 305 void*& pword(int __index); 306 307 // destructor 308 virtual ~ios_base(); 309 310 // 27.5.2.6 callbacks; 311 enum event { erase_event, imbue_event, copyfmt_event }; 312 typedef void (*event_callback)(event, ios_base&, int __index); 313 void register_callback(event_callback __fn, int __index); 314 315 ios_base(const ios_base&) = delete; 316 ios_base& operator=(const ios_base&) = delete; 317 318 static bool sync_with_stdio(bool __sync = true); 319 320 _LIBCPP_INLINE_VISIBILITY iostate rdstate() const; 321 void clear(iostate __state = goodbit); 322 _LIBCPP_INLINE_VISIBILITY void setstate(iostate __state); 323 324 _LIBCPP_INLINE_VISIBILITY bool good() const; 325 _LIBCPP_INLINE_VISIBILITY bool eof() const; 326 _LIBCPP_INLINE_VISIBILITY bool fail() const; 327 _LIBCPP_INLINE_VISIBILITY bool bad() const; 328 329 _LIBCPP_INLINE_VISIBILITY iostate exceptions() const; 330 _LIBCPP_INLINE_VISIBILITY void exceptions(iostate __iostate); 331 332 void __set_badbit_and_consider_rethrow(); 333 void __set_failbit_and_consider_rethrow(); 334 335 _LIBCPP_INLINE_VISIBILITY 336 void __setstate_nothrow(iostate __state) 337 { 338 if (__rdbuf_) 339 __rdstate_ |= __state; 340 else 341 __rdstate_ |= __state | ios_base::badbit; 342 } 343 344protected: 345 _LIBCPP_INLINE_VISIBILITY 346 ios_base() {// purposefully does no initialization 347 } 348 349 void init(void* __sb); 350 _LIBCPP_INLINE_VISIBILITY void* rdbuf() const {return __rdbuf_;} 351 352 _LIBCPP_INLINE_VISIBILITY 353 void rdbuf(void* __sb) 354 { 355 __rdbuf_ = __sb; 356 clear(); 357 } 358 359 void __call_callbacks(event); 360 void copyfmt(const ios_base&); 361 void move(ios_base&); 362 void swap(ios_base&) _NOEXCEPT; 363 364 _LIBCPP_INLINE_VISIBILITY 365 void set_rdbuf(void* __sb) 366 { 367 __rdbuf_ = __sb; 368 } 369 370private: 371 // All data members must be scalars 372 fmtflags __fmtflags_; 373 streamsize __precision_; 374 streamsize __width_; 375 iostate __rdstate_; 376 iostate __exceptions_; 377 void* __rdbuf_; 378 void* __loc_; 379 event_callback* __fn_; 380 int* __index_; 381 size_t __event_size_; 382 size_t __event_cap_; 383// TODO(EricWF): Enable this for both Clang and GCC. Currently it is only 384// enabled with clang. 385#if defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS) 386 static atomic<int> __xindex_; 387#else 388 static int __xindex_; 389#endif 390 long* __iarray_; 391 size_t __iarray_size_; 392 size_t __iarray_cap_; 393 void** __parray_; 394 size_t __parray_size_; 395 size_t __parray_cap_; 396}; 397 398//enum class io_errc 399_LIBCPP_DECLARE_STRONG_ENUM(io_errc) 400{ 401 stream = 1 402}; 403_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(io_errc) 404 405template <> 406struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc> : public true_type { }; 407 408#ifdef _LIBCPP_CXX03_LANG 409template <> 410struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc::__lx> : public true_type { }; 411#endif 412 413_LIBCPP_FUNC_VIS 414const error_category& iostream_category() _NOEXCEPT; 415 416inline _LIBCPP_INLINE_VISIBILITY 417error_code 418make_error_code(io_errc __e) _NOEXCEPT 419{ 420 return error_code(static_cast<int>(__e), iostream_category()); 421} 422 423inline _LIBCPP_INLINE_VISIBILITY 424error_condition 425make_error_condition(io_errc __e) _NOEXCEPT 426{ 427 return error_condition(static_cast<int>(__e), iostream_category()); 428} 429 430class _LIBCPP_EXCEPTION_ABI ios_base::failure 431 : public system_error 432{ 433public: 434 explicit failure(const string& __msg, const error_code& __ec = io_errc::stream); 435 explicit failure(const char* __msg, const error_code& __ec = io_errc::stream); 436 failure(const failure&) _NOEXCEPT = default; 437 virtual ~failure() _NOEXCEPT; 438}; 439 440_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY 441void __throw_failure(char const* __msg) { 442#ifndef _LIBCPP_NO_EXCEPTIONS 443 throw ios_base::failure(__msg); 444#else 445 ((void)__msg); 446 _VSTD::abort(); 447#endif 448} 449 450class _LIBCPP_TYPE_VIS ios_base::Init 451{ 452public: 453 Init(); 454 ~Init(); 455}; 456 457// fmtflags 458 459inline _LIBCPP_INLINE_VISIBILITY 460ios_base::fmtflags 461ios_base::flags() const 462{ 463 return __fmtflags_; 464} 465 466inline _LIBCPP_INLINE_VISIBILITY 467ios_base::fmtflags 468ios_base::flags(fmtflags __fmtfl) 469{ 470 fmtflags __r = __fmtflags_; 471 __fmtflags_ = __fmtfl; 472 return __r; 473} 474 475inline _LIBCPP_INLINE_VISIBILITY 476ios_base::fmtflags 477ios_base::setf(fmtflags __fmtfl) 478{ 479 fmtflags __r = __fmtflags_; 480 __fmtflags_ |= __fmtfl; 481 return __r; 482} 483 484inline _LIBCPP_INLINE_VISIBILITY 485void 486ios_base::unsetf(fmtflags __mask) 487{ 488 __fmtflags_ &= ~__mask; 489} 490 491inline _LIBCPP_INLINE_VISIBILITY 492ios_base::fmtflags 493ios_base::setf(fmtflags __fmtfl, fmtflags __mask) 494{ 495 fmtflags __r = __fmtflags_; 496 unsetf(__mask); 497 __fmtflags_ |= __fmtfl & __mask; 498 return __r; 499} 500 501// precision 502 503inline _LIBCPP_INLINE_VISIBILITY 504streamsize 505ios_base::precision() const 506{ 507 return __precision_; 508} 509 510inline _LIBCPP_INLINE_VISIBILITY 511streamsize 512ios_base::precision(streamsize __prec) 513{ 514 streamsize __r = __precision_; 515 __precision_ = __prec; 516 return __r; 517} 518 519// width 520 521inline _LIBCPP_INLINE_VISIBILITY 522streamsize 523ios_base::width() const 524{ 525 return __width_; 526} 527 528inline _LIBCPP_INLINE_VISIBILITY 529streamsize 530ios_base::width(streamsize __wide) 531{ 532 streamsize __r = __width_; 533 __width_ = __wide; 534 return __r; 535} 536 537// iostate 538 539inline _LIBCPP_INLINE_VISIBILITY 540ios_base::iostate 541ios_base::rdstate() const 542{ 543 return __rdstate_; 544} 545 546inline _LIBCPP_INLINE_VISIBILITY 547void 548ios_base::setstate(iostate __state) 549{ 550 clear(__rdstate_ | __state); 551} 552 553inline _LIBCPP_INLINE_VISIBILITY 554bool 555ios_base::good() const 556{ 557 return __rdstate_ == 0; 558} 559 560inline _LIBCPP_INLINE_VISIBILITY 561bool 562ios_base::eof() const 563{ 564 return (__rdstate_ & eofbit) != 0; 565} 566 567inline _LIBCPP_INLINE_VISIBILITY 568bool 569ios_base::fail() const 570{ 571 return (__rdstate_ & (failbit | badbit)) != 0; 572} 573 574inline _LIBCPP_INLINE_VISIBILITY 575bool 576ios_base::bad() const 577{ 578 return (__rdstate_ & badbit) != 0; 579} 580 581inline _LIBCPP_INLINE_VISIBILITY 582ios_base::iostate 583ios_base::exceptions() const 584{ 585 return __exceptions_; 586} 587 588inline _LIBCPP_INLINE_VISIBILITY 589void 590ios_base::exceptions(iostate __iostate) 591{ 592 __exceptions_ = __iostate; 593 clear(__rdstate_); 594} 595 596template <class _CharT, class _Traits> 597class _LIBCPP_TEMPLATE_VIS basic_ios 598 : public ios_base 599{ 600public: 601 // types: 602 typedef _CharT char_type; 603 typedef _Traits traits_type; 604 605 typedef typename traits_type::int_type int_type; 606 typedef typename traits_type::pos_type pos_type; 607 typedef typename traits_type::off_type off_type; 608 609 static_assert((is_same<_CharT, typename traits_type::char_type>::value), 610 "traits_type::char_type must be the same type as CharT"); 611 612#ifdef _LIBCPP_CXX03_LANG 613 // Preserve the ability to compare with literal 0, 614 // and implicitly convert to bool, but not implicitly convert to int. 615 _LIBCPP_INLINE_VISIBILITY 616 operator void*() const {return fail() ? nullptr : (void*)this;} 617#else 618 _LIBCPP_INLINE_VISIBILITY 619 explicit operator bool() const {return !fail();} 620#endif 621 622 _LIBCPP_INLINE_VISIBILITY bool operator!() const {return fail();} 623 _LIBCPP_INLINE_VISIBILITY iostate rdstate() const {return ios_base::rdstate();} 624 _LIBCPP_INLINE_VISIBILITY void clear(iostate __state = goodbit) {ios_base::clear(__state);} 625 _LIBCPP_INLINE_VISIBILITY void setstate(iostate __state) {ios_base::setstate(__state);} 626 _LIBCPP_INLINE_VISIBILITY bool good() const {return ios_base::good();} 627 _LIBCPP_INLINE_VISIBILITY bool eof() const {return ios_base::eof();} 628 _LIBCPP_INLINE_VISIBILITY bool fail() const {return ios_base::fail();} 629 _LIBCPP_INLINE_VISIBILITY bool bad() const {return ios_base::bad();} 630 631 _LIBCPP_INLINE_VISIBILITY iostate exceptions() const {return ios_base::exceptions();} 632 _LIBCPP_INLINE_VISIBILITY void exceptions(iostate __iostate) {ios_base::exceptions(__iostate);} 633 634 // 27.5.4.1 Constructor/destructor: 635 _LIBCPP_INLINE_VISIBILITY 636 explicit basic_ios(basic_streambuf<char_type,traits_type>* __sb); 637 virtual ~basic_ios(); 638 639 // 27.5.4.2 Members: 640 _LIBCPP_INLINE_VISIBILITY 641 basic_ostream<char_type, traits_type>* tie() const; 642 _LIBCPP_INLINE_VISIBILITY 643 basic_ostream<char_type, traits_type>* tie(basic_ostream<char_type, traits_type>* __tiestr); 644 645 _LIBCPP_INLINE_VISIBILITY 646 basic_streambuf<char_type, traits_type>* rdbuf() const; 647 _LIBCPP_INLINE_VISIBILITY 648 basic_streambuf<char_type, traits_type>* rdbuf(basic_streambuf<char_type, traits_type>* __sb); 649 650 basic_ios& copyfmt(const basic_ios& __rhs); 651 652 _LIBCPP_INLINE_VISIBILITY 653 char_type fill() const; 654 _LIBCPP_INLINE_VISIBILITY 655 char_type fill(char_type __ch); 656 657 _LIBCPP_INLINE_VISIBILITY 658 locale imbue(const locale& __loc); 659 660 _LIBCPP_INLINE_VISIBILITY 661 char narrow(char_type __c, char __dfault) const; 662 _LIBCPP_INLINE_VISIBILITY 663 char_type widen(char __c) const; 664 665protected: 666 _LIBCPP_INLINE_VISIBILITY 667 basic_ios() {// purposefully does no initialization 668 } 669 _LIBCPP_INLINE_VISIBILITY 670 void init(basic_streambuf<char_type, traits_type>* __sb); 671 672 _LIBCPP_INLINE_VISIBILITY 673 void move(basic_ios& __rhs); 674 _LIBCPP_INLINE_VISIBILITY 675 void move(basic_ios&& __rhs) {move(__rhs);} 676 _LIBCPP_INLINE_VISIBILITY 677 void swap(basic_ios& __rhs) _NOEXCEPT; 678 _LIBCPP_INLINE_VISIBILITY 679 void set_rdbuf(basic_streambuf<char_type, traits_type>* __sb); 680private: 681 basic_ostream<char_type, traits_type>* __tie_; 682 mutable int_type __fill_; 683}; 684 685template <class _CharT, class _Traits> 686inline _LIBCPP_INLINE_VISIBILITY 687basic_ios<_CharT, _Traits>::basic_ios(basic_streambuf<char_type,traits_type>* __sb) 688{ 689 init(__sb); 690} 691 692template <class _CharT, class _Traits> 693basic_ios<_CharT, _Traits>::~basic_ios() 694{ 695} 696 697template <class _CharT, class _Traits> 698inline _LIBCPP_INLINE_VISIBILITY 699void 700basic_ios<_CharT, _Traits>::init(basic_streambuf<char_type, traits_type>* __sb) 701{ 702 ios_base::init(__sb); 703 __tie_ = nullptr; 704 __fill_ = traits_type::eof(); 705} 706 707template <class _CharT, class _Traits> 708inline _LIBCPP_INLINE_VISIBILITY 709basic_ostream<_CharT, _Traits>* 710basic_ios<_CharT, _Traits>::tie() const 711{ 712 return __tie_; 713} 714 715template <class _CharT, class _Traits> 716inline _LIBCPP_INLINE_VISIBILITY 717basic_ostream<_CharT, _Traits>* 718basic_ios<_CharT, _Traits>::tie(basic_ostream<char_type, traits_type>* __tiestr) 719{ 720 basic_ostream<char_type, traits_type>* __r = __tie_; 721 __tie_ = __tiestr; 722 return __r; 723} 724 725template <class _CharT, class _Traits> 726inline _LIBCPP_INLINE_VISIBILITY 727basic_streambuf<_CharT, _Traits>* 728basic_ios<_CharT, _Traits>::rdbuf() const 729{ 730 return static_cast<basic_streambuf<char_type, traits_type>*>(ios_base::rdbuf()); 731} 732 733template <class _CharT, class _Traits> 734inline _LIBCPP_INLINE_VISIBILITY 735basic_streambuf<_CharT, _Traits>* 736basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<char_type, traits_type>* __sb) 737{ 738 basic_streambuf<char_type, traits_type>* __r = rdbuf(); 739 ios_base::rdbuf(__sb); 740 return __r; 741} 742 743template <class _CharT, class _Traits> 744inline _LIBCPP_INLINE_VISIBILITY 745locale 746basic_ios<_CharT, _Traits>::imbue(const locale& __loc) 747{ 748 locale __r = getloc(); 749 ios_base::imbue(__loc); 750 if (rdbuf()) 751 rdbuf()->pubimbue(__loc); 752 return __r; 753} 754 755template <class _CharT, class _Traits> 756inline _LIBCPP_INLINE_VISIBILITY 757char 758basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const 759{ 760 return use_facet<ctype<char_type> >(getloc()).narrow(__c, __dfault); 761} 762 763template <class _CharT, class _Traits> 764inline _LIBCPP_INLINE_VISIBILITY 765_CharT 766basic_ios<_CharT, _Traits>::widen(char __c) const 767{ 768 return use_facet<ctype<char_type> >(getloc()).widen(__c); 769} 770 771template <class _CharT, class _Traits> 772inline _LIBCPP_INLINE_VISIBILITY 773_CharT 774basic_ios<_CharT, _Traits>::fill() const 775{ 776 if (traits_type::eq_int_type(traits_type::eof(), __fill_)) 777 __fill_ = widen(' '); 778 return __fill_; 779} 780 781template <class _CharT, class _Traits> 782inline _LIBCPP_INLINE_VISIBILITY 783_CharT 784basic_ios<_CharT, _Traits>::fill(char_type __ch) 785{ 786 if (traits_type::eq_int_type(traits_type::eof(), __fill_)) 787 __fill_ = widen(' '); 788 char_type __r = __fill_; 789 __fill_ = __ch; 790 return __r; 791} 792 793template <class _CharT, class _Traits> 794basic_ios<_CharT, _Traits>& 795basic_ios<_CharT, _Traits>::copyfmt(const basic_ios& __rhs) 796{ 797 if (this != &__rhs) 798 { 799 __call_callbacks(erase_event); 800 ios_base::copyfmt(__rhs); 801 __tie_ = __rhs.__tie_; 802 __fill_ = __rhs.__fill_; 803 __call_callbacks(copyfmt_event); 804 exceptions(__rhs.exceptions()); 805 } 806 return *this; 807} 808 809template <class _CharT, class _Traits> 810inline _LIBCPP_INLINE_VISIBILITY 811void 812basic_ios<_CharT, _Traits>::move(basic_ios& __rhs) 813{ 814 ios_base::move(__rhs); 815 __tie_ = __rhs.__tie_; 816 __rhs.__tie_ = nullptr; 817 __fill_ = __rhs.__fill_; 818} 819 820template <class _CharT, class _Traits> 821inline _LIBCPP_INLINE_VISIBILITY 822void 823basic_ios<_CharT, _Traits>::swap(basic_ios& __rhs) _NOEXCEPT 824{ 825 ios_base::swap(__rhs); 826 _VSTD::swap(__tie_, __rhs.__tie_); 827 _VSTD::swap(__fill_, __rhs.__fill_); 828} 829 830template <class _CharT, class _Traits> 831inline _LIBCPP_INLINE_VISIBILITY 832void 833basic_ios<_CharT, _Traits>::set_rdbuf(basic_streambuf<char_type, traits_type>* __sb) 834{ 835 ios_base::set_rdbuf(__sb); 836} 837 838inline 839ios_base& 840boolalpha(ios_base& __str) 841{ 842 __str.setf(ios_base::boolalpha); 843 return __str; 844} 845 846inline 847ios_base& 848noboolalpha(ios_base& __str) 849{ 850 __str.unsetf(ios_base::boolalpha); 851 return __str; 852} 853 854inline 855ios_base& 856showbase(ios_base& __str) 857{ 858 __str.setf(ios_base::showbase); 859 return __str; 860} 861 862inline 863ios_base& 864noshowbase(ios_base& __str) 865{ 866 __str.unsetf(ios_base::showbase); 867 return __str; 868} 869 870inline 871ios_base& 872showpoint(ios_base& __str) 873{ 874 __str.setf(ios_base::showpoint); 875 return __str; 876} 877 878inline 879ios_base& 880noshowpoint(ios_base& __str) 881{ 882 __str.unsetf(ios_base::showpoint); 883 return __str; 884} 885 886inline 887ios_base& 888showpos(ios_base& __str) 889{ 890 __str.setf(ios_base::showpos); 891 return __str; 892} 893 894inline 895ios_base& 896noshowpos(ios_base& __str) 897{ 898 __str.unsetf(ios_base::showpos); 899 return __str; 900} 901 902inline 903ios_base& 904skipws(ios_base& __str) 905{ 906 __str.setf(ios_base::skipws); 907 return __str; 908} 909 910inline 911ios_base& 912noskipws(ios_base& __str) 913{ 914 __str.unsetf(ios_base::skipws); 915 return __str; 916} 917 918inline 919ios_base& 920uppercase(ios_base& __str) 921{ 922 __str.setf(ios_base::uppercase); 923 return __str; 924} 925 926inline 927ios_base& 928nouppercase(ios_base& __str) 929{ 930 __str.unsetf(ios_base::uppercase); 931 return __str; 932} 933 934inline 935ios_base& 936unitbuf(ios_base& __str) 937{ 938 __str.setf(ios_base::unitbuf); 939 return __str; 940} 941 942inline 943ios_base& 944nounitbuf(ios_base& __str) 945{ 946 __str.unsetf(ios_base::unitbuf); 947 return __str; 948} 949 950inline 951ios_base& 952internal(ios_base& __str) 953{ 954 __str.setf(ios_base::internal, ios_base::adjustfield); 955 return __str; 956} 957 958inline 959ios_base& 960left(ios_base& __str) 961{ 962 __str.setf(ios_base::left, ios_base::adjustfield); 963 return __str; 964} 965 966inline 967ios_base& 968right(ios_base& __str) 969{ 970 __str.setf(ios_base::right, ios_base::adjustfield); 971 return __str; 972} 973 974inline 975ios_base& 976dec(ios_base& __str) 977{ 978 __str.setf(ios_base::dec, ios_base::basefield); 979 return __str; 980} 981 982inline 983ios_base& 984hex(ios_base& __str) 985{ 986 __str.setf(ios_base::hex, ios_base::basefield); 987 return __str; 988} 989 990inline 991ios_base& 992oct(ios_base& __str) 993{ 994 __str.setf(ios_base::oct, ios_base::basefield); 995 return __str; 996} 997 998inline 999ios_base& 1000fixed(ios_base& __str) 1001{ 1002 __str.setf(ios_base::fixed, ios_base::floatfield); 1003 return __str; 1004} 1005 1006inline 1007ios_base& 1008scientific(ios_base& __str) 1009{ 1010 __str.setf(ios_base::scientific, ios_base::floatfield); 1011 return __str; 1012} 1013 1014inline 1015ios_base& 1016hexfloat(ios_base& __str) 1017{ 1018 __str.setf(ios_base::fixed | ios_base::scientific, ios_base::floatfield); 1019 return __str; 1020} 1021 1022inline 1023ios_base& 1024defaultfloat(ios_base& __str) 1025{ 1026 __str.unsetf(ios_base::floatfield); 1027 return __str; 1028} 1029 1030_LIBCPP_END_NAMESPACE_STD 1031 1032#endif // _LIBCPP_IOS 1033