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;
53 else { if (_tie
) _tie
->flush(); _IO_flockfile(_strbuf
); return 1;} }
54 void osfx() { _IO_funlockfile(_strbuf
);
55 if (flags() & (ios::unitbuf
|ios::stdio
))
58 ostream
& put(char c
) { _strbuf
->sputc(c
); return *this; }
60 /* Temporary binary compatibility. REMOVE IN NEXT RELEASE. */
61 ostream
& put(unsigned char c
) { return put((char)c
); }
62 ostream
& put(signed char c
) { return put((char)c
); }
64 ostream
& write(const char *s
, streamsize n
);
65 ostream
& write(const unsigned char *s
, streamsize n
)
66 { return write((const char*)s
, n
);}
67 ostream
& write(const signed char *s
, streamsize n
)
68 { return write((const char*)s
, n
);}
69 ostream
& write(const void *s
, streamsize n
)
70 { return write((const char*)s
, n
);}
72 // [zooey]: added for R5-compatibility with bdb,
73 // these can't be inlined as they wouldn't end up in the lib then.
74 ostream
& write(const char *s
, int n
);
75 ostream
& write(const unsigned char *s
, int n
);
76 ostream
& write(const signed char *s
, int n
);
77 ostream
& write(const void *s
, int n
);
79 ostream
& seekp(streampos
);
80 ostream
& seekp(streamoff
, _seek_dir
);
82 ostream
& form(const char *format
...);
83 ostream
& vform(const char *format
, _IO_va_list args
);
85 ostream
& operator<<(char c
);
86 ostream
& operator<<(unsigned char c
) { return (*this) << (char)c
; }
87 ostream
& operator<<(signed char c
) { return (*this) << (char)c
; }
88 ostream
& operator<<(const char *s
);
89 ostream
& operator<<(const unsigned char *s
)
90 { return (*this) << (const char*)s
; }
91 ostream
& operator<<(const signed char *s
)
92 { return (*this) << (const char*)s
; }
93 ostream
& operator<<(const void *p
);
94 ostream
& operator<<(int n
);
95 ostream
& operator<<(unsigned int n
);
96 ostream
& operator<<(long n
);
97 ostream
& operator<<(unsigned long n
);
99 __extension__ ostream
& operator<<(long long n
);
100 __extension__ ostream
& operator<<(unsigned long long n
);
102 ostream
& operator<<(short n
) {return operator<<((int)n
);}
103 ostream
& operator<<(unsigned short n
) {return operator<<((unsigned int)n
);}
105 ostream
& operator<<(bool b
) { return operator<<((int)b
); }
107 ostream
& operator<<(double n
);
108 ostream
& operator<<(float n
) { return operator<<((double)n
); }
109 #if _G_HAVE_LONG_DOUBLE_IO
110 ostream
& operator<<(long double n
);
112 ostream
& operator<<(long double n
) { return operator<<((double)n
); }
114 ostream
& operator<<(__omanip func
) { return (*func
)(*this); }
115 ostream
& operator<<(__manip func
) {(*func
)(*this); return *this;}
116 ostream
& operator<<(streambuf
*);
117 #ifdef _STREAM_COMPAT
118 streambuf
* ostreambuf() const { return _strbuf
; }
122 class istream
: virtual public ios
124 // NOTE: If fields are changed, you must fix _fake_istream in stdstreams.C!
130 istream(): _gcount (0) { }
131 istream(streambuf
* sb
, ostream
*tied
=NULL
);
132 istream
& get(char* ptr
, int len
, char delim
= '\n');
133 istream
& get(unsigned char* ptr
, int len
, char delim
= '\n')
134 { return get((char*)ptr
, len
, delim
); }
135 istream
& get(char& c
);
136 istream
& get(unsigned char& c
) { return get((char&)c
); }
137 istream
& getline(char* ptr
, int len
, char delim
= '\n');
138 istream
& getline(unsigned char* ptr
, int len
, char delim
= '\n')
139 { return getline((char*)ptr
, len
, delim
); }
140 istream
& get(signed char& c
) { return get((char&)c
); }
141 istream
& get(signed char* ptr
, int len
, char delim
= '\n')
142 { return get((char*)ptr
, len
, delim
); }
143 istream
& getline(signed char* ptr
, int len
, char delim
= '\n')
144 { return getline((char*)ptr
, len
, delim
); }
145 istream
& read(char *ptr
, streamsize n
);
146 istream
& read(unsigned char *ptr
, streamsize n
)
147 { return read((char*)ptr
, n
); }
148 istream
& read(signed char *ptr
, streamsize n
)
149 { return read((char*)ptr
, n
); }
150 istream
& read(void *ptr
, streamsize n
)
151 { return read((char*)ptr
, n
); }
152 #ifdef _STREAM_COMPAT
153 // [zooey]: added for R5-compatibility with bdb,
154 // these can't be inlined as they wouldn't end up in the lib then.
155 istream
& read(char *ptr
, int n
);
156 istream
& read(unsigned char *ptr
, int n
);
157 istream
& read(signed char *ptr
, int n
);
158 istream
& read(void *ptr
, int n
);
160 istream
& get(streambuf
& sb
, char delim
= '\n');
161 istream
& gets(char **s
, char delim
= '\n');
162 int ipfx(int need
= 0) {
163 if (!good()) { set(ios::failbit
); return 0; }
165 _IO_flockfile(_strbuf
);
166 if (_tie
&& (need
== 0 || rdbuf()->in_avail() < need
)) _tie
->flush();
167 if (!need
&& (flags() & ios::skipws
)) return _skip_ws();
171 int ipfx0() { // Optimized version of ipfx(0).
172 if (!good()) { set(ios::failbit
); return 0; }
174 _IO_flockfile(_strbuf
);
175 if (_tie
) _tie
->flush();
176 if (flags() & ios::skipws
) return _skip_ws();
180 int ipfx1() { // Optimized version of ipfx(1).
181 if (!good()) { set(ios::failbit
); return 0; }
183 _IO_flockfile(_strbuf
);
184 if (_tie
&& rdbuf()->in_avail() == 0) _tie
->flush();
188 void isfx() { _IO_funlockfile(_strbuf
); }
189 int get() { if (!ipfx1()) return EOF
;
190 else { int ch
= _strbuf
->sbumpc();
191 if (ch
== EOF
) set(ios::eofbit
);
196 _IO_size_t
gcount() { return _gcount
; }
197 istream
& ignore(int n
=1, int delim
= EOF
);
199 istream
& seekg(streampos
);
200 istream
& seekg(streamoff
, _seek_dir
);
202 istream
& putback(char ch
) {
203 if (good() && _strbuf
->sputbackc(ch
) == EOF
) clear(ios::badbit
);
206 if (good() && _strbuf
->sungetc() == EOF
) clear(ios::badbit
);
208 istream
& scan(const char *format
...);
209 istream
& vscan(const char *format
, _IO_va_list args
);
210 #ifdef _STREAM_COMPAT
211 istream
& unget(char ch
) { return putback(ch
); }
213 streambuf
* istreambuf() const { return _strbuf
; }
216 istream
& operator>>(char*);
217 istream
& operator>>(unsigned char* p
) { return operator>>((char*)p
); }
218 istream
& operator>>(signed char*p
) { return operator>>((char*)p
); }
219 istream
& operator>>(char& c
);
220 istream
& operator>>(unsigned char& c
) {return operator>>((char&)c
);}
221 istream
& operator>>(signed char& c
) {return operator>>((char&)c
);}
222 istream
& operator>>(int&);
223 istream
& operator>>(long&);
224 #if defined(__GNUC__)
225 __extension__ istream
& operator>>(long long&);
226 __extension__ istream
& operator>>(unsigned long long&);
228 istream
& operator>>(short&);
229 istream
& operator>>(unsigned int&);
230 istream
& operator>>(unsigned long&);
231 istream
& operator>>(unsigned short&);
233 istream
& operator>>(bool&);
235 istream
& operator>>(float&);
236 istream
& operator>>(double&);
237 istream
& operator>>(long double&);
238 istream
& operator>>( __manip func
) {(*func
)(*this); return *this;}
239 istream
& operator>>(__imanip func
) { return (*func
)(*this); }
240 istream
& operator>>(streambuf
*);
243 class iostream
: public istream
, public ostream
247 iostream(streambuf
* sb
, ostream
*tied
=NULL
);
250 class _IO_istream_withassign
: public istream
{
252 _IO_istream_withassign
& operator=(istream
&);
253 _IO_istream_withassign
& operator=(_IO_istream_withassign
& rhs
)
254 { return operator= (static_cast<istream
&> (rhs
)); }
257 class _IO_ostream_withassign
: public ostream
{
259 _IO_ostream_withassign
& operator=(ostream
&);
260 _IO_ostream_withassign
& operator=(_IO_ostream_withassign
& rhs
)
261 { return operator= (static_cast<ostream
&> (rhs
)); }
264 extern _IO_istream_withassign cin
;
265 // clog->rdbuf() == cerr->rdbuf()
266 extern _IO_ostream_withassign cout
, cerr
;
268 extern _IO_ostream_withassign clog
270 __asm__ ("__IO_clog")
274 extern istream
& lock(istream
& ins
);
275 extern istream
& unlock(istream
& ins
);
276 extern ostream
& lock(ostream
& outs
);
277 extern ostream
& unlock(ostream
& outs
);
279 struct Iostream_init
{ } ; // Compatibility hack for AT&T library.
281 inline ios
& dec(ios
& i
)
282 { i
.setf(ios::dec
, ios::dec
|ios::hex
|ios::oct
); return i
; }
283 inline ios
& hex(ios
& i
)
284 { i
.setf(ios::hex
, ios::dec
|ios::hex
|ios::oct
); return i
; }
285 inline ios
& oct(ios
& i
)
286 { i
.setf(ios::oct
, ios::dec
|ios::hex
|ios::oct
); return i
; }
289 #endif /*!_IOSTREAM_H*/