blob: 040b2d4e04f1e1f9a4fb669f4b28cc1e279b8480 [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;
Marshall Clow8aadda92015-10-29 05:43:30 +0000117 typedef typename traits::int_type int_type; // removed in C++17
118 typedef typename traits::pos_type pos_type; // removed in C++17
119 typedef typename traits::off_type off_type; // removed in C++17
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
Eric Fiselier00f4a492015-08-19 17:21:46 +0000219#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
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:
Eric Fiseliera6013cc2016-04-21 23:00:33 +0000234 class _LIBCPP_EXCEPTION_ABI 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;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000257 static const iostate badbit = 0x1;
258 static const iostate eofbit = 0x2;
259 static const iostate failbit = 0x4;
260 static const iostate goodbit = 0x0;
261
262 typedef unsigned int openmode;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000263 static const openmode app = 0x01;
264 static const openmode ate = 0x02;
265 static const openmode binary = 0x04;
266 static const openmode in = 0x08;
267 static const openmode out = 0x10;
268 static const openmode trunc = 0x20;
269
270 enum seekdir {beg, cur, end};
Marshall Clow8aadda92015-10-29 05:43:30 +0000271
272#if _LIBCPP_STD_VER <= 14
273 typedef iostate io_state;
274 typedef openmode open_mode;
275 typedef seekdir seek_dir;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000276
Howard Hinnant0949eed2011-06-30 21:18:19 +0000277 typedef _VSTD::streamoff streamoff;
278 typedef _VSTD::streampos streampos;
Marshall Clow8aadda92015-10-29 05:43:30 +0000279#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000280
Howard Hinnant83eade62013-03-06 23:30:19 +0000281 class _LIBCPP_TYPE_VIS Init;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000282
283 // 27.5.2.2 fmtflags state:
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000284 _LIBCPP_INLINE_VISIBILITY fmtflags flags() const;
285 _LIBCPP_INLINE_VISIBILITY fmtflags flags(fmtflags __fmtfl);
286 _LIBCPP_INLINE_VISIBILITY fmtflags setf(fmtflags __fmtfl);
287 _LIBCPP_INLINE_VISIBILITY fmtflags setf(fmtflags __fmtfl, fmtflags __mask);
288 _LIBCPP_INLINE_VISIBILITY void unsetf(fmtflags __mask);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000289
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000290 _LIBCPP_INLINE_VISIBILITY streamsize precision() const;
291 _LIBCPP_INLINE_VISIBILITY streamsize precision(streamsize __prec);
292 _LIBCPP_INLINE_VISIBILITY streamsize width() const;
293 _LIBCPP_INLINE_VISIBILITY streamsize width(streamsize __wide);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000294
295 // 27.5.2.3 locales:
296 locale imbue(const locale& __loc);
297 locale getloc() const;
298
299 // 27.5.2.5 storage:
300 static int xalloc();
301 long& iword(int __index);
302 void*& pword(int __index);
303
304 // destructor
305 virtual ~ios_base();
306
307 // 27.5.2.6 callbacks;
308 enum event { erase_event, imbue_event, copyfmt_event };
309 typedef void (*event_callback)(event, ios_base&, int __index);
310 void register_callback(event_callback __fn, int __index);
311
312private:
313 ios_base(const ios_base&); // = delete;
314 ios_base& operator=(const ios_base&); // = delete;
315
316public:
317 static bool sync_with_stdio(bool __sync = true);
318
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000319 _LIBCPP_INLINE_VISIBILITY iostate rdstate() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000320 void clear(iostate __state = goodbit);
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000321 _LIBCPP_INLINE_VISIBILITY void setstate(iostate __state);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000322
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000323 _LIBCPP_INLINE_VISIBILITY bool good() const;
324 _LIBCPP_INLINE_VISIBILITY bool eof() const;
325 _LIBCPP_INLINE_VISIBILITY bool fail() const;
326 _LIBCPP_INLINE_VISIBILITY bool bad() const;
Howard Hinnant324bb032010-08-22 00:02:43 +0000327
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000328 _LIBCPP_INLINE_VISIBILITY iostate exceptions() const;
Howard Hinnante0640552013-10-06 21:00:29 +0000329 _LIBCPP_INLINE_VISIBILITY void exceptions(iostate __iostate);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000330
331 void __set_badbit_and_consider_rethrow();
332 void __set_failbit_and_consider_rethrow();
333
334protected:
Howard Hinnant68a8e902010-09-22 15:29:08 +0000335 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000336 ios_base() {// purposefully does no initialization
337 }
338
339 void init(void* __sb);
Louis Dionne54238052018-07-11 23:14:33 +0000340 _LIBCPP_INLINE_VISIBILITY void* rdbuf() const {return __rdbuf_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000341
Louis Dionne54238052018-07-11 23:14:33 +0000342 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000343 void rdbuf(void* __sb)
344 {
345 __rdbuf_ = __sb;
346 clear();
347 }
348
349 void __call_callbacks(event);
350 void copyfmt(const ios_base&);
351 void move(ios_base&);
Howard Hinnantf57bd562012-07-21 01:03:40 +0000352 void swap(ios_base&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000353
Louis Dionne54238052018-07-11 23:14:33 +0000354 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000355 void set_rdbuf(void* __sb)
356 {
357 __rdbuf_ = __sb;
358 }
359
360private:
361 // All data members must be scalars
362 fmtflags __fmtflags_;
363 streamsize __precision_;
364 streamsize __width_;
365 iostate __rdstate_;
366 iostate __exceptions_;
367 void* __rdbuf_;
368 void* __loc_;
369 event_callback* __fn_;
370 int* __index_;
371 size_t __event_size_;
372 size_t __event_cap_;
Eric Fiselier00f4a492015-08-19 17:21:46 +0000373// TODO(EricWF): Enable this for both Clang and GCC. Currently it is only
374// enabled with clang.
375#if defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS)
Marshall Clow206ce1f2013-10-12 19:13:52 +0000376 static atomic<int> __xindex_;
377#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000378 static int __xindex_;
Marshall Clow206ce1f2013-10-12 19:13:52 +0000379#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000380 long* __iarray_;
381 size_t __iarray_size_;
382 size_t __iarray_cap_;
383 void** __parray_;
384 size_t __parray_size_;
385 size_t __parray_cap_;
386};
387
388//enum class io_errc
Howard Hinnantf6d875f2011-12-02 19:36:40 +0000389_LIBCPP_DECLARE_STRONG_ENUM(io_errc)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000390{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000391 stream = 1
392};
Howard Hinnantf6d875f2011-12-02 19:36:40 +0000393_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(io_errc)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000394
Howard Hinnant68a8e902010-09-22 15:29:08 +0000395template <>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000396struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc> : public true_type { };
Howard Hinnantf6d875f2011-12-02 19:36:40 +0000397
398#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
Howard Hinnant68a8e902010-09-22 15:29:08 +0000399template <>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000400struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc::__lx> : public true_type { };
Howard Hinnantf6d875f2011-12-02 19:36:40 +0000401#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000402
Howard Hinnant83eade62013-03-06 23:30:19 +0000403_LIBCPP_FUNC_VIS
Marshall Clow61a84222013-10-12 22:49:56 +0000404const error_category& iostream_category() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000405
406inline _LIBCPP_INLINE_VISIBILITY
407error_code
Marshall Clow61a84222013-10-12 22:49:56 +0000408make_error_code(io_errc __e) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000409{
410 return error_code(static_cast<int>(__e), iostream_category());
411}
412
413inline _LIBCPP_INLINE_VISIBILITY
414error_condition
Marshall Clow61a84222013-10-12 22:49:56 +0000415make_error_condition(io_errc __e) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000416{
417 return error_condition(static_cast<int>(__e), iostream_category());
418}
419
Howard Hinnant68a8e902010-09-22 15:29:08 +0000420class _LIBCPP_EXCEPTION_ABI ios_base::failure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000421 : public system_error
Howard Hinnant324bb032010-08-22 00:02:43 +0000422{
423public:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000424 explicit failure(const string& __msg, const error_code& __ec = io_errc::stream);
Howard Hinnant324bb032010-08-22 00:02:43 +0000425 explicit failure(const char* __msg, const error_code& __ec = io_errc::stream);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000426 virtual ~failure() throw();
427};
428
Howard Hinnant83eade62013-03-06 23:30:19 +0000429class _LIBCPP_TYPE_VIS ios_base::Init
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000430{
431public:
432 Init();
433 ~Init();
434};
435
436// fmtflags
437
438inline _LIBCPP_INLINE_VISIBILITY
439ios_base::fmtflags
440ios_base::flags() const
441{
442 return __fmtflags_;
443}
444
445inline _LIBCPP_INLINE_VISIBILITY
446ios_base::fmtflags
447ios_base::flags(fmtflags __fmtfl)
448{
449 fmtflags __r = __fmtflags_;
450 __fmtflags_ = __fmtfl;
451 return __r;
452}
453
454inline _LIBCPP_INLINE_VISIBILITY
455ios_base::fmtflags
456ios_base::setf(fmtflags __fmtfl)
457{
458 fmtflags __r = __fmtflags_;
459 __fmtflags_ |= __fmtfl;
460 return __r;
461}
462
463inline _LIBCPP_INLINE_VISIBILITY
464void
465ios_base::unsetf(fmtflags __mask)
466{
467 __fmtflags_ &= ~__mask;
468}
469
470inline _LIBCPP_INLINE_VISIBILITY
471ios_base::fmtflags
472ios_base::setf(fmtflags __fmtfl, fmtflags __mask)
473{
474 fmtflags __r = __fmtflags_;
475 unsetf(__mask);
476 __fmtflags_ |= __fmtfl & __mask;
477 return __r;
478}
479
480// precision
481
482inline _LIBCPP_INLINE_VISIBILITY
483streamsize
484ios_base::precision() const
485{
486 return __precision_;
487}
488
489inline _LIBCPP_INLINE_VISIBILITY
490streamsize
491ios_base::precision(streamsize __prec)
492{
493 streamsize __r = __precision_;
494 __precision_ = __prec;
495 return __r;
496}
497
498// width
499
500inline _LIBCPP_INLINE_VISIBILITY
501streamsize
502ios_base::width() const
503{
504 return __width_;
505}
506
507inline _LIBCPP_INLINE_VISIBILITY
508streamsize
509ios_base::width(streamsize __wide)
510{
511 streamsize __r = __width_;
512 __width_ = __wide;
513 return __r;
514}
515
516// iostate
517
518inline _LIBCPP_INLINE_VISIBILITY
519ios_base::iostate
520ios_base::rdstate() const
521{
522 return __rdstate_;
523}
524
525inline _LIBCPP_INLINE_VISIBILITY
526void
527ios_base::setstate(iostate __state)
528{
529 clear(__rdstate_ | __state);
530}
531
532inline _LIBCPP_INLINE_VISIBILITY
533bool
534ios_base::good() const
535{
536 return __rdstate_ == 0;
537}
538
539inline _LIBCPP_INLINE_VISIBILITY
540bool
541ios_base::eof() const
542{
Marshall Clow8a43fca2013-10-21 14:41:05 +0000543 return (__rdstate_ & eofbit) != 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000544}
545
546inline _LIBCPP_INLINE_VISIBILITY
547bool
548ios_base::fail() const
549{
Marshall Clow8a43fca2013-10-21 14:41:05 +0000550 return (__rdstate_ & (failbit | badbit)) != 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000551}
552
553inline _LIBCPP_INLINE_VISIBILITY
554bool
555ios_base::bad() const
556{
Marshall Clow8a43fca2013-10-21 14:41:05 +0000557 return (__rdstate_ & badbit) != 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000558}
559
560inline _LIBCPP_INLINE_VISIBILITY
561ios_base::iostate
562ios_base::exceptions() const
563{
564 return __exceptions_;
565}
566
567inline _LIBCPP_INLINE_VISIBILITY
568void
Howard Hinnante0640552013-10-06 21:00:29 +0000569ios_base::exceptions(iostate __iostate)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000570{
Howard Hinnante0640552013-10-06 21:00:29 +0000571 __exceptions_ = __iostate;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000572 clear(__rdstate_);
573}
574
Eric Fiselier1a147b72017-01-13 18:03:46 +0000575#if defined(_LIBCPP_CXX03_LANG)
Eric Fiselier1669d3d2017-01-13 18:25:13 +0000576struct _LIBCPP_TYPE_VIS __cxx03_bool {
Eric Fiselier1a147b72017-01-13 18:03:46 +0000577 typedef void (__cxx03_bool::*__bool_type)();
578 void __true_value() {}
579};
580#endif
581
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000582template <class _CharT, class _Traits>
Eric Fiselierc3589a82017-01-04 23:56:00 +0000583class _LIBCPP_TEMPLATE_VIS basic_ios
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000584 : public ios_base
585{
586public:
587 // types:
588 typedef _CharT char_type;
589 typedef _Traits traits_type;
590
591 typedef typename traits_type::int_type int_type;
592 typedef typename traits_type::pos_type pos_type;
593 typedef typename traits_type::off_type off_type;
594
Marshall Clow75075c62018-02-01 03:55:27 +0000595 static_assert((is_same<_CharT, typename traits_type::char_type>::value),
596 "traits_type::char_type must be the same type as CharT");
597
Eric Fiselier1a147b72017-01-13 18:03:46 +0000598 // __true_value will generate undefined references when linking unless
599 // we give it internal linkage.
600
601#if defined(_LIBCPP_CXX03_LANG)
Louis Dionne54238052018-07-11 23:14:33 +0000602 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier1a147b72017-01-13 18:03:46 +0000603 operator __cxx03_bool::__bool_type() const {
604 return !fail() ? &__cxx03_bool::__true_value : nullptr;
605 }
606#else
Louis Dionne54238052018-07-11 23:14:33 +0000607 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierbc06f262016-12-30 14:05:52 +0000608 _LIBCPP_EXPLICIT operator bool() const {return !fail();}
Eric Fiselier1a147b72017-01-13 18:03:46 +0000609#endif
Eric Fiselierbc06f262016-12-30 14:05:52 +0000610
Louis Dionne54238052018-07-11 23:14:33 +0000611 _LIBCPP_INLINE_VISIBILITY bool operator!() const {return fail();}
612 _LIBCPP_INLINE_VISIBILITY iostate rdstate() const {return ios_base::rdstate();}
613 _LIBCPP_INLINE_VISIBILITY void clear(iostate __state = goodbit) {ios_base::clear(__state);}
614 _LIBCPP_INLINE_VISIBILITY void setstate(iostate __state) {ios_base::setstate(__state);}
615 _LIBCPP_INLINE_VISIBILITY bool good() const {return ios_base::good();}
616 _LIBCPP_INLINE_VISIBILITY bool eof() const {return ios_base::eof();}
617 _LIBCPP_INLINE_VISIBILITY bool fail() const {return ios_base::fail();}
618 _LIBCPP_INLINE_VISIBILITY bool bad() const {return ios_base::bad();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000619
Louis Dionne54238052018-07-11 23:14:33 +0000620 _LIBCPP_INLINE_VISIBILITY iostate exceptions() const {return ios_base::exceptions();}
621 _LIBCPP_INLINE_VISIBILITY void exceptions(iostate __iostate) {ios_base::exceptions(__iostate);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000622
623 // 27.5.4.1 Constructor/destructor:
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000624 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000625 explicit basic_ios(basic_streambuf<char_type,traits_type>* __sb);
626 virtual ~basic_ios();
627
628 // 27.5.4.2 Members:
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000629 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000630 basic_ostream<char_type, traits_type>* tie() const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000631 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000632 basic_ostream<char_type, traits_type>* tie(basic_ostream<char_type, traits_type>* __tiestr);
633
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000634 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000635 basic_streambuf<char_type, traits_type>* rdbuf() const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000636 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000637 basic_streambuf<char_type, traits_type>* rdbuf(basic_streambuf<char_type, traits_type>* __sb);
638
639 basic_ios& copyfmt(const basic_ios& __rhs);
640
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000641 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000642 char_type fill() const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000643 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000644 char_type fill(char_type __ch);
645
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000646 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000647 locale imbue(const locale& __loc);
648
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000649 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000650 char narrow(char_type __c, char __dfault) const;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000651 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000652 char_type widen(char __c) const;
653
654protected:
Louis Dionne54238052018-07-11 23:14:33 +0000655 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000656 basic_ios() {// purposefully does no initialization
657 }
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000658 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000659 void init(basic_streambuf<char_type, traits_type>* __sb);
660
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000661 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000662 void move(basic_ios& __rhs);
Eric Fiselieraa55cef2017-04-19 01:34:08 +0000663#ifndef _LIBCPP_CXX03_LANG
Louis Dionne54238052018-07-11 23:14:33 +0000664 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000665 void move(basic_ios&& __rhs) {move(__rhs);}
666#endif
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000667 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf57bd562012-07-21 01:03:40 +0000668 void swap(basic_ios& __rhs) _NOEXCEPT;
Howard Hinnant2d72b1e2010-12-17 14:46:43 +0000669 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000670 void set_rdbuf(basic_streambuf<char_type, traits_type>* __sb);
671private:
672 basic_ostream<char_type, traits_type>* __tie_;
Bruce Mitchener26a02742018-02-14 00:29:38 +0000673 mutable int_type __fill_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000674};
675
676template <class _CharT, class _Traits>
677inline _LIBCPP_INLINE_VISIBILITY
678basic_ios<_CharT, _Traits>::basic_ios(basic_streambuf<char_type,traits_type>* __sb)
679{
680 init(__sb);
681}
682
683template <class _CharT, class _Traits>
684basic_ios<_CharT, _Traits>::~basic_ios()
685{
686}
687
688template <class _CharT, class _Traits>
689inline _LIBCPP_INLINE_VISIBILITY
690void
691basic_ios<_CharT, _Traits>::init(basic_streambuf<char_type, traits_type>* __sb)
692{
693 ios_base::init(__sb);
694 __tie_ = 0;
Howard Hinnantc417a802012-08-26 18:05:35 +0000695 __fill_ = traits_type::eof();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000696}
697
698template <class _CharT, class _Traits>
699inline _LIBCPP_INLINE_VISIBILITY
700basic_ostream<_CharT, _Traits>*
701basic_ios<_CharT, _Traits>::tie() const
702{
703 return __tie_;
704}
705
706template <class _CharT, class _Traits>
707inline _LIBCPP_INLINE_VISIBILITY
708basic_ostream<_CharT, _Traits>*
709basic_ios<_CharT, _Traits>::tie(basic_ostream<char_type, traits_type>* __tiestr)
710{
711 basic_ostream<char_type, traits_type>* __r = __tie_;
712 __tie_ = __tiestr;
713 return __r;
714}
715
716template <class _CharT, class _Traits>
717inline _LIBCPP_INLINE_VISIBILITY
718basic_streambuf<_CharT, _Traits>*
719basic_ios<_CharT, _Traits>::rdbuf() const
720{
721 return static_cast<basic_streambuf<char_type, traits_type>*>(ios_base::rdbuf());
722}
723
724template <class _CharT, class _Traits>
725inline _LIBCPP_INLINE_VISIBILITY
726basic_streambuf<_CharT, _Traits>*
727basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<char_type, traits_type>* __sb)
728{
729 basic_streambuf<char_type, traits_type>* __r = rdbuf();
730 ios_base::rdbuf(__sb);
731 return __r;
732}
733
734template <class _CharT, class _Traits>
735inline _LIBCPP_INLINE_VISIBILITY
736locale
737basic_ios<_CharT, _Traits>::imbue(const locale& __loc)
738{
739 locale __r = getloc();
740 ios_base::imbue(__loc);
741 if (rdbuf())
742 rdbuf()->pubimbue(__loc);
743 return __r;
744}
745
746template <class _CharT, class _Traits>
747inline _LIBCPP_INLINE_VISIBILITY
748char
749basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const
750{
751 return use_facet<ctype<char_type> >(getloc()).narrow(__c, __dfault);
752}
753
754template <class _CharT, class _Traits>
755inline _LIBCPP_INLINE_VISIBILITY
756_CharT
757basic_ios<_CharT, _Traits>::widen(char __c) const
758{
759 return use_facet<ctype<char_type> >(getloc()).widen(__c);
760}
761
762template <class _CharT, class _Traits>
763inline _LIBCPP_INLINE_VISIBILITY
764_CharT
765basic_ios<_CharT, _Traits>::fill() const
766{
Howard Hinnantc417a802012-08-26 18:05:35 +0000767 if (traits_type::eq_int_type(traits_type::eof(), __fill_))
768 __fill_ = widen(' ');
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000769 return __fill_;
770}
771
772template <class _CharT, class _Traits>
773inline _LIBCPP_INLINE_VISIBILITY
774_CharT
775basic_ios<_CharT, _Traits>::fill(char_type __ch)
776{
777 char_type __r = __fill_;
778 __fill_ = __ch;
779 return __r;
780}
781
782template <class _CharT, class _Traits>
783basic_ios<_CharT, _Traits>&
784basic_ios<_CharT, _Traits>::copyfmt(const basic_ios& __rhs)
785{
786 if (this != &__rhs)
787 {
788 __call_callbacks(erase_event);
789 ios_base::copyfmt(__rhs);
790 __tie_ = __rhs.__tie_;
791 __fill_ = __rhs.__fill_;
792 __call_callbacks(copyfmt_event);
793 exceptions(__rhs.exceptions());
794 }
795 return *this;
796}
797
798template <class _CharT, class _Traits>
799inline _LIBCPP_INLINE_VISIBILITY
800void
801basic_ios<_CharT, _Traits>::move(basic_ios& __rhs)
802{
803 ios_base::move(__rhs);
804 __tie_ = __rhs.__tie_;
805 __rhs.__tie_ = 0;
806 __fill_ = __rhs.__fill_;
807}
808
809template <class _CharT, class _Traits>
810inline _LIBCPP_INLINE_VISIBILITY
811void
Howard Hinnantf57bd562012-07-21 01:03:40 +0000812basic_ios<_CharT, _Traits>::swap(basic_ios& __rhs) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000813{
814 ios_base::swap(__rhs);
Howard Hinnant0949eed2011-06-30 21:18:19 +0000815 _VSTD::swap(__tie_, __rhs.__tie_);
816 _VSTD::swap(__fill_, __rhs.__fill_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000817}
818
819template <class _CharT, class _Traits>
820inline _LIBCPP_INLINE_VISIBILITY
821void
822basic_ios<_CharT, _Traits>::set_rdbuf(basic_streambuf<char_type, traits_type>* __sb)
823{
824 ios_base::set_rdbuf(__sb);
825}
826
827inline _LIBCPP_INLINE_VISIBILITY
828ios_base&
829boolalpha(ios_base& __str)
830{
831 __str.setf(ios_base::boolalpha);
832 return __str;
833}
834
835inline _LIBCPP_INLINE_VISIBILITY
836ios_base&
837noboolalpha(ios_base& __str)
838{
839 __str.unsetf(ios_base::boolalpha);
840 return __str;
841}
842
843inline _LIBCPP_INLINE_VISIBILITY
844ios_base&
845showbase(ios_base& __str)
846{
847 __str.setf(ios_base::showbase);
848 return __str;
849}
850
851inline _LIBCPP_INLINE_VISIBILITY
852ios_base&
853noshowbase(ios_base& __str)
854{
855 __str.unsetf(ios_base::showbase);
856 return __str;
857}
858
859inline _LIBCPP_INLINE_VISIBILITY
860ios_base&
861showpoint(ios_base& __str)
862{
863 __str.setf(ios_base::showpoint);
864 return __str;
865}
866
867inline _LIBCPP_INLINE_VISIBILITY
868ios_base&
869noshowpoint(ios_base& __str)
870{
871 __str.unsetf(ios_base::showpoint);
872 return __str;
873}
874
875inline _LIBCPP_INLINE_VISIBILITY
876ios_base&
877showpos(ios_base& __str)
878{
879 __str.setf(ios_base::showpos);
880 return __str;
881}
882
883inline _LIBCPP_INLINE_VISIBILITY
884ios_base&
885noshowpos(ios_base& __str)
886{
887 __str.unsetf(ios_base::showpos);
888 return __str;
889}
890
891inline _LIBCPP_INLINE_VISIBILITY
892ios_base&
893skipws(ios_base& __str)
894{
895 __str.setf(ios_base::skipws);
896 return __str;
897}
898
899inline _LIBCPP_INLINE_VISIBILITY
900ios_base&
901noskipws(ios_base& __str)
902{
903 __str.unsetf(ios_base::skipws);
904 return __str;
905}
906
907inline _LIBCPP_INLINE_VISIBILITY
908ios_base&
909uppercase(ios_base& __str)
910{
911 __str.setf(ios_base::uppercase);
912 return __str;
913}
914
915inline _LIBCPP_INLINE_VISIBILITY
916ios_base&
917nouppercase(ios_base& __str)
918{
919 __str.unsetf(ios_base::uppercase);
920 return __str;
921}
922
923inline _LIBCPP_INLINE_VISIBILITY
924ios_base&
925unitbuf(ios_base& __str)
926{
927 __str.setf(ios_base::unitbuf);
928 return __str;
929}
930
931inline _LIBCPP_INLINE_VISIBILITY
932ios_base&
933nounitbuf(ios_base& __str)
934{
935 __str.unsetf(ios_base::unitbuf);
936 return __str;
937}
938
939inline _LIBCPP_INLINE_VISIBILITY
940ios_base&
941internal(ios_base& __str)
942{
943 __str.setf(ios_base::internal, ios_base::adjustfield);
944 return __str;
945}
946
947inline _LIBCPP_INLINE_VISIBILITY
948ios_base&
949left(ios_base& __str)
950{
951 __str.setf(ios_base::left, ios_base::adjustfield);
952 return __str;
953}
954
955inline _LIBCPP_INLINE_VISIBILITY
956ios_base&
957right(ios_base& __str)
958{
959 __str.setf(ios_base::right, ios_base::adjustfield);
960 return __str;
961}
962
963inline _LIBCPP_INLINE_VISIBILITY
964ios_base&
965dec(ios_base& __str)
966{
967 __str.setf(ios_base::dec, ios_base::basefield);
968 return __str;
969}
970
971inline _LIBCPP_INLINE_VISIBILITY
972ios_base&
973hex(ios_base& __str)
974{
975 __str.setf(ios_base::hex, ios_base::basefield);
976 return __str;
977}
978
979inline _LIBCPP_INLINE_VISIBILITY
980ios_base&
981oct(ios_base& __str)
982{
983 __str.setf(ios_base::oct, ios_base::basefield);
984 return __str;
985}
986
987inline _LIBCPP_INLINE_VISIBILITY
988ios_base&
989fixed(ios_base& __str)
990{
991 __str.setf(ios_base::fixed, ios_base::floatfield);
992 return __str;
993}
994
995inline _LIBCPP_INLINE_VISIBILITY
996ios_base&
997scientific(ios_base& __str)
998{
999 __str.setf(ios_base::scientific, ios_base::floatfield);
1000 return __str;
1001}
1002
1003inline _LIBCPP_INLINE_VISIBILITY
1004ios_base&
1005hexfloat(ios_base& __str)
1006{
1007 __str.setf(ios_base::fixed | ios_base::scientific, ios_base::floatfield);
1008 return __str;
1009}
1010
1011inline _LIBCPP_INLINE_VISIBILITY
1012ios_base&
1013defaultfloat(ios_base& __str)
1014{
1015 __str.unsetf(ios_base::floatfield);
1016 return __str;
1017}
1018
Marshall Clow809e93f2013-07-09 20:34:14 +00001019template <class _CharT, class _Traits>
1020class __save_flags
1021{
1022 typedef basic_ios<_CharT, _Traits> __stream_type;
1023 typedef typename __stream_type::fmtflags fmtflags;
1024
1025 __stream_type& __stream_;
1026 fmtflags __fmtflags_;
1027 _CharT __fill_;
1028
1029 __save_flags(const __save_flags&);
1030 __save_flags& operator=(const __save_flags&);
1031public:
1032 _LIBCPP_INLINE_VISIBILITY
1033 explicit __save_flags(__stream_type& __stream)
1034 : __stream_(__stream),
1035 __fmtflags_(__stream.flags()),
1036 __fill_(__stream.fill())
1037 {}
1038 _LIBCPP_INLINE_VISIBILITY
1039 ~__save_flags()
1040 {
1041 __stream_.flags(__fmtflags_);
1042 __stream_.fill(__fill_);
1043 }
1044};
1045
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001046_LIBCPP_END_NAMESPACE_STD
1047
1048#endif // _LIBCPP_IOS