OSDN Git Service

d03e656b29e5f0bb49cc32fa242705e529120b96
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / bits / basic_ios.h
1 // Iostreams base classes -*- C++ -*-
2
3 // Copyright (C) 1997, 1998, 1999, 2001 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 #ifndef _CPP_BITS_BASICIOS_H
31 #define _CPP_BITS_BASICIOS_H 1
32
33 #include <bits/sbuf_iter.h>
34 #include <bits/locale_facets.h>
35
36 namespace std {
37
38   // 27.4.5  Template class basic_ios
39   template<typename _CharT, typename _Traits>
40     class basic_ios : public ios_base
41     {
42     public:
43
44       // Types:
45       typedef _CharT                            char_type;
46       typedef typename _Traits::int_type        int_type;
47       typedef typename _Traits::pos_type        pos_type;
48       typedef typename _Traits::off_type        off_type;
49       typedef _Traits                           traits_type;
50
51       // Non-standard Types:
52       typedef ctype<_CharT>                     __ctype_type;
53       // From ostream
54       typedef ostreambuf_iterator<_CharT>               __ostreambuf_iter;
55       typedef num_put<_CharT, __ostreambuf_iter>        __numput_type;
56       typedef istreambuf_iterator<_CharT>               __istreambuf_iter;
57       typedef num_get<_CharT, __istreambuf_iter>        __numget_type;
58       
59       // Data members:
60     private:
61       basic_ostream<_CharT, _Traits>*   _M_tie;
62       char_type                         _M_fill;
63       iostate                           _M_exception;
64
65     protected:
66       basic_streambuf<_CharT, _Traits>* _M_streambuf;
67       iostate                           _M_streambuf_state;
68
69       // Cached use_facet<ctype>, which is based on the current locale info.
70       const __ctype_type*               _M_ios_fctype;      
71       // From ostream.
72       const __numput_type*              _M_fnumput;
73       // From istream.
74       const __numget_type*              _M_fnumget;
75
76     public:
77
78       inline const __ctype_type*        
79       _M_get_fctype_ios(void)
80       { return _M_ios_fctype; }
81
82       inline const __numget_type* 
83       _M_get_fnumget(void)
84       { return _M_fnumget; }
85
86       inline const __numput_type* 
87       _M_get_fnumput(void)
88       { return _M_fnumput; }
89
90       operator void*() const 
91       { return this->fail() ? 0 : const_cast<basic_ios*>(this); }
92
93       inline bool 
94       operator!() const 
95       { return this->fail(); }
96
97       inline iostate 
98       rdstate() const 
99       { return _M_streambuf_state; }
100
101       inline void 
102       clear(iostate __state = goodbit)
103       { 
104         if (this->rdbuf())
105           _M_streambuf_state = __state;
106         else
107           _M_streambuf_state = __state | badbit;
108         if ((this->rdstate() & this->exceptions()))
109           __throw_ios_failure("basic_ios::clear(iostate) caused exception");
110       }
111
112       inline void 
113       setstate(iostate __state) 
114       { this->clear(this->rdstate() | __state); }
115
116       inline bool 
117       good() const 
118       { return this->rdstate() == 0; }
119
120       inline bool 
121       eof() const 
122       { return (this->rdstate() & eofbit) != 0; }
123
124       inline bool 
125       fail() const 
126       { return (this->rdstate() & (badbit | failbit)) != 0; }
127
128       inline bool 
129       bad() const 
130       { return (this->rdstate() & badbit) != 0; }
131
132       inline iostate 
133       exceptions() const 
134       { return _M_exception; }
135
136       inline void 
137       exceptions(iostate __except) 
138       { 
139         _M_exception = __except; 
140         this->clear(_M_streambuf_state); 
141       }
142
143       // Constructor/destructor:
144       explicit 
145       basic_ios(basic_streambuf<_CharT, _Traits>* __sb) : ios_base() 
146       { this->init(__sb); }
147
148       virtual 
149       ~basic_ios() { }
150       
151       // Members:
152       inline basic_ostream<_CharT, _Traits>*
153       tie() const      
154       { return _M_tie; }
155
156       inline basic_ostream<_CharT, _Traits>*
157       tie(basic_ostream<_CharT, _Traits>* __tiestr)
158       {
159         basic_ostream<_CharT, _Traits>* __old = _M_tie;
160         _M_tie = __tiestr;
161         return __old;
162       }
163
164       inline basic_streambuf<_CharT, _Traits>*
165       rdbuf() const    
166       { return _M_streambuf; }
167
168       basic_streambuf<_CharT, _Traits>* 
169       rdbuf(basic_streambuf<_CharT, _Traits>* __sb);
170
171       basic_ios&
172       copyfmt(const basic_ios& __rhs);
173
174       inline char_type 
175       fill() const 
176       { return _M_fill; }
177
178       inline char_type 
179       fill(char_type __ch)
180       {
181         char_type __old = _M_fill;
182         _M_fill = __ch;
183         return __old;
184       }
185
186       // Locales:
187       locale 
188       imbue(const locale& __loc);
189
190       char 
191       narrow(char_type __c, char __dfault) const;
192
193       char_type 
194       widen(char __c) const;
195      
196     protected:
197       // 27.4.5.1  basic_ios constructors
198       basic_ios() : ios_base() 
199       { }
200
201       void 
202       init(basic_streambuf<_CharT, _Traits>* __sb);
203     };
204   
205 } // namespace std
206
207 #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
208 # define export
209 #include <bits/basic_ios.tcc>
210 #endif
211
212 #endif /* _CPP_BITS_BASICIOS_H */
213
214
215
216
217
218
219
220