]>
Commit | Line | Data |
---|---|---|
a32e3c09 BK |
1 | // ostream classes -*- C++ -*- |
2 | ||
8d0a564b | 3 | // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003 |
a32e3c09 | 4 | // Free Software Foundation, Inc. |
725dc051 BK |
5 | // |
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) | |
10 | // any later version. | |
11 | ||
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. | |
16 | ||
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, | |
20 | // USA. | |
21 | ||
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. | |
30 | ||
31 | // | |
32 | // ISO C++ 14882: 27.6.2 Output streams | |
33 | // | |
34 | ||
3d7c150e BK |
35 | #ifndef _OSTREAM_TCC |
36 | #define _OSTREAM_TCC 1 | |
37 | ||
3b794528 BK |
38 | #pragma GCC system_header |
39 | ||
54c1bf78 | 40 | #include <locale> |
725dc051 | 41 | |
a16ad779 BK |
42 | namespace std |
43 | { | |
725dc051 BK |
44 | template<typename _CharT, typename _Traits> |
45 | basic_ostream<_CharT, _Traits>::sentry:: | |
12841eb3 | 46 | sentry(basic_ostream<_CharT, _Traits>& __os) |
ff5d863f | 47 | : _M_os(__os) |
725dc051 | 48 | { |
ff5d863f | 49 | // XXX MT |
b7bb6d4a | 50 | if (__os.tie() && __os.good()) |
ff5d863f PC |
51 | __os.tie()->flush(); |
52 | ||
53 | if (__os.good()) | |
54 | _M_ok = true; | |
55 | else | |
56 | { | |
57 | _M_ok = false; | |
58 | __os.setstate(ios_base::failbit); | |
59 | } | |
725dc051 BK |
60 | } |
61 | ||
62 | template<typename _CharT, typename _Traits> | |
63 | basic_ostream<_CharT, _Traits>& | |
64 | basic_ostream<_CharT, _Traits>:: | |
65 | operator<<(__ostream_type& (*__pf)(__ostream_type&)) | |
66 | { | |
5681c890 PR |
67 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
68 | // DR 60. What is a formatted input function? | |
69 | // The inserters for manipulators are *not* formatted output functions. | |
70 | return __pf(*this); | |
725dc051 BK |
71 | } |
72 | ||
73 | template<typename _CharT, typename _Traits> | |
74 | basic_ostream<_CharT, _Traits>& | |
75 | basic_ostream<_CharT, _Traits>:: | |
76 | operator<<(__ios_type& (*__pf)(__ios_type&)) | |
77 | { | |
5681c890 PR |
78 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
79 | // DR 60. What is a formatted input function? | |
80 | // The inserters for manipulators are *not* formatted output functions. | |
81 | __pf(*this); | |
725dc051 BK |
82 | return *this; |
83 | } | |
84 | ||
85 | template<typename _CharT, typename _Traits> | |
86 | basic_ostream<_CharT, _Traits>& | |
87 | basic_ostream<_CharT, _Traits>:: | |
88 | operator<<(ios_base& (*__pf)(ios_base&)) | |
89 | { | |
5681c890 PR |
90 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
91 | // DR 60. What is a formatted input function? | |
92 | // The inserters for manipulators are *not* formatted output functions. | |
93 | __pf(*this); | |
725dc051 BK |
94 | return *this; |
95 | } | |
96 | ||
6cf5465d BK |
97 | template<typename _CharT, typename _Traits> |
98 | basic_ostream<_CharT, _Traits>& | |
12841eb3 BK |
99 | basic_ostream<_CharT, _Traits>:: |
100 | operator<<(bool __n) | |
725dc051 BK |
101 | { |
102 | sentry __cerb(*this); | |
103 | if (__cerb) | |
104 | { | |
12841eb3 | 105 | ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); |
a16ad779 BK |
106 | try |
107 | { | |
2803847d BK |
108 | const __num_put_type& __np = __check_facet(this->_M_num_put); |
109 | if (__np.put(*this, *this, this->fill(), __n).failed()) | |
12841eb3 | 110 | __err |= ios_base::badbit; |
a16ad779 | 111 | } |
06e7ca50 | 112 | catch(...) |
12841eb3 BK |
113 | { this->_M_setstate(ios_base::badbit); } |
114 | this->setstate(__err); | |
725dc051 BK |
115 | } |
116 | return *this; | |
117 | } | |
118 | ||
119 | template<typename _CharT, typename _Traits> | |
120 | basic_ostream<_CharT, _Traits>& | |
12841eb3 BK |
121 | basic_ostream<_CharT, _Traits>:: |
122 | operator<<(long __n) | |
725dc051 BK |
123 | { |
124 | sentry __cerb(*this); | |
125 | if (__cerb) | |
126 | { | |
12841eb3 | 127 | ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); |
a16ad779 BK |
128 | try |
129 | { | |
0cd1de6f | 130 | bool __b = false; |
bfa1e6b1 | 131 | char_type __c = this->fill(); |
a16ad779 | 132 | ios_base::fmtflags __fmt = this->flags() & ios_base::basefield; |
2803847d | 133 | const __num_put_type& __np = __check_facet(this->_M_num_put); |
0cd1de6f | 134 | if ((__fmt & ios_base::oct) || (__fmt & ios_base::hex)) |
bfa1e6b1 | 135 | { |
0cd1de6f | 136 | unsigned long __l = static_cast<unsigned long>(__n); |
2803847d | 137 | __b = __np.put(*this, *this, __c, __l).failed(); |
bfa1e6b1 | 138 | } |
0cd1de6f | 139 | else |
2803847d | 140 | __b = __np.put(*this, *this, __c, __n).failed(); |
0cd1de6f | 141 | if (__b) |
12841eb3 | 142 | __err |= ios_base::badbit; |
a16ad779 | 143 | } |
06e7ca50 | 144 | catch(...) |
12841eb3 BK |
145 | { this->_M_setstate(ios_base::badbit); } |
146 | this->setstate(__err); | |
725dc051 BK |
147 | } |
148 | return *this; | |
149 | } | |
150 | ||
151 | template<typename _CharT, typename _Traits> | |
152 | basic_ostream<_CharT, _Traits>& | |
12841eb3 BK |
153 | basic_ostream<_CharT, _Traits>:: |
154 | operator<<(unsigned long __n) | |
725dc051 BK |
155 | { |
156 | sentry __cerb(*this); | |
157 | if (__cerb) | |
158 | { | |
12841eb3 | 159 | ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); |
a16ad779 BK |
160 | try |
161 | { | |
2803847d BK |
162 | const __num_put_type& __np = __check_facet(this->_M_num_put); |
163 | if (__np.put(*this, *this, this->fill(), __n).failed()) | |
12841eb3 | 164 | __err |= ios_base::badbit; |
a16ad779 | 165 | } |
06e7ca50 | 166 | catch(...) |
12841eb3 BK |
167 | { this->_M_setstate(ios_base::badbit); } |
168 | this->setstate(__err); | |
725dc051 BK |
169 | } |
170 | return *this; | |
171 | } | |
172 | ||
3d7c150e | 173 | #ifdef _GLIBCXX_USE_LONG_LONG |
725dc051 BK |
174 | template<typename _CharT, typename _Traits> |
175 | basic_ostream<_CharT, _Traits>& | |
12841eb3 BK |
176 | basic_ostream<_CharT, _Traits>:: |
177 | operator<<(long long __n) | |
725dc051 BK |
178 | { |
179 | sentry __cerb(*this); | |
180 | if (__cerb) | |
181 | { | |
12841eb3 | 182 | ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); |
a16ad779 BK |
183 | try |
184 | { | |
0cd1de6f | 185 | bool __b = false; |
bfa1e6b1 | 186 | char_type __c = this->fill(); |
a16ad779 | 187 | ios_base::fmtflags __fmt = this->flags() & ios_base::basefield; |
2803847d | 188 | const __num_put_type& __np = __check_facet(this->_M_num_put); |
0cd1de6f | 189 | if ((__fmt & ios_base::oct) || (__fmt & ios_base::hex)) |
bfa1e6b1 | 190 | { |
0cd1de6f BK |
191 | unsigned long long __l; |
192 | __l = static_cast<unsigned long long>(__n); | |
2803847d | 193 | __b = __np.put(*this, *this, __c, __l).failed(); |
bfa1e6b1 | 194 | } |
0cd1de6f | 195 | else |
2803847d | 196 | __b = __np.put(*this, *this, __c, __n).failed(); |
0cd1de6f | 197 | if (__b) |
12841eb3 | 198 | __err |= ios_base::badbit; |
a16ad779 | 199 | } |
06e7ca50 | 200 | catch(...) |
12841eb3 BK |
201 | { this->_M_setstate(ios_base::badbit); } |
202 | this->setstate(__err); | |
725dc051 BK |
203 | } |
204 | return *this; | |
205 | } | |
206 | ||
207 | template<typename _CharT, typename _Traits> | |
208 | basic_ostream<_CharT, _Traits>& | |
12841eb3 BK |
209 | basic_ostream<_CharT, _Traits>:: |
210 | operator<<(unsigned long long __n) | |
725dc051 BK |
211 | { |
212 | sentry __cerb(*this); | |
213 | if (__cerb) | |
214 | { | |
12841eb3 | 215 | ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); |
a16ad779 BK |
216 | try |
217 | { | |
2803847d BK |
218 | const __num_put_type& __np = __check_facet(this->_M_num_put); |
219 | if (__np.put(*this, *this, this->fill(), __n).failed()) | |
12841eb3 | 220 | __err |= ios_base::badbit; |
a16ad779 | 221 | } |
06e7ca50 | 222 | catch(...) |
12841eb3 BK |
223 | { this->_M_setstate(ios_base::badbit); } |
224 | this->setstate(__err); | |
725dc051 BK |
225 | } |
226 | return *this; | |
227 | } | |
228 | #endif | |
a16ad779 | 229 | |
725dc051 BK |
230 | template<typename _CharT, typename _Traits> |
231 | basic_ostream<_CharT, _Traits>& | |
12841eb3 BK |
232 | basic_ostream<_CharT, _Traits>:: |
233 | operator<<(double __n) | |
725dc051 BK |
234 | { |
235 | sentry __cerb(*this); | |
236 | if (__cerb) | |
237 | { | |
12841eb3 | 238 | ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); |
a16ad779 BK |
239 | try |
240 | { | |
2803847d BK |
241 | const __num_put_type& __np = __check_facet(this->_M_num_put); |
242 | if (__np.put(*this, *this, this->fill(), __n).failed()) | |
12841eb3 | 243 | __err |= ios_base::badbit; |
a16ad779 | 244 | } |
06e7ca50 | 245 | catch(...) |
12841eb3 BK |
246 | { this->_M_setstate(ios_base::badbit); } |
247 | this->setstate(__err); | |
725dc051 BK |
248 | } |
249 | return *this; | |
250 | } | |
a16ad779 | 251 | |
725dc051 BK |
252 | template<typename _CharT, typename _Traits> |
253 | basic_ostream<_CharT, _Traits>& | |
12841eb3 BK |
254 | basic_ostream<_CharT, _Traits>:: |
255 | operator<<(long double __n) | |
725dc051 BK |
256 | { |
257 | sentry __cerb(*this); | |
258 | if (__cerb) | |
259 | { | |
12841eb3 | 260 | ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); |
a16ad779 BK |
261 | try |
262 | { | |
2803847d BK |
263 | const __num_put_type& __np = __check_facet(this->_M_num_put); |
264 | if (__np.put(*this, *this, this->fill(), __n).failed()) | |
12841eb3 | 265 | __err |= ios_base::badbit; |
a16ad779 | 266 | } |
06e7ca50 | 267 | catch(...) |
12841eb3 BK |
268 | { this->_M_setstate(ios_base::badbit); } |
269 | this->setstate(__err); | |
725dc051 BK |
270 | } |
271 | return *this; | |
272 | } | |
273 | ||
274 | template<typename _CharT, typename _Traits> | |
275 | basic_ostream<_CharT, _Traits>& | |
12841eb3 BK |
276 | basic_ostream<_CharT, _Traits>:: |
277 | operator<<(const void* __n) | |
725dc051 BK |
278 | { |
279 | sentry __cerb(*this); | |
280 | if (__cerb) | |
281 | { | |
12841eb3 | 282 | ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); |
a16ad779 BK |
283 | try |
284 | { | |
2803847d BK |
285 | const __num_put_type& __np = __check_facet(this->_M_num_put); |
286 | if (__np.put(*this, *this, this->fill(), __n).failed()) | |
12841eb3 | 287 | __err |= ios_base::badbit; |
a16ad779 | 288 | } |
06e7ca50 | 289 | catch(...) |
12841eb3 BK |
290 | { this->_M_setstate(ios_base::badbit); } |
291 | this->setstate(__err); | |
292 | } | |
293 | return *this; | |
294 | } | |
295 | ||
296 | template<typename _CharT, typename _Traits> | |
297 | basic_ostream<_CharT, _Traits>& | |
298 | basic_ostream<_CharT, _Traits>:: | |
299 | operator<<(__streambuf_type* __sbin) | |
300 | { | |
301 | ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); | |
302 | sentry __cerb(*this); | |
303 | if (__cerb && __sbin) | |
304 | { | |
305 | try | |
a16ad779 | 306 | { |
12841eb3 BK |
307 | if (!__copy_streambufs(*this, __sbin, this->rdbuf())) |
308 | __err |= ios_base::failbit; | |
a16ad779 | 309 | } |
12841eb3 BK |
310 | catch(...) |
311 | { this->_M_setstate(ios_base::failbit); } | |
725dc051 | 312 | } |
12841eb3 BK |
313 | else if (!__sbin) |
314 | __err |= ios_base::badbit; | |
315 | this->setstate(__err); | |
725dc051 BK |
316 | return *this; |
317 | } | |
318 | ||
725dc051 BK |
319 | template<typename _CharT, typename _Traits> |
320 | basic_ostream<_CharT, _Traits>& | |
12841eb3 BK |
321 | basic_ostream<_CharT, _Traits>:: |
322 | put(char_type __c) | |
725dc051 | 323 | { |
5681c890 PR |
324 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
325 | // DR 60. What is a formatted input function? | |
326 | // basic_ostream::put(char_type) is an unformatted output function. | |
327 | // DR 63. Exception-handling policy for unformatted output. | |
328 | // Unformatted output functions should catch exceptions thrown | |
329 | // from streambuf members. | |
725dc051 BK |
330 | sentry __cerb(*this); |
331 | if (__cerb) | |
332 | { | |
12841eb3 | 333 | ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); |
5681c890 PR |
334 | try |
335 | { | |
336 | int_type __put = this->rdbuf()->sputc(__c); | |
337 | if (traits_type::eq_int_type(__put, traits_type::eof())) | |
12841eb3 | 338 | __err |= ios_base::badbit; |
5681c890 PR |
339 | } |
340 | catch (...) | |
12841eb3 BK |
341 | { this->_M_setstate(ios_base::badbit); } |
342 | this->setstate(__err); | |
725dc051 | 343 | } |
8d0a564b | 344 | return *this; |
725dc051 BK |
345 | } |
346 | ||
347 | template<typename _CharT, typename _Traits> | |
348 | basic_ostream<_CharT, _Traits>& | |
12841eb3 BK |
349 | basic_ostream<_CharT, _Traits>:: |
350 | write(const _CharT* __s, streamsize __n) | |
725dc051 | 351 | { |
5681c890 PR |
352 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
353 | // DR 60. What is a formatted input function? | |
354 | // basic_ostream::write(const char_type*, streamsize) is an | |
355 | // unformatted output function. | |
356 | // DR 63. Exception-handling policy for unformatted output. | |
357 | // Unformatted output functions should catch exceptions thrown | |
358 | // from streambuf members. | |
725dc051 BK |
359 | sentry __cerb(*this); |
360 | if (__cerb) | |
5681c890 PR |
361 | { |
362 | try | |
363 | { _M_write(__s, __n); } | |
364 | catch (...) | |
12841eb3 | 365 | { this->_M_setstate(ios_base::badbit); } |
5681c890 | 366 | } |
725dc051 BK |
367 | return *this; |
368 | } | |
369 | ||
370 | template<typename _CharT, typename _Traits> | |
371 | basic_ostream<_CharT, _Traits>& | |
12841eb3 BK |
372 | basic_ostream<_CharT, _Traits>:: |
373 | flush() | |
725dc051 | 374 | { |
5681c890 PR |
375 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
376 | // DR 60. What is a formatted input function? | |
377 | // basic_ostream::flush() is *not* an unformatted output function. | |
12841eb3 BK |
378 | ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); |
379 | try | |
380 | { | |
381 | if (this->rdbuf() && this->rdbuf()->pubsync() == -1) | |
382 | __err |= ios_base::badbit; | |
383 | } | |
384 | catch(...) | |
385 | { this->_M_setstate(ios_base::badbit); } | |
386 | this->setstate(__err); | |
725dc051 BK |
387 | return *this; |
388 | } | |
389 | ||
390 | template<typename _CharT, typename _Traits> | |
391 | typename basic_ostream<_CharT, _Traits>::pos_type | |
12841eb3 BK |
392 | basic_ostream<_CharT, _Traits>:: |
393 | tellp() | |
725dc051 BK |
394 | { |
395 | pos_type __ret = pos_type(-1); | |
12841eb3 BK |
396 | try |
397 | { | |
398 | if (!this->fail()) | |
399 | __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out); | |
400 | } | |
401 | catch(...) | |
402 | { this->_M_setstate(ios_base::badbit); } | |
725dc051 BK |
403 | return __ret; |
404 | } | |
405 | ||
725dc051 BK |
406 | template<typename _CharT, typename _Traits> |
407 | basic_ostream<_CharT, _Traits>& | |
12841eb3 BK |
408 | basic_ostream<_CharT, _Traits>:: |
409 | seekp(pos_type __pos) | |
725dc051 | 410 | { |
12841eb3 BK |
411 | ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); |
412 | try | |
d52a9847 | 413 | { |
12841eb3 BK |
414 | if (!this->fail()) |
415 | { | |
416 | // _GLIBCXX_RESOLVE_LIB_DEFECTS | |
417 | // 136. seekp, seekg setting wrong streams? | |
418 | pos_type __p = this->rdbuf()->pubseekpos(__pos, ios_base::out); | |
419 | ||
420 | // 129. Need error indication from seekp() and seekg() | |
421 | if (__p == pos_type(off_type(-1))) | |
422 | __err |= ios_base::failbit; | |
423 | } | |
d52a9847 | 424 | } |
12841eb3 BK |
425 | catch(...) |
426 | { this->_M_setstate(ios_base::badbit); } | |
427 | this->setstate(__err); | |
725dc051 BK |
428 | return *this; |
429 | } | |
430 | ||
431 | template<typename _CharT, typename _Traits> | |
432 | basic_ostream<_CharT, _Traits>& | |
433 | basic_ostream<_CharT, _Traits>:: | |
12841eb3 | 434 | seekp(off_type __off, ios_base::seekdir __dir) |
725dc051 | 435 | { |
12841eb3 BK |
436 | ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); |
437 | try | |
d52a9847 | 438 | { |
12841eb3 BK |
439 | if (!this->fail()) |
440 | { | |
441 | // _GLIBCXX_RESOLVE_LIB_DEFECTS | |
442 | // 136. seekp, seekg setting wrong streams? | |
443 | pos_type __p = this->rdbuf()->pubseekoff(__off, __dir, | |
444 | ios_base::out); | |
445 | ||
446 | // 129. Need error indication from seekp() and seekg() | |
447 | if (__p == pos_type(off_type(-1))) | |
448 | __err |= ios_base::failbit; | |
449 | } | |
037cfe71 | 450 | } |
12841eb3 BK |
451 | catch(...) |
452 | { this->_M_setstate(ios_base::badbit); } | |
453 | this->setstate(__err); | |
725dc051 BK |
454 | return *this; |
455 | } | |
456 | ||
b6a95741 | 457 | // 27.6.2.5.4 Character inserters. |
725dc051 BK |
458 | template<typename _CharT, typename _Traits> |
459 | basic_ostream<_CharT, _Traits>& | |
460 | operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c) | |
461 | { | |
462 | typedef basic_ostream<_CharT, _Traits> __ostream_type; | |
bcd0cabb | 463 | typename __ostream_type::sentry __cerb(__out); |
725dc051 BK |
464 | if (__cerb) |
465 | { | |
a16ad779 BK |
466 | try |
467 | { | |
6b61bca4 | 468 | const streamsize __w = __out.width(); |
a16ad779 | 469 | streamsize __len = 1; |
6b61bca4 | 470 | _CharT* __cs = &__c; |
a16ad779 BK |
471 | if (__w > __len) |
472 | { | |
6b61bca4 PC |
473 | __cs = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) |
474 | * __w)); | |
475 | __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs, | |
f13a69ec | 476 | &__c, __w, __len, false); |
a16ad779 BK |
477 | __len = __w; |
478 | } | |
6b61bca4 | 479 | __out._M_write(__cs, __len); |
a16ad779 BK |
480 | __out.width(0); |
481 | } | |
06e7ca50 | 482 | catch(...) |
12841eb3 | 483 | { __out._M_setstate(ios_base::badbit); } |
725dc051 BK |
484 | } |
485 | return __out; | |
486 | } | |
a16ad779 | 487 | |
b6a95741 | 488 | // Specializations. |
725dc051 BK |
489 | template <class _Traits> |
490 | basic_ostream<char, _Traits>& | |
491 | operator<<(basic_ostream<char, _Traits>& __out, char __c) | |
492 | { | |
493 | typedef basic_ostream<char, _Traits> __ostream_type; | |
bcd0cabb | 494 | typename __ostream_type::sentry __cerb(__out); |
725dc051 BK |
495 | if (__cerb) |
496 | { | |
a16ad779 BK |
497 | try |
498 | { | |
6b61bca4 | 499 | const streamsize __w = __out.width(); |
a16ad779 | 500 | streamsize __len = 1; |
6b61bca4 | 501 | char* __cs = &__c; |
a16ad779 BK |
502 | if (__w > __len) |
503 | { | |
6b61bca4 PC |
504 | __cs = static_cast<char*>(__builtin_alloca(__w)); |
505 | __pad<char, _Traits>::_S_pad(__out, __out.fill(), __cs, | |
f13a69ec | 506 | &__c, __w, __len, false); |
a16ad779 BK |
507 | __len = __w; |
508 | } | |
6b61bca4 | 509 | __out._M_write(__cs, __len); |
a16ad779 BK |
510 | __out.width(0); |
511 | } | |
06e7ca50 | 512 | catch(...) |
12841eb3 | 513 | { __out._M_setstate(ios_base::badbit); } |
725dc051 BK |
514 | } |
515 | return __out; | |
516 | } | |
517 | ||
518 | template<typename _CharT, typename _Traits> | |
519 | basic_ostream<_CharT, _Traits>& | |
520 | operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s) | |
521 | { | |
522 | typedef basic_ostream<_CharT, _Traits> __ostream_type; | |
bcd0cabb | 523 | typename __ostream_type::sentry __cerb(__out); |
52f02d94 | 524 | if (__cerb && __s) |
725dc051 | 525 | { |
a16ad779 BK |
526 | try |
527 | { | |
6b61bca4 | 528 | const streamsize __w = __out.width(); |
52f02d94 | 529 | streamsize __len = static_cast<streamsize>(_Traits::length(__s)); |
a16ad779 BK |
530 | if (__w > __len) |
531 | { | |
6b61bca4 PC |
532 | _CharT* __cs = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) |
533 | * __w)); | |
534 | __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs, | |
f13a69ec | 535 | __s, __w, __len, false); |
6b61bca4 | 536 | __s = __cs; |
a16ad779 BK |
537 | __len = __w; |
538 | } | |
8d0a564b | 539 | __out._M_write(__s, __len); |
a16ad779 BK |
540 | __out.width(0); |
541 | } | |
06e7ca50 | 542 | catch(...) |
12841eb3 | 543 | { __out._M_setstate(ios_base::badbit); } |
725dc051 | 544 | } |
52f02d94 BK |
545 | else if (!__s) |
546 | __out.setstate(ios_base::badbit); | |
725dc051 BK |
547 | return __out; |
548 | } | |
549 | ||
550 | template<typename _CharT, typename _Traits> | |
551 | basic_ostream<_CharT, _Traits>& | |
552 | operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s) | |
553 | { | |
554 | typedef basic_ostream<_CharT, _Traits> __ostream_type; | |
f5677b15 PC |
555 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
556 | // 167. Improper use of traits_type::length() | |
557 | // Note that this is only in 'Review' status. | |
7bd9b6d4 | 558 | typedef char_traits<char> __traits_type; |
bcd0cabb | 559 | typename __ostream_type::sentry __cerb(__out); |
52f02d94 | 560 | if (__cerb && __s) |
725dc051 | 561 | { |
52f02d94 | 562 | size_t __clen = __traits_type::length(__s); |
6b61bca4 PC |
563 | _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) |
564 | * __clen)); | |
7bd9b6d4 | 565 | for (size_t __i = 0; __i < __clen; ++__i) |
725dc051 BK |
566 | __ws[__i] = __out.widen(__s[__i]); |
567 | _CharT* __str = __ws; | |
568 | ||
a16ad779 BK |
569 | try |
570 | { | |
6b61bca4 | 571 | const streamsize __w = __out.width(); |
a16ad779 | 572 | streamsize __len = static_cast<streamsize>(__clen); |
a16ad779 BK |
573 | if (__w > __len) |
574 | { | |
6b61bca4 PC |
575 | _CharT* __cs = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) |
576 | * __w)); | |
577 | __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs, | |
f13a69ec | 578 | __ws, __w, __len, false); |
6b61bca4 | 579 | __str = __cs; |
a16ad779 BK |
580 | __len = __w; |
581 | } | |
8d0a564b | 582 | __out._M_write(__str, __len); |
a16ad779 BK |
583 | __out.width(0); |
584 | } | |
06e7ca50 | 585 | catch(...) |
12841eb3 | 586 | { __out._M_setstate(ios_base::badbit); } |
725dc051 | 587 | } |
52f02d94 BK |
588 | else if (!__s) |
589 | __out.setstate(ios_base::badbit); | |
725dc051 BK |
590 | return __out; |
591 | } | |
592 | ||
b6a95741 | 593 | // Partial specializations. |
725dc051 BK |
594 | template<class _Traits> |
595 | basic_ostream<char, _Traits>& | |
596 | operator<<(basic_ostream<char, _Traits>& __out, const char* __s) | |
597 | { | |
598 | typedef basic_ostream<char, _Traits> __ostream_type; | |
bcd0cabb | 599 | typename __ostream_type::sentry __cerb(__out); |
52f02d94 | 600 | if (__cerb && __s) |
725dc051 | 601 | { |
a16ad779 BK |
602 | try |
603 | { | |
6b61bca4 | 604 | const streamsize __w = __out.width(); |
52f02d94 | 605 | streamsize __len = static_cast<streamsize>(_Traits::length(__s)); |
a16ad779 BK |
606 | if (__w > __len) |
607 | { | |
6b61bca4 PC |
608 | char* __cs = static_cast<char*>(__builtin_alloca(__w)); |
609 | __pad<char, _Traits>::_S_pad(__out, __out.fill(), __cs, | |
f13a69ec | 610 | __s, __w, __len, false); |
6b61bca4 | 611 | __s = __cs; |
a16ad779 BK |
612 | __len = __w; |
613 | } | |
8d0a564b | 614 | __out._M_write(__s, __len); |
a16ad779 BK |
615 | __out.width(0); |
616 | } | |
06e7ca50 | 617 | catch(...) |
12841eb3 | 618 | { __out._M_setstate(ios_base::badbit); } |
725dc051 | 619 | } |
52f02d94 BK |
620 | else if (!__s) |
621 | __out.setstate(ios_base::badbit); | |
725dc051 BK |
622 | return __out; |
623 | } | |
624 | ||
a16ad779 | 625 | // 21.3.7.9 basic_string::operator<< |
725dc051 BK |
626 | template<typename _CharT, typename _Traits, typename _Alloc> |
627 | basic_ostream<_CharT, _Traits>& | |
628 | operator<<(basic_ostream<_CharT, _Traits>& __out, | |
a16ad779 BK |
629 | const basic_string<_CharT, _Traits, _Alloc>& __str) |
630 | { | |
631 | typedef basic_ostream<_CharT, _Traits> __ostream_type; | |
632 | typename __ostream_type::sentry __cerb(__out); | |
633 | if (__cerb) | |
634 | { | |
6b61bca4 | 635 | const streamsize __w = __out.width(); |
a16ad779 | 636 | streamsize __len = static_cast<streamsize>(__str.size()); |
6b61bca4 | 637 | const _CharT* __s = __str.data(); |
12841eb3 | 638 | |
f5677b15 | 639 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
a16ad779 | 640 | // 25. String operator<< uses width() value wrong |
a16ad779 BK |
641 | if (__w > __len) |
642 | { | |
e0f05105 | 643 | _CharT* __cs = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __w)); |
6b61bca4 | 644 | __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs, __s, |
f13a69ec | 645 | __w, __len, false); |
6b61bca4 | 646 | __s = __cs; |
a16ad779 BK |
647 | __len = __w; |
648 | } | |
8d0a564b | 649 | __out._M_write(__s, __len); |
a16ad779 | 650 | __out.width(0); |
a16ad779 BK |
651 | } |
652 | return __out; | |
653 | } | |
a32e3c09 BK |
654 | |
655 | // Inhibit implicit instantiations for required instantiations, | |
656 | // which are defined via explicit instantiations elsewhere. | |
657 | // NB: This syntax is a GNU extension. | |
3d7c150e | 658 | #if _GLIBCXX_EXTERN_TEMPLATE |
a32e3c09 BK |
659 | extern template class basic_ostream<char>; |
660 | extern template ostream& endl(ostream&); | |
661 | extern template ostream& ends(ostream&); | |
662 | extern template ostream& flush(ostream&); | |
663 | extern template ostream& operator<<(ostream&, char); | |
664 | extern template ostream& operator<<(ostream&, unsigned char); | |
665 | extern template ostream& operator<<(ostream&, signed char); | |
666 | extern template ostream& operator<<(ostream&, const char*); | |
667 | extern template ostream& operator<<(ostream&, const unsigned char*); | |
668 | extern template ostream& operator<<(ostream&, const signed char*); | |
669 | ||
3d7c150e | 670 | #ifdef _GLIBCXX_USE_WCHAR_T |
a32e3c09 BK |
671 | extern template class basic_ostream<wchar_t>; |
672 | extern template wostream& endl(wostream&); | |
673 | extern template wostream& ends(wostream&); | |
674 | extern template wostream& flush(wostream&); | |
675 | extern template wostream& operator<<(wostream&, wchar_t); | |
676 | extern template wostream& operator<<(wostream&, char); | |
677 | extern template wostream& operator<<(wostream&, const wchar_t*); | |
678 | extern template wostream& operator<<(wostream&, const char*); | |
3522a91b | 679 | #endif |
1bc8b0ad | 680 | #endif |
725dc051 | 681 | } // namespace std |
3d7c150e BK |
682 | |
683 | #endif |