1 // Output streams -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
32 // ISO C++ 14882: 27.6.2 Output streams
36 * This is a Standard C++ Library header. You should @c #include this header
37 * in your programs, rather than any of the "st[dl]_*.h" implementation files.
41 #define _CPP_OSTREAM 1
43 #pragma GCC system_header
49 // 27.6.2.1 Template class basic_ostream
50 template<typename _CharT
, typename _Traits
>
51 class basic_ostream
: virtual public basic_ios
<_CharT
, _Traits
>
54 // Types (inherited from basic_ios (27.4.4)):
55 typedef _CharT char_type
;
56 typedef typename
_Traits::int_type int_type
;
57 typedef typename
_Traits::pos_type pos_type
;
58 typedef typename
_Traits::off_type off_type
;
59 typedef _Traits traits_type
;
61 // Non-standard Types:
62 typedef basic_streambuf
<_CharT
, _Traits
> __streambuf_type
;
63 typedef basic_ios
<_CharT
, _Traits
> __ios_type
;
64 typedef basic_ostream
<_CharT
, _Traits
> __ostream_type
;
65 typedef ostreambuf_iterator
<_CharT
, _Traits
> __ostreambuf_iter
;
66 typedef num_put
<_CharT
, __ostreambuf_iter
> __numput_type
;
67 typedef ctype
<_CharT
> __ctype_type
;
69 // 27.6.2.2 Constructor/destructor:
71 basic_ostream(__streambuf_type
* __sb
)
77 // 27.6.2.3 Prefix/suffix:
81 // 27.6.2.5 Formatted output:
82 // 27.6.2.5.3 basic_ostream::operator<<
84 operator<<(__ostream_type
& (*__pf
)(__ostream_type
&));
87 operator<<(__ios_type
& (*__pf
)(__ios_type
&));
90 operator<<(ios_base
& (*__pf
) (ios_base
&));
92 // 27.6.2.5.2 Arithmetic Inserters
97 operator<<(unsigned long __n
);
100 operator<<(bool __n
);
103 operator<<(short __n
)
105 ios_base::fmtflags __fmt
= this->flags() & ios_base::basefield
;
106 if (__fmt
& ios_base::oct
|| __fmt
& ios_base::hex
)
107 return this->operator<<(static_cast<unsigned long>
108 (static_cast<unsigned short>(__n
)));
110 return this->operator<<(static_cast<long>(__n
));
114 operator<<(unsigned short __n
)
115 { return this->operator<<(static_cast<unsigned long>(__n
)); }
120 ios_base::fmtflags __fmt
= this->flags() & ios_base::basefield
;
121 if (__fmt
& ios_base::oct
|| __fmt
& ios_base::hex
)
122 return this->operator<<(static_cast<unsigned long>
123 (static_cast<unsigned int>(__n
)));
125 return this->operator<<(static_cast<long>(__n
));
129 operator<<(unsigned int __n
)
130 { return this->operator<<(static_cast<unsigned long>(__n
)); }
132 #ifdef _GLIBCPP_USE_LONG_LONG
134 operator<<(long long __n
);
137 operator<<(unsigned long long __n
);
141 operator<<(double __f
);
144 operator<<(float __f
)
145 { return this->operator<<(static_cast<double>(__f
)); }
148 operator<<(long double __f
);
151 operator<<(const void* __p
);
154 operator<<(__streambuf_type
* __sb
);
156 // Unformatted output:
161 write(const char_type
* __s
, streamsize __n
);
174 seekp(off_type
, ios_base::seekdir
);
177 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
178 // Not defined. (Side effect of DR 50.)
180 operator=(const __ostream_type
&);
182 basic_ostream(const __ostream_type
&);
186 // 27.6.2.3 Class basic_ostream::sentry
187 template <typename _CharT
, typename _Traits
>
188 class basic_ostream
<_CharT
, _Traits
>::sentry
192 basic_ostream
<_CharT
,_Traits
>& _M_os
;
196 sentry(basic_ostream
<_CharT
,_Traits
>& __os
);
201 if (_M_os
.flags() & ios_base::unitbuf
&& !uncaught_exception())
203 // Can't call flush directly or else will get into recursive lock.
204 if (_M_os
.rdbuf() && _M_os
.rdbuf()->pubsync() == -1)
205 _M_os
.setstate(ios_base::badbit
);
213 template<typename _CharT
, typename _Traits
>
214 basic_ostream
<_CharT
, _Traits
>&
215 operator<<(basic_ostream
<_CharT
, _Traits
>& __out
, _CharT __c
);
217 template<typename _CharT
, typename _Traits
>
218 basic_ostream
<_CharT
, _Traits
>&
219 operator<<(basic_ostream
<_CharT
, _Traits
>& __out
, char __c
)
220 { return (__out
<< __out
.widen(__c
)); }
223 template <class _Traits
>
224 basic_ostream
<char, _Traits
>&
225 operator<<(basic_ostream
<char, _Traits
>& __out
, char __c
);
227 // Signed and unsigned
228 template<class _Traits
>
229 basic_ostream
<char, _Traits
>&
230 operator<<(basic_ostream
<char, _Traits
>& __out
, signed char __c
)
231 { return (__out
<< static_cast<char>(__c
)); }
233 template<class _Traits
>
234 basic_ostream
<char, _Traits
>&
235 operator<<(basic_ostream
<char, _Traits
>& __out
, unsigned char __c
)
236 { return (__out
<< static_cast<char>(__c
)); }
238 template<typename _CharT
, typename _Traits
>
239 basic_ostream
<_CharT
, _Traits
>&
240 operator<<(basic_ostream
<_CharT
, _Traits
>& __out
, const _CharT
* __s
);
242 template<typename _CharT
, typename _Traits
>
243 basic_ostream
<_CharT
, _Traits
> &
244 operator<<(basic_ostream
<_CharT
, _Traits
>& __out
, const char* __s
);
246 // Partial specializationss
247 template<class _Traits
>
248 basic_ostream
<char, _Traits
>&
249 operator<<(basic_ostream
<char, _Traits
>& __out
, const char* __s
);
251 // Signed and unsigned
252 template<class _Traits
>
253 basic_ostream
<char, _Traits
>&
254 operator<<(basic_ostream
<char, _Traits
>& __out
, const signed char* __s
)
255 { return (__out
<< reinterpret_cast<const char*>(__s
)); }
257 template<class _Traits
>
258 basic_ostream
<char, _Traits
> &
259 operator<<(basic_ostream
<char, _Traits
>& __out
, const unsigned char* __s
)
260 { return (__out
<< reinterpret_cast<const char*>(__s
)); }
262 // 27.6.2.7 Standard basic_ostream manipulators
263 template<typename _CharT
, typename _Traits
>
264 basic_ostream
<_CharT
, _Traits
>&
265 endl(basic_ostream
<_CharT
, _Traits
>& __os
)
266 { return flush(__os
.put(__os
.widen('\n'))); }
268 template<typename _CharT
, typename _Traits
>
269 basic_ostream
<_CharT
, _Traits
>&
270 ends(basic_ostream
<_CharT
, _Traits
>& __os
)
271 { return __os
.put(_CharT()); }
273 template<typename _CharT
, typename _Traits
>
274 basic_ostream
<_CharT
, _Traits
>&
275 flush(basic_ostream
<_CharT
, _Traits
>& __os
)
276 { return __os
.flush(); }
280 #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
282 #ifdef _GLIBCPP_FULLY_COMPLIANT_HEADERS
283 # include <bits/ostream.tcc>
287 #endif /* _CPP_OSTREAM */