ios 24 KB

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