ostream_insert.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef _OSTREAM_INSERT_H
00036 #define _OSTREAM_INSERT_H 1
00037
00038 #pragma GCC system_header
00039
00040 #include <iosfwd>
00041 #include <cxxabi-forced.h>
00042
00043 _GLIBCXX_BEGIN_NAMESPACE(std)
00044
00045 template<typename _CharT, typename _Traits>
00046 inline void
00047 __ostream_write(basic_ostream<_CharT, _Traits>& __out,
00048 const _CharT* __s, streamsize __n)
00049 {
00050 typedef basic_ostream<_CharT, _Traits> __ostream_type;
00051 typedef typename __ostream_type::ios_base __ios_base;
00052
00053 const streamsize __put = __out.rdbuf()->sputn(__s, __n);
00054 if (__put != __n)
00055 __out.setstate(__ios_base::badbit);
00056 }
00057
00058 template<typename _CharT, typename _Traits>
00059 inline void
00060 __ostream_fill(basic_ostream<_CharT, _Traits>& __out, streamsize __n)
00061 {
00062 typedef basic_ostream<_CharT, _Traits> __ostream_type;
00063 typedef typename __ostream_type::ios_base __ios_base;
00064
00065 const _CharT __c = __out.fill();
00066 for (; __n > 0; --__n)
00067 {
00068 const typename _Traits::int_type __put = __out.rdbuf()->sputc(__c);
00069 if (_Traits::eq_int_type(__put, _Traits::eof()))
00070 {
00071 __out.setstate(__ios_base::badbit);
00072 break;
00073 }
00074 }
00075 }
00076
00077 template<typename _CharT, typename _Traits>
00078 basic_ostream<_CharT, _Traits>&
00079 __ostream_insert(basic_ostream<_CharT, _Traits>& __out,
00080 const _CharT* __s, streamsize __n)
00081 {
00082 typedef basic_ostream<_CharT, _Traits> __ostream_type;
00083 typedef typename __ostream_type::ios_base __ios_base;
00084
00085 typename __ostream_type::sentry __cerb(__out);
00086 if (__cerb)
00087 {
00088 try
00089 {
00090 const streamsize __w = __out.width();
00091 if (__w > __n)
00092 {
00093 const bool __left = ((__out.flags()
00094 & __ios_base::adjustfield)
00095 == __ios_base::left);
00096 if (!__left)
00097 __ostream_fill(__out, __w - __n);
00098 if (__out.good())
00099 __ostream_write(__out, __s, __n);
00100 if (__left && __out.good())
00101 __ostream_fill(__out, __w - __n);
00102 }
00103 else
00104 __ostream_write(__out, __s, __n);
00105 __out.width(0);
00106 }
00107 catch(__cxxabiv1::__forced_unwind&)
00108 {
00109 __out._M_setstate(__ios_base::badbit);
00110 __throw_exception_again;
00111 }
00112 catch(...)
00113 { __out._M_setstate(__ios_base::badbit); }
00114 }
00115 return __out;
00116 }
00117
00118
00119
00120
00121 #if _GLIBCXX_EXTERN_TEMPLATE
00122 extern template ostream& __ostream_insert(ostream&, const char*, streamsize);
00123
00124 #ifdef _GLIBCXX_USE_WCHAR_T
00125 extern template wostream& __ostream_insert(wostream&, const wchar_t*,
00126 streamsize);
00127 #endif
00128 #endif
00129
00130 _GLIBCXX_END_NAMESPACE
00131
00132 #endif