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