ios 25 KB

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