blob: ff79998b0bbf9fc00ffc4a43a3ecf2f4c821fdd3 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===---------------------------- ios -------------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_IOS
12#define _LIBCPP_IOS
13
14/*
15 ios synopsis
16
17#include <iosfwd>
18
19namespace std
20{
21
22typedef OFF_T streamoff;
23typedef SZ_T streamsize;
24template <class stateT> class fpos;
25
26class ios_base
27{
28public:
29 class failure;
30
31 typedef T1 fmtflags;
Howard Hinnantf57bd562012-07-21 01:03:40 +000032 static constexpr fmtflags boolalpha;
33 static constexpr fmtflags dec;
34 static constexpr fmtflags fixed;
35 static constexpr fmtflags hex;
36 static constexpr fmtflags internal;
37 static constexpr fmtflags left;
38 static constexpr fmtflags oct;
39 static constexpr fmtflags right;
40 static constexpr fmtflags scientific;
41 static constexpr fmtflags showbase;
42 static constexpr fmtflags showpoint;
43 static constexpr fmtflags showpos;
44 static constexpr fmtflags skipws;
45 static constexpr fmtflags unitbuf;
46 static constexpr fmtflags uppercase;
47 static constexpr fmtflags adjustfield;
48 static constexpr fmtflags basefield;
49 static constexpr fmtflags floatfield;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000050
51 typedef T2 iostate;
Howard Hinnantf57bd562012-07-21 01:03:40 +000052 static constexpr iostate badbit;
53 static constexpr iostate eofbit;
54 static constexpr iostate failbit;
55 static constexpr iostate goodbit;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000056
57 typedef T3 openmode;
Howard Hinnantf57bd562012-07-21 01:03:40 +000058 static constexpr openmode app;
59 static constexpr openmode ate;
60 static constexpr openmode binary;
61 static constexpr openmode in;
62 static constexpr openmode out;
63 static constexpr openmode trunc;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000064
65 typedef T4 seekdir;
Howard Hinnantf57bd562012-07-21 01:03:40 +000066 static constexpr seekdir beg;
67 static constexpr seekdir cur;
68 static constexpr seekdir end;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000069
70 class Init;
71
72 // 27.5.2.2 fmtflags state:
73 fmtflags flags() const;
74 fmtflags flags(fmtflags fmtfl);
75 fmtflags setf(fmtflags fmtfl);
76 fmtflags setf(fmtflags fmtfl, fmtflags mask);
77 void unsetf(fmtflags mask);
78
79 streamsize precision() const;
80 streamsize precision(streamsize prec);
81 streamsize width() const;
82 streamsize width(streamsize wide);
83
84 // 27.5.2.3 locales:
85 locale imbue(const locale& loc);
86 locale getloc() const;
87
88 // 27.5.2.5 storage:
89 static int xalloc();
90 long& iword(int index);
91 void*& pword(int index);
92
93 // destructor
94 virtual ~ios_base();
95
96 // 27.5.2.6 callbacks;
97 enum event { erase_event, imbue_event, copyfmt_event };
98 typedef void (*event_callback)(event, ios_base&, int index);
99 void register_callback(event_callback fn, int index);
100
101 ios_base(const ios_base&) = delete;
102 ios_base& operator=(const ios_base&) = delete;
103
104 static bool sync_with_stdio(bool sync = true);
105
106protected:
107 ios_base();
108};
109
110template <class charT, class traits = char_traits<charT> >
111class basic_ios
112 : public ios_base
113{
114public:
115 // types:
116 typedef charT char_type;
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700117 typedef typename traits::int_type int_type;
118 typedef typename traits::pos_type pos_type;
119 typedef typename traits::off_type off_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000120 typedef traits traits_type;
121
122 operator unspecified-bool-type() const;
123 bool operator!() const;
124 iostate rdstate() const;
125 void clear(iostate state = goodbit);
126 void setstate(iostate state);
127 bool good() const;
128 bool eof() const;
129 bool fail() const;
130 bool bad() const;
131
132 iostate exceptions() const;
133 void exceptions(iostate except);
134
135 // 27.5.4.1 Constructor/destructor:
136 explicit basic_ios(basic_streambuf<charT,traits>* sb);
137 virtual ~basic_ios();
138
139 // 27.5.4.2 Members:
140 basic_ostream<charT,traits>* tie() const;
141 basic_ostream<charT,traits>* tie(basic_ostream<charT,traits>* tiestr);
142
143 basic_streambuf<charT,traits>* rdbuf() const;
144 basic_streambuf<charT,traits>* rdbuf(basic_streambuf<charT,traits>* sb);
145
146 basic_ios& copyfmt(const basic_ios& rhs);
147
148 char_type fill() const;
149 char_type fill(char_type ch);
150
151 locale imbue(const locale& loc);
152
153 char narrow(char_type c, char dfault) const;
154 char_type widen(char c) const;
155
156 basic_ios(const basic_ios& ) = delete;
157 basic_ios& operator=(const basic_ios&) = delete;
158
159protected:
160 basic_ios();
161 void init(basic_streambuf<charT,traits>* sb);
162 void move(basic_ios& rhs);
Howard Hinnantf57bd562012-07-21 01:03:40 +0000163 void swap(basic_ios& rhs) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000164 void set_rdbuf(basic_streambuf<charT, traits>* sb);
165};
166
167// 27.5.5, manipulators:
168ios_base& boolalpha (ios_base& str);
169ios_base& noboolalpha(ios_base& str);
170ios_base& showbase (ios_base& str);
171ios_base& noshowbase (ios_base& str);
172ios_base& showpoint (ios_base& str);
173ios_base& noshowpoint(ios_base& str);
174ios_base& showpos (ios_base& str);
175ios_base& noshowpos (ios_base& str);
176ios_base& skipws (ios_base& str);
177ios_base& noskipws (ios_base& str);
178ios_base& uppercase (ios_base& str);
179ios_base& nouppercase(ios_base& str);
180ios_base& unitbuf (ios_base& str);
181ios_base& nounitbuf (ios_base& str);
182
183// 27.5.5.2 adjustfield:
184ios_base& internal (ios_base& str);
185ios_base& left (ios_base& str);
186ios_base& right (ios_base& str);
187
188// 27.5.5.3 basefield:
189ios_base& dec (ios_base& str);
190ios_base& hex (ios_base& str);
191ios_base& oct (ios_base& str);
192
193// 27.5.5.4 floatfield:
194ios_base& fixed (ios_base& str);
195ios_base& scientific (ios_base& str);
196ios_base& hexfloat (ios_base& str);
197ios_base& defaultfloat(ios_base& str);
198
199// 27.5.5.5 error reporting:
200enum class io_errc
201{
202 stream = 1
203};
204
205concept_map ErrorCodeEnum<io_errc> { };
Marshall Clow61a84222013-10-12 22:49:56 +0000206error_code make_error_code(io_errc e) noexcept;
207error_condition make_error_condition(io_errc e) noexcept;
208storage-class-specifier const error_category& iostream_category() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000209
210} // std
211
212*/
213
214#include <__config>
215#include <iosfwd>
216#include <__locale>
217#include <system_error>
218
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700219#if __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
Marshall Clow206ce1f2013-10-12 19:13:52 +0000220#include <atomic> // for __xindex_
221#endif
222
Howard Hinnant08e17472011-10-17 20:05:10 +0000223#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000224#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000225#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000226
227_LIBCPP_BEGIN_NAMESPACE_STD
228
229typedef ptrdiff_t streamsize;
230
Howard Hinnant83eade62013-03-06 23:30:19 +0000231class _LIBCPP_TYPE_VIS ios_base
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000232{
233public:
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700234 class _LIBCPP_TYPE_VIS failure;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000235
236 typedef unsigned int fmtflags;
237 static const fmtflags boolalpha = 0x0001;
238 static const fmtflags dec = 0x0002;
239 static const fmtflags fixed = 0x0004;
240 static const fmtflags hex = 0x0008;
241 static const fmtflags internal = 0x0010;
242 static const fmtflags left = 0x0020;
243 static const fmtflags oct = 0x0040;
244 static const fmtflags right = 0x0080;
245 static const fmtflags scientific = 0x0100;
246 static const fmtflags showbase = 0x0200;
247 static const fmtflags showpoint = 0x0400;
248 static const fmtflags showpos = 0x0800;
249 static const fmtflags skipws = 0x1000;
250 static const fmtflags unitbuf = 0x2000;
251 static const fmtflags uppercase = 0x4000;
252 static const fmtflags adjustfield = left | right | internal;
253 static const fmtflags basefield = dec | oct | hex;
254 static const fmtflags floatfield = scientific | fixed;
255
256 typedef unsigned int iostate;
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700257 typedef iostate io_state;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000258 static const iostate badbit = 0x1;
259 static const iostate eofbit = 0x2;
260 static const iostate failbit = 0x4;
261 static const iostate goodbit = 0x0;
262
263 typedef unsigned int openmode;
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700264 typedef openmode open_mode;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000265 static const openmode app = 0x01;
266 static const openmode ate = 0x02;
267 static const openmode binary = 0x04;
268 static const openmode in = 0x08;
269 static const openmode out = 0x10;
270 static const openmode trunc = 0x20;
271
272 enum seekdir {beg, cur, end};
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700273 typedef seekdir seek_dir;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000274
Howard Hinnant0949eed2011-06-30 21:18:19 +0000275 typedef _VSTD::streamoff streamoff;
276 typedef _VSTD::streampos streampos;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000277
Howard Hinnant83eade62013-03-06 23:30:19 +0000278 class _LIBCPP_TYPE_VIS Init;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000279
280 // 27.5.2.2 fmtflags state:
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000281 _LIBCPP_INLINE_VISIBILITY fmtflags flags() const;
282 _LIBCPP_INLINE_VISIBILITY fmtflags flags(fmtflags __fmtfl);
283 _LIBCPP_INLINE_VISIBILITY fmtflags setf(fmtflags __fmtfl);
284 _LIBCPP_INLINE_VISIBILITY fmtflags setf(fmtflags __fmtfl, fmtflags __mask);
285 _LIBCPP_INLINE_VISIBILITY void unsetf(fmtflags __mask);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000286
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000287 _LIBCPP_INLINE_VISIBILITY streamsize precision() const;
288 _LIBCPP_INLINE_VISIBILITY streamsize precision(streamsize __prec);
289 _LIBCPP_INLINE_VISIBILITY streamsize width() const;
290 _LIBCPP_INLINE_VISIBILITY streamsize width(streamsize __wide);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000291
292 // 27.5.2.3 locales:
293 locale imbue(const locale& __loc);
294 locale getloc() const;
295
296 // 27.5.2.5 storage:
297 static int xalloc();
298 long& iword(int __index);
299 void*& pword(int __index);
300
301 // destructor
302 virtual ~ios_base();
303
304 // 27.5.2.6 callbacks;
305 enum event { erase_event, imbue_event, copyfmt_event };
306 typedef void (*event_callback)(event, ios_base&, int __index);
307 void register_callback(event_callback __fn, int __index);
308
309private:
310 ios_base(const ios_base&); // = delete;
311 ios_base& operator=(const ios_base&); // = delete;
312
313public:
314 static bool sync_with_stdio(bool __sync = true);
315
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000316 _LIBCPP_INLINE_VISIBILITY iostate rdstate() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000317 void clear(iostate __state = goodbit);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000318 _LIBCPP_INLINE_VISIBILITY void setstate(iostate __state);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000319
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000320 _LIBCPP_INLINE_VISIBILITY bool good() const;
321 _LIBCPP_INLINE_VISIBILITY bool eof() const;
322 _LIBCPP_INLINE_VISIBILITY bool fail() const;
323 _LIBCPP_INLINE_VISIBILITY bool bad() const;
Howard Hinnant324bb032010-08-22 00:02:43 +0000324
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000325 _LIBCPP_INLINE_VISIBILITY iostate exceptions() const;
Howard Hinnante0640552013-10-06 21:00:29 +0000326 _LIBCPP_INLINE_VISIBILITY void exceptions(iostate __iostate);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000327
328 void __set_badbit_and_consider_rethrow();
329 void __set_failbit_and_consider_rethrow();
330
331protected:
Howard Hinnant68a8e902010-09-22 15:29:08 +0000332 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000333 ios_base() {// purposefully does no initialization
334 }
335
336 void init(void* __sb);
337 _LIBCPP_ALWAYS_INLINE void* rdbuf() const {return __rdbuf_;}
338
339 _LIBCPP_ALWAYS_INLINE
340 void rdbuf(void* __sb)
341 {
342 __rdbuf_ = __sb;
343 clear();
344 }
345
346 void __call_callbacks(event);
347 void copyfmt(const ios_base&);
348 void move(ios_base&);
Howard Hinnantf57bd562012-07-21 01:03:40 +0000349 void swap(ios_base&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000350
351 _LIBCPP_ALWAYS_INLINE
352 void set_rdbuf(void* __sb)
353 {
354 __rdbuf_ = __sb;
355 }
356
357private:
358 // All data members must be scalars
359 fmtflags __fmtflags_;
360 streamsize __precision_;
361 streamsize __width_;
362 iostate __rdstate_;
363 iostate __exceptions_;
364 void* __rdbuf_;
365 void* __loc_;
366 event_callback* __fn_;
367 int* __index_;
368 size_t __event_size_;
369 size_t __event_cap_;
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700370#if __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
Marshall Clow206ce1f2013-10-12 19:13:52 +0000371 static atomic<int> __xindex_;
372#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000373 static int __xindex_;
Marshall Clow206ce1f2013-10-12 19:13:52 +0000374#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000375 long* __iarray_;
376 size_t __iarray_size_;
377 size_t __iarray_cap_;
378 void** __parray_;
379 size_t __parray_size_;
380 size_t __parray_cap_;
381};
382
383//enum class io_errc
Howard Hinnantf6d875f2011-12-02 19:36:40 +0000384_LIBCPP_DECLARE_STRONG_ENUM(io_errc)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000385{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000386 stream = 1
387};
Howard Hinnantf6d875f2011-12-02 19:36:40 +0000388_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(io_errc)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000389
Howard Hinnant68a8e902010-09-22 15:29:08 +0000390template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000391struct _LIBCPP_TYPE_VIS_ONLY is_error_code_enum<io_errc> : public true_type { };
Howard Hinnantf6d875f2011-12-02 19:36:40 +0000392
393#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
Howard Hinnant68a8e902010-09-22 15:29:08 +0000394template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000395struct _LIBCPP_TYPE_VIS_ONLY is_error_code_enum<io_errc::__lx> : public true_type { };
Howard Hinnantf6d875f2011-12-02 19:36:40 +0000396#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000397
Howard Hinnant83eade62013-03-06 23:30:19 +0000398_LIBCPP_FUNC_VIS
Marshall Clow61a84222013-10-12 22:49:56 +0000399const error_category& iostream_category() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000400
401inline _LIBCPP_INLINE_VISIBILITY
402error_code
Marshall Clow61a84222013-10-12 22:49:56 +0000403make_error_code(io_errc __e) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000404{
405 return error_code(static_cast<int>(__e), iostream_category());
406}
407
408inline _LIBCPP_INLINE_VISIBILITY
409error_condition
Marshall Clow61a84222013-10-12 22:49:56 +0000410make_error_condition(io_errc __e) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000411{
412 return error_condition(static_cast<int>(__e), iostream_category());
413}
414
Howard Hinnant68a8e902010-09-22 15:29:08 +0000415class _LIBCPP_EXCEPTION_ABI ios_base::failure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000416 : public system_error
Howard Hinnant324bb032010-08-22 00:02:43 +0000417{
418public:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000419 explicit failure(const string& __msg, const error_code& __ec = io_errc::stream);
Howard Hinnant324bb032010-08-22 00:02:43 +0000420 explicit failure(const char* __msg, const error_code& __ec = io_errc::stream);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000421 virtual ~failure() throw();
422};
423
Howard Hinnant83eade62013-03-06 23:30:19 +0000424class _LIBCPP_TYPE_VIS ios_base::Init
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000425{
426public:
427 Init();
428 ~Init();
429};
430
431// fmtflags
432
433inline _LIBCPP_INLINE_VISIBILITY
434ios_base::fmtflags
435ios_base::flags() const
436{
437 return __fmtflags_;
438}
439
440inline _LIBCPP_INLINE_VISIBILITY
441ios_base::fmtflags
442ios_base::flags(fmtflags __fmtfl)
443{
444 fmtflags __r = __fmtflags_;
445 __fmtflags_ = __fmtfl;
446 return __r;
447}
448
449inline _LIBCPP_INLINE_VISIBILITY
450ios_base::fmtflags
451ios_base::setf(fmtflags __fmtfl)
452{
453 fmtflags __r = __fmtflags_;
454 __fmtflags_ |= __fmtfl;
455 return __r;
456}
457
458inline _LIBCPP_INLINE_VISIBILITY
459void
460ios_base::unsetf(fmtflags __mask)
461{
462 __fmtflags_ &= ~__mask;
463}
464
465inline _LIBCPP_INLINE_VISIBILITY
466ios_base::fmtflags
467ios_base::setf(fmtflags __fmtfl, fmtflags __mask)
468{
469 fmtflags __r = __fmtflags_;
470 unsetf(__mask);
471 __fmtflags_ |= __fmtfl & __mask;
472 return __r;
473}
474
475// precision
476
477inline _LIBCPP_INLINE_VISIBILITY
478streamsize
479ios_base::precision() const
480{
481 return __precision_;
482}
483
484inline _LIBCPP_INLINE_VISIBILITY
485streamsize
486ios_base::precision(streamsize __prec)
487{
488 streamsize __r = __precision_;
489 __precision_ = __prec;
490 return __r;
491}
492
493// width
494
495inline _LIBCPP_INLINE_VISIBILITY
496streamsize
497ios_base::width() const
498{
499 return __width_;
500}
501
502inline _LIBCPP_INLINE_VISIBILITY
503streamsize
504ios_base::width(streamsize __wide)
505{
506 streamsize __r = __width_;
507 __width_ = __wide;
508 return __r;
509}
510
511// iostate
512
513inline _LIBCPP_INLINE_VISIBILITY
514ios_base::iostate
515ios_base::rdstate() const
516{
517 return __rdstate_;
518}
519
520inline _LIBCPP_INLINE_VISIBILITY
521void
522ios_base::setstate(iostate __state)
523{
524 clear(__rdstate_ | __state);
525}
526
527inline _LIBCPP_INLINE_VISIBILITY
528bool
529ios_base::good() const
530{
531 return __rdstate_ == 0;
532}
533
534inline _LIBCPP_INLINE_VISIBILITY
535bool
536ios_base::eof() const
537{
Marshall Clow8a43fca2013-10-21 14:41:05 +0000538 return (__rdstate_ & eofbit) != 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000539}
540
541inline _LIBCPP_INLINE_VISIBILITY
542bool
543ios_base::fail() const
544{
Marshall Clow8a43fca2013-10-21 14:41:05 +0000545 return (__rdstate_ & (failbit | badbit)) != 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000546}
547
548inline _LIBCPP_INLINE_VISIBILITY
549bool
550ios_base::bad() const
551{
Marshall Clow8a43fca2013-10-21 14:41:05 +0000552 return (__rdstate_ & badbit) != 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000553}
554
555inline _LIBCPP_INLINE_VISIBILITY
556ios_base::iostate
557ios_base::exceptions() const
558{
559 return __exceptions_;
560}
561
562inline _LIBCPP_INLINE_VISIBILITY
563void
Howard Hinnante0640552013-10-06 21:00:29 +0000564ios_base::exceptions(iostate __iostate)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000565{
Howard Hinnante0640552013-10-06 21:00:29 +0000566 __exceptions_ = __iostate;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000567 clear(__rdstate_);
568}
569
570template <class _CharT, class _Traits>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000571class _LIBCPP_TYPE_VIS_ONLY basic_ios
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000572 : public ios_base
573{
574public:
575 // types:
576 typedef _CharT char_type;
577 typedef _Traits traits_type;
578
579 typedef typename traits_type::int_type int_type;
580 typedef typename traits_type::pos_type pos_type;
581 typedef typename traits_type::off_type off_type;
582
Howard Hinnant77861882012-02-21 21:46:43 +0000583 _LIBCPP_ALWAYS_INLINE
584 _LIBCPP_EXPLICIT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000585 operator bool() const {return !fail();}
586 _LIBCPP_ALWAYS_INLINE bool operator!() const {return fail();}
587 _LIBCPP_ALWAYS_INLINE iostate rdstate() const {return ios_base::rdstate();}
588 _LIBCPP_ALWAYS_INLINE void clear(iostate __state = goodbit) {ios_base::clear(__state);}
589 _LIBCPP_ALWAYS_INLINE void setstate(iostate __state) {ios_base::setstate(__state);}
590 _LIBCPP_ALWAYS_INLINE bool good() const {return ios_base::good();}
591 _LIBCPP_ALWAYS_INLINE bool eof() const {return ios_base::eof();}
592 _LIBCPP_ALWAYS_INLINE bool fail() const {return ios_base::fail();}
593 _LIBCPP_ALWAYS_INLINE bool bad() const {return ios_base::bad();}
594
595 _LIBCPP_ALWAYS_INLINE iostate exceptions() const {return ios_base::exceptions();}
Howard Hinnante0640552013-10-06 21:00:29 +0000596 _LIBCPP_ALWAYS_INLINE void exceptions(iostate __iostate) {ios_base::exceptions(__iostate);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000597
598 // 27.5.4.1 Constructor/destructor:
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000599 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000600 explicit basic_ios(basic_streambuf<char_type,traits_type>* __sb);
601 virtual ~basic_ios();
602
603 // 27.5.4.2 Members:
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000604 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000605 basic_ostream<char_type, traits_type>* tie() const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000606 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000607 basic_ostream<char_type, traits_type>* tie(basic_ostream<char_type, traits_type>* __tiestr);
608
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000609 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000610 basic_streambuf<char_type, traits_type>* rdbuf() const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000611 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000612 basic_streambuf<char_type, traits_type>* rdbuf(basic_streambuf<char_type, traits_type>* __sb);
613
614 basic_ios& copyfmt(const basic_ios& __rhs);
615
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000616 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000617 char_type fill() const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000618 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000619 char_type fill(char_type __ch);
620
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000622 locale imbue(const locale& __loc);
623
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000624 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000625 char narrow(char_type __c, char __dfault) const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000626 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000627 char_type widen(char __c) const;
628
629protected:
Howard Hinnant68a8e902010-09-22 15:29:08 +0000630 _LIBCPP_ALWAYS_INLINE
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000631 basic_ios() {// purposefully does no initialization
632 }
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000633 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000634 void init(basic_streambuf<char_type, traits_type>* __sb);
635
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000636 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000637 void move(basic_ios& __rhs);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000638#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant68a8e902010-09-22 15:29:08 +0000639 _LIBCPP_ALWAYS_INLINE
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000640 void move(basic_ios&& __rhs) {move(__rhs);}
641#endif
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000642 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf57bd562012-07-21 01:03:40 +0000643 void swap(basic_ios& __rhs) _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000644 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000645 void set_rdbuf(basic_streambuf<char_type, traits_type>* __sb);
646private:
647 basic_ostream<char_type, traits_type>* __tie_;
Howard Hinnantc417a802012-08-26 18:05:35 +0000648 mutable int_type __fill_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000649};
650
651template <class _CharT, class _Traits>
652inline _LIBCPP_INLINE_VISIBILITY
653basic_ios<_CharT, _Traits>::basic_ios(basic_streambuf<char_type,traits_type>* __sb)
654{
655 init(__sb);
656}
657
658template <class _CharT, class _Traits>
659basic_ios<_CharT, _Traits>::~basic_ios()
660{
661}
662
663template <class _CharT, class _Traits>
664inline _LIBCPP_INLINE_VISIBILITY
665void
666basic_ios<_CharT, _Traits>::init(basic_streambuf<char_type, traits_type>* __sb)
667{
668 ios_base::init(__sb);
669 __tie_ = 0;
Howard Hinnantc417a802012-08-26 18:05:35 +0000670 __fill_ = traits_type::eof();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000671}
672
673template <class _CharT, class _Traits>
674inline _LIBCPP_INLINE_VISIBILITY
675basic_ostream<_CharT, _Traits>*
676basic_ios<_CharT, _Traits>::tie() const
677{
678 return __tie_;
679}
680
681template <class _CharT, class _Traits>
682inline _LIBCPP_INLINE_VISIBILITY
683basic_ostream<_CharT, _Traits>*
684basic_ios<_CharT, _Traits>::tie(basic_ostream<char_type, traits_type>* __tiestr)
685{
686 basic_ostream<char_type, traits_type>* __r = __tie_;
687 __tie_ = __tiestr;
688 return __r;
689}
690
691template <class _CharT, class _Traits>
692inline _LIBCPP_INLINE_VISIBILITY
693basic_streambuf<_CharT, _Traits>*
694basic_ios<_CharT, _Traits>::rdbuf() const
695{
696 return static_cast<basic_streambuf<char_type, traits_type>*>(ios_base::rdbuf());
697}
698
699template <class _CharT, class _Traits>
700inline _LIBCPP_INLINE_VISIBILITY
701basic_streambuf<_CharT, _Traits>*
702basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<char_type, traits_type>* __sb)
703{
704 basic_streambuf<char_type, traits_type>* __r = rdbuf();
705 ios_base::rdbuf(__sb);
706 return __r;
707}
708
709template <class _CharT, class _Traits>
710inline _LIBCPP_INLINE_VISIBILITY
711locale
712basic_ios<_CharT, _Traits>::imbue(const locale& __loc)
713{
714 locale __r = getloc();
715 ios_base::imbue(__loc);
716 if (rdbuf())
717 rdbuf()->pubimbue(__loc);
718 return __r;
719}
720
721template <class _CharT, class _Traits>
722inline _LIBCPP_INLINE_VISIBILITY
723char
724basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const
725{
726 return use_facet<ctype<char_type> >(getloc()).narrow(__c, __dfault);
727}
728
729template <class _CharT, class _Traits>
730inline _LIBCPP_INLINE_VISIBILITY
731_CharT
732basic_ios<_CharT, _Traits>::widen(char __c) const
733{
734 return use_facet<ctype<char_type> >(getloc()).widen(__c);
735}
736
737template <class _CharT, class _Traits>
738inline _LIBCPP_INLINE_VISIBILITY
739_CharT
740basic_ios<_CharT, _Traits>::fill() const
741{
Howard Hinnantc417a802012-08-26 18:05:35 +0000742 if (traits_type::eq_int_type(traits_type::eof(), __fill_))
743 __fill_ = widen(' ');
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000744 return __fill_;
745}
746
747template <class _CharT, class _Traits>
748inline _LIBCPP_INLINE_VISIBILITY
749_CharT
750basic_ios<_CharT, _Traits>::fill(char_type __ch)
751{
752 char_type __r = __fill_;
753 __fill_ = __ch;
754 return __r;
755}
756
757template <class _CharT, class _Traits>
758basic_ios<_CharT, _Traits>&
759basic_ios<_CharT, _Traits>::copyfmt(const basic_ios& __rhs)
760{
761 if (this != &__rhs)
762 {
763 __call_callbacks(erase_event);
764 ios_base::copyfmt(__rhs);
765 __tie_ = __rhs.__tie_;
766 __fill_ = __rhs.__fill_;
767 __call_callbacks(copyfmt_event);
768 exceptions(__rhs.exceptions());
769 }
770 return *this;
771}
772
773template <class _CharT, class _Traits>
774inline _LIBCPP_INLINE_VISIBILITY
775void
776basic_ios<_CharT, _Traits>::move(basic_ios& __rhs)
777{
778 ios_base::move(__rhs);
779 __tie_ = __rhs.__tie_;
780 __rhs.__tie_ = 0;
781 __fill_ = __rhs.__fill_;
782}
783
784template <class _CharT, class _Traits>
785inline _LIBCPP_INLINE_VISIBILITY
786void
Howard Hinnantf57bd562012-07-21 01:03:40 +0000787basic_ios<_CharT, _Traits>::swap(basic_ios& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000788{
789 ios_base::swap(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000790 _VSTD::swap(__tie_, __rhs.__tie_);
791 _VSTD::swap(__fill_, __rhs.__fill_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000792}
793
794template <class _CharT, class _Traits>
795inline _LIBCPP_INLINE_VISIBILITY
796void
797basic_ios<_CharT, _Traits>::set_rdbuf(basic_streambuf<char_type, traits_type>* __sb)
798{
799 ios_base::set_rdbuf(__sb);
800}
801
802inline _LIBCPP_INLINE_VISIBILITY
803ios_base&
804boolalpha(ios_base& __str)
805{
806 __str.setf(ios_base::boolalpha);
807 return __str;
808}
809
810inline _LIBCPP_INLINE_VISIBILITY
811ios_base&
812noboolalpha(ios_base& __str)
813{
814 __str.unsetf(ios_base::boolalpha);
815 return __str;
816}
817
818inline _LIBCPP_INLINE_VISIBILITY
819ios_base&
820showbase(ios_base& __str)
821{
822 __str.setf(ios_base::showbase);
823 return __str;
824}
825
826inline _LIBCPP_INLINE_VISIBILITY
827ios_base&
828noshowbase(ios_base& __str)
829{
830 __str.unsetf(ios_base::showbase);
831 return __str;
832}
833
834inline _LIBCPP_INLINE_VISIBILITY
835ios_base&
836showpoint(ios_base& __str)
837{
838 __str.setf(ios_base::showpoint);
839 return __str;
840}
841
842inline _LIBCPP_INLINE_VISIBILITY
843ios_base&
844noshowpoint(ios_base& __str)
845{
846 __str.unsetf(ios_base::showpoint);
847 return __str;
848}
849
850inline _LIBCPP_INLINE_VISIBILITY
851ios_base&
852showpos(ios_base& __str)
853{
854 __str.setf(ios_base::showpos);
855 return __str;
856}
857
858inline _LIBCPP_INLINE_VISIBILITY
859ios_base&
860noshowpos(ios_base& __str)
861{
862 __str.unsetf(ios_base::showpos);
863 return __str;
864}
865
866inline _LIBCPP_INLINE_VISIBILITY
867ios_base&
868skipws(ios_base& __str)
869{
870 __str.setf(ios_base::skipws);
871 return __str;
872}
873
874inline _LIBCPP_INLINE_VISIBILITY
875ios_base&
876noskipws(ios_base& __str)
877{
878 __str.unsetf(ios_base::skipws);
879 return __str;
880}
881
882inline _LIBCPP_INLINE_VISIBILITY
883ios_base&
884uppercase(ios_base& __str)
885{
886 __str.setf(ios_base::uppercase);
887 return __str;
888}
889
890inline _LIBCPP_INLINE_VISIBILITY
891ios_base&
892nouppercase(ios_base& __str)
893{
894 __str.unsetf(ios_base::uppercase);
895 return __str;
896}
897
898inline _LIBCPP_INLINE_VISIBILITY
899ios_base&
900unitbuf(ios_base& __str)
901{
902 __str.setf(ios_base::unitbuf);
903 return __str;
904}
905
906inline _LIBCPP_INLINE_VISIBILITY
907ios_base&
908nounitbuf(ios_base& __str)
909{
910 __str.unsetf(ios_base::unitbuf);
911 return __str;
912}
913
914inline _LIBCPP_INLINE_VISIBILITY
915ios_base&
916internal(ios_base& __str)
917{
918 __str.setf(ios_base::internal, ios_base::adjustfield);
919 return __str;
920}
921
922inline _LIBCPP_INLINE_VISIBILITY
923ios_base&
924left(ios_base& __str)
925{
926 __str.setf(ios_base::left, ios_base::adjustfield);
927 return __str;
928}
929
930inline _LIBCPP_INLINE_VISIBILITY
931ios_base&
932right(ios_base& __str)
933{
934 __str.setf(ios_base::right, ios_base::adjustfield);
935 return __str;
936}
937
938inline _LIBCPP_INLINE_VISIBILITY
939ios_base&
940dec(ios_base& __str)
941{
942 __str.setf(ios_base::dec, ios_base::basefield);
943 return __str;
944}
945
946inline _LIBCPP_INLINE_VISIBILITY
947ios_base&
948hex(ios_base& __str)
949{
950 __str.setf(ios_base::hex, ios_base::basefield);
951 return __str;
952}
953
954inline _LIBCPP_INLINE_VISIBILITY
955ios_base&
956oct(ios_base& __str)
957{
958 __str.setf(ios_base::oct, ios_base::basefield);
959 return __str;
960}
961
962inline _LIBCPP_INLINE_VISIBILITY
963ios_base&
964fixed(ios_base& __str)
965{
966 __str.setf(ios_base::fixed, ios_base::floatfield);
967 return __str;
968}
969
970inline _LIBCPP_INLINE_VISIBILITY
971ios_base&
972scientific(ios_base& __str)
973{
974 __str.setf(ios_base::scientific, ios_base::floatfield);
975 return __str;
976}
977
978inline _LIBCPP_INLINE_VISIBILITY
979ios_base&
980hexfloat(ios_base& __str)
981{
982 __str.setf(ios_base::fixed | ios_base::scientific, ios_base::floatfield);
983 return __str;
984}
985
986inline _LIBCPP_INLINE_VISIBILITY
987ios_base&
988defaultfloat(ios_base& __str)
989{
990 __str.unsetf(ios_base::floatfield);
991 return __str;
992}
993
Marshall Clow809e93f2013-07-09 20:34:14 +0000994template <class _CharT, class _Traits>
995class __save_flags
996{
997 typedef basic_ios<_CharT, _Traits> __stream_type;
998 typedef typename __stream_type::fmtflags fmtflags;
999
1000 __stream_type& __stream_;
1001 fmtflags __fmtflags_;
1002 _CharT __fill_;
1003
1004 __save_flags(const __save_flags&);
1005 __save_flags& operator=(const __save_flags&);
1006public:
1007 _LIBCPP_INLINE_VISIBILITY
1008 explicit __save_flags(__stream_type& __stream)
1009 : __stream_(__stream),
1010 __fmtflags_(__stream.flags()),
1011 __fill_(__stream.fill())
1012 {}
1013 _LIBCPP_INLINE_VISIBILITY
1014 ~__save_flags()
1015 {
1016 __stream_.flags(__fmtflags_);
1017 __stream_.fill(__fill_);
1018 }
1019};
1020
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001021_LIBCPP_END_NAMESPACE_STD
1022
1023#endif // _LIBCPP_IOS