This commit was manufactured by cvs2svn to create branch 'egcs'.
[official-gcc.git] / libio / iostream.h
blobd663b42430ca09174f5f2c1ca22950a777b45abd
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)
8 any later version.
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. */
25 #ifndef _IOSTREAM_H
26 #ifdef __GNUG__
27 #pragma interface
28 #endif
29 #define _IOSTREAM_H
31 #include <streambuf.h>
33 extern "C++" {
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!
47 void do_osfx();
48 public:
49 ostream() { }
50 ostream(streambuf* sb, ostream* tied=NULL);
51 int opfx() {
52 if (!good()) return 0; else { if (_tie) _tie->flush(); return 1;} }
53 void osfx() { if (flags() & (ios::unitbuf|ios::stdio))
54 do_osfx(); }
55 ostream& flush();
56 ostream& put(char c) { _strbuf->sputc(c); return *this; }
57 #ifdef _STREAM_COMPAT
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); }
61 #endif
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);
71 streampos tellp();
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);
88 #if defined(__GNUC__)
89 __extension__ ostream& operator<<(long long n);
90 __extension__ ostream& operator<<(unsigned long long n);
91 #endif
92 ostream& operator<<(short n) {return operator<<((int)n);}
93 ostream& operator<<(unsigned short n) {return operator<<((unsigned int)n);}
94 #if _G_HAVE_BOOL
95 ostream& operator<<(bool b) { return operator<<((int)b); }
96 #endif
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; }
105 #endif
108 class istream : virtual public ios
110 // NOTE: If fields are changed, you must fix _fake_istream in stdstreams.C!
111 protected:
112 _IO_size_t _gcount;
114 int _skip_ws();
115 public:
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; }
142 else {
143 if (_tie && (need == 0 || rdbuf()->in_avail() < need)) _tie->flush();
144 if (!need && (flags() & ios::skipws)) return _skip_ws();
145 else return 1;
148 int ipfx0() { // Optimized version of ipfx(0).
149 if (!good()) { set(ios::failbit); return 0; }
150 else {
151 if (_tie) _tie->flush();
152 if (flags() & ios::skipws) return _skip_ws();
153 else return 1;
156 int ipfx1() { // Optimized version of ipfx(1).
157 if (!good()) { set(ios::failbit); return 0; }
158 else {
159 if (_tie && rdbuf()->in_avail() == 0) _tie->flush();
160 return 1;
163 void isfx() { }
164 int get() { if (!ipfx1()) return EOF;
165 else { int ch = _strbuf->sbumpc();
166 if (ch == EOF) set(ios::eofbit);
167 return ch;
169 int peek();
170 _IO_size_t gcount() { return _gcount; }
171 istream& ignore(int n=1, int delim = EOF);
172 int sync ();
173 istream& seekg(streampos);
174 istream& seekg(streamoff, _seek_dir);
175 streampos tellg();
176 istream& putback(char ch) {
177 if (good() && _strbuf->sputbackc(ch) == EOF) clear(ios::badbit);
178 return *this;}
179 istream& unget() {
180 if (good() && _strbuf->sungetc() == EOF) clear(ios::badbit);
181 return *this;}
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); }
186 int skip(int i);
187 streambuf* istreambuf() const { return _strbuf; }
188 #endif
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&);
201 #endif
202 istream& operator>>(short&);
203 istream& operator>>(unsigned int&);
204 istream& operator>>(unsigned long&);
205 istream& operator>>(unsigned short&);
206 #if _G_HAVE_BOOL
207 istream& operator>>(bool&);
208 #endif
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
219 public:
220 iostream() { }
221 iostream(streambuf* sb, ostream*tied=NULL);
224 class _IO_istream_withassign : public istream {
225 public:
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 {
232 public:
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
243 #if _G_CLOG_CONFLICT
244 __asm__ ("__IO_clog")
245 #endif
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; }
256 } // extern "C++"
258 #endif /*!_IOSTREAM_H*/