ios 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  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 noreplace; // since C++23
  53. static constexpr openmode out;
  54. static constexpr openmode trunc;
  55. typedef T4 seekdir;
  56. static constexpr seekdir beg;
  57. static constexpr seekdir cur;
  58. static constexpr seekdir end;
  59. class Init;
  60. // 27.5.2.2 fmtflags state:
  61. fmtflags flags() const;
  62. fmtflags flags(fmtflags fmtfl);
  63. fmtflags setf(fmtflags fmtfl);
  64. fmtflags setf(fmtflags fmtfl, fmtflags mask);
  65. void unsetf(fmtflags mask);
  66. streamsize precision() const;
  67. streamsize precision(streamsize prec);
  68. streamsize width() const;
  69. streamsize width(streamsize wide);
  70. // 27.5.2.3 locales:
  71. locale imbue(const locale& loc);
  72. locale getloc() const;
  73. // 27.5.2.5 storage:
  74. static int xalloc();
  75. long& iword(int index);
  76. void*& pword(int index);
  77. // destructor
  78. virtual ~ios_base();
  79. // 27.5.2.6 callbacks;
  80. enum event { erase_event, imbue_event, copyfmt_event };
  81. typedef void (*event_callback)(event, ios_base&, int index);
  82. void register_callback(event_callback fn, int index);
  83. ios_base(const ios_base&) = delete;
  84. ios_base& operator=(const ios_base&) = delete;
  85. static bool sync_with_stdio(bool sync = true);
  86. protected:
  87. ios_base();
  88. };
  89. template <class charT, class traits = char_traits<charT> >
  90. class basic_ios
  91. : public ios_base
  92. {
  93. public:
  94. // types:
  95. typedef charT char_type;
  96. typedef typename traits::int_type int_type; // removed in C++17
  97. typedef typename traits::pos_type pos_type; // removed in C++17
  98. typedef typename traits::off_type off_type; // removed in C++17
  99. typedef traits traits_type;
  100. operator unspecified-bool-type() const;
  101. bool operator!() const;
  102. iostate rdstate() const;
  103. void clear(iostate state = goodbit);
  104. void setstate(iostate state);
  105. bool good() const;
  106. bool eof() const;
  107. bool fail() const;
  108. bool bad() const;
  109. iostate exceptions() const;
  110. void exceptions(iostate except);
  111. // 27.5.4.1 Constructor/destructor:
  112. explicit basic_ios(basic_streambuf<charT,traits>* sb);
  113. virtual ~basic_ios();
  114. // 27.5.4.2 Members:
  115. basic_ostream<charT,traits>* tie() const;
  116. basic_ostream<charT,traits>* tie(basic_ostream<charT,traits>* tiestr);
  117. basic_streambuf<charT,traits>* rdbuf() const;
  118. basic_streambuf<charT,traits>* rdbuf(basic_streambuf<charT,traits>* sb);
  119. basic_ios& copyfmt(const basic_ios& rhs);
  120. char_type fill() const;
  121. char_type fill(char_type ch);
  122. locale imbue(const locale& loc);
  123. char narrow(char_type c, char dfault) const;
  124. char_type widen(char c) const;
  125. basic_ios(const basic_ios& ) = delete;
  126. basic_ios& operator=(const basic_ios&) = delete;
  127. protected:
  128. basic_ios();
  129. void init(basic_streambuf<charT,traits>* sb);
  130. void move(basic_ios& rhs);
  131. void swap(basic_ios& rhs) noexcept;
  132. void set_rdbuf(basic_streambuf<charT, traits>* sb);
  133. };
  134. // 27.5.5, manipulators:
  135. ios_base& boolalpha (ios_base& str);
  136. ios_base& noboolalpha(ios_base& str);
  137. ios_base& showbase (ios_base& str);
  138. ios_base& noshowbase (ios_base& str);
  139. ios_base& showpoint (ios_base& str);
  140. ios_base& noshowpoint(ios_base& str);
  141. ios_base& showpos (ios_base& str);
  142. ios_base& noshowpos (ios_base& str);
  143. ios_base& skipws (ios_base& str);
  144. ios_base& noskipws (ios_base& str);
  145. ios_base& uppercase (ios_base& str);
  146. ios_base& nouppercase(ios_base& str);
  147. ios_base& unitbuf (ios_base& str);
  148. ios_base& nounitbuf (ios_base& str);
  149. // 27.5.5.2 adjustfield:
  150. ios_base& internal (ios_base& str);
  151. ios_base& left (ios_base& str);
  152. ios_base& right (ios_base& str);
  153. // 27.5.5.3 basefield:
  154. ios_base& dec (ios_base& str);
  155. ios_base& hex (ios_base& str);
  156. ios_base& oct (ios_base& str);
  157. // 27.5.5.4 floatfield:
  158. ios_base& fixed (ios_base& str);
  159. ios_base& scientific (ios_base& str);
  160. ios_base& hexfloat (ios_base& str);
  161. ios_base& defaultfloat(ios_base& str);
  162. // 27.5.5.5 error reporting:
  163. enum class io_errc
  164. {
  165. stream = 1
  166. };
  167. concept_map ErrorCodeEnum<io_errc> { };
  168. error_code make_error_code(io_errc e) noexcept;
  169. error_condition make_error_condition(io_errc e) noexcept;
  170. storage-class-specifier const error_category& iostream_category() noexcept;
  171. } // std
  172. */
  173. #include <__config>
  174. #if defined(_LIBCPP_HAS_NO_LOCALIZATION)
  175. # error "The iostreams library is not supported since libc++ has been configured without support for localization."
  176. #endif
  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_PUSH_MACROS
  197. #include <__undef_macros>
  198. _LIBCPP_BEGIN_NAMESPACE_STD
  199. typedef ptrdiff_t streamsize;
  200. class _LIBCPP_EXPORTED_FROM_ABI ios_base {
  201. public:
  202. class _LIBCPP_EXPORTED_FROM_ABI failure;
  203. typedef unsigned int fmtflags;
  204. static const fmtflags boolalpha = 0x0001;
  205. static const fmtflags dec = 0x0002;
  206. static const fmtflags fixed = 0x0004;
  207. static const fmtflags hex = 0x0008;
  208. static const fmtflags internal = 0x0010;
  209. static const fmtflags left = 0x0020;
  210. static const fmtflags oct = 0x0040;
  211. static const fmtflags right = 0x0080;
  212. static const fmtflags scientific = 0x0100;
  213. static const fmtflags showbase = 0x0200;
  214. static const fmtflags showpoint = 0x0400;
  215. static const fmtflags showpos = 0x0800;
  216. static const fmtflags skipws = 0x1000;
  217. static const fmtflags unitbuf = 0x2000;
  218. static const fmtflags uppercase = 0x4000;
  219. static const fmtflags adjustfield = left | right | internal;
  220. static const fmtflags basefield = dec | oct | hex;
  221. static const fmtflags floatfield = scientific | fixed;
  222. typedef unsigned int iostate;
  223. static const iostate badbit = 0x1;
  224. static const iostate eofbit = 0x2;
  225. static const iostate failbit = 0x4;
  226. static const iostate goodbit = 0x0;
  227. typedef unsigned int openmode;
  228. static const openmode app = 0x01;
  229. static const openmode ate = 0x02;
  230. static const openmode binary = 0x04;
  231. static const openmode in = 0x08;
  232. static const openmode out = 0x10;
  233. static const openmode trunc = 0x20;
  234. #if _LIBCPP_STD_VER >= 23
  235. static const openmode noreplace = 0x40;
  236. #endif
  237. enum seekdir { beg, cur, end };
  238. #if _LIBCPP_STD_VER <= 14
  239. typedef iostate io_state;
  240. typedef openmode open_mode;
  241. typedef seekdir seek_dir;
  242. typedef std::streamoff streamoff;
  243. typedef std::streampos streampos;
  244. #endif
  245. class _LIBCPP_EXPORTED_FROM_ABI Init;
  246. // 27.5.2.2 fmtflags state:
  247. _LIBCPP_HIDE_FROM_ABI fmtflags flags() const;
  248. _LIBCPP_HIDE_FROM_ABI fmtflags flags(fmtflags __fmtfl);
  249. _LIBCPP_HIDE_FROM_ABI fmtflags setf(fmtflags __fmtfl);
  250. _LIBCPP_HIDE_FROM_ABI fmtflags setf(fmtflags __fmtfl, fmtflags __mask);
  251. _LIBCPP_HIDE_FROM_ABI void unsetf(fmtflags __mask);
  252. _LIBCPP_HIDE_FROM_ABI streamsize precision() const;
  253. _LIBCPP_HIDE_FROM_ABI streamsize precision(streamsize __prec);
  254. _LIBCPP_HIDE_FROM_ABI streamsize width() const;
  255. _LIBCPP_HIDE_FROM_ABI streamsize width(streamsize __wide);
  256. // 27.5.2.3 locales:
  257. locale imbue(const locale& __loc);
  258. locale getloc() const;
  259. // 27.5.2.5 storage:
  260. static int xalloc();
  261. long& iword(int __index);
  262. void*& pword(int __index);
  263. // destructor
  264. virtual ~ios_base();
  265. // 27.5.2.6 callbacks;
  266. enum event { erase_event, imbue_event, copyfmt_event };
  267. typedef void (*event_callback)(event, ios_base&, int __index);
  268. void register_callback(event_callback __fn, int __index);
  269. ios_base(const ios_base&) = delete;
  270. ios_base& operator=(const ios_base&) = delete;
  271. static bool sync_with_stdio(bool __sync = true);
  272. _LIBCPP_HIDE_FROM_ABI iostate rdstate() const;
  273. void clear(iostate __state = goodbit);
  274. _LIBCPP_HIDE_FROM_ABI void setstate(iostate __state);
  275. _LIBCPP_HIDE_FROM_ABI bool good() const;
  276. _LIBCPP_HIDE_FROM_ABI bool eof() const;
  277. _LIBCPP_HIDE_FROM_ABI bool fail() const;
  278. _LIBCPP_HIDE_FROM_ABI bool bad() const;
  279. _LIBCPP_HIDE_FROM_ABI iostate exceptions() const;
  280. _LIBCPP_HIDE_FROM_ABI void exceptions(iostate __iostate);
  281. void __set_badbit_and_consider_rethrow();
  282. void __set_failbit_and_consider_rethrow();
  283. _LIBCPP_HIDE_FROM_ABI void __setstate_nothrow(iostate __state) {
  284. if (__rdbuf_)
  285. __rdstate_ |= __state;
  286. else
  287. __rdstate_ |= __state | ios_base::badbit;
  288. }
  289. protected:
  290. _LIBCPP_HIDE_FROM_ABI ios_base() : __loc_(nullptr) {
  291. // Purposefully does no initialization
  292. //
  293. // Except for the locale, this is a sentinel to avoid destroying
  294. // an uninitialized object. See
  295. // test/libcxx/input.output/iostreams.base/ios.base/ios.base.cons/dtor.uninitialized.pass.cpp
  296. // for the details.
  297. }
  298. void init(void* __sb);
  299. _LIBCPP_HIDE_FROM_ABI void* rdbuf() const { return __rdbuf_; }
  300. _LIBCPP_HIDE_FROM_ABI void rdbuf(void* __sb) {
  301. __rdbuf_ = __sb;
  302. clear();
  303. }
  304. void __call_callbacks(event);
  305. void copyfmt(const ios_base&);
  306. void move(ios_base&);
  307. void swap(ios_base&) _NOEXCEPT;
  308. _LIBCPP_HIDE_FROM_ABI void set_rdbuf(void* __sb) { __rdbuf_ = __sb; }
  309. private:
  310. // All data members must be scalars
  311. fmtflags __fmtflags_;
  312. streamsize __precision_;
  313. streamsize __width_;
  314. iostate __rdstate_;
  315. iostate __exceptions_;
  316. void* __rdbuf_;
  317. void* __loc_;
  318. event_callback* __fn_;
  319. int* __index_;
  320. size_t __event_size_;
  321. size_t __event_cap_;
  322. // TODO(EricWF): Enable this for both Clang and GCC. Currently it is only
  323. // enabled with clang.
  324. #if defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS)
  325. static atomic<int> __xindex_;
  326. #else
  327. static int __xindex_;
  328. #endif
  329. long* __iarray_;
  330. size_t __iarray_size_;
  331. size_t __iarray_cap_;
  332. void** __parray_;
  333. size_t __parray_size_;
  334. size_t __parray_cap_;
  335. };
  336. // enum class io_errc
  337. _LIBCPP_DECLARE_STRONG_ENUM(io_errc){stream = 1};
  338. _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(io_errc)
  339. template <>
  340. struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc> : public true_type {};
  341. #ifdef _LIBCPP_CXX03_LANG
  342. template <>
  343. struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc::__lx> : public true_type {};
  344. #endif
  345. _LIBCPP_EXPORTED_FROM_ABI const error_category& iostream_category() _NOEXCEPT;
  346. inline _LIBCPP_HIDE_FROM_ABI error_code make_error_code(io_errc __e) _NOEXCEPT {
  347. return error_code(static_cast<int>(__e), iostream_category());
  348. }
  349. inline _LIBCPP_HIDE_FROM_ABI error_condition make_error_condition(io_errc __e) _NOEXCEPT {
  350. return error_condition(static_cast<int>(__e), iostream_category());
  351. }
  352. class _LIBCPP_EXPORTED_FROM_ABI ios_base::failure : public system_error {
  353. public:
  354. explicit failure(const string& __msg, const error_code& __ec = io_errc::stream);
  355. explicit failure(const char* __msg, const error_code& __ec = io_errc::stream);
  356. _LIBCPP_HIDE_FROM_ABI failure(const failure&) _NOEXCEPT = default;
  357. ~failure() _NOEXCEPT override;
  358. };
  359. _LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_failure(char const* __msg) {
  360. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  361. throw ios_base::failure(__msg);
  362. #else
  363. _LIBCPP_VERBOSE_ABORT("ios_base::failure was thrown in -fno-exceptions mode with message \"%s\"", __msg);
  364. #endif
  365. }
  366. class _LIBCPP_EXPORTED_FROM_ABI ios_base::Init {
  367. public:
  368. Init();
  369. ~Init();
  370. };
  371. // fmtflags
  372. inline _LIBCPP_HIDE_FROM_ABI ios_base::fmtflags ios_base::flags() const { return __fmtflags_; }
  373. inline _LIBCPP_HIDE_FROM_ABI ios_base::fmtflags ios_base::flags(fmtflags __fmtfl) {
  374. fmtflags __r = __fmtflags_;
  375. __fmtflags_ = __fmtfl;
  376. return __r;
  377. }
  378. inline _LIBCPP_HIDE_FROM_ABI ios_base::fmtflags ios_base::setf(fmtflags __fmtfl) {
  379. fmtflags __r = __fmtflags_;
  380. __fmtflags_ |= __fmtfl;
  381. return __r;
  382. }
  383. inline _LIBCPP_HIDE_FROM_ABI void ios_base::unsetf(fmtflags __mask) { __fmtflags_ &= ~__mask; }
  384. inline _LIBCPP_HIDE_FROM_ABI ios_base::fmtflags ios_base::setf(fmtflags __fmtfl, fmtflags __mask) {
  385. fmtflags __r = __fmtflags_;
  386. unsetf(__mask);
  387. __fmtflags_ |= __fmtfl & __mask;
  388. return __r;
  389. }
  390. // precision
  391. inline _LIBCPP_HIDE_FROM_ABI streamsize ios_base::precision() const { return __precision_; }
  392. inline _LIBCPP_HIDE_FROM_ABI streamsize ios_base::precision(streamsize __prec) {
  393. streamsize __r = __precision_;
  394. __precision_ = __prec;
  395. return __r;
  396. }
  397. // width
  398. inline _LIBCPP_HIDE_FROM_ABI streamsize ios_base::width() const { return __width_; }
  399. inline _LIBCPP_HIDE_FROM_ABI streamsize ios_base::width(streamsize __wide) {
  400. streamsize __r = __width_;
  401. __width_ = __wide;
  402. return __r;
  403. }
  404. // iostate
  405. inline _LIBCPP_HIDE_FROM_ABI ios_base::iostate ios_base::rdstate() const { return __rdstate_; }
  406. inline _LIBCPP_HIDE_FROM_ABI void ios_base::setstate(iostate __state) { clear(__rdstate_ | __state); }
  407. inline _LIBCPP_HIDE_FROM_ABI bool ios_base::good() const { return __rdstate_ == 0; }
  408. inline _LIBCPP_HIDE_FROM_ABI bool ios_base::eof() const { return (__rdstate_ & eofbit) != 0; }
  409. inline _LIBCPP_HIDE_FROM_ABI bool ios_base::fail() const { return (__rdstate_ & (failbit | badbit)) != 0; }
  410. inline _LIBCPP_HIDE_FROM_ABI bool ios_base::bad() const { return (__rdstate_ & badbit) != 0; }
  411. inline _LIBCPP_HIDE_FROM_ABI ios_base::iostate ios_base::exceptions() const { return __exceptions_; }
  412. inline _LIBCPP_HIDE_FROM_ABI void ios_base::exceptions(iostate __iostate) {
  413. __exceptions_ = __iostate;
  414. clear(__rdstate_);
  415. }
  416. template <class _CharT, class _Traits>
  417. class _LIBCPP_TEMPLATE_VIS basic_ios : public ios_base {
  418. public:
  419. // types:
  420. typedef _CharT char_type;
  421. typedef _Traits traits_type;
  422. typedef typename traits_type::int_type int_type;
  423. typedef typename traits_type::pos_type pos_type;
  424. typedef typename traits_type::off_type off_type;
  425. static_assert((is_same<_CharT, typename traits_type::char_type>::value),
  426. "traits_type::char_type must be the same type as CharT");
  427. #ifdef _LIBCPP_CXX03_LANG
  428. // Preserve the ability to compare with literal 0,
  429. // and implicitly convert to bool, but not implicitly convert to int.
  430. _LIBCPP_HIDE_FROM_ABI operator void*() const { return fail() ? nullptr : (void*)this; }
  431. #else
  432. _LIBCPP_HIDE_FROM_ABI explicit operator bool() const { return !fail(); }
  433. #endif
  434. _LIBCPP_HIDE_FROM_ABI bool operator!() const { return fail(); }
  435. _LIBCPP_HIDE_FROM_ABI iostate rdstate() const { return ios_base::rdstate(); }
  436. _LIBCPP_HIDE_FROM_ABI void clear(iostate __state = goodbit) { ios_base::clear(__state); }
  437. _LIBCPP_HIDE_FROM_ABI void setstate(iostate __state) { ios_base::setstate(__state); }
  438. _LIBCPP_HIDE_FROM_ABI bool good() const { return ios_base::good(); }
  439. _LIBCPP_HIDE_FROM_ABI bool eof() const { return ios_base::eof(); }
  440. _LIBCPP_HIDE_FROM_ABI bool fail() const { return ios_base::fail(); }
  441. _LIBCPP_HIDE_FROM_ABI bool bad() const { return ios_base::bad(); }
  442. _LIBCPP_HIDE_FROM_ABI iostate exceptions() const { return ios_base::exceptions(); }
  443. _LIBCPP_HIDE_FROM_ABI void exceptions(iostate __iostate) { ios_base::exceptions(__iostate); }
  444. // 27.5.4.1 Constructor/destructor:
  445. _LIBCPP_HIDE_FROM_ABI explicit basic_ios(basic_streambuf<char_type, traits_type>* __sb);
  446. ~basic_ios() override;
  447. // 27.5.4.2 Members:
  448. _LIBCPP_HIDE_FROM_ABI basic_ostream<char_type, traits_type>* tie() const;
  449. _LIBCPP_HIDE_FROM_ABI basic_ostream<char_type, traits_type>* tie(basic_ostream<char_type, traits_type>* __tiestr);
  450. _LIBCPP_HIDE_FROM_ABI basic_streambuf<char_type, traits_type>* rdbuf() const;
  451. _LIBCPP_HIDE_FROM_ABI basic_streambuf<char_type, traits_type>* rdbuf(basic_streambuf<char_type, traits_type>* __sb);
  452. basic_ios& copyfmt(const basic_ios& __rhs);
  453. _LIBCPP_HIDE_FROM_ABI char_type fill() const;
  454. _LIBCPP_HIDE_FROM_ABI char_type fill(char_type __ch);
  455. _LIBCPP_HIDE_FROM_ABI locale imbue(const locale& __loc);
  456. _LIBCPP_HIDE_FROM_ABI char narrow(char_type __c, char __dfault) const;
  457. _LIBCPP_HIDE_FROM_ABI char_type widen(char __c) const;
  458. protected:
  459. _LIBCPP_HIDE_FROM_ABI basic_ios() {
  460. // purposefully does no initialization
  461. // since the destructor does nothing this does not have ios_base issues.
  462. }
  463. _LIBCPP_HIDE_FROM_ABI void init(basic_streambuf<char_type, traits_type>* __sb);
  464. _LIBCPP_HIDE_FROM_ABI void move(basic_ios& __rhs);
  465. _LIBCPP_HIDE_FROM_ABI void move(basic_ios&& __rhs) { move(__rhs); }
  466. _LIBCPP_HIDE_FROM_ABI void swap(basic_ios& __rhs) _NOEXCEPT;
  467. _LIBCPP_HIDE_FROM_ABI void set_rdbuf(basic_streambuf<char_type, traits_type>* __sb);
  468. private:
  469. basic_ostream<char_type, traits_type>* __tie_;
  470. mutable int_type __fill_;
  471. };
  472. template <class _CharT, class _Traits>
  473. inline _LIBCPP_HIDE_FROM_ABI basic_ios<_CharT, _Traits>::basic_ios(basic_streambuf<char_type, traits_type>* __sb) {
  474. init(__sb);
  475. }
  476. template <class _CharT, class _Traits>
  477. basic_ios<_CharT, _Traits>::~basic_ios() {}
  478. template <class _CharT, class _Traits>
  479. inline _LIBCPP_HIDE_FROM_ABI void basic_ios<_CharT, _Traits>::init(basic_streambuf<char_type, traits_type>* __sb) {
  480. ios_base::init(__sb);
  481. __tie_ = nullptr;
  482. __fill_ = traits_type::eof();
  483. }
  484. template <class _CharT, class _Traits>
  485. inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>* basic_ios<_CharT, _Traits>::tie() const {
  486. return __tie_;
  487. }
  488. template <class _CharT, class _Traits>
  489. inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>*
  490. basic_ios<_CharT, _Traits>::tie(basic_ostream<char_type, traits_type>* __tiestr) {
  491. basic_ostream<char_type, traits_type>* __r = __tie_;
  492. __tie_ = __tiestr;
  493. return __r;
  494. }
  495. template <class _CharT, class _Traits>
  496. inline _LIBCPP_HIDE_FROM_ABI basic_streambuf<_CharT, _Traits>* basic_ios<_CharT, _Traits>::rdbuf() const {
  497. return static_cast<basic_streambuf<char_type, traits_type>*>(ios_base::rdbuf());
  498. }
  499. template <class _CharT, class _Traits>
  500. inline _LIBCPP_HIDE_FROM_ABI basic_streambuf<_CharT, _Traits>*
  501. basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<char_type, traits_type>* __sb) {
  502. basic_streambuf<char_type, traits_type>* __r = rdbuf();
  503. ios_base::rdbuf(__sb);
  504. return __r;
  505. }
  506. template <class _CharT, class _Traits>
  507. inline _LIBCPP_HIDE_FROM_ABI locale basic_ios<_CharT, _Traits>::imbue(const locale& __loc) {
  508. locale __r = getloc();
  509. ios_base::imbue(__loc);
  510. if (rdbuf())
  511. rdbuf()->pubimbue(__loc);
  512. return __r;
  513. }
  514. template <class _CharT, class _Traits>
  515. inline _LIBCPP_HIDE_FROM_ABI char basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const {
  516. return std::use_facet<ctype<char_type> >(getloc()).narrow(__c, __dfault);
  517. }
  518. template <class _CharT, class _Traits>
  519. inline _LIBCPP_HIDE_FROM_ABI _CharT basic_ios<_CharT, _Traits>::widen(char __c) const {
  520. return std::use_facet<ctype<char_type> >(getloc()).widen(__c);
  521. }
  522. template <class _CharT, class _Traits>
  523. inline _LIBCPP_HIDE_FROM_ABI _CharT basic_ios<_CharT, _Traits>::fill() const {
  524. if (traits_type::eq_int_type(traits_type::eof(), __fill_))
  525. __fill_ = widen(' ');
  526. return __fill_;
  527. }
  528. template <class _CharT, class _Traits>
  529. inline _LIBCPP_HIDE_FROM_ABI _CharT basic_ios<_CharT, _Traits>::fill(char_type __ch) {
  530. if (traits_type::eq_int_type(traits_type::eof(), __fill_))
  531. __fill_ = widen(' ');
  532. char_type __r = __fill_;
  533. __fill_ = __ch;
  534. return __r;
  535. }
  536. template <class _CharT, class _Traits>
  537. basic_ios<_CharT, _Traits>& basic_ios<_CharT, _Traits>::copyfmt(const basic_ios& __rhs) {
  538. if (this != &__rhs) {
  539. __call_callbacks(erase_event);
  540. ios_base::copyfmt(__rhs);
  541. __tie_ = __rhs.__tie_;
  542. __fill_ = __rhs.__fill_;
  543. __call_callbacks(copyfmt_event);
  544. exceptions(__rhs.exceptions());
  545. }
  546. return *this;
  547. }
  548. template <class _CharT, class _Traits>
  549. inline _LIBCPP_HIDE_FROM_ABI void basic_ios<_CharT, _Traits>::move(basic_ios& __rhs) {
  550. ios_base::move(__rhs);
  551. __tie_ = __rhs.__tie_;
  552. __rhs.__tie_ = nullptr;
  553. __fill_ = __rhs.__fill_;
  554. }
  555. template <class _CharT, class _Traits>
  556. inline _LIBCPP_HIDE_FROM_ABI void basic_ios<_CharT, _Traits>::swap(basic_ios& __rhs) _NOEXCEPT {
  557. ios_base::swap(__rhs);
  558. std::swap(__tie_, __rhs.__tie_);
  559. std::swap(__fill_, __rhs.__fill_);
  560. }
  561. template <class _CharT, class _Traits>
  562. inline _LIBCPP_HIDE_FROM_ABI void basic_ios<_CharT, _Traits>::set_rdbuf(basic_streambuf<char_type, traits_type>* __sb) {
  563. ios_base::set_rdbuf(__sb);
  564. }
  565. extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios<char>;
  566. #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
  567. extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios<wchar_t>;
  568. #endif
  569. _LIBCPP_HIDE_FROM_ABI inline ios_base& boolalpha(ios_base& __str) {
  570. __str.setf(ios_base::boolalpha);
  571. return __str;
  572. }
  573. _LIBCPP_HIDE_FROM_ABI inline ios_base& noboolalpha(ios_base& __str) {
  574. __str.unsetf(ios_base::boolalpha);
  575. return __str;
  576. }
  577. _LIBCPP_HIDE_FROM_ABI inline ios_base& showbase(ios_base& __str) {
  578. __str.setf(ios_base::showbase);
  579. return __str;
  580. }
  581. _LIBCPP_HIDE_FROM_ABI inline ios_base& noshowbase(ios_base& __str) {
  582. __str.unsetf(ios_base::showbase);
  583. return __str;
  584. }
  585. _LIBCPP_HIDE_FROM_ABI inline ios_base& showpoint(ios_base& __str) {
  586. __str.setf(ios_base::showpoint);
  587. return __str;
  588. }
  589. _LIBCPP_HIDE_FROM_ABI inline ios_base& noshowpoint(ios_base& __str) {
  590. __str.unsetf(ios_base::showpoint);
  591. return __str;
  592. }
  593. _LIBCPP_HIDE_FROM_ABI inline ios_base& showpos(ios_base& __str) {
  594. __str.setf(ios_base::showpos);
  595. return __str;
  596. }
  597. _LIBCPP_HIDE_FROM_ABI inline ios_base& noshowpos(ios_base& __str) {
  598. __str.unsetf(ios_base::showpos);
  599. return __str;
  600. }
  601. _LIBCPP_HIDE_FROM_ABI inline ios_base& skipws(ios_base& __str) {
  602. __str.setf(ios_base::skipws);
  603. return __str;
  604. }
  605. _LIBCPP_HIDE_FROM_ABI inline ios_base& noskipws(ios_base& __str) {
  606. __str.unsetf(ios_base::skipws);
  607. return __str;
  608. }
  609. _LIBCPP_HIDE_FROM_ABI inline ios_base& uppercase(ios_base& __str) {
  610. __str.setf(ios_base::uppercase);
  611. return __str;
  612. }
  613. _LIBCPP_HIDE_FROM_ABI inline ios_base& nouppercase(ios_base& __str) {
  614. __str.unsetf(ios_base::uppercase);
  615. return __str;
  616. }
  617. _LIBCPP_HIDE_FROM_ABI inline ios_base& unitbuf(ios_base& __str) {
  618. __str.setf(ios_base::unitbuf);
  619. return __str;
  620. }
  621. _LIBCPP_HIDE_FROM_ABI inline ios_base& nounitbuf(ios_base& __str) {
  622. __str.unsetf(ios_base::unitbuf);
  623. return __str;
  624. }
  625. _LIBCPP_HIDE_FROM_ABI inline ios_base& internal(ios_base& __str) {
  626. __str.setf(ios_base::internal, ios_base::adjustfield);
  627. return __str;
  628. }
  629. _LIBCPP_HIDE_FROM_ABI inline ios_base& left(ios_base& __str) {
  630. __str.setf(ios_base::left, ios_base::adjustfield);
  631. return __str;
  632. }
  633. _LIBCPP_HIDE_FROM_ABI inline ios_base& right(ios_base& __str) {
  634. __str.setf(ios_base::right, ios_base::adjustfield);
  635. return __str;
  636. }
  637. _LIBCPP_HIDE_FROM_ABI inline ios_base& dec(ios_base& __str) {
  638. __str.setf(ios_base::dec, ios_base::basefield);
  639. return __str;
  640. }
  641. _LIBCPP_HIDE_FROM_ABI inline ios_base& hex(ios_base& __str) {
  642. __str.setf(ios_base::hex, ios_base::basefield);
  643. return __str;
  644. }
  645. _LIBCPP_HIDE_FROM_ABI inline ios_base& oct(ios_base& __str) {
  646. __str.setf(ios_base::oct, ios_base::basefield);
  647. return __str;
  648. }
  649. _LIBCPP_HIDE_FROM_ABI inline ios_base& fixed(ios_base& __str) {
  650. __str.setf(ios_base::fixed, ios_base::floatfield);
  651. return __str;
  652. }
  653. _LIBCPP_HIDE_FROM_ABI inline ios_base& scientific(ios_base& __str) {
  654. __str.setf(ios_base::scientific, ios_base::floatfield);
  655. return __str;
  656. }
  657. _LIBCPP_HIDE_FROM_ABI inline ios_base& hexfloat(ios_base& __str) {
  658. __str.setf(ios_base::fixed | ios_base::scientific, ios_base::floatfield);
  659. return __str;
  660. }
  661. _LIBCPP_HIDE_FROM_ABI inline ios_base& defaultfloat(ios_base& __str) {
  662. __str.unsetf(ios_base::floatfield);
  663. return __str;
  664. }
  665. _LIBCPP_END_NAMESPACE_STD
  666. _LIBCPP_POP_MACROS
  667. #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
  668. # include <atomic>
  669. # include <concepts>
  670. # include <cstddef>
  671. # include <cstdlib>
  672. # include <cstring>
  673. # include <initializer_list>
  674. # include <limits>
  675. # include <mutex>
  676. # include <new>
  677. # include <stdexcept>
  678. # include <system_error>
  679. # include <type_traits>
  680. # include <typeinfo>
  681. #endif
  682. #endif // _LIBCPP_IOS