ios 26 KB

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