1 // This may look like C code, but it is really -*- C++ -*-
3 Copyright (C) 1989 Free Software Foundation
4 written by Doug Lea (dl@rocky.oswego.edu)
6 This file is part of GNU CC.
8 GNU CC is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY. No author or distributor
10 accepts responsibility to anyone for the consequences of using it
11 or for whether it serves any particular purpose or works at all,
12 unless he says so in writing. Refer to the GNU CC General Public
13 License for full details.
15 Everyone is granted permission to copy, modify and redistribute
16 GNU CC, but only under the conditions described in the
17 GNU CC General Public License. A copy of this license is
18 supposed to have been given to you along with GNU CC so you
19 can know your rights and responsibilities. It should be in a
20 file named COPYING. Among other things, the copyright notice
21 and this notice must be preserved on all copies.
24 /* *** Version 1.2 -- nearly 100% AT&T 1.2 compatible *** */
26 /* istream.h now separately includable */
37 #include <streambuf.h>
41 class whitespace
// a class used only to input and
42 { // discard white space characters
50 friend void eatwhite(istream
& s
);
53 state_value state
; // _good/_eof/_fail/_bad
58 char* readline (int chunk_number
, char terminator
);
61 istream(const char* filename
, io_mode m
, access_mode a
,
62 int sk
=1, ostream
* t
= 0);
63 istream(const char* filename
, const char* m
,
64 int sk
=1, ostream
* t
= 0);
65 istream(int filedesc
, io_mode m
, int sk
=1, ostream
* t
= 0);
66 istream(FILE* fileptr
, int sk
=1, ostream
* t
= 0);
67 istream(int sz
, char* buf
, int sk
=1, ostream
* t
= 0);
68 istream(int filedesc
, int sk
=1, ostream
* t
= 0);
69 istream(int filedesc
, char* buf
, int buflen
,
70 int sk
, ostream
* t
= 0);
71 istream(streambuf
* s
, int sk
=1, ostream
* t
= 0);
75 istream
& open(const char* filename
, io_mode m
, access_mode a
);
76 istream
& open(const char* filename
, const char* m
);
77 istream
& open(int filedesc
, io_mode m
);
78 istream
& open(FILE* fileptr
);
79 istream
& open(const char* filenam
, open_mode m
);
83 ostream
* tie(ostream
* s
);
94 // other status queries
110 void clear(state_value f
= _good
); // poorly named
111 void set(state_value f
); // set corresponding bit
112 void unset(state_value f
); // clear corresponding bit
113 istream
& failif(int cond
);
117 istream
& get(char& c
);
118 istream
& unget(char c
);
119 istream
& putback(char c
); // a synonym for unget
121 istream
& get (char* s
, int n
, char terminator
= '\n');
122 istream
& getline(char* s
, int n
, char terminator
= '\n');
123 istream
& gets (char **s
, char terminator
= '\n');
126 istream
& operator >> (char& c
);
127 istream
& operator >> (short& n
);
128 istream
& operator >> (unsigned short& n
);
129 istream
& operator >> (int& n
);
130 istream
& operator >> (unsigned int& n
);
131 istream
& operator >> (long& n
);
132 istream
& operator >> (unsigned long& n
);
134 istream
& operator >> (long long& n
);
135 istream
& operator >> (unsigned long long& n
);
137 istream
& operator >> (float& n
);
138 istream
& operator >> (double& n
);
139 istream
& operator >> (char* s
);
140 istream
& operator >> (whitespace
& w
);
143 // pre-declared streams
145 extern istream cin
; // stdin
147 extern whitespace WS
; // for convenience
149 #if defined(__OPTIMIZE__) || defined(USE_LIBGXX_INLINES)
152 inline void istream::clear(state_value flag
)
157 inline void istream::set(state_value flag
)
159 state
= state_value(int(state
) | int(flag
));
162 inline void istream::unset(state_value flag
)
164 state
= state_value(int(state
) & ~int(flag
));
167 inline int istream::rdstate()
172 inline int istream::good()
174 return state
== _good
;
177 inline int istream::eof()
179 return int(state
) & int(_eof
);
182 inline int istream::fail()
184 return int(state
) & int(_fail
);
187 inline int istream::bad()
189 return int(state
) & int(_bad
);
192 inline istream::operator void*()
194 return (state
== _good
)? this : 0;
197 inline int istream::operator !()
199 return (state
!= _good
);
202 inline istream
& istream::failif(int cond
)
204 if (cond
) set(_fail
); return *this;
207 inline int istream::is_open()
209 return bp
->is_open();
212 inline int istream::readable()
214 return (bp
!= 0) && (bp
->is_open()) && (state
== _good
);
217 inline int istream::writable()
223 inline char* istream::bufptr()
229 inline istream
& istream::close()
231 bp
->close(); return *this;
235 inline int istream::skip(int sk
)
237 int was
= skipws
; skipws
= sk
; return was
;
241 inline istream
& istream::unget(char c
)
243 if (bp
->sputbackc(c
) == EOF
) set(_fail
); return *this;
246 inline istream
& istream::putback(char c
)
248 if (bp
->sputbackc(c
) == EOF
) set(_fail
); return *this;
251 inline void eatwhite(istream
& s
)