| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
#ifndef _OSTREAM_INSERT_H |
| 31 |
#define _OSTREAM_INSERT_H 1 |
| 32 |
|
| 33 |
#ifdef _GLIBCXX_SYSHDR |
| 34 |
#pragma GCC system_header |
| 35 |
#endif |
| 36 |
|
| 37 |
#include <iosfwd> |
| 38 |
#include <bits/cxxabi_forced.h> |
| 39 |
#include <bits/exception_defines.h> |
| 40 |
|
| 41 |
#pragma GCC diagnostic push |
| 42 |
#pragma GCC diagnostic ignored "-Wc++11-extensions" // extern template |
| 43 |
|
| 44 |
namespace std _GLIBCXX_VISIBILITY(default) |
| 45 |
{ |
| 46 |
_GLIBCXX_BEGIN_NAMESPACE_VERSION |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
template<typename _CharT, typename _Traits> |
| 51 |
inline void |
| 52 |
__ostream_write(basic_ostream<_CharT, _Traits>& __out, |
| 53 |
const _CharT* __s, streamsize __n) |
| 54 |
{ |
| 55 |
typedef basic_ostream<_CharT, _Traits> __ostream_type; |
| 56 |
typedef typename __ostream_type::ios_base __ios_base; |
| 57 |
|
| 58 |
const streamsize __put = __out.rdbuf()->sputn(__s, __n); |
| 59 |
if (__put != __n) |
| 60 |
__out.setstate(__ios_base::badbit); |
| 61 |
} |
| 62 |
|
| 63 |
template<typename _CharT, typename _Traits> |
| 64 |
inline void |
| 65 |
__ostream_fill(basic_ostream<_CharT, _Traits>& __out, streamsize __n) |
| 66 |
{ |
| 67 |
typedef basic_ostream<_CharT, _Traits> __ostream_type; |
| 68 |
typedef typename __ostream_type::ios_base __ios_base; |
| 69 |
|
| 70 |
const _CharT __c = __out.fill(); |
| 71 |
for (; __n > 0; --__n) |
| 72 |
{ |
| 73 |
const typename _Traits::int_type __put = __out.rdbuf()->sputc(__c); |
| 74 |
if (_Traits::eq_int_type(__put, _Traits::eof())) |
| 75 |
{ |
| 76 |
__out.setstate(__ios_base::badbit); |
| 77 |
break; |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
template<typename _CharT, typename _Traits> |
| 83 |
basic_ostream<_CharT, _Traits>& |
| 84 |
__ostream_insert(basic_ostream<_CharT, _Traits>& __out, |
| 85 |
const _CharT* __s, streamsize __n) |
| 86 |
{ |
| 87 |
typedef basic_ostream<_CharT, _Traits> __ostream_type; |
| 88 |
typedef typename __ostream_type::ios_base __ios_base; |
| 89 |
|
| 90 |
typename __ostream_type::sentry __cerb(__out); |
| 91 |
if (__cerb) |
| 92 |
{ |
| 93 |
__try |
| 94 |
{ |
| 95 |
const streamsize __w = __out.width(); |
| 96 |
if (__w > __n) |
| 97 |
{ |
| 98 |
const bool __left = ((__out.flags() |
| 99 |
& __ios_base::adjustfield) |
| 100 |
== __ios_base::left); |
| 101 |
if (!__left) |
| 102 |
__ostream_fill(__out, __w - __n); |
| 103 |
if (__out.good()) |
| 104 |
__ostream_write(__out, __s, __n); |
| 105 |
if (__left && __out.good()) |
| 106 |
__ostream_fill(__out, __w - __n); |
| 107 |
} |
| 108 |
else |
| 109 |
__ostream_write(__out, __s, __n); |
| 110 |
__out.width(0); |
| 111 |
} |
| 112 |
__catch(__cxxabiv1::__forced_unwind&) |
| 113 |
{ |
| 114 |
__out._M_setstate(__ios_base::badbit); |
| 115 |
__throw_exception_again; |
| 116 |
} |
| 117 |
__catch(...) |
| 118 |
{ __out._M_setstate(__ios_base::badbit); } |
| 119 |
} |
| 120 |
return __out; |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
#if _GLIBCXX_EXTERN_TEMPLATE |
| 126 |
extern template ostream& __ostream_insert(ostream&, const char*, streamsize); |
| 127 |
|
| 128 |
#ifdef _GLIBCXX_USE_WCHAR_T |
| 129 |
extern template wostream& __ostream_insert(wostream&, const wchar_t*, |
| 130 |
streamsize); |
| 131 |
#endif |
| 132 |
#endif |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
_GLIBCXX_END_NAMESPACE_VERSION |
| 137 |
} |
| 138 |
|
| 139 |
#pragma GCC diagnostic pop |
| 140 |
#endif |