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 | #pragma GCC system_header |
34 | |
35 | #include <iosfwd> |
36 | #include <bits/cxxabi_forced.h> |
37 | |
38 | namespace std _GLIBCXX_VISIBILITY(default) |
39 | { |
40 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
41 | |
42 | template<typename _CharT, typename _Traits> |
43 | inline void |
44 | __ostream_write(basic_ostream<_CharT, _Traits>& __out, |
45 | const _CharT* __s, streamsize __n) |
46 | { |
47 | typedef basic_ostream<_CharT, _Traits> __ostream_type; |
48 | typedef typename __ostream_type::ios_base __ios_base; |
49 | |
50 | const streamsize __put = __out.rdbuf()->sputn(__s, __n); |
51 | if (__put != __n) |
52 | __out.setstate(__ios_base::badbit); |
53 | } |
54 | |
55 | template<typename _CharT, typename _Traits> |
56 | inline void |
57 | __ostream_fill(basic_ostream<_CharT, _Traits>& __out, streamsize __n) |
58 | { |
59 | typedef basic_ostream<_CharT, _Traits> __ostream_type; |
60 | typedef typename __ostream_type::ios_base __ios_base; |
61 | |
62 | const _CharT __c = __out.fill(); |
63 | for (; __n > 0; --__n) |
64 | { |
65 | const typename _Traits::int_type __put = __out.rdbuf()->sputc(__c); |
66 | if (_Traits::eq_int_type(__put, _Traits::eof())) |
67 | { |
68 | __out.setstate(__ios_base::badbit); |
69 | break; |
70 | } |
71 | } |
72 | } |
73 | |
74 | template<typename _CharT, typename _Traits> |
75 | basic_ostream<_CharT, _Traits>& |
76 | __ostream_insert(basic_ostream<_CharT, _Traits>& __out, |
77 | const _CharT* __s, streamsize __n) |
78 | { |
79 | typedef basic_ostream<_CharT, _Traits> __ostream_type; |
80 | typedef typename __ostream_type::ios_base __ios_base; |
81 | |
82 | typename __ostream_type::sentry __cerb(__out); |
83 | if (__cerb) |
84 | { |
85 | __try |
86 | { |
87 | const streamsize __w = __out.width(); |
88 | if (__w > __n) |
89 | { |
90 | const bool __left = ((__out.flags() |
91 | & __ios_base::adjustfield) |
92 | == __ios_base::left); |
93 | if (!__left) |
94 | __ostream_fill(__out, __w - __n); |
95 | if (__out.good()) |
96 | __ostream_write(__out, __s, __n); |
97 | if (__left && __out.good()) |
98 | __ostream_fill(__out, __w - __n); |
99 | } |
100 | else |
101 | __ostream_write(__out, __s, __n); |
102 | __out.width(0); |
103 | } |
104 | __catch(__cxxabiv1::__forced_unwind&) |
105 | { |
106 | __out._M_setstate(__ios_base::badbit); |
107 | __throw_exception_again; |
108 | } |
109 | __catch(...) |
110 | { __out._M_setstate(__ios_base::badbit); } |
111 | } |
112 | return __out; |
113 | } |
114 | |
115 | |
116 | |
117 | #if _GLIBCXX_EXTERN_TEMPLATE |
118 | extern template ostream& __ostream_insert(ostream&, const char*, streamsize); |
119 | |
120 | #ifdef _GLIBCXX_USE_WCHAR_T |
121 | extern template wostream& __ostream_insert(wostream&, const wchar_t*, |
122 | streamsize); |
123 | #endif |
124 | #endif |
125 | |
126 | _GLIBCXX_END_NAMESPACE_VERSION |
127 | } |
128 | |
129 | #endif |
130 | |