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