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