1 /* This is part of libio/iostream, providing -*- C++ -*- input/output.
2 Copyright (C) 1993 Free Software Foundation
4 This file is part of the GNU IO Library. This library is free
5 software; you can redistribute it and/or modify it under the
6 terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option)
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this library; see the file COPYING. If not, write to the Free
17 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 As a special exception, if you link this library with files
20 compiled with a GNU compiler to produce an executable, this does not cause
21 the resulting executable to be covered by the GNU General Public License.
22 This exception does not however invalidate any other reasons why
23 the executable file might be covered by the GNU General Public License. */
31 #include <streambuf.h>
34 class istream
; class ostream
;
35 typedef ios
& (*__manip
)(ios
&);
36 typedef istream
& (*__imanip
)(istream
&);
37 typedef ostream
& (*__omanip
)(ostream
&);
39 extern istream
& ws(istream
& ins
);
40 extern ostream
& flush(ostream
& outs
);
41 extern ostream
& endl(ostream
& outs
);
42 extern ostream
& ends(ostream
& outs
);
44 class ostream
: virtual public ios
46 // NOTE: If fields are changed, you must fix _fake_ostream in stdstreams.C!
50 ostream(streambuf
* sb
, ostream
* tied
=NULL
);
52 if (!good()) return 0; else { if (_tie
) _tie
->flush(); return 1;} }
53 void osfx() { if (flags() & (ios::unitbuf
|ios::stdio
))
56 ostream
& put(char c
) { _strbuf
->sputc(c
); return *this; }
58 /* Temporary binary compatibility. REMOVE IN NEXT RELEASE. */
59 ostream
& put(unsigned char c
) { return put((char)c
); }
60 ostream
& put(signed char c
) { return put((char)c
); }
62 ostream
& write(const char *s
, streamsize n
);
63 ostream
& write(const unsigned char *s
, streamsize n
)
64 { return write((const char*)s
, n
);}
65 ostream
& write(const signed char *s
, streamsize n
)
66 { return write((const char*)s
, n
);}
67 ostream
& write(const void *s
, streamsize n
)
68 { return write((const char*)s
, n
);}
69 ostream
& seekp(streampos
);
70 ostream
& seekp(streamoff
, _seek_dir
);
72 ostream
& form(const char *format
...);
73 ostream
& vform(const char *format
, _IO_va_list args
);
75 ostream
& operator<<(char c
);
76 ostream
& operator<<(unsigned char c
) { return (*this) << (char)c
; }
77 ostream
& operator<<(signed char c
) { return (*this) << (char)c
; }
78 ostream
& operator<<(const char *s
);
79 ostream
& operator<<(const unsigned char *s
)
80 { return (*this) << (const char*)s
; }
81 ostream
& operator<<(const signed char *s
)
82 { return (*this) << (const char*)s
; }
83 ostream
& operator<<(const void *p
);
84 ostream
& operator<<(int n
);
85 ostream
& operator<<(unsigned int n
);
86 ostream
& operator<<(long n
);
87 ostream
& operator<<(unsigned long n
);
89 __extension__ ostream
& operator<<(long long n
);
90 __extension__ ostream
& operator<<(unsigned long long n
);
92 ostream
& operator<<(short n
) {return operator<<((int)n
);}
93 ostream
& operator<<(unsigned short n
) {return operator<<((unsigned int)n
);}
95 ostream
& operator<<(bool b
) { return operator<<((int)b
); }
97 ostream
& operator<<(double n
);
98 ostream
& operator<<(float n
) { return operator<<((double)n
); }
99 ostream
& operator<<(long double n
) { return operator<<((double)n
); }
100 ostream
& operator<<(__omanip func
) { return (*func
)(*this); }
101 ostream
& operator<<(__manip func
) {(*func
)(*this); return *this;}
102 ostream
& operator<<(streambuf
*);
103 #ifdef _STREAM_COMPAT
104 streambuf
* ostreambuf() const { return _strbuf
; }
108 class istream
: virtual public ios
110 // NOTE: If fields are changed, you must fix _fake_istream in stdstreams.C!
116 istream(): _gcount (0) { }
117 istream(streambuf
* sb
, ostream
*tied
=NULL
);
118 istream
& get(char* ptr
, int len
, char delim
= '\n');
119 istream
& get(unsigned char* ptr
, int len
, char delim
= '\n')
120 { return get((char*)ptr
, len
, delim
); }
121 istream
& get(char& c
);
122 istream
& get(unsigned char& c
) { return get((char&)c
); }
123 istream
& getline(char* ptr
, int len
, char delim
= '\n');
124 istream
& getline(unsigned char* ptr
, int len
, char delim
= '\n')
125 { return getline((char*)ptr
, len
, delim
); }
126 istream
& get(signed char& c
) { return get((char&)c
); }
127 istream
& get(signed char* ptr
, int len
, char delim
= '\n')
128 { return get((char*)ptr
, len
, delim
); }
129 istream
& getline(signed char* ptr
, int len
, char delim
= '\n')
130 { return getline((char*)ptr
, len
, delim
); }
131 istream
& read(char *ptr
, streamsize n
);
132 istream
& read(unsigned char *ptr
, streamsize n
)
133 { return read((char*)ptr
, n
); }
134 istream
& read(signed char *ptr
, streamsize n
)
135 { return read((char*)ptr
, n
); }
136 istream
& read(void *ptr
, streamsize n
)
137 { return read((char*)ptr
, n
); }
138 istream
& get(streambuf
& sb
, char delim
= '\n');
139 istream
& gets(char **s
, char delim
= '\n');
140 int ipfx(int need
= 0) {
141 if (!good()) { set(ios::failbit
); return 0; }
143 if (_tie
&& (need
== 0 || rdbuf()->in_avail() < need
)) _tie
->flush();
144 if (!need
&& (flags() & ios::skipws
)) return _skip_ws();
148 int ipfx0() { // Optimized version of ipfx(0).
149 if (!good()) { set(ios::failbit
); return 0; }
151 if (_tie
) _tie
->flush();
152 if (flags() & ios::skipws
) return _skip_ws();
156 int ipfx1() { // Optimized version of ipfx(1).
157 if (!good()) { set(ios::failbit
); return 0; }
159 if (_tie
&& rdbuf()->in_avail() == 0) _tie
->flush();
164 int get() { if (!ipfx1()) return EOF
;
165 else { int ch
= _strbuf
->sbumpc();
166 if (ch
== EOF
) set(ios::eofbit
);
170 _IO_size_t
gcount() { return _gcount
; }
171 istream
& ignore(int n
=1, int delim
= EOF
);
173 istream
& seekg(streampos
);
174 istream
& seekg(streamoff
, _seek_dir
);
176 istream
& putback(char ch
) {
177 if (good() && _strbuf
->sputbackc(ch
) == EOF
) clear(ios::badbit
);
180 if (good() && _strbuf
->sungetc() == EOF
) clear(ios::badbit
);
182 istream
& scan(const char *format
...);
183 istream
& vscan(const char *format
, _IO_va_list args
);
184 #ifdef _STREAM_COMPAT
185 istream
& unget(char ch
) { return putback(ch
); }
187 streambuf
* istreambuf() const { return _strbuf
; }
190 istream
& operator>>(char*);
191 istream
& operator>>(unsigned char* p
) { return operator>>((char*)p
); }
192 istream
& operator>>(signed char*p
) { return operator>>((char*)p
); }
193 istream
& operator>>(char& c
);
194 istream
& operator>>(unsigned char& c
) {return operator>>((char&)c
);}
195 istream
& operator>>(signed char& c
) {return operator>>((char&)c
);}
196 istream
& operator>>(int&);
197 istream
& operator>>(long&);
198 #if defined(__GNUC__)
199 __extension__ istream
& operator>>(long long&);
200 __extension__ istream
& operator>>(unsigned long long&);
202 istream
& operator>>(short&);
203 istream
& operator>>(unsigned int&);
204 istream
& operator>>(unsigned long&);
205 istream
& operator>>(unsigned short&);
207 istream
& operator>>(bool&);
209 istream
& operator>>(float&);
210 istream
& operator>>(double&);
211 istream
& operator>>(long double&);
212 istream
& operator>>( __manip func
) {(*func
)(*this); return *this;}
213 istream
& operator>>(__imanip func
) { return (*func
)(*this); }
214 istream
& operator>>(streambuf
*);
217 class iostream
: public istream
, public ostream
221 iostream(streambuf
* sb
, ostream
*tied
=NULL
);
224 class _IO_istream_withassign
: public istream
{
226 _IO_istream_withassign
& operator=(istream
&);
227 _IO_istream_withassign
& operator=(_IO_istream_withassign
& rhs
)
228 { return operator= (static_cast<istream
&> (rhs
)); }
231 class _IO_ostream_withassign
: public ostream
{
233 _IO_ostream_withassign
& operator=(ostream
&);
234 _IO_ostream_withassign
& operator=(_IO_ostream_withassign
& rhs
)
235 { return operator= (static_cast<ostream
&> (rhs
)); }
238 extern _IO_istream_withassign cin
;
239 // clog->rdbuf() == cerr->rdbuf()
240 extern _IO_ostream_withassign cout
, cerr
;
242 extern _IO_ostream_withassign clog
244 __asm__ ("__IO_clog")
248 struct Iostream_init
{ } ; // Compatibility hack for AT&T library.
250 inline ios
& dec(ios
& i
)
251 { i
.setf(ios::dec
, ios::dec
|ios::hex
|ios::oct
); return i
; }
252 inline ios
& hex(ios
& i
)
253 { i
.setf(ios::hex
, ios::dec
|ios::hex
|ios::oct
); return i
; }
254 inline ios
& oct(ios
& i
)
255 { i
.setf(ios::oct
, ios::dec
|ios::hex
|ios::oct
); return i
; }
258 #endif /*!_IOSTREAM_H*/