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