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 /* ostream.h now separately includable */
35 /* uncomment the next line to disable ostream << char */
36 //#define NO_OUTPUT_CHAR
40 #include <streambuf.h>
51 state_value state
; // _good/_eof/_fail/_bad
52 char ownbuf
; // true if we own *bp
55 ostream(const char* filename
, io_mode m
, access_mode a
);
56 ostream(const char* filename
, const char* m
);
57 ostream(int filedesc
, io_mode m
);
58 ostream(FILE* fileptr
);
59 ostream(int sz
, char* buf
);
60 ostream(int filedesc
, char* buf
, int buflen
);
61 ostream(int filedesc
);
62 ostream(streambuf
* s
);
66 ostream
& open(const char* filename
, io_mode m
, access_mode a
);
67 ostream
& open(const char* filename
, const char* m
);
68 ostream
& open(int filedesc
, io_mode m
);
69 ostream
& open(FILE* fileptr
);
70 ostream
& open(const char* filenam
, open_mode m
);
83 // other status queries
99 void clear(state_value f
= _good
); // poorly named
100 void set(state_value f
); // set corresponding bit
101 void unset(state_value
); // clear corresponding bit
102 ostream
& failif(int cond
);
106 ostream
& put(char c
);
107 ostream
& put(const char* s
);
108 ostream
& put(const char* s
, int slen
);
112 ostream
& form(const char* fmt
, ...);
114 ostream
& operator << (short n
);
115 ostream
& operator << (unsigned short n
);
116 ostream
& operator << (int n
);
117 ostream
& operator << (unsigned int n
);
118 ostream
& operator << (long n
);
119 ostream
& operator << (unsigned long n
);
121 ostream
& operator << (long long n
);
122 ostream
& operator << (unsigned long long n
);
124 ostream
& operator << (float n
);
125 ostream
& operator << (double n
);
126 ostream
& operator << (const char* s
);
127 ostream
& operator << (const void* ptr
);
129 #ifndef NO_OUTPUT_CHAR
130 ostream
& operator << (char c
);
135 extern ostream cout
; // stdout
136 extern ostream cerr
; // stderr
138 #if defined(__OPTIMIZE__) || defined(USE_LIBGXX_INLINES)
141 inline void ostream::clear(state_value flag
)
146 inline void ostream::set(state_value flag
)
148 state
= state_value(int(state
) | int(flag
));
151 inline void ostream::unset(state_value flag
)
153 state
= state_value(int(state
) & ~int(flag
));
156 inline int ostream::rdstate()
161 inline int ostream::good()
163 return state
== _good
;
166 inline int ostream::eof()
168 return int(state
) & int(_eof
);
171 inline int ostream::fail()
173 return int(state
) & int(_fail
);
176 inline int ostream::bad()
178 return int(state
) & int(_bad
);
181 inline ostream::operator void*()
183 return (state
== _good
)? this : 0;
186 inline int ostream::operator !()
188 return (state
!= _good
);
191 inline ostream
& ostream::failif(int cond
)
193 if (cond
) set(_fail
); return *this;
196 inline int ostream::is_open()
198 return bp
->is_open();
201 inline int ostream::readable()
206 inline int ostream::writable()
208 return (bp
!= 0) && (state
== _good
);
212 inline char* ostream::bufptr()
217 inline ostream
& ostream::flush()
219 bp
->overflow(); return *this;
222 inline ostream
& ostream::close()
224 bp
->overflow(); bp
->close(); return *this;
227 inline ostream
& ostream::put(char ch
)
229 return failif((state
!= _good
) || bp
->sputc((int)ch
&0xff) == EOF
);
232 #ifndef NO_OUTPUT_CHAR
233 inline ostream
& ostream::operator << (char ch
)
235 return failif((state
!= _good
) || bp
->sputc((int)ch
&0xff) == EOF
);
239 inline ostream
& ostream::put(const char* s
)
241 return failif((state
!= _good
) || bp
->sputs(s
) == EOF
);
244 inline ostream
& ostream::put(const char* s
, int len
)
246 return failif((state
!= _good
) || bp
->sputsn(s
, len
) == EOF
);
249 inline ostream
& ostream::operator << (const char* s
)
251 return failif((state
!= _good
) || bp
->sputs(s
) == EOF
);