Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
2 * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
5 * Silicon Graphics Computer Systems, Inc.
10 * This material is provided "as is", with absolutely no warranty expressed
11 * or implied. Any use is at your own risk.
13 * Permission to use or copy this software for any purpose is hereby granted
14 * without fee, provided the above notices are retained on all copies.
15 * Permission to modify the code and to distribute modified code is granted,
16 * provided the above notices are retained, and a notice that the code was
17 * modified is included with the above copyright notice.
20 #ifndef _STLP_OSTREAM_C
21 #define _STLP_OSTREAM_C
24 #ifndef _STLP_INTERNAL_OSTREAM_H
25 # include <stl/_ostream.h>
28 #if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION)
30 #if !defined (_STLP_INTERNAL_NUM_PUT_H)
31 # include <stl/_num_put.h> // For basic_streambuf and iterators
36 // Helper functions for istream<>::sentry constructor.
37 template <class _CharT, class _Traits>
39 _M_init(basic_ostream<_CharT, _Traits>& __str) {
41 // boris : check if this is needed !
43 __str.setstate(ios_base::badbit);
51 //----------------------------------------------------------------------
52 // Definitions of non-inline member functions.
54 // Constructor, destructor
56 template <class _CharT, class _Traits>
57 _STLP_EXP_DECLSPEC basic_ostream<_CharT, _Traits>
58 ::basic_ostream(basic_streambuf<_CharT, _Traits>* __buf)
59 : basic_ios<_CharT, _Traits>()
64 template <class _CharT, class _Traits>
65 _STLP_EXP_DECLSPEC basic_ostream<_CharT, _Traits>::~basic_ostream()
68 // Output directly from a streambuf.
69 template <class _CharT, class _Traits>
70 _STLP_EXP_DECLSPEC basic_ostream<_CharT, _Traits>&
71 basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<_CharT, _Traits>* __from)
73 sentry __sentry(*this);
76 bool __any_inserted = __from->gptr() != __from->egptr()
77 ? this->_M_copy_buffered(__from, this->rdbuf())
78 : this->_M_copy_unbuffered(__from, this->rdbuf());
80 this->setstate(ios_base::failbit);
83 this->setstate(ios_base::badbit);
89 // Helper functions for the streambuf version of operator<<. The
90 // exception-handling code is complicated because exceptions thrown
91 // while extracting characters are treated differently than exceptions
92 // thrown while inserting characters.
94 template <class _CharT, class _Traits>
95 bool basic_ostream<_CharT, _Traits>
96 ::_M_copy_buffered(basic_streambuf<_CharT, _Traits>* __from,
97 basic_streambuf<_CharT, _Traits>* __to)
99 bool __any_inserted = false;
101 while (__from->egptr() != __from->gptr()) {
102 const ptrdiff_t __avail = __from->egptr() - __from->gptr();
104 streamsize __nwritten;
106 __nwritten = __to->sputn(__from->gptr(), __avail);
107 __from->gbump((int)__nwritten);
110 this->_M_handle_exception(ios_base::badbit);
111 return __any_inserted;
114 if (__nwritten == __avail) {
116 if (this->_S_eof(__from->sgetc()))
119 __any_inserted = true;
122 this->_M_handle_exception(ios_base::failbit);
127 else if (__nwritten != 0)
131 return __any_inserted;
134 // No characters are in the buffer, but we aren't at EOF. Switch to
136 return __any_inserted || this->_M_copy_unbuffered(__from, __to);
139 template <class _CharT, class _Traits>
140 bool basic_ostream<_CharT, _Traits>
141 ::_M_copy_unbuffered(basic_streambuf<_CharT, _Traits>* __from,
142 basic_streambuf<_CharT, _Traits>* __to)
144 bool __any_inserted = false;
149 __c = __from->sgetc();;
152 this->_M_handle_exception(ios_base::failbit);
153 return __any_inserted;
157 if (this->_S_eof(__c))
158 return __any_inserted;
163 __tmp = __to->sputc(__c);
166 this->_M_handle_exception(ios_base::badbit);
167 return __any_inserted;
170 if (this->_S_eof(__tmp)) {
174 __any_inserted = true;
177 __c = __from->snextc();
180 this->_M_handle_exception(ios_base::failbit);
181 return __any_inserted;
188 __c = __from->sbumpc();
191 this->_M_handle_exception(ios_base::failbit);
192 return __any_inserted;
195 if (this->_S_eof(__c))
196 return __any_inserted;
201 __tmp = __to->sputc(__c);
204 this->_M_handle_exception(ios_base::badbit);
205 return __any_inserted;
208 if (this->_S_eof(__tmp)) {
210 /* __tmp = */ __from->sputbackc(__c);
213 this->_M_handle_exception(ios_base::badbit);
214 return __any_inserted;
218 __any_inserted = true;
222 return __any_inserted;
225 // Helper function for numeric output.
227 template <class _CharT, class _Traits, class _Number>
228 basic_ostream<_CharT, _Traits>& _STLP_CALL
229 _M_put_num(basic_ostream<_CharT, _Traits>& __os, _Number __x)
231 typedef typename basic_ostream<_CharT, _Traits>::sentry _Sentry;
232 _Sentry __sentry(__os);
233 bool __failed = true;
237 typedef num_put<_CharT, ostreambuf_iterator<_CharT, _Traits> > _NumPut;
238 __failed = (use_facet<_NumPut>(__os.getloc())).put(
239 ostreambuf_iterator<_CharT, _Traits>(__os.rdbuf()),
244 __os._M_handle_exception(ios_base::badbit);
248 __os.setstate(ios_base::badbit);
252 # if defined (_STLP_USE_TEMPLATE_EXPORT) && defined (__BUILDING_STLPORT)
253 _STLP_EXPORT_TEMPLATE _STLP_EXP_DECLSPEC basic_ostream<char, char_traits<char> >& _STLP_CALL
254 _M_put_num(basic_ostream<char, char_traits<char> >&, unsigned long);
255 _STLP_EXPORT_TEMPLATE _STLP_EXP_DECLSPEC basic_ostream<char, char_traits<char> >& _STLP_CALL
256 _M_put_num(basic_ostream<char, char_traits<char> >&, long);
257 # if defined (_STLP_LONG_LONG)
258 _STLP_EXPORT_TEMPLATE _STLP_EXP_DECLSPEC basic_ostream<char, char_traits<char> >& _STLP_CALL
259 _M_put_num(basic_ostream<char, char_traits<char> >&, unsigned _STLP_LONG_LONG);
260 _STLP_EXPORT_TEMPLATE _STLP_EXP_DECLSPEC basic_ostream<char, char_traits<char> >& _STLP_CALL
261 _M_put_num(basic_ostream<char, char_traits<char> >&, _STLP_LONG_LONG );
265 template <class _CharT, class _Traits>
266 void basic_ostream<_CharT, _Traits>::_M_put_char(_CharT __c)
268 sentry __sentry(*this);
270 bool __failed = true;
272 streamsize __npad = this->width() > 0 ? this->width() - 1 : 0;
275 __failed = this->_S_eof(this->rdbuf()->sputc(__c));
276 else if ((this->flags() & ios_base::adjustfield) == ios_base::left) {
277 __failed = this->_S_eof(this->rdbuf()->sputc(__c));
278 __failed = __failed ||
279 this->rdbuf()->_M_sputnc(this->fill(), __npad) != __npad;
282 __failed = this->rdbuf()->_M_sputnc(this->fill(), __npad) != __npad;
283 __failed = __failed || this->_S_eof(this->rdbuf()->sputc(__c));
289 this->_M_handle_exception(ios_base::badbit);
293 this->setstate(ios_base::badbit);
297 template <class _CharT, class _Traits>
298 void basic_ostream<_CharT, _Traits>::_M_put_nowiden(const _CharT* __s)
300 sentry __sentry(*this);
302 bool __failed = true;
303 streamsize __n = _Traits::length(__s);
304 streamsize __npad = this->width() > __n ? this->width() - __n : 0;
308 __failed = this->rdbuf()->sputn(__s, __n) != __n;
309 else if ((this->flags() & ios_base::adjustfield) == ios_base::left) {
310 __failed = this->rdbuf()->sputn(__s, __n) != __n;
311 __failed = __failed ||
312 this->rdbuf()->_M_sputnc(this->fill(), __npad) != __npad;
315 __failed = this->rdbuf()->_M_sputnc(this->fill(), __npad) != __npad;
316 __failed = __failed || this->rdbuf()->sputn(__s, __n) != __n;
322 this->_M_handle_exception(ios_base::badbit);
326 this->setstate(ios_base::failbit);
330 template <class _CharT, class _Traits>
331 void basic_ostream<_CharT, _Traits>::_M_put_widen(const char* __s)
333 sentry __sentry(*this);
335 bool __failed = true;
336 streamsize __n = char_traits<char>::length(__s);
337 streamsize __npad = this->width() > __n ? this->width() - __n : 0;
341 __failed = !this->_M_put_widen_aux(__s, __n);
342 else if ((this->flags() & ios_base::adjustfield) == ios_base::left) {
343 __failed = !this->_M_put_widen_aux(__s, __n);
344 __failed = __failed ||
345 this->rdbuf()->_M_sputnc(this->fill(), __npad) != __npad;
348 __failed = this->rdbuf()->_M_sputnc(this->fill(), __npad) != __npad;
349 __failed = __failed || !this->_M_put_widen_aux(__s, __n);
355 this->_M_handle_exception(ios_base::badbit);
359 this->setstate(ios_base::failbit);
363 template <class _CharT, class _Traits>
364 bool basic_ostream<_CharT, _Traits>::_M_put_widen_aux(const char* __s,
367 basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
369 for ( ; __n > 0 ; --__n)
370 if (this->_S_eof(__buf->sputc(this->widen(*__s++))))
375 // Unformatted output of a single character.
376 template <class _CharT, class _Traits>
377 _STLP_EXP_DECLSPEC basic_ostream<_CharT, _Traits>&
378 basic_ostream<_CharT, _Traits>::put(char_type __c)
380 sentry __sentry(*this);
381 bool __failed = true;
385 __failed = this->_S_eof(this->rdbuf()->sputc(__c));
388 this->_M_handle_exception(ios_base::badbit);
393 this->setstate(ios_base::badbit);
398 // Unformatted output of a single character.
399 template <class _CharT, class _Traits>
400 _STLP_EXP_DECLSPEC basic_ostream<_CharT, _Traits>&
401 basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n)
403 sentry __sentry(*this);
404 bool __failed = true;
408 __failed = this->rdbuf()->sputn(__s, __n) != __n;
411 this->_M_handle_exception(ios_base::badbit);
416 this->setstate(ios_base::badbit);
423 #endif /* defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) */
425 #endif /* _STLP_OSTREAM_C */