ios 24 KB

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