| 1 | // Iostreams base classes -*- C++ -*-
|
|---|
| 2 |
|
|---|
| 3 | // Copyright (C) 1997, 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
|
|---|
| 4 | //
|
|---|
| 5 | // This file is part of the GNU ISO C++ Library. This library is free
|
|---|
| 6 | // software; you can redistribute it and/or modify it under the
|
|---|
| 7 | // terms of the GNU General Public License as published by the
|
|---|
| 8 | // Free Software Foundation; either version 2, or (at your option)
|
|---|
| 9 | // any later version.
|
|---|
| 10 |
|
|---|
| 11 | // This library is distributed in the hope that it will be useful,
|
|---|
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 14 | // GNU General Public License for more details.
|
|---|
| 15 |
|
|---|
| 16 | // You should have received a copy of the GNU General Public License along
|
|---|
| 17 | // with this library; see the file COPYING. If not, write to the Free
|
|---|
| 18 | // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|---|
| 19 | // USA.
|
|---|
| 20 |
|
|---|
| 21 | // As a special exception, you may use this file as part of a free software
|
|---|
| 22 | // library without restriction. Specifically, if other files instantiate
|
|---|
| 23 | // templates or use macros or inline functions from this file, or you compile
|
|---|
| 24 | // this file and link it with other files to produce an executable, this
|
|---|
| 25 | // file does not by itself cause the resulting executable to be covered by
|
|---|
| 26 | // the GNU General Public License. This exception does not however
|
|---|
| 27 | // invalidate any other reasons why the executable file might be covered by
|
|---|
| 28 | // the GNU General Public License.
|
|---|
| 29 |
|
|---|
| 30 | /** @file basic_ios.h
|
|---|
| 31 | * This is an internal header file, included by other library headers.
|
|---|
| 32 | * You should not attempt to use it directly.
|
|---|
| 33 | */
|
|---|
| 34 |
|
|---|
| 35 | #ifndef _CPP_BITS_BASICIOS_H
|
|---|
| 36 | #define _CPP_BITS_BASICIOS_H 1
|
|---|
| 37 |
|
|---|
| 38 | #pragma GCC system_header
|
|---|
| 39 |
|
|---|
| 40 | #include <bits/streambuf_iterator.h>
|
|---|
| 41 | #include <bits/locale_facets.h>
|
|---|
| 42 |
|
|---|
| 43 | namespace std
|
|---|
| 44 | {
|
|---|
| 45 | // 27.4.5 Template class basic_ios
|
|---|
| 46 | template<typename _CharT, typename _Traits>
|
|---|
| 47 | class basic_ios : public ios_base
|
|---|
| 48 | {
|
|---|
| 49 | public:
|
|---|
| 50 | // Types:
|
|---|
| 51 | typedef _CharT char_type;
|
|---|
| 52 | typedef typename _Traits::int_type int_type;
|
|---|
| 53 | typedef typename _Traits::pos_type pos_type;
|
|---|
| 54 | typedef typename _Traits::off_type off_type;
|
|---|
| 55 | typedef _Traits traits_type;
|
|---|
| 56 |
|
|---|
| 57 | // Non-standard Types:
|
|---|
| 58 | typedef ctype<_CharT> __ctype_type;
|
|---|
| 59 | typedef ostreambuf_iterator<_CharT, _Traits> __ostreambuf_iter;
|
|---|
| 60 | typedef num_put<_CharT, __ostreambuf_iter> __numput_type;
|
|---|
| 61 | typedef istreambuf_iterator<_CharT, _Traits> __istreambuf_iter;
|
|---|
| 62 | typedef num_get<_CharT, __istreambuf_iter> __numget_type;
|
|---|
| 63 |
|
|---|
| 64 | // Data members:
|
|---|
| 65 | protected:
|
|---|
| 66 | basic_ostream<_CharT, _Traits>* _M_tie;
|
|---|
| 67 | mutable char_type _M_fill;
|
|---|
| 68 | mutable bool _M_fill_init;
|
|---|
| 69 | basic_streambuf<_CharT, _Traits>* _M_streambuf;
|
|---|
| 70 |
|
|---|
| 71 | // Cached use_facet<ctype>, which is based on the current locale info.
|
|---|
| 72 | const __ctype_type* _M_fctype;
|
|---|
| 73 | // From ostream.
|
|---|
| 74 | const __numput_type* _M_fnumput;
|
|---|
| 75 | // From istream.
|
|---|
| 76 | const __numget_type* _M_fnumget;
|
|---|
| 77 |
|
|---|
| 78 | public:
|
|---|
| 79 | operator void*() const
|
|---|
| 80 | { return this->fail() ? 0 : const_cast<basic_ios*>(this); }
|
|---|
| 81 |
|
|---|
| 82 | bool
|
|---|
| 83 | operator!() const
|
|---|
| 84 | { return this->fail(); }
|
|---|
| 85 |
|
|---|
| 86 | iostate
|
|---|
| 87 | rdstate() const
|
|---|
| 88 | { return _M_streambuf_state; }
|
|---|
| 89 |
|
|---|
| 90 | void
|
|---|
| 91 | clear(iostate __state = goodbit);
|
|---|
| 92 |
|
|---|
| 93 | void
|
|---|
| 94 | setstate(iostate __state)
|
|---|
| 95 | { this->clear(this->rdstate() | __state); }
|
|---|
| 96 |
|
|---|
| 97 | bool
|
|---|
| 98 | good() const
|
|---|
| 99 | { return this->rdstate() == 0; }
|
|---|
| 100 |
|
|---|
| 101 | bool
|
|---|
| 102 | eof() const
|
|---|
| 103 | { return (this->rdstate() & eofbit) != 0; }
|
|---|
| 104 |
|
|---|
| 105 | bool
|
|---|
| 106 | fail() const
|
|---|
| 107 | { return (this->rdstate() & (badbit | failbit)) != 0; }
|
|---|
| 108 |
|
|---|
| 109 | bool
|
|---|
| 110 | bad() const
|
|---|
| 111 | { return (this->rdstate() & badbit) != 0; }
|
|---|
| 112 |
|
|---|
| 113 | iostate
|
|---|
| 114 | exceptions() const
|
|---|
| 115 | { return _M_exception; }
|
|---|
| 116 |
|
|---|
| 117 | void
|
|---|
| 118 | exceptions(iostate __except)
|
|---|
| 119 | {
|
|---|
| 120 | _M_exception = __except;
|
|---|
| 121 | this->clear(_M_streambuf_state);
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | // Constructor/destructor:
|
|---|
| 125 | explicit
|
|---|
| 126 | basic_ios(basic_streambuf<_CharT, _Traits>* __sb) : ios_base()
|
|---|
| 127 | { this->init(__sb); }
|
|---|
| 128 |
|
|---|
| 129 | virtual
|
|---|
| 130 | ~basic_ios() { }
|
|---|
| 131 |
|
|---|
| 132 | // Members:
|
|---|
| 133 | basic_ostream<_CharT, _Traits>*
|
|---|
| 134 | tie() const
|
|---|
| 135 | { return _M_tie; }
|
|---|
| 136 |
|
|---|
| 137 | basic_ostream<_CharT, _Traits>*
|
|---|
| 138 | tie(basic_ostream<_CharT, _Traits>* __tiestr)
|
|---|
| 139 | {
|
|---|
| 140 | basic_ostream<_CharT, _Traits>* __old = _M_tie;
|
|---|
| 141 | _M_tie = __tiestr;
|
|---|
| 142 | return __old;
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | basic_streambuf<_CharT, _Traits>*
|
|---|
| 146 | rdbuf() const
|
|---|
| 147 | { return _M_streambuf; }
|
|---|
| 148 |
|
|---|
| 149 | basic_streambuf<_CharT, _Traits>*
|
|---|
| 150 | rdbuf(basic_streambuf<_CharT, _Traits>* __sb);
|
|---|
| 151 |
|
|---|
| 152 | basic_ios&
|
|---|
| 153 | copyfmt(const basic_ios& __rhs);
|
|---|
| 154 |
|
|---|
| 155 | char_type
|
|---|
| 156 | fill() const
|
|---|
| 157 | {
|
|---|
| 158 | if (!_M_fill_init)
|
|---|
| 159 | {
|
|---|
| 160 | _M_fill = this->widen(' ');
|
|---|
| 161 | _M_fill_init = true;
|
|---|
| 162 | }
|
|---|
| 163 | return _M_fill;
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | char_type
|
|---|
| 167 | fill(char_type __ch)
|
|---|
| 168 | {
|
|---|
| 169 | char_type __old = this->fill();
|
|---|
| 170 | _M_fill = __ch;
|
|---|
| 171 | return __old;
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | // Locales:
|
|---|
| 175 | locale
|
|---|
| 176 | imbue(const locale& __loc);
|
|---|
| 177 |
|
|---|
| 178 | char
|
|---|
| 179 | narrow(char_type __c, char __dfault) const;
|
|---|
| 180 |
|
|---|
| 181 | char_type
|
|---|
| 182 | widen(char __c) const;
|
|---|
| 183 |
|
|---|
| 184 | protected:
|
|---|
| 185 | // 27.4.5.1 basic_ios constructors
|
|---|
| 186 | basic_ios() : ios_base()
|
|---|
| 187 | { }
|
|---|
| 188 |
|
|---|
| 189 | void
|
|---|
| 190 | init(basic_streambuf<_CharT, _Traits>* __sb);
|
|---|
| 191 |
|
|---|
| 192 | bool
|
|---|
| 193 | _M_check_facet(const locale::facet* __f) const
|
|---|
| 194 | {
|
|---|
| 195 | if (!__f)
|
|---|
| 196 | __throw_bad_cast();
|
|---|
| 197 | return true;
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | void
|
|---|
| 201 | _M_cache_facets(const locale& __loc);
|
|---|
| 202 | };
|
|---|
| 203 | } // namespace std
|
|---|
| 204 |
|
|---|
| 205 | #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
|
|---|
| 206 | # define export
|
|---|
| 207 | #include <bits/basic_ios.tcc>
|
|---|
| 208 | #endif
|
|---|
| 209 |
|
|---|
| 210 | #endif /* _CPP_BITS_BASICIOS_H */
|
|---|