Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4680 | right-hear | 1 | // Output streams -*- C++ -*- |
2 | |||
3 | // Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. |
||
4 | // |
||
5 | // This file is part of the GNU ISO C++ Library. This library is free |
||
6 | // software; you can redistribute it and/or modify it under the |
||
7 | // terms of the GNU General Public License as published by the |
||
8 | // Free Software Foundation; either version 2, or (at your option) |
||
9 | // any later version. |
||
10 | |||
11 | // This library is distributed in the hope that it will be useful, |
||
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
14 | // GNU General Public License for more details. |
||
15 | |||
16 | // You should have received a copy of the GNU General Public License along |
||
17 | // with this library; see the file COPYING. If not, write to the Free |
||
18 | // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
||
19 | // USA. |
||
20 | |||
21 | // As a special exception, you may use this file as part of a free software |
||
22 | // library without restriction. Specifically, if other files instantiate |
||
23 | // templates or use macros or inline functions from this file, or you compile |
||
24 | // this file and link it with other files to produce an executable, this |
||
25 | // file does not by itself cause the resulting executable to be covered by |
||
26 | // the GNU General Public License. This exception does not however |
||
27 | // invalidate any other reasons why the executable file might be covered by |
||
28 | // the GNU General Public License. |
||
29 | |||
30 | // |
||
31 | // ISO C++ 14882: 27.6.2 Output streams |
||
32 | // |
||
33 | |||
34 | #ifndef _CPP_OSTREAM |
||
35 | #define _CPP_OSTREAM 1 |
||
36 | |||
37 | #pragma GCC system_header |
||
38 | |||
39 | #include |
||
40 | |||
41 | namespace std |
||
42 | { |
||
43 | // 27.6.2.1 Template class basic_ostream |
||
44 | template |
||
45 | class basic_ostream : virtual public basic_ios<_CharT, _Traits> |
||
46 | { |
||
47 | public: |
||
48 | |||
49 | // Types (inherited from basic_ios (27.4.4)): |
||
50 | typedef _CharT char_type; |
||
51 | typedef typename _Traits::int_type int_type; |
||
52 | typedef typename _Traits::pos_type pos_type; |
||
53 | typedef typename _Traits::off_type off_type; |
||
54 | typedef _Traits traits_type; |
||
55 | |||
56 | // Non-standard Types: |
||
57 | typedef basic_streambuf<_CharT, _Traits> __streambuf_type; |
||
58 | typedef basic_ios<_CharT, _Traits> __ios_type; |
||
59 | typedef basic_ostream<_CharT, _Traits> __ostream_type; |
||
60 | typedef ostreambuf_iterator<_CharT, _Traits> __ostreambuf_iter; |
||
61 | typedef num_put<_CharT, __ostreambuf_iter> __numput_type; |
||
62 | typedef ctype<_CharT> __ctype_type; |
||
63 | |||
64 | // 27.6.2.2 Constructor/destructor: |
||
65 | explicit |
||
66 | basic_ostream(__streambuf_type* __sb) |
||
67 | { this->init(__sb); } |
||
68 | |||
69 | virtual |
||
70 | ~basic_ostream() { } |
||
71 | |||
72 | // 27.6.2.3 Prefix/suffix: |
||
73 | class sentry; |
||
74 | friend class sentry; |
||
75 | |||
76 | // 27.6.2.5 Formatted output: |
||
77 | // 27.6.2.5.3 basic_ostream::operator<< |
||
78 | __ostream_type& |
||
79 | operator<<(__ostream_type& (*__pf)(__ostream_type&)); |
||
80 | |||
81 | __ostream_type& |
||
82 | operator<<(__ios_type& (*__pf)(__ios_type&)); |
||
83 | |||
84 | __ostream_type& |
||
85 | operator<<(ios_base& (*__pf) (ios_base&)); |
||
86 | |||
87 | // 27.6.2.5.2 Arithmetic Inserters |
||
88 | __ostream_type& |
||
89 | operator<<(long __n); |
||
90 | |||
91 | __ostream_type& |
||
92 | operator<<(unsigned long __n); |
||
93 | |||
94 | __ostream_type& |
||
95 | operator<<(bool __n); |
||
96 | |||
97 | __ostream_type& |
||
98 | operator<<(short __n) |
||
99 | { |
||
100 | ios_base::fmtflags __fmt = this->flags() & ios_base::basefield; |
||
101 | if (__fmt & ios_base::oct || __fmt & ios_base::hex) |
||
102 | return this->operator<<(static_cast |
||
103 | (static_cast |
||
104 | else |
||
105 | return this->operator<<(static_cast |
||
106 | } |
||
107 | |||
108 | __ostream_type& |
||
109 | operator<<(unsigned short __n) |
||
110 | { return this->operator<<(static_cast |
||
111 | |||
112 | __ostream_type& |
||
113 | operator<<(int __n) |
||
114 | { |
||
115 | ios_base::fmtflags __fmt = this->flags() & ios_base::basefield; |
||
116 | if (__fmt & ios_base::oct || __fmt & ios_base::hex) |
||
117 | return this->operator<<(static_cast |
||
118 | (static_cast |
||
119 | else |
||
120 | return this->operator<<(static_cast |
||
121 | } |
||
122 | |||
123 | __ostream_type& |
||
124 | operator<<(unsigned int __n) |
||
125 | { return this->operator<<(static_cast |
||
126 | |||
127 | #ifdef _GLIBCPP_USE_LONG_LONG |
||
128 | __ostream_type& |
||
129 | operator<<(long long __n); |
||
130 | |||
131 | __ostream_type& |
||
132 | operator<<(unsigned long long __n); |
||
133 | #endif |
||
134 | |||
135 | __ostream_type& |
||
136 | operator<<(double __f); |
||
137 | |||
138 | __ostream_type& |
||
139 | operator<<(float __f) |
||
140 | { return this->operator<<(static_cast |
||
141 | |||
142 | __ostream_type& |
||
143 | operator<<(long double __f); |
||
144 | |||
145 | __ostream_type& |
||
146 | operator<<(const void* __p); |
||
147 | |||
148 | __ostream_type& |
||
149 | operator<<(__streambuf_type* __sb); |
||
150 | |||
151 | // Unformatted output: |
||
152 | __ostream_type& |
||
153 | put(char_type __c); |
||
154 | |||
155 | __ostream_type& |
||
156 | write(const char_type* __s, streamsize __n); |
||
157 | |||
158 | __ostream_type& |
||
159 | flush(); |
||
160 | |||
161 | // Seeks: |
||
162 | pos_type |
||
163 | tellp(); |
||
164 | |||
165 | __ostream_type& |
||
166 | seekp(pos_type); |
||
167 | |||
168 | __ostream_type& |
||
169 | seekp(off_type, ios_base::seekdir); |
||
170 | |||
171 | private: |
||
172 | #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS |
||
173 | // Not defined. |
||
174 | __ostream_type& |
||
175 | operator=(const __ostream_type&); |
||
176 | |||
177 | basic_ostream(const __ostream_type&); |
||
178 | #endif |
||
179 | }; |
||
180 | |||
181 | // 27.6.2.3 Class basic_ostream::sentry |
||
182 | template |
||
183 | class basic_ostream<_CharT, _Traits>::sentry |
||
184 | { |
||
185 | // Data Members: |
||
186 | bool _M_ok; |
||
187 | basic_ostream<_CharT,_Traits>& _M_os; |
||
188 | |||
189 | public: |
||
190 | explicit |
||
191 | sentry(basic_ostream<_CharT,_Traits>& __os); |
||
192 | |||
193 | ~sentry() |
||
194 | { |
||
195 | // XXX MT |
||
196 | if (_M_os.flags() & ios_base::unitbuf && !uncaught_exception()) |
||
197 | { |
||
198 | // Can't call flush directly or else will get into recursive lock. |
||
199 | if (_M_os.rdbuf() && _M_os.rdbuf()->pubsync() == -1) |
||
200 | _M_os.setstate(ios_base::badbit); |
||
201 | } |
||
202 | } |
||
203 | |||
204 | operator bool() |
||
205 | { return _M_ok; } |
||
206 | }; |
||
207 | |||
208 | template |
||
209 | basic_ostream<_CharT, _Traits>& |
||
210 | operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c); |
||
211 | |||
212 | template |
||
213 | basic_ostream<_CharT, _Traits>& |
||
214 | operator<<(basic_ostream<_CharT, _Traits>& __out, char __c) |
||
215 | { return (__out << __out.widen(__c)); } |
||
216 | |||
217 | // Specialization |
||
218 | template |
||
219 | basic_ostream |
||
220 | operator<<(basic_ostream |
||
221 | |||
222 | // Signed and unsigned |
||
223 | template |
||
224 | basic_ostream |
||
225 | operator<<(basic_ostream |
||
226 | { return (__out << static_cast |
||
227 | |||
228 | template |
||
229 | basic_ostream |
||
230 | operator<<(basic_ostream |
||
231 | { return (__out << static_cast |
||
232 | |||
233 | template |
||
234 | basic_ostream<_CharT, _Traits>& |
||
235 | operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s); |
||
236 | |||
237 | template |
||
238 | basic_ostream<_CharT, _Traits> & |
||
239 | operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s); |
||
240 | |||
241 | // Partial specializationss |
||
242 | template |
||
243 | basic_ostream |
||
244 | operator<<(basic_ostream |
||
245 | |||
246 | // Signed and unsigned |
||
247 | template |
||
248 | basic_ostream |
||
249 | operator<<(basic_ostream |
||
250 | { return (__out << reinterpret_cast |
||
251 | |||
252 | template |
||
253 | basic_ostream |
||
254 | operator<<(basic_ostream |
||
255 | { return (__out << reinterpret_cast |
||
256 | |||
257 | // 27.6.2.7 Standard basic_ostream manipulators |
||
258 | template |
||
259 | basic_ostream<_CharT, _Traits>& |
||
260 | endl(basic_ostream<_CharT, _Traits>& __os) |
||
261 | { return flush(__os.put(__os.widen('\n'))); } |
||
262 | |||
263 | template |
||
264 | basic_ostream<_CharT, _Traits>& |
||
265 | ends(basic_ostream<_CharT, _Traits>& __os) |
||
266 | { return __os.put(_CharT()); } |
||
267 | |||
268 | template |
||
269 | basic_ostream<_CharT, _Traits>& |
||
270 | flush(basic_ostream<_CharT, _Traits>& __os) |
||
271 | { return __os.flush(); } |
||
272 | |||
273 | } // namespace std |
||
274 | |||
275 | #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT |
||
276 | # define export |
||
277 | #ifdef _GLIBCPP_FULLY_COMPLIANT_HEADERS |
||
278 | # include |
||
279 | #endif |
||
280 | #endif |
||
281 | |||
282 | #endif /* _CPP_OSTREAM */><>(basic_ostream |
||
283 |