1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
// This may look like C code, but it is really -*- C++ -*-
/*
Copyright (C) 1989 Free Software Foundation
written by Doug Lea (dl@rocky.oswego.edu)
This file is part of GNU CC.
GNU CC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY. No author or distributor
accepts responsibility to anyone for the consequences of using it
or for whether it serves any particular purpose or works at all,
unless he says so in writing. Refer to the GNU CC General Public
License for full details.
Everyone is granted permission to copy, modify and redistribute
GNU CC, but only under the conditions described in the
GNU CC General Public License. A copy of this license is
supposed to have been given to you along with GNU CC so you
can know your rights and responsibilities. It should be in a
file named COPYING. Among other things, the copyright notice
and this notice must be preserved on all copies.
*/
/* *** Version 1.2 -- nearly 100% AT&T 1.2 compatible *** */
/* istream.h now separately includable */
#ifndef _istream_h
#ifdef __GNUG__
#pragma once
#pragma interface
#endif
#define _istream_h 1
#include <File.h>
#include <streambuf.h>
#include <filebuf.h>
#include <Filebuf.h>
class whitespace // a class used only to input and
{ // discard white space characters
char filler;
};
class ostream;
class istream
{
friend void eatwhite(istream& s);
protected:
streambuf* bp;
state_value state; // _good/_eof/_fail/_bad
ostream* tied_to;
char skipws;
char ownbuf;
void _flush();
char* readline (int chunk_number, char terminator);
public:
istream(const char* filename, io_mode m, access_mode a,
int sk=1, ostream* t = 0);
istream(const char* filename, const char* m,
int sk=1, ostream* t = 0);
istream(int filedesc, io_mode m, int sk=1, ostream* t = 0);
istream(FILE* fileptr, int sk=1, ostream* t = 0);
istream(int sz, char* buf, int sk=1, ostream* t = 0);
istream(int filedesc, int sk=1, ostream* t = 0);
istream(int filedesc, char* buf, int buflen,
int sk, ostream* t = 0);
istream(streambuf* s, int sk=1, ostream* t = 0);
~istream();
istream& open(const char* filename, io_mode m, access_mode a);
istream& open(const char* filename, const char* m);
istream& open(int filedesc, io_mode m);
istream& open(FILE* fileptr);
istream& open(const char* filenam, open_mode m);
istream& close();
ostream* tie(ostream* s);
int skip(int);
// stream status
int rdstate();
int eof();
int fail();
int bad();
int good();
// other status queries
int readable();
int writable();
int is_open();
operator void*();
int operator !();
const char* name();
char* bufptr();
// error handling
void error();
void clear(state_value f = _good); // poorly named
void set(state_value f); // set corresponding bit
void unset(state_value f); // clear corresponding bit
istream& failif(int cond);
// unformatted IO
istream& get(char& c);
istream& unget(char c);
istream& putback(char c); // a synonym for unget
istream& get (char* s, int n, char terminator = '\n');
istream& getline(char* s, int n, char terminator = '\n');
istream& gets (char **s, char terminator = '\n');
istream& operator >> (char& c);
istream& operator >> (short& n);
istream& operator >> (unsigned short& n);
istream& operator >> (int& n);
istream& operator >> (unsigned int& n);
istream& operator >> (long& n);
istream& operator >> (unsigned long& n);
#ifdef __GNUG__
istream& operator >> (long long& n);
istream& operator >> (unsigned long long& n);
#endif
istream& operator >> (float& n);
istream& operator >> (double& n);
istream& operator >> (char* s);
istream& operator >> (whitespace& w);
};
// pre-declared streams
extern istream cin; // stdin
extern whitespace WS; // for convenience
#if defined(__OPTIMIZE__) || defined(USE_LIBGXX_INLINES)
inline void istream::clear(state_value flag)
{
state = flag;
}
inline void istream::set(state_value flag)
{
state = state_value(int(state) | int(flag));
}
inline void istream::unset(state_value flag)
{
state = state_value(int(state) & ~int(flag));
}
inline int istream::rdstate()
{
return int(state);
}
inline int istream::good()
{
return state == _good;
}
inline int istream::eof()
{
return int(state) & int(_eof);
}
inline int istream::fail()
{
return int(state) & int(_fail);
}
inline int istream::bad()
{
return int(state) & int(_bad);
}
inline istream::operator void*()
{
return (state == _good)? this : 0;
}
inline int istream::operator !()
{
return (state != _good);
}
inline istream& istream::failif(int cond)
{
if (cond) set(_fail); return *this;
}
inline int istream::is_open()
{
return bp->is_open();
}
inline int istream::readable()
{
return (bp != 0) && (bp->is_open()) && (state == _good);
}
inline int istream::writable()
{
return 0;
}
inline char* istream::bufptr()
{
return bp->base;
}
inline istream& istream::close()
{
bp->close(); return *this;
}
inline int istream::skip(int sk)
{
int was = skipws; skipws = sk; return was;
}
inline istream& istream::unget(char c)
{
if (bp->sputbackc(c) == EOF) set(_fail); return *this;
}
inline istream& istream::putback(char c)
{
if (bp->sputbackc(c) == EOF) set(_fail); return *this;
}
inline void eatwhite(istream& s)
{
s >> WS;
}
#endif
#endif
|