OSDN Git Service

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