1 | // -*- C++ -*- |
2 | //===---------------------------- ios -------------------------------------===// |
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 | |
10 | #ifndef _LIBCPP_IOS |
11 | #define _LIBCPP_IOS |
12 | |
13 | /* |
14 | ios synopsis |
15 | |
16 | #include <iosfwd> |
17 | |
18 | namespace std |
19 | { |
20 | |
21 | typedef OFF_T streamoff; |
22 | typedef SZ_T streamsize; |
23 | template <class stateT> class fpos; |
24 | |
25 | class ios_base |
26 | { |
27 | public: |
28 | class failure; |
29 | |
30 | typedef T1 fmtflags; |
31 | static constexpr fmtflags boolalpha; |
32 | static constexpr fmtflags dec; |
33 | static constexpr fmtflags fixed; |
34 | static constexpr fmtflags hex; |
35 | static constexpr fmtflags internal; |
36 | static constexpr fmtflags left; |
37 | static constexpr fmtflags oct; |
38 | static constexpr fmtflags right; |
39 | static constexpr fmtflags scientific; |
40 | static constexpr fmtflags showbase; |
41 | static constexpr fmtflags showpoint; |
42 | static constexpr fmtflags showpos; |
43 | static constexpr fmtflags skipws; |
44 | static constexpr fmtflags unitbuf; |
45 | static constexpr fmtflags uppercase; |
46 | static constexpr fmtflags adjustfield; |
47 | static constexpr fmtflags basefield; |
48 | static constexpr fmtflags floatfield; |
49 | |
50 | typedef T2 iostate; |
51 | static constexpr iostate badbit; |
52 | static constexpr iostate eofbit; |
53 | static constexpr iostate failbit; |
54 | static constexpr iostate goodbit; |
55 | |
56 | typedef T3 openmode; |
57 | static constexpr openmode app; |
58 | static constexpr openmode ate; |
59 | static constexpr openmode binary; |
60 | static constexpr openmode in; |
61 | static constexpr openmode out; |
62 | static constexpr openmode trunc; |
63 | |
64 | typedef T4 seekdir; |
65 | static constexpr seekdir beg; |
66 | static constexpr seekdir cur; |
67 | static constexpr seekdir end; |
68 | |
69 | class Init; |
70 | |
71 | // 27.5.2.2 fmtflags state: |
72 | fmtflags flags() const; |
73 | fmtflags flags(fmtflags fmtfl); |
74 | fmtflags setf(fmtflags fmtfl); |
75 | fmtflags setf(fmtflags fmtfl, fmtflags mask); |
76 | void unsetf(fmtflags mask); |
77 | |
78 | streamsize precision() const; |
79 | streamsize precision(streamsize prec); |
80 | streamsize width() const; |
81 | streamsize width(streamsize wide); |
82 | |
83 | // 27.5.2.3 locales: |
84 | locale imbue(const locale& loc); |
85 | locale getloc() const; |
86 | |
87 | // 27.5.2.5 storage: |
88 | static int xalloc(); |
89 | long& iword(int index); |
90 | void*& pword(int index); |
91 | |
92 | // destructor |
93 | virtual ~ios_base(); |
94 | |
95 | // 27.5.2.6 callbacks; |
96 | enum event { erase_event, imbue_event, copyfmt_event }; |
97 | typedef void (*event_callback)(event, ios_base&, int index); |
98 | void register_callback(event_callback fn, int index); |
99 | |
100 | ios_base(const ios_base&) = delete; |
101 | ios_base& operator=(const ios_base&) = delete; |
102 | |
103 | static bool sync_with_stdio(bool sync = true); |
104 | |
105 | protected: |
106 | ios_base(); |
107 | }; |
108 | |
109 | template <class charT, class traits = char_traits<charT> > |
110 | class basic_ios |
111 | : public ios_base |
112 | { |
113 | public: |
114 | // types: |
115 | typedef charT char_type; |
116 | typedef typename traits::int_type int_type; // removed in C++17 |
117 | typedef typename traits::pos_type pos_type; // removed in C++17 |
118 | typedef typename traits::off_type off_type; // removed in C++17 |
119 | typedef traits traits_type; |
120 | |
121 | operator unspecified-bool-type() const; |
122 | bool operator!() const; |
123 | iostate rdstate() const; |
124 | void clear(iostate state = goodbit); |
125 | void setstate(iostate state); |
126 | bool good() const; |
127 | bool eof() const; |
128 | bool fail() const; |
129 | bool bad() const; |
130 | |
131 | iostate exceptions() const; |
132 | void exceptions(iostate except); |
133 | |
134 | // 27.5.4.1 Constructor/destructor: |
135 | explicit basic_ios(basic_streambuf<charT,traits>* sb); |
136 | virtual ~basic_ios(); |
137 | |
138 | // 27.5.4.2 Members: |
139 | basic_ostream<charT,traits>* tie() const; |
140 | basic_ostream<charT,traits>* tie(basic_ostream<charT,traits>* tiestr); |
141 | |
142 | basic_streambuf<charT,traits>* rdbuf() const; |
143 | basic_streambuf<charT,traits>* rdbuf(basic_streambuf<charT,traits>* sb); |
144 | |
145 | basic_ios& copyfmt(const basic_ios& rhs); |
146 | |
147 | char_type fill() const; |
148 | char_type fill(char_type ch); |
149 | |
150 | locale imbue(const locale& loc); |
151 | |
152 | char narrow(char_type c, char dfault) const; |
153 | char_type widen(char c) const; |
154 | |
155 | basic_ios(const basic_ios& ) = delete; |
156 | basic_ios& operator=(const basic_ios&) = delete; |
157 | |
158 | protected: |
159 | basic_ios(); |
160 | void init(basic_streambuf<charT,traits>* sb); |
161 | void move(basic_ios& rhs); |
162 | void swap(basic_ios& rhs) noexcept; |
163 | void set_rdbuf(basic_streambuf<charT, traits>* sb); |
164 | }; |
165 | |
166 | // 27.5.5, manipulators: |
167 | ios_base& boolalpha (ios_base& str); |
168 | ios_base& noboolalpha(ios_base& str); |
169 | ios_base& showbase (ios_base& str); |
170 | ios_base& noshowbase (ios_base& str); |
171 | ios_base& showpoint (ios_base& str); |
172 | ios_base& noshowpoint(ios_base& str); |
173 | ios_base& showpos (ios_base& str); |
174 | ios_base& noshowpos (ios_base& str); |
175 | ios_base& skipws (ios_base& str); |
176 | ios_base& noskipws (ios_base& str); |
177 | ios_base& uppercase (ios_base& str); |
178 | ios_base& nouppercase(ios_base& str); |
179 | ios_base& unitbuf (ios_base& str); |
180 | ios_base& nounitbuf (ios_base& str); |
181 | |
182 | // 27.5.5.2 adjustfield: |
183 | ios_base& internal (ios_base& str); |
184 | ios_base& left (ios_base& str); |
185 | ios_base& right (ios_base& str); |
186 | |
187 | // 27.5.5.3 basefield: |
188 | ios_base& dec (ios_base& str); |
189 | ios_base& hex (ios_base& str); |
190 | ios_base& oct (ios_base& str); |
191 | |
192 | // 27.5.5.4 floatfield: |
193 | ios_base& fixed (ios_base& str); |
194 | ios_base& scientific (ios_base& str); |
195 | ios_base& hexfloat (ios_base& str); |
196 | ios_base& defaultfloat(ios_base& str); |
197 | |
198 | // 27.5.5.5 error reporting: |
199 | enum class io_errc |
200 | { |
201 | stream = 1 |
202 | }; |
203 | |
204 | concept_map ErrorCodeEnum<io_errc> { }; |
205 | error_code make_error_code(io_errc e) noexcept; |
206 | error_condition make_error_condition(io_errc e) noexcept; |
207 | storage-class-specifier const error_category& iostream_category() noexcept; |
208 | |
209 | } // std |
210 | |
211 | */ |
212 | |
213 | #include <__config> |
214 | #include <iosfwd> |
215 | #include <__locale> |
216 | #include <system_error> |
217 | |
218 | #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) |
219 | #include <atomic> // for __xindex_ |
220 | #endif |
221 | |
222 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
223 | #pragma GCC system_header |
224 | #endif |
225 | |
226 | _LIBCPP_BEGIN_NAMESPACE_STD |
227 | |
228 | typedef ptrdiff_t streamsize; |
229 | |
230 | class _LIBCPP_TYPE_VIS ios_base |
231 | { |
232 | public: |
233 | class _LIBCPP_EXCEPTION_ABI failure; |
234 | |
235 | typedef unsigned int fmtflags; |
236 | static const fmtflags boolalpha = 0x0001; |
237 | static const fmtflags dec = 0x0002; |
238 | static const fmtflags fixed = 0x0004; |
239 | static const fmtflags hex = 0x0008; |
240 | static const fmtflags internal = 0x0010; |
241 | static const fmtflags left = 0x0020; |
242 | static const fmtflags oct = 0x0040; |
243 | static const fmtflags right = 0x0080; |
244 | static const fmtflags scientific = 0x0100; |
245 | static const fmtflags showbase = 0x0200; |
246 | static const fmtflags showpoint = 0x0400; |
247 | static const fmtflags showpos = 0x0800; |
248 | static const fmtflags skipws = 0x1000; |
249 | static const fmtflags unitbuf = 0x2000; |
250 | static const fmtflags uppercase = 0x4000; |
251 | static const fmtflags adjustfield = left | right | internal; |
252 | static const fmtflags basefield = dec | oct | hex; |
253 | static const fmtflags floatfield = scientific | fixed; |
254 | |
255 | typedef unsigned int iostate; |
256 | static const iostate badbit = 0x1; |
257 | static const iostate eofbit = 0x2; |
258 | static const iostate failbit = 0x4; |
259 | static const iostate goodbit = 0x0; |
260 | |
261 | typedef unsigned int openmode; |
262 | static const openmode app = 0x01; |
263 | static const openmode ate = 0x02; |
264 | static const openmode binary = 0x04; |
265 | static const openmode in = 0x08; |
266 | static const openmode out = 0x10; |
267 | static const openmode trunc = 0x20; |
268 | |
269 | enum seekdir {beg, cur, end}; |
270 | |
271 | #if _LIBCPP_STD_VER <= 14 |
272 | typedef iostate io_state; |
273 | typedef openmode open_mode; |
274 | typedef seekdir seek_dir; |
275 | |
276 | typedef _VSTD::streamoff streamoff; |
277 | typedef _VSTD::streampos streampos; |
278 | #endif |
279 | |
280 | class _LIBCPP_TYPE_VIS Init; |
281 | |
282 | // 27.5.2.2 fmtflags state: |
283 | _LIBCPP_INLINE_VISIBILITY fmtflags flags() const; |
284 | _LIBCPP_INLINE_VISIBILITY fmtflags flags(fmtflags __fmtfl); |
285 | _LIBCPP_INLINE_VISIBILITY fmtflags setf(fmtflags __fmtfl); |
286 | _LIBCPP_INLINE_VISIBILITY fmtflags setf(fmtflags __fmtfl, fmtflags __mask); |
287 | _LIBCPP_INLINE_VISIBILITY void unsetf(fmtflags __mask); |
288 | |
289 | _LIBCPP_INLINE_VISIBILITY streamsize precision() const; |
290 | _LIBCPP_INLINE_VISIBILITY streamsize precision(streamsize __prec); |
291 | _LIBCPP_INLINE_VISIBILITY streamsize width() const; |
292 | _LIBCPP_INLINE_VISIBILITY streamsize width(streamsize __wide); |
293 | |
294 | // 27.5.2.3 locales: |
295 | locale imbue(const locale& __loc); |
296 | locale getloc() const; |
297 | |
298 | // 27.5.2.5 storage: |
299 | static int xalloc(); |
300 | long& iword(int __index); |
301 | void*& pword(int __index); |
302 | |
303 | // destructor |
304 | virtual ~ios_base(); |
305 | |
306 | // 27.5.2.6 callbacks; |
307 | enum event { erase_event, imbue_event, copyfmt_event }; |
308 | typedef void (*event_callback)(event, ios_base&, int __index); |
309 | void register_callback(event_callback __fn, int __index); |
310 | |
311 | private: |
312 | ios_base(const ios_base&); // = delete; |
313 | ios_base& operator=(const ios_base&); // = delete; |
314 | |
315 | public: |
316 | static bool sync_with_stdio(bool __sync = true); |
317 | |
318 | _LIBCPP_INLINE_VISIBILITY iostate rdstate() const; |
319 | void clear(iostate __state = goodbit); |
320 | _LIBCPP_INLINE_VISIBILITY void setstate(iostate __state); |
321 | |
322 | _LIBCPP_INLINE_VISIBILITY bool good() const; |
323 | _LIBCPP_INLINE_VISIBILITY bool eof() const; |
324 | _LIBCPP_INLINE_VISIBILITY bool fail() const; |
325 | _LIBCPP_INLINE_VISIBILITY bool bad() const; |
326 | |
327 | _LIBCPP_INLINE_VISIBILITY iostate exceptions() const; |
328 | _LIBCPP_INLINE_VISIBILITY void exceptions(iostate __iostate); |
329 | |
330 | void __set_badbit_and_consider_rethrow(); |
331 | void __set_failbit_and_consider_rethrow(); |
332 | |
333 | protected: |
334 | _LIBCPP_INLINE_VISIBILITY |
335 | ios_base() {// purposefully does no initialization |
336 | } |
337 | |
338 | void init(void* __sb); |
339 | _LIBCPP_INLINE_VISIBILITY void* rdbuf() const {return __rdbuf_;} |
340 | |
341 | _LIBCPP_INLINE_VISIBILITY |
342 | void rdbuf(void* __sb) |
343 | { |
344 | __rdbuf_ = __sb; |
345 | clear(); |
346 | } |
347 | |
348 | void __call_callbacks(event); |
349 | void copyfmt(const ios_base&); |
350 | void move(ios_base&); |
351 | void swap(ios_base&) _NOEXCEPT; |
352 | |
353 | _LIBCPP_INLINE_VISIBILITY |
354 | void set_rdbuf(void* __sb) |
355 | { |
356 | __rdbuf_ = __sb; |
357 | } |
358 | |
359 | private: |
360 | // All data members must be scalars |
361 | fmtflags __fmtflags_; |
362 | streamsize __precision_; |
363 | streamsize __width_; |
364 | iostate __rdstate_; |
365 | iostate __exceptions_; |
366 | void* __rdbuf_; |
367 | void* __loc_; |
368 | event_callback* __fn_; |
369 | int* __index_; |
370 | size_t __event_size_; |
371 | size_t __event_cap_; |
372 | // TODO(EricWF): Enable this for both Clang and GCC. Currently it is only |
373 | // enabled with clang. |
374 | #if defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS) |
375 | static atomic<int> __xindex_; |
376 | #else |
377 | static int __xindex_; |
378 | #endif |
379 | long* __iarray_; |
380 | size_t __iarray_size_; |
381 | size_t __iarray_cap_; |
382 | void** __parray_; |
383 | size_t __parray_size_; |
384 | size_t __parray_cap_; |
385 | }; |
386 | |
387 | //enum class io_errc |
388 | _LIBCPP_DECLARE_STRONG_ENUM(io_errc) |
389 | { |
390 | stream = 1 |
391 | }; |
392 | _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(io_errc) |
393 | |
394 | template <> |
395 | struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc> : public true_type { }; |
396 | |
397 | #ifdef _LIBCPP_HAS_NO_STRONG_ENUMS |
398 | template <> |
399 | struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc::__lx> : public true_type { }; |
400 | #endif |
401 | |
402 | _LIBCPP_FUNC_VIS |
403 | const error_category& iostream_category() _NOEXCEPT; |
404 | |
405 | inline _LIBCPP_INLINE_VISIBILITY |
406 | error_code |
407 | make_error_code(io_errc __e) _NOEXCEPT |
408 | { |
409 | return error_code(static_cast<int>(__e), iostream_category()); |
410 | } |
411 | |
412 | inline _LIBCPP_INLINE_VISIBILITY |
413 | error_condition |
414 | make_error_condition(io_errc __e) _NOEXCEPT |
415 | { |
416 | return error_condition(static_cast<int>(__e), iostream_category()); |
417 | } |
418 | |
419 | class _LIBCPP_EXCEPTION_ABI ios_base::failure |
420 | : public system_error |
421 | { |
422 | public: |
423 | explicit failure(const string& __msg, const error_code& __ec = io_errc::stream); |
424 | explicit failure(const char* __msg, const error_code& __ec = io_errc::stream); |
425 | virtual ~failure() throw(); |
426 | }; |
427 | |
428 | _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY |
429 | void __throw_failure(char const* __msg) { |
430 | #ifndef _LIBCPP_NO_EXCEPTIONS |
431 | throw ios_base::failure(__msg); |
432 | #else |
433 | ((void)__msg); |
434 | _VSTD::abort(); |
435 | #endif |
436 | } |
437 | |
438 | class _LIBCPP_TYPE_VIS ios_base::Init |
439 | { |
440 | public: |
441 | Init(); |
442 | ~Init(); |
443 | }; |
444 | |
445 | // fmtflags |
446 | |
447 | inline _LIBCPP_INLINE_VISIBILITY |
448 | ios_base::fmtflags |
449 | ios_base::flags() const |
450 | { |
451 | return __fmtflags_; |
452 | } |
453 | |
454 | inline _LIBCPP_INLINE_VISIBILITY |
455 | ios_base::fmtflags |
456 | ios_base::flags(fmtflags __fmtfl) |
457 | { |
458 | fmtflags __r = __fmtflags_; |
459 | __fmtflags_ = __fmtfl; |
460 | return __r; |
461 | } |
462 | |
463 | inline _LIBCPP_INLINE_VISIBILITY |
464 | ios_base::fmtflags |
465 | ios_base::setf(fmtflags __fmtfl) |
466 | { |
467 | fmtflags __r = __fmtflags_; |
468 | __fmtflags_ |= __fmtfl; |
469 | return __r; |
470 | } |
471 | |
472 | inline _LIBCPP_INLINE_VISIBILITY |
473 | void |
474 | ios_base::unsetf(fmtflags __mask) |
475 | { |
476 | __fmtflags_ &= ~__mask; |
477 | } |
478 | |
479 | inline _LIBCPP_INLINE_VISIBILITY |
480 | ios_base::fmtflags |
481 | ios_base::setf(fmtflags __fmtfl, fmtflags __mask) |
482 | { |
483 | fmtflags __r = __fmtflags_; |
484 | unsetf(__mask); |
485 | __fmtflags_ |= __fmtfl & __mask; |
486 | return __r; |
487 | } |
488 | |
489 | // precision |
490 | |
491 | inline _LIBCPP_INLINE_VISIBILITY |
492 | streamsize |
493 | ios_base::precision() const |
494 | { |
495 | return __precision_; |
496 | } |
497 | |
498 | inline _LIBCPP_INLINE_VISIBILITY |
499 | streamsize |
500 | ios_base::precision(streamsize __prec) |
501 | { |
502 | streamsize __r = __precision_; |
503 | __precision_ = __prec; |
504 | return __r; |
505 | } |
506 | |
507 | // width |
508 | |
509 | inline _LIBCPP_INLINE_VISIBILITY |
510 | streamsize |
511 | ios_base::width() const |
512 | { |
513 | return __width_; |
514 | } |
515 | |
516 | inline _LIBCPP_INLINE_VISIBILITY |
517 | streamsize |
518 | ios_base::width(streamsize __wide) |
519 | { |
520 | streamsize __r = __width_; |
521 | __width_ = __wide; |
522 | return __r; |
523 | } |
524 | |
525 | // iostate |
526 | |
527 | inline _LIBCPP_INLINE_VISIBILITY |
528 | ios_base::iostate |
529 | ios_base::rdstate() const |
530 | { |
531 | return __rdstate_; |
532 | } |
533 | |
534 | inline _LIBCPP_INLINE_VISIBILITY |
535 | void |
536 | ios_base::setstate(iostate __state) |
537 | { |
538 | clear(__rdstate_ | __state); |
539 | } |
540 | |
541 | inline _LIBCPP_INLINE_VISIBILITY |
542 | bool |
543 | ios_base::good() const |
544 | { |
545 | return __rdstate_ == 0; |
546 | } |
547 | |
548 | inline _LIBCPP_INLINE_VISIBILITY |
549 | bool |
550 | ios_base::eof() const |
551 | { |
552 | return (__rdstate_ & eofbit) != 0; |
553 | } |
554 | |
555 | inline _LIBCPP_INLINE_VISIBILITY |
556 | bool |
557 | ios_base::fail() const |
558 | { |
559 | return (__rdstate_ & (failbit | badbit)) != 0; |
560 | } |
561 | |
562 | inline _LIBCPP_INLINE_VISIBILITY |
563 | bool |
564 | ios_base::bad() const |
565 | { |
566 | return (__rdstate_ & badbit) != 0; |
567 | } |
568 | |
569 | inline _LIBCPP_INLINE_VISIBILITY |
570 | ios_base::iostate |
571 | ios_base::exceptions() const |
572 | { |
573 | return __exceptions_; |
574 | } |
575 | |
576 | inline _LIBCPP_INLINE_VISIBILITY |
577 | void |
578 | ios_base::exceptions(iostate __iostate) |
579 | { |
580 | __exceptions_ = __iostate; |
581 | clear(__rdstate_); |
582 | } |
583 | |
584 | #if defined(_LIBCPP_CXX03_LANG) |
585 | struct _LIBCPP_TYPE_VIS __cxx03_bool { |
586 | typedef void (__cxx03_bool::*__bool_type)(); |
587 | void __true_value() {} |
588 | }; |
589 | #endif |
590 | |
591 | template <class _CharT, class _Traits> |
592 | class _LIBCPP_TEMPLATE_VIS basic_ios |
593 | : public ios_base |
594 | { |
595 | public: |
596 | // types: |
597 | typedef _CharT char_type; |
598 | typedef _Traits traits_type; |
599 | |
600 | typedef typename traits_type::int_type int_type; |
601 | typedef typename traits_type::pos_type pos_type; |
602 | typedef typename traits_type::off_type off_type; |
603 | |
604 | static_assert((is_same<_CharT, typename traits_type::char_type>::value), |
605 | "traits_type::char_type must be the same type as CharT" ); |
606 | |
607 | // __true_value will generate undefined references when linking unless |
608 | // we give it internal linkage. |
609 | |
610 | #if defined(_LIBCPP_CXX03_LANG) |
611 | _LIBCPP_INLINE_VISIBILITY |
612 | operator __cxx03_bool::__bool_type() const { |
613 | return !fail() ? &__cxx03_bool::__true_value : nullptr; |
614 | } |
615 | #else |
616 | _LIBCPP_INLINE_VISIBILITY |
617 | _LIBCPP_EXPLICIT operator bool() const {return !fail();} |
618 | #endif |
619 | |
620 | _LIBCPP_INLINE_VISIBILITY bool operator!() const {return fail();} |
621 | _LIBCPP_INLINE_VISIBILITY iostate rdstate() const {return ios_base::rdstate();} |
622 | _LIBCPP_INLINE_VISIBILITY void clear(iostate __state = goodbit) {ios_base::clear(__state);} |
623 | _LIBCPP_INLINE_VISIBILITY void setstate(iostate __state) {ios_base::setstate(__state);} |
624 | _LIBCPP_INLINE_VISIBILITY bool good() const {return ios_base::good();} |
625 | _LIBCPP_INLINE_VISIBILITY bool eof() const {return ios_base::eof();} |
626 | _LIBCPP_INLINE_VISIBILITY bool fail() const {return ios_base::fail();} |
627 | _LIBCPP_INLINE_VISIBILITY bool bad() const {return ios_base::bad();} |
628 | |
629 | _LIBCPP_INLINE_VISIBILITY iostate exceptions() const {return ios_base::exceptions();} |
630 | _LIBCPP_INLINE_VISIBILITY void exceptions(iostate __iostate) {ios_base::exceptions(__iostate);} |
631 | |
632 | // 27.5.4.1 Constructor/destructor: |
633 | _LIBCPP_INLINE_VISIBILITY |
634 | explicit basic_ios(basic_streambuf<char_type,traits_type>* __sb); |
635 | virtual ~basic_ios(); |
636 | |
637 | // 27.5.4.2 Members: |
638 | _LIBCPP_INLINE_VISIBILITY |
639 | basic_ostream<char_type, traits_type>* tie() const; |
640 | _LIBCPP_INLINE_VISIBILITY |
641 | basic_ostream<char_type, traits_type>* tie(basic_ostream<char_type, traits_type>* __tiestr); |
642 | |
643 | _LIBCPP_INLINE_VISIBILITY |
644 | basic_streambuf<char_type, traits_type>* rdbuf() const; |
645 | _LIBCPP_INLINE_VISIBILITY |
646 | basic_streambuf<char_type, traits_type>* rdbuf(basic_streambuf<char_type, traits_type>* __sb); |
647 | |
648 | basic_ios& copyfmt(const basic_ios& __rhs); |
649 | |
650 | _LIBCPP_INLINE_VISIBILITY |
651 | char_type fill() const; |
652 | _LIBCPP_INLINE_VISIBILITY |
653 | char_type fill(char_type __ch); |
654 | |
655 | _LIBCPP_INLINE_VISIBILITY |
656 | locale imbue(const locale& __loc); |
657 | |
658 | _LIBCPP_INLINE_VISIBILITY |
659 | char narrow(char_type __c, char __dfault) const; |
660 | _LIBCPP_INLINE_VISIBILITY |
661 | char_type widen(char __c) const; |
662 | |
663 | protected: |
664 | _LIBCPP_INLINE_VISIBILITY |
665 | basic_ios() {// purposefully does no initialization |
666 | } |
667 | _LIBCPP_INLINE_VISIBILITY |
668 | void init(basic_streambuf<char_type, traits_type>* __sb); |
669 | |
670 | _LIBCPP_INLINE_VISIBILITY |
671 | void move(basic_ios& __rhs); |
672 | #ifndef _LIBCPP_CXX03_LANG |
673 | _LIBCPP_INLINE_VISIBILITY |
674 | void move(basic_ios&& __rhs) {move(__rhs);} |
675 | #endif |
676 | _LIBCPP_INLINE_VISIBILITY |
677 | void swap(basic_ios& __rhs) _NOEXCEPT; |
678 | _LIBCPP_INLINE_VISIBILITY |
679 | void set_rdbuf(basic_streambuf<char_type, traits_type>* __sb); |
680 | private: |
681 | basic_ostream<char_type, traits_type>* __tie_; |
682 | mutable int_type __fill_; |
683 | }; |
684 | |
685 | template <class _CharT, class _Traits> |
686 | inline _LIBCPP_INLINE_VISIBILITY |
687 | basic_ios<_CharT, _Traits>::basic_ios(basic_streambuf<char_type,traits_type>* __sb) |
688 | { |
689 | init(__sb); |
690 | } |
691 | |
692 | template <class _CharT, class _Traits> |
693 | basic_ios<_CharT, _Traits>::~basic_ios() |
694 | { |
695 | } |
696 | |
697 | template <class _CharT, class _Traits> |
698 | inline _LIBCPP_INLINE_VISIBILITY |
699 | void |
700 | basic_ios<_CharT, _Traits>::init(basic_streambuf<char_type, traits_type>* __sb) |
701 | { |
702 | ios_base::init(__sb); |
703 | __tie_ = 0; |
704 | __fill_ = traits_type::eof(); |
705 | } |
706 | |
707 | template <class _CharT, class _Traits> |
708 | inline _LIBCPP_INLINE_VISIBILITY |
709 | basic_ostream<_CharT, _Traits>* |
710 | basic_ios<_CharT, _Traits>::tie() const |
711 | { |
712 | return __tie_; |
713 | } |
714 | |
715 | template <class _CharT, class _Traits> |
716 | inline _LIBCPP_INLINE_VISIBILITY |
717 | basic_ostream<_CharT, _Traits>* |
718 | basic_ios<_CharT, _Traits>::tie(basic_ostream<char_type, traits_type>* __tiestr) |
719 | { |
720 | basic_ostream<char_type, traits_type>* __r = __tie_; |
721 | __tie_ = __tiestr; |
722 | return __r; |
723 | } |
724 | |
725 | template <class _CharT, class _Traits> |
726 | inline _LIBCPP_INLINE_VISIBILITY |
727 | basic_streambuf<_CharT, _Traits>* |
728 | basic_ios<_CharT, _Traits>::rdbuf() const |
729 | { |
730 | return static_cast<basic_streambuf<char_type, traits_type>*>(ios_base::rdbuf()); |
731 | } |
732 | |
733 | template <class _CharT, class _Traits> |
734 | inline _LIBCPP_INLINE_VISIBILITY |
735 | basic_streambuf<_CharT, _Traits>* |
736 | basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<char_type, traits_type>* __sb) |
737 | { |
738 | basic_streambuf<char_type, traits_type>* __r = rdbuf(); |
739 | ios_base::rdbuf(__sb); |
740 | return __r; |
741 | } |
742 | |
743 | template <class _CharT, class _Traits> |
744 | inline _LIBCPP_INLINE_VISIBILITY |
745 | locale |
746 | basic_ios<_CharT, _Traits>::imbue(const locale& __loc) |
747 | { |
748 | locale __r = getloc(); |
749 | ios_base::imbue(__loc); |
750 | if (rdbuf()) |
751 | rdbuf()->pubimbue(__loc); |
752 | return __r; |
753 | } |
754 | |
755 | template <class _CharT, class _Traits> |
756 | inline _LIBCPP_INLINE_VISIBILITY |
757 | char |
758 | basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const |
759 | { |
760 | return use_facet<ctype<char_type> >(getloc()).narrow(__c, __dfault); |
761 | } |
762 | |
763 | template <class _CharT, class _Traits> |
764 | inline _LIBCPP_INLINE_VISIBILITY |
765 | _CharT |
766 | basic_ios<_CharT, _Traits>::widen(char __c) const |
767 | { |
768 | return use_facet<ctype<char_type> >(getloc()).widen(__c); |
769 | } |
770 | |
771 | template <class _CharT, class _Traits> |
772 | inline _LIBCPP_INLINE_VISIBILITY |
773 | _CharT |
774 | basic_ios<_CharT, _Traits>::fill() const |
775 | { |
776 | if (traits_type::eq_int_type(traits_type::eof(), __fill_)) |
777 | __fill_ = widen(' '); |
778 | return __fill_; |
779 | } |
780 | |
781 | template <class _CharT, class _Traits> |
782 | inline _LIBCPP_INLINE_VISIBILITY |
783 | _CharT |
784 | basic_ios<_CharT, _Traits>::fill(char_type __ch) |
785 | { |
786 | char_type __r = __fill_; |
787 | __fill_ = __ch; |
788 | return __r; |
789 | } |
790 | |
791 | template <class _CharT, class _Traits> |
792 | basic_ios<_CharT, _Traits>& |
793 | basic_ios<_CharT, _Traits>::copyfmt(const basic_ios& __rhs) |
794 | { |
795 | if (this != &__rhs) |
796 | { |
797 | __call_callbacks(erase_event); |
798 | ios_base::copyfmt(__rhs); |
799 | __tie_ = __rhs.__tie_; |
800 | __fill_ = __rhs.__fill_; |
801 | __call_callbacks(copyfmt_event); |
802 | exceptions(__rhs.exceptions()); |
803 | } |
804 | return *this; |
805 | } |
806 | |
807 | template <class _CharT, class _Traits> |
808 | inline _LIBCPP_INLINE_VISIBILITY |
809 | void |
810 | basic_ios<_CharT, _Traits>::move(basic_ios& __rhs) |
811 | { |
812 | ios_base::move(__rhs); |
813 | __tie_ = __rhs.__tie_; |
814 | __rhs.__tie_ = 0; |
815 | __fill_ = __rhs.__fill_; |
816 | } |
817 | |
818 | template <class _CharT, class _Traits> |
819 | inline _LIBCPP_INLINE_VISIBILITY |
820 | void |
821 | basic_ios<_CharT, _Traits>::swap(basic_ios& __rhs) _NOEXCEPT |
822 | { |
823 | ios_base::swap(__rhs); |
824 | _VSTD::swap(__tie_, __rhs.__tie_); |
825 | _VSTD::swap(__fill_, __rhs.__fill_); |
826 | } |
827 | |
828 | template <class _CharT, class _Traits> |
829 | inline _LIBCPP_INLINE_VISIBILITY |
830 | void |
831 | basic_ios<_CharT, _Traits>::set_rdbuf(basic_streambuf<char_type, traits_type>* __sb) |
832 | { |
833 | ios_base::set_rdbuf(__sb); |
834 | } |
835 | |
836 | inline _LIBCPP_INLINE_VISIBILITY |
837 | ios_base& |
838 | boolalpha(ios_base& __str) |
839 | { |
840 | __str.setf(ios_base::boolalpha); |
841 | return __str; |
842 | } |
843 | |
844 | inline _LIBCPP_INLINE_VISIBILITY |
845 | ios_base& |
846 | noboolalpha(ios_base& __str) |
847 | { |
848 | __str.unsetf(ios_base::boolalpha); |
849 | return __str; |
850 | } |
851 | |
852 | inline _LIBCPP_INLINE_VISIBILITY |
853 | ios_base& |
854 | showbase(ios_base& __str) |
855 | { |
856 | __str.setf(ios_base::showbase); |
857 | return __str; |
858 | } |
859 | |
860 | inline _LIBCPP_INLINE_VISIBILITY |
861 | ios_base& |
862 | noshowbase(ios_base& __str) |
863 | { |
864 | __str.unsetf(ios_base::showbase); |
865 | return __str; |
866 | } |
867 | |
868 | inline _LIBCPP_INLINE_VISIBILITY |
869 | ios_base& |
870 | showpoint(ios_base& __str) |
871 | { |
872 | __str.setf(ios_base::showpoint); |
873 | return __str; |
874 | } |
875 | |
876 | inline _LIBCPP_INLINE_VISIBILITY |
877 | ios_base& |
878 | noshowpoint(ios_base& __str) |
879 | { |
880 | __str.unsetf(ios_base::showpoint); |
881 | return __str; |
882 | } |
883 | |
884 | inline _LIBCPP_INLINE_VISIBILITY |
885 | ios_base& |
886 | showpos(ios_base& __str) |
887 | { |
888 | __str.setf(ios_base::showpos); |
889 | return __str; |
890 | } |
891 | |
892 | inline _LIBCPP_INLINE_VISIBILITY |
893 | ios_base& |
894 | noshowpos(ios_base& __str) |
895 | { |
896 | __str.unsetf(ios_base::showpos); |
897 | return __str; |
898 | } |
899 | |
900 | inline _LIBCPP_INLINE_VISIBILITY |
901 | ios_base& |
902 | skipws(ios_base& __str) |
903 | { |
904 | __str.setf(ios_base::skipws); |
905 | return __str; |
906 | } |
907 | |
908 | inline _LIBCPP_INLINE_VISIBILITY |
909 | ios_base& |
910 | noskipws(ios_base& __str) |
911 | { |
912 | __str.unsetf(ios_base::skipws); |
913 | return __str; |
914 | } |
915 | |
916 | inline _LIBCPP_INLINE_VISIBILITY |
917 | ios_base& |
918 | uppercase(ios_base& __str) |
919 | { |
920 | __str.setf(ios_base::uppercase); |
921 | return __str; |
922 | } |
923 | |
924 | inline _LIBCPP_INLINE_VISIBILITY |
925 | ios_base& |
926 | nouppercase(ios_base& __str) |
927 | { |
928 | __str.unsetf(ios_base::uppercase); |
929 | return __str; |
930 | } |
931 | |
932 | inline _LIBCPP_INLINE_VISIBILITY |
933 | ios_base& |
934 | unitbuf(ios_base& __str) |
935 | { |
936 | __str.setf(ios_base::unitbuf); |
937 | return __str; |
938 | } |
939 | |
940 | inline _LIBCPP_INLINE_VISIBILITY |
941 | ios_base& |
942 | nounitbuf(ios_base& __str) |
943 | { |
944 | __str.unsetf(ios_base::unitbuf); |
945 | return __str; |
946 | } |
947 | |
948 | inline _LIBCPP_INLINE_VISIBILITY |
949 | ios_base& |
950 | internal(ios_base& __str) |
951 | { |
952 | __str.setf(ios_base::internal, ios_base::adjustfield); |
953 | return __str; |
954 | } |
955 | |
956 | inline _LIBCPP_INLINE_VISIBILITY |
957 | ios_base& |
958 | left(ios_base& __str) |
959 | { |
960 | __str.setf(ios_base::left, ios_base::adjustfield); |
961 | return __str; |
962 | } |
963 | |
964 | inline _LIBCPP_INLINE_VISIBILITY |
965 | ios_base& |
966 | right(ios_base& __str) |
967 | { |
968 | __str.setf(ios_base::right, ios_base::adjustfield); |
969 | return __str; |
970 | } |
971 | |
972 | inline _LIBCPP_INLINE_VISIBILITY |
973 | ios_base& |
974 | dec(ios_base& __str) |
975 | { |
976 | __str.setf(ios_base::dec, ios_base::basefield); |
977 | return __str; |
978 | } |
979 | |
980 | inline _LIBCPP_INLINE_VISIBILITY |
981 | ios_base& |
982 | hex(ios_base& __str) |
983 | { |
984 | __str.setf(ios_base::hex, ios_base::basefield); |
985 | return __str; |
986 | } |
987 | |
988 | inline _LIBCPP_INLINE_VISIBILITY |
989 | ios_base& |
990 | oct(ios_base& __str) |
991 | { |
992 | __str.setf(ios_base::oct, ios_base::basefield); |
993 | return __str; |
994 | } |
995 | |
996 | inline _LIBCPP_INLINE_VISIBILITY |
997 | ios_base& |
998 | fixed(ios_base& __str) |
999 | { |
1000 | __str.setf(ios_base::fixed, ios_base::floatfield); |
1001 | return __str; |
1002 | } |
1003 | |
1004 | inline _LIBCPP_INLINE_VISIBILITY |
1005 | ios_base& |
1006 | scientific(ios_base& __str) |
1007 | { |
1008 | __str.setf(ios_base::scientific, ios_base::floatfield); |
1009 | return __str; |
1010 | } |
1011 | |
1012 | inline _LIBCPP_INLINE_VISIBILITY |
1013 | ios_base& |
1014 | hexfloat(ios_base& __str) |
1015 | { |
1016 | __str.setf(ios_base::fixed | ios_base::scientific, ios_base::floatfield); |
1017 | return __str; |
1018 | } |
1019 | |
1020 | inline _LIBCPP_INLINE_VISIBILITY |
1021 | ios_base& |
1022 | defaultfloat(ios_base& __str) |
1023 | { |
1024 | __str.unsetf(ios_base::floatfield); |
1025 | return __str; |
1026 | } |
1027 | |
1028 | template <class _CharT, class _Traits> |
1029 | class __save_flags |
1030 | { |
1031 | typedef basic_ios<_CharT, _Traits> __stream_type; |
1032 | typedef typename __stream_type::fmtflags fmtflags; |
1033 | |
1034 | __stream_type& __stream_; |
1035 | fmtflags __fmtflags_; |
1036 | _CharT __fill_; |
1037 | |
1038 | __save_flags(const __save_flags&); |
1039 | __save_flags& operator=(const __save_flags&); |
1040 | public: |
1041 | _LIBCPP_INLINE_VISIBILITY |
1042 | explicit __save_flags(__stream_type& __stream) |
1043 | : __stream_(__stream), |
1044 | __fmtflags_(__stream.flags()), |
1045 | __fill_(__stream.fill()) |
1046 | {} |
1047 | _LIBCPP_INLINE_VISIBILITY |
1048 | ~__save_flags() |
1049 | { |
1050 | __stream_.flags(__fmtflags_); |
1051 | __stream_.fill(__fill_); |
1052 | } |
1053 | }; |
1054 | |
1055 | _LIBCPP_END_NAMESPACE_STD |
1056 | |
1057 | #endif // _LIBCPP_IOS |
1058 | |