]>
Commit | Line | Data |
---|---|---|
54c1bf78 | 1 | // Output streams -*- C++ -*- |
de96ac46 | 2 | |
54c1bf78 | 3 | // Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. |
de96ac46 BK |
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 | ||
54c1bf78 BK |
30 | // |
31 | // ISO C++ 14882: 27.6.2 Output streams | |
32 | // | |
33 | ||
34 | /** @file std_ostream.h | |
35 | * This is an internal header file, included by other library headers. | |
36 | * You should not attempt to use it directly. | |
2f9d51b8 PE |
37 | */ |
38 | ||
725dc051 | 39 | #ifndef _CPP_OSTREAM |
54c1bf78 BK |
40 | #define _CPP_OSTREAM 1 |
41 | ||
42 | #pragma GCC system_header | |
43 | ||
44 | #include <ios> | |
45 | ||
46 | namespace std | |
47 | { | |
48 | // 27.6.2.1 Template class basic_ostream | |
49 | template<typename _CharT, typename _Traits> | |
50 | class basic_ostream : virtual public basic_ios<_CharT, _Traits> | |
51 | { | |
52 | public: | |
53 | ||
54 | // Types (inherited from basic_ios (27.4.4)): | |
55 | typedef _CharT char_type; | |
56 | typedef typename _Traits::int_type int_type; | |
57 | typedef typename _Traits::pos_type pos_type; | |
58 | typedef typename _Traits::off_type off_type; | |
59 | typedef _Traits traits_type; | |
60 | ||
61 | // Non-standard Types: | |
62 | typedef basic_streambuf<_CharT, _Traits> __streambuf_type; | |
63 | typedef basic_ios<_CharT, _Traits> __ios_type; | |
64 | typedef basic_ostream<_CharT, _Traits> __ostream_type; | |
65 | typedef ostreambuf_iterator<_CharT, _Traits> __ostreambuf_iter; | |
66 | typedef num_put<_CharT, __ostreambuf_iter> __numput_type; | |
67 | typedef ctype<_CharT> __ctype_type; | |
68 | ||
69 | // 27.6.2.2 Constructor/destructor: | |
70 | explicit | |
71 | basic_ostream(__streambuf_type* __sb) | |
72 | { this->init(__sb); } | |
73 | ||
74 | virtual | |
75 | ~basic_ostream() { } | |
76 | ||
77 | // 27.6.2.3 Prefix/suffix: | |
78 | class sentry; | |
79 | friend class sentry; | |
80 | ||
81 | // 27.6.2.5 Formatted output: | |
82 | // 27.6.2.5.3 basic_ostream::operator<< | |
83 | __ostream_type& | |
84 | operator<<(__ostream_type& (*__pf)(__ostream_type&)); | |
85 | ||
86 | __ostream_type& | |
87 | operator<<(__ios_type& (*__pf)(__ios_type&)); | |
88 | ||
89 | __ostream_type& | |
90 | operator<<(ios_base& (*__pf) (ios_base&)); | |
91 | ||
92 | // 27.6.2.5.2 Arithmetic Inserters | |
93 | __ostream_type& | |
94 | operator<<(long __n); | |
95 | ||
96 | __ostream_type& | |
97 | operator<<(unsigned long __n); | |
98 | ||
99 | __ostream_type& | |
100 | operator<<(bool __n); | |
101 | ||
102 | __ostream_type& | |
103 | operator<<(short __n) | |
104 | { | |
105 | ios_base::fmtflags __fmt = this->flags() & ios_base::basefield; | |
106 | if (__fmt & ios_base::oct || __fmt & ios_base::hex) | |
107 | return this->operator<<(static_cast<unsigned long> | |
108 | (static_cast<unsigned short>(__n))); | |
109 | else | |
110 | return this->operator<<(static_cast<long>(__n)); | |
111 | } | |
112 | ||
113 | __ostream_type& | |
114 | operator<<(unsigned short __n) | |
115 | { return this->operator<<(static_cast<unsigned long>(__n)); } | |
116 | ||
117 | __ostream_type& | |
118 | operator<<(int __n) | |
119 | { | |
120 | ios_base::fmtflags __fmt = this->flags() & ios_base::basefield; | |
121 | if (__fmt & ios_base::oct || __fmt & ios_base::hex) | |
122 | return this->operator<<(static_cast<unsigned long> | |
123 | (static_cast<unsigned int>(__n))); | |
124 | else | |
125 | return this->operator<<(static_cast<long>(__n)); | |
126 | } | |
127 | ||
128 | __ostream_type& | |
129 | operator<<(unsigned int __n) | |
130 | { return this->operator<<(static_cast<unsigned long>(__n)); } | |
131 | ||
132 | #ifdef _GLIBCPP_USE_LONG_LONG | |
133 | __ostream_type& | |
134 | operator<<(long long __n); | |
135 | ||
136 | __ostream_type& | |
137 | operator<<(unsigned long long __n); | |
138 | #endif | |
139 | ||
140 | __ostream_type& | |
141 | operator<<(double __f); | |
142 | ||
143 | __ostream_type& | |
144 | operator<<(float __f) | |
145 | { return this->operator<<(static_cast<double>(__f)); } | |
146 | ||
147 | __ostream_type& | |
148 | operator<<(long double __f); | |
149 | ||
150 | __ostream_type& | |
151 | operator<<(const void* __p); | |
152 | ||
153 | __ostream_type& | |
154 | operator<<(__streambuf_type* __sb); | |
155 | ||
156 | // Unformatted output: | |
157 | __ostream_type& | |
158 | put(char_type __c); | |
159 | ||
160 | __ostream_type& | |
161 | write(const char_type* __s, streamsize __n); | |
162 | ||
163 | __ostream_type& | |
164 | flush(); | |
165 | ||
166 | // Seeks: | |
167 | pos_type | |
168 | tellp(); | |
169 | ||
170 | __ostream_type& | |
171 | seekp(pos_type); | |
172 | ||
173 | __ostream_type& | |
174 | seekp(off_type, ios_base::seekdir); | |
175 | ||
176 | private: | |
177 | #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS | |
178 | // Not defined. (Side effect of DR 50.) | |
179 | __ostream_type& | |
180 | operator=(const __ostream_type&); | |
181 | ||
182 | basic_ostream(const __ostream_type&); | |
725dc051 | 183 | #endif |
54c1bf78 BK |
184 | }; |
185 | ||
186 | // 27.6.2.3 Class basic_ostream::sentry | |
187 | template <typename _CharT, typename _Traits> | |
188 | class basic_ostream<_CharT, _Traits>::sentry | |
189 | { | |
190 | // Data Members: | |
191 | bool _M_ok; | |
192 | basic_ostream<_CharT,_Traits>& _M_os; | |
193 | ||
194 | public: | |
195 | explicit | |
196 | sentry(basic_ostream<_CharT,_Traits>& __os); | |
197 | ||
198 | ~sentry() | |
199 | { | |
200 | // XXX MT | |
201 | if (_M_os.flags() & ios_base::unitbuf && !uncaught_exception()) | |
202 | { | |
203 | // Can't call flush directly or else will get into recursive lock. | |
204 | if (_M_os.rdbuf() && _M_os.rdbuf()->pubsync() == -1) | |
205 | _M_os.setstate(ios_base::badbit); | |
206 | } | |
207 | } | |
208 | ||
209 | operator bool() | |
210 | { return _M_ok; } | |
211 | }; | |
212 | ||
213 | template<typename _CharT, typename _Traits> | |
214 | basic_ostream<_CharT, _Traits>& | |
215 | operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c); | |
216 | ||
217 | template<typename _CharT, typename _Traits> | |
218 | basic_ostream<_CharT, _Traits>& | |
219 | operator<<(basic_ostream<_CharT, _Traits>& __out, char __c) | |
220 | { return (__out << __out.widen(__c)); } | |
221 | ||
222 | // Specialization | |
223 | template <class _Traits> | |
224 | basic_ostream<char, _Traits>& | |
225 | operator<<(basic_ostream<char, _Traits>& __out, char __c); | |
226 | ||
227 | // Signed and unsigned | |
228 | template<class _Traits> | |
229 | basic_ostream<char, _Traits>& | |
230 | operator<<(basic_ostream<char, _Traits>& __out, signed char __c) | |
231 | { return (__out << static_cast<char>(__c)); } | |
232 | ||
233 | template<class _Traits> | |
234 | basic_ostream<char, _Traits>& | |
235 | operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c) | |
236 | { return (__out << static_cast<char>(__c)); } | |
237 | ||
238 | template<typename _CharT, typename _Traits> | |
239 | basic_ostream<_CharT, _Traits>& | |
240 | operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s); | |
241 | ||
242 | template<typename _CharT, typename _Traits> | |
243 | basic_ostream<_CharT, _Traits> & | |
244 | operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s); | |
245 | ||
246 | // Partial specializationss | |
247 | template<class _Traits> | |
248 | basic_ostream<char, _Traits>& | |
249 | operator<<(basic_ostream<char, _Traits>& __out, const char* __s); | |
250 | ||
251 | // Signed and unsigned | |
252 | template<class _Traits> | |
253 | basic_ostream<char, _Traits>& | |
254 | operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s) | |
255 | { return (__out << reinterpret_cast<const char*>(__s)); } | |
256 | ||
257 | template<class _Traits> | |
258 | basic_ostream<char, _Traits> & | |
259 | operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s) | |
260 | { return (__out << reinterpret_cast<const char*>(__s)); } | |
261 | ||
262 | // 27.6.2.7 Standard basic_ostream manipulators | |
263 | template<typename _CharT, typename _Traits> | |
264 | basic_ostream<_CharT, _Traits>& | |
265 | endl(basic_ostream<_CharT, _Traits>& __os) | |
266 | { return flush(__os.put(__os.widen('\n'))); } | |
267 | ||
268 | template<typename _CharT, typename _Traits> | |
269 | basic_ostream<_CharT, _Traits>& | |
270 | ends(basic_ostream<_CharT, _Traits>& __os) | |
271 | { return __os.put(_CharT()); } | |
272 | ||
273 | template<typename _CharT, typename _Traits> | |
274 | basic_ostream<_CharT, _Traits>& | |
275 | flush(basic_ostream<_CharT, _Traits>& __os) | |
276 | { return __os.flush(); } | |
277 | ||
278 | } // namespace std | |
279 | ||
280 | #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT | |
281 | # define export | |
282 | #ifdef _GLIBCPP_FULLY_COMPLIANT_HEADERS | |
283 | # include <bits/ostream.tcc> | |
284 | #endif | |
285 | #endif | |
286 | ||
287 | #endif /* _CPP_OSTREAM */ | |
288 |