]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/bits/std_ostream.h
1 // Output streams -*- C++ -*-
3 // Copyright (C) 1997-1999, 2000 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
31 // ISO C++ 14882: 27.6.2 Output streams
35 #define _CPP_OSTREAM 1
37 #include <bits/std_ios.h>
41 // 27.6.2.1 Template class basic_ostream
42 template<typename _CharT
, typename _Traits
>
43 class basic_ostream
: virtual public basic_ios
<_CharT
, _Traits
>
47 // Types (inherited from basic_ios (27.4.4)):
48 typedef _CharT char_type
;
49 typedef typename
_Traits::int_type int_type
;
50 typedef typename
_Traits::pos_type pos_type
;
51 typedef typename
_Traits::off_type off_type
;
52 typedef _Traits traits_type
;
54 // Non-standard Types:
55 typedef basic_streambuf
<_CharT
, _Traits
> __streambuf_type
;
56 typedef basic_ios
<_CharT
, _Traits
> __ios_type
;
57 typedef basic_ostream
<_CharT
, _Traits
> __ostream_type
;
58 typedef ostreambuf_iterator
<_CharT
> __ostreambuf_iter
;
59 typedef num_put
<_CharT
, __ostreambuf_iter
> __numput_type
;
60 typedef ctype
<_CharT
> __ctype_type
;
62 // 27.6.2.2 Constructor/destructor:
64 basic_ostream(__streambuf_type
* __sb
)
69 { _M_fnumput
= NULL
; }
71 // 27.6.2.3 Prefix/suffix:
75 // 27.6.2.5 Formatted output:
76 // 27.6.2.5.3 basic_ostream::operator<<
78 operator<<(__ostream_type
& (*__pf
)(__ostream_type
&));
81 operator<<(__ios_type
& (*__pf
)(__ios_type
&));
84 operator<<(ios_base
& (*__pf
) (ios_base
&));
86 // 27.6.2.5.2 Arithmetic Inserters
91 operator<<(unsigned long __n
);
99 ios_base::fmtflags __fmt
= this->flags() & ios_base::basefield
;
100 if (__fmt
& ios_base::oct
|| __fmt
& ios_base::hex
)
101 return this->operator<<(static_cast<unsigned long>
102 (static_cast<unsigned short>(__n
)));
104 return this->operator<<(static_cast<long>(__n
));
108 operator<<(unsigned short __n
)
109 { return this->operator<<(static_cast<unsigned long>(__n
)); }
114 ios_base::fmtflags __fmt
= this->flags() & ios_base::basefield
;
115 if (__fmt
& ios_base::oct
|| __fmt
& ios_base::hex
)
116 return this->operator<<(static_cast<unsigned long>
117 (static_cast<unsigned int>(__n
)));
119 return this->operator<<(static_cast<long>(__n
));
123 operator<<(unsigned int __n
)
124 { return this->operator<<(static_cast<unsigned long>(__n
)); }
126 #ifdef _GLIBCPP_USE_LONG_LONG
128 operator<<(long long __n
);
131 operator<<(unsigned long long __n
);
135 operator<<(double __f
);
138 operator<<(float __f
)
139 { return this->operator<<(static_cast<double>(__f
)); }
142 operator<<(long double __f
);
145 operator<<(const void* __p
);
148 operator<<(__streambuf_type
* __sb
);
150 // Unformatted output:
155 write(const char_type
* __s
, streamsize __n
);
168 seekp(off_type
, ios_base::seekdir
);
171 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
174 operator=(const __ostream_type
&);
176 basic_ostream(const __ostream_type
&);
180 // 27.6.2.3 Class basic_ostream::sentry
181 template <typename _CharT
, typename _Traits
>
182 class basic_ostream
<_CharT
, _Traits
>::sentry
186 basic_ostream
<_CharT
,_Traits
>& _M_os
;
190 sentry(basic_ostream
<_CharT
,_Traits
>& __os
);
195 if (_M_os
.flags() & ios_base::unitbuf
&& !uncaught_exception())
197 // Can't call flush directly or else will get into recursive lock.
198 if (_M_os
.rdbuf() && _M_os
.rdbuf()->pubsync() == -1)
199 _M_os
.setstate(ios_base::badbit
);
207 template<typename _CharT
, typename _Traits
>
208 basic_ostream
<_CharT
, _Traits
>&
209 operator<<(basic_ostream
<_CharT
, _Traits
>& __out
, _CharT __c
);
211 template<typename _CharT
, typename _Traits
>
212 basic_ostream
<_CharT
, _Traits
>&
213 operator<<(basic_ostream
<_CharT
, _Traits
>& __out
, char __c
)
214 { return (__out
<< __out
.widen(__c
)); }
217 template <class _Traits
>
218 basic_ostream
<char, _Traits
>&
219 operator<<(basic_ostream
<char, _Traits
>& __out
, char __c
);
221 // Signed and unsigned
222 template<class _Traits
>
223 basic_ostream
<char, _Traits
>&
224 operator<<(basic_ostream
<char, _Traits
>& __out
, signed char __c
)
225 { return (__out
<< static_cast<char>(__c
)); }
227 template<class _Traits
>
228 basic_ostream
<char, _Traits
>&
229 operator<<(basic_ostream
<char, _Traits
>& __out
, unsigned char __c
)
230 { return (__out
<< static_cast<char>(__c
)); }
232 template<typename _CharT
, typename _Traits
>
233 basic_ostream
<_CharT
, _Traits
>&
234 operator<<(basic_ostream
<_CharT
, _Traits
>& __out
, const _CharT
* __s
);
236 template<typename _CharT
, typename _Traits
>
237 basic_ostream
<_CharT
, _Traits
> &
238 operator<<(basic_ostream
<_CharT
, _Traits
>& __out
, const char* __s
);
240 // Partial specializationss
241 template<class _Traits
>
242 basic_ostream
<char, _Traits
>&
243 operator<<(basic_ostream
<char, _Traits
>& __out
, const char* __s
);
245 // Signed and unsigned
246 template<class _Traits
>
247 basic_ostream
<char, _Traits
>&
248 operator<<(basic_ostream
<char, _Traits
>& __out
, const signed char* __s
)
249 { return (__out
<< reinterpret_cast<const char*>(__s
)); }
251 template<class _Traits
>
252 basic_ostream
<char, _Traits
> &
253 operator<<(basic_ostream
<char, _Traits
>& __out
, const unsigned char* __s
)
254 { return (__out
<< reinterpret_cast<const char*>(__s
)); }
256 // 27.6.2.7 Standard basic_ostream manipulators
257 template<typename _CharT
, typename _Traits
>
258 basic_ostream
<_CharT
, _Traits
>&
259 endl(basic_ostream
<_CharT
, _Traits
>& __os
)
260 { return flush(__os
.put(__os
.widen('\n'))); }
262 template<typename _CharT
, typename _Traits
>
263 basic_ostream
<_CharT
, _Traits
>&
264 ends(basic_ostream
<_CharT
, _Traits
>& __os
)
265 { return __os
.put(_Traits::_S_eos()); }
267 template<typename _CharT
, typename _Traits
>
268 basic_ostream
<_CharT
, _Traits
>&
269 flush(basic_ostream
<_CharT
, _Traits
>& __os
)
270 { return __os
.flush(); }
274 #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
276 #ifdef _GLIBCPP_FULLY_COMPLIANT_HEADERS
277 # include <bits/ostream.tcc>
281 #endif /* _CPP_OSTREAM */