ios 24 KB

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