ios 25 KB

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