OSDN Git Service

* Makefile.in (c-decl.o): Depends on defaults.h.
[pf3gnuchains/gcc-fork.git] / libio / iostream.h
1 /*  This is part of libio/iostream, providing -*- C++ -*- input/output.
2 Copyright (C) 1993 Free Software Foundation
3
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.
9
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.
14
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.
18
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. */
24
25 #ifndef _IOSTREAM_H
26 #ifdef __GNUG__
27 #pragma interface
28 #endif
29 #define _IOSTREAM_H
30
31 #include <streambuf.h>
32
33 extern "C++" {
34 class istream; class ostream;
35 typedef ios& (*__manip)(ios&);
36 typedef istream& (*__imanip)(istream&);
37 typedef ostream& (*__omanip)(ostream&);
38
39 extern istream& ws(istream& ins);
40 extern ostream& flush(ostream& outs);
41 extern ostream& endl(ostream& outs);
42 extern ostream& ends(ostream& outs);
43
44 class ostream : virtual public ios
45 {
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;
53         else { if (_tie) _tie->flush(); _IO_flockfile(_strbuf); return 1;} }
54     void osfx() { _IO_funlockfile(_strbuf);
55                   if (flags() & (ios::unitbuf|ios::stdio))
56                       do_osfx(); }
57     ostream& flush();
58     ostream& put(char c) { _strbuf->sputc(c); return *this; }
59 #ifdef _STREAM_COMPAT
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); }
63 #endif
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);}
71     ostream& seekp(streampos);
72     ostream& seekp(streamoff, _seek_dir);
73     streampos tellp();
74     ostream& form(const char *format ...);
75     ostream& vform(const char *format, _IO_va_list args);
76
77     ostream& operator<<(char c);
78     ostream& operator<<(unsigned char c) { return (*this) << (char)c; }
79     ostream& operator<<(signed char c) { return (*this) << (char)c; }
80     ostream& operator<<(const char *s);
81     ostream& operator<<(const unsigned char *s)
82         { return (*this) << (const char*)s; }
83     ostream& operator<<(const signed char *s)
84         { return (*this) << (const char*)s; }
85     ostream& operator<<(const void *p);
86     ostream& operator<<(int n);
87     ostream& operator<<(unsigned int n);
88     ostream& operator<<(long n);
89     ostream& operator<<(unsigned long n);
90 #if defined(__GNUC__)
91     __extension__ ostream& operator<<(long long n);
92     __extension__ ostream& operator<<(unsigned long long n);
93 #endif
94     ostream& operator<<(short n) {return operator<<((int)n);}
95     ostream& operator<<(unsigned short n) {return operator<<((unsigned int)n);}
96 #if _G_HAVE_BOOL
97     ostream& operator<<(bool b) { return operator<<((int)b); }
98 #endif
99     ostream& operator<<(double n);
100     ostream& operator<<(float n) { return operator<<((double)n); }
101 #if _G_HAVE_LONG_DOUBLE_IO
102     ostream& operator<<(long double n);
103 #else
104     ostream& operator<<(long double n) { return operator<<((double)n); }
105 #endif
106     ostream& operator<<(__omanip func) { return (*func)(*this); }
107     ostream& operator<<(__manip func) {(*func)(*this); return *this;}
108     ostream& operator<<(streambuf*);
109 #ifdef _STREAM_COMPAT
110     streambuf* ostreambuf() const { return _strbuf; }
111 #endif
112 };
113
114 class istream : virtual public ios
115 {
116     // NOTE: If fields are changed, you must fix _fake_istream in stdstreams.C!
117 protected:
118     _IO_size_t _gcount;
119
120     int _skip_ws();
121   public:
122     istream(): _gcount (0) { }
123     istream(streambuf* sb, ostream*tied=NULL);
124     istream& get(char* ptr, int len, char delim = '\n');
125     istream& get(unsigned char* ptr, int len, char delim = '\n')
126         { return get((char*)ptr, len, delim); }
127     istream& get(char& c);
128     istream& get(unsigned char& c) { return get((char&)c); }
129     istream& getline(char* ptr, int len, char delim = '\n');
130     istream& getline(unsigned char* ptr, int len, char delim = '\n')
131         { return getline((char*)ptr, len, delim); }
132     istream& get(signed char& c)  { return get((char&)c); }
133     istream& get(signed char* ptr, int len, char delim = '\n')
134         { return get((char*)ptr, len, delim); }
135     istream& getline(signed char* ptr, int len, char delim = '\n')
136         { return getline((char*)ptr, len, delim); }
137     istream& read(char *ptr, streamsize n);
138     istream& read(unsigned char *ptr, streamsize n)
139       { return read((char*)ptr, n); }
140     istream& read(signed char *ptr, streamsize n)
141       { return read((char*)ptr, n); }
142     istream& read(void *ptr, streamsize n)
143       { return read((char*)ptr, n); }
144     istream& get(streambuf& sb, char delim = '\n');
145     istream& gets(char **s, char delim = '\n');
146     int ipfx(int need = 0) {
147         if (!good()) { set(ios::failbit); return 0; }
148         else {
149           _IO_flockfile(_strbuf);
150           if (_tie && (need == 0 || rdbuf()->in_avail() < need)) _tie->flush();
151           if (!need && (flags() & ios::skipws)) return _skip_ws();
152           else return 1;
153         }
154     }
155     int ipfx0() { // Optimized version of ipfx(0).
156         if (!good()) { set(ios::failbit); return 0; }
157         else {
158           _IO_flockfile(_strbuf);
159           if (_tie) _tie->flush();
160           if (flags() & ios::skipws) return _skip_ws();
161           else return 1;
162         }
163     }
164     int ipfx1() { // Optimized version of ipfx(1).
165         if (!good()) { set(ios::failbit); return 0; }
166         else {
167           _IO_flockfile(_strbuf);
168           if (_tie && rdbuf()->in_avail() == 0) _tie->flush();
169           return 1;
170         }
171     }
172     void isfx() { _IO_funlockfile(_strbuf); }
173     int get() { if (!ipfx1()) return EOF;
174                 else { int ch = _strbuf->sbumpc();
175                        if (ch == EOF) set(ios::eofbit);
176                        return ch;
177                      } }
178     int peek();
179     _IO_size_t gcount() { return _gcount; }
180     istream& ignore(int n=1, int delim = EOF);
181     int sync ();
182     istream& seekg(streampos);
183     istream& seekg(streamoff, _seek_dir);
184     streampos tellg();
185     istream& putback(char ch) {
186         if (good() && _strbuf->sputbackc(ch) == EOF) clear(ios::badbit);
187         return *this;}
188     istream& unget() {
189         if (good() && _strbuf->sungetc() == EOF) clear(ios::badbit);
190         return *this;}
191     istream& scan(const char *format ...);
192     istream& vscan(const char *format, _IO_va_list args);
193 #ifdef _STREAM_COMPAT
194     istream& unget(char ch) { return putback(ch); }
195     int skip(int i);
196     streambuf* istreambuf() const { return _strbuf; }
197 #endif
198
199     istream& operator>>(char*);
200     istream& operator>>(unsigned char* p) { return operator>>((char*)p); }
201     istream& operator>>(signed char*p) { return operator>>((char*)p); }
202     istream& operator>>(char& c);
203     istream& operator>>(unsigned char& c) {return operator>>((char&)c);}
204     istream& operator>>(signed char& c) {return operator>>((char&)c);}
205     istream& operator>>(int&);
206     istream& operator>>(long&);
207 #if defined(__GNUC__)
208     __extension__ istream& operator>>(long long&);
209     __extension__ istream& operator>>(unsigned long long&);
210 #endif
211     istream& operator>>(short&);
212     istream& operator>>(unsigned int&);
213     istream& operator>>(unsigned long&);
214     istream& operator>>(unsigned short&);
215 #if _G_HAVE_BOOL
216     istream& operator>>(bool&);
217 #endif
218     istream& operator>>(float&);
219     istream& operator>>(double&);
220     istream& operator>>(long double&);
221     istream& operator>>( __manip func) {(*func)(*this); return *this;}
222     istream& operator>>(__imanip func) { return (*func)(*this); }
223     istream& operator>>(streambuf*);
224 };
225
226 class iostream : public istream, public ostream
227 {
228   public:
229     iostream() { }
230     iostream(streambuf* sb, ostream*tied=NULL);
231 };
232
233 class _IO_istream_withassign : public istream {
234 public:
235   _IO_istream_withassign& operator=(istream&);
236   _IO_istream_withassign& operator=(_IO_istream_withassign& rhs)
237     { return operator= (static_cast<istream&> (rhs)); }
238 };
239
240 class _IO_ostream_withassign : public ostream {
241 public:
242   _IO_ostream_withassign& operator=(ostream&);
243   _IO_ostream_withassign& operator=(_IO_ostream_withassign& rhs)
244     { return operator= (static_cast<ostream&> (rhs)); }
245 };
246
247 extern _IO_istream_withassign cin;
248 // clog->rdbuf() == cerr->rdbuf()
249 extern _IO_ostream_withassign cout, cerr;
250
251 extern _IO_ostream_withassign clog
252 #if _G_CLOG_CONFLICT
253 __asm__ ("__IO_clog")
254 #endif
255 ;
256
257 extern istream& lock(istream& ins);
258 extern istream& unlock(istream& ins);
259 extern ostream& lock(ostream& outs);
260 extern ostream& unlock(ostream& outs);
261
262 struct Iostream_init { } ;  // Compatibility hack for AT&T library.
263
264 inline ios& dec(ios& i)
265 { i.setf(ios::dec, ios::dec|ios::hex|ios::oct); return i; }
266 inline ios& hex(ios& i)
267 { i.setf(ios::hex, ios::dec|ios::hex|ios::oct); return i; }
268 inline ios& oct(ios& i)
269 { i.setf(ios::oct, ios::dec|ios::hex|ios::oct); return i; }
270 } // extern "C++"
271
272 #endif /*!_IOSTREAM_H*/