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 #ifndef _OSTREAM_INSERT_H
00031 #define _OSTREAM_INSERT_H 1
00032
00033 #pragma GCC system_header
00034
00035 #include <iosfwd>
00036 #include <cxxabi-forced.h>
00037
00038 _GLIBCXX_BEGIN_NAMESPACE(std)
00039
00040 template<typename _CharT, typename _Traits>
00041 inline void
00042 __ostream_write(basic_ostream<_CharT, _Traits>& __out,
00043 const _CharT* __s, streamsize __n)
00044 {
00045 typedef basic_ostream<_CharT, _Traits> __ostream_type;
00046 typedef typename __ostream_type::ios_base __ios_base;
00047
00048 const streamsize __put = __out.rdbuf()->sputn(__s, __n);
00049 if (__put != __n)
00050 __out.setstate(__ios_base::badbit);
00051 }
00052
00053 template<typename _CharT, typename _Traits>
00054 inline void
00055 __ostream_fill(basic_ostream<_CharT, _Traits>& __out, streamsize __n)
00056 {
00057 typedef basic_ostream<_CharT, _Traits> __ostream_type;
00058 typedef typename __ostream_type::ios_base __ios_base;
00059
00060 const _CharT __c = __out.fill();
00061 for (; __n > 0; --__n)
00062 {
00063 const typename _Traits::int_type __put = __out.rdbuf()->sputc(__c);
00064 if (_Traits::eq_int_type(__put, _Traits::eof()))
00065 {
00066 __out.setstate(__ios_base::badbit);
00067 break;
00068 }
00069 }
00070 }
00071
00072 template<typename _CharT, typename _Traits>
00073 basic_ostream<_CharT, _Traits>&
00074 __ostream_insert(basic_ostream<_CharT, _Traits>& __out,
00075 const _CharT* __s, streamsize __n)
00076 {
00077 typedef basic_ostream<_CharT, _Traits> __ostream_type;
00078 typedef typename __ostream_type::ios_base __ios_base;
00079
00080 typename __ostream_type::sentry __cerb(__out);
00081 if (__cerb)
00082 {
00083 __try
00084 {
00085 const streamsize __w = __out.width();
00086 if (__w > __n)
00087 {
00088 const bool __left = ((__out.flags()
00089 & __ios_base::adjustfield)
00090 == __ios_base::left);
00091 if (!__left)
00092 __ostream_fill(__out, __w - __n);
00093 if (__out.good())
00094 __ostream_write(__out, __s, __n);
00095 if (__left && __out.good())
00096 __ostream_fill(__out, __w - __n);
00097 }
00098 else
00099 __ostream_write(__out, __s, __n);
00100 __out.width(0);
00101 }
00102 __catch(__cxxabiv1::__forced_unwind&)
00103 {
00104 __out._M_setstate(__ios_base::badbit);
00105 __throw_exception_again;
00106 }
00107 __catch(...)
00108 { __out._M_setstate(__ios_base::badbit); }
00109 }
00110 return __out;
00111 }
00112
00113
00114
00115
00116 #if _GLIBCXX_EXTERN_TEMPLATE
00117 extern template ostream& __ostream_insert(ostream&, const char*, streamsize);
00118
00119 #ifdef _GLIBCXX_USE_WCHAR_T
00120 extern template wostream& __ostream_insert(wostream&, const wchar_t*,
00121 streamsize);
00122 #endif
00123 #endif
00124
00125 _GLIBCXX_END_NAMESPACE
00126
00127 #endif