ios 26 KB

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