]>
Commit | Line | Data |
---|---|---|
725dc051 BK |
1 | // Iostreams base classes -*- C++ -*- |
2 | ||
3cbc7af0 | 3 | // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 |
17325050 | 4 | // Free Software Foundation, Inc. |
725dc051 BK |
5 | // |
6 | // This file is part of the GNU ISO C++ Library. This library is free | |
7 | // software; you can redistribute it and/or modify it under the | |
8 | // terms of the GNU General Public License as published by the | |
9 | // Free Software Foundation; either version 2, or (at your option) | |
10 | // any later version. | |
11 | ||
12 | // This library is distributed in the hope that it will be useful, | |
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | // GNU General Public License for more details. | |
16 | ||
17 | // You should have received a copy of the GNU General Public License along | |
18 | // with this library; see the file COPYING. If not, write to the Free | |
83f51799 | 19 | // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, |
725dc051 BK |
20 | // USA. |
21 | ||
22 | // As a special exception, you may use this file as part of a free software | |
23 | // library without restriction. Specifically, if other files instantiate | |
24 | // templates or use macros or inline functions from this file, or you compile | |
25 | // this file and link it with other files to produce an executable, this | |
26 | // file does not by itself cause the resulting executable to be covered by | |
27 | // the GNU General Public License. This exception does not however | |
28 | // invalidate any other reasons why the executable file might be covered by | |
29 | // the GNU General Public License. | |
30 | ||
31 | // | |
93d04686 | 32 | // ISO C++ 14882: 27.4 Iostreams base classes |
725dc051 BK |
33 | // |
34 | ||
729e3d3f PE |
35 | /** @file ios_base.h |
36 | * This is an internal header file, included by other library headers. | |
37 | * You should not attempt to use it directly. | |
38 | */ | |
39 | ||
3d7c150e BK |
40 | #ifndef _IOS_BASE_H |
41 | #define _IOS_BASE_H 1 | |
725dc051 | 42 | |
b0a85b86 GDR |
43 | #pragma GCC system_header |
44 | ||
17325050 | 45 | #include <bits/atomicity.h> |
e6686813 BK |
46 | #include <bits/localefwd.h> |
47 | #include <bits/locale_classes.h> | |
17325050 | 48 | |
3cbc7af0 BK |
49 | _GLIBCXX_BEGIN_NAMESPACE(std) |
50 | ||
725dc051 BK |
51 | // The following definitions of bitmask types are enums, not ints, |
52 | // as permitted (but not required) in the standard, in order to provide | |
53 | // better type safety in iostream calls. A side effect is that | |
54 | // expressions involving them are no longer compile-time constants. | |
bd80bd9b BK |
55 | enum _Ios_Fmtflags |
56 | { | |
57 | _S_boolalpha = 1L << 0, | |
58 | _S_dec = 1L << 1, | |
59 | _S_fixed = 1L << 2, | |
60 | _S_hex = 1L << 3, | |
61 | _S_internal = 1L << 4, | |
62 | _S_left = 1L << 5, | |
63 | _S_oct = 1L << 6, | |
64 | _S_right = 1L << 7, | |
65 | _S_scientific = 1L << 8, | |
66 | _S_showbase = 1L << 9, | |
67 | _S_showpoint = 1L << 10, | |
68 | _S_showpos = 1L << 11, | |
69 | _S_skipws = 1L << 12, | |
70 | _S_unitbuf = 1L << 13, | |
71 | _S_uppercase = 1L << 14, | |
72 | _S_adjustfield = _S_left | _S_right | _S_internal, | |
73 | _S_basefield = _S_dec | _S_oct | _S_hex, | |
74 | _S_floatfield = _S_scientific | _S_fixed, | |
75 | _S_ios_fmtflags_end = 1L << 16 | |
76 | }; | |
725dc051 | 77 | |
ed6814f7 | 78 | inline _Ios_Fmtflags |
725dc051 BK |
79 | operator&(_Ios_Fmtflags __a, _Ios_Fmtflags __b) |
80 | { return _Ios_Fmtflags(static_cast<int>(__a) & static_cast<int>(__b)); } | |
81 | ||
ed6814f7 | 82 | inline _Ios_Fmtflags |
725dc051 BK |
83 | operator|(_Ios_Fmtflags __a, _Ios_Fmtflags __b) |
84 | { return _Ios_Fmtflags(static_cast<int>(__a) | static_cast<int>(__b)); } | |
85 | ||
ed6814f7 | 86 | inline _Ios_Fmtflags |
725dc051 BK |
87 | operator^(_Ios_Fmtflags __a, _Ios_Fmtflags __b) |
88 | { return _Ios_Fmtflags(static_cast<int>(__a) ^ static_cast<int>(__b)); } | |
89 | ||
bd80bd9b | 90 | inline _Ios_Fmtflags& |
725dc051 BK |
91 | operator|=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) |
92 | { return __a = __a | __b; } | |
93 | ||
bd80bd9b | 94 | inline _Ios_Fmtflags& |
725dc051 BK |
95 | operator&=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) |
96 | { return __a = __a & __b; } | |
97 | ||
bd80bd9b | 98 | inline _Ios_Fmtflags& |
725dc051 BK |
99 | operator^=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) |
100 | { return __a = __a ^ __b; } | |
101 | ||
ed6814f7 | 102 | inline _Ios_Fmtflags |
725dc051 BK |
103 | operator~(_Ios_Fmtflags __a) |
104 | { return _Ios_Fmtflags(~static_cast<int>(__a)); } | |
105 | ||
106 | ||
bd80bd9b BK |
107 | enum _Ios_Openmode |
108 | { | |
109 | _S_app = 1L << 0, | |
110 | _S_ate = 1L << 1, | |
111 | _S_bin = 1L << 2, | |
112 | _S_in = 1L << 3, | |
113 | _S_out = 1L << 4, | |
114 | _S_trunc = 1L << 5, | |
115 | _S_ios_openmode_end = 1L << 16 | |
116 | }; | |
725dc051 | 117 | |
ed6814f7 | 118 | inline _Ios_Openmode |
725dc051 BK |
119 | operator&(_Ios_Openmode __a, _Ios_Openmode __b) |
120 | { return _Ios_Openmode(static_cast<int>(__a) & static_cast<int>(__b)); } | |
121 | ||
ed6814f7 | 122 | inline _Ios_Openmode |
725dc051 BK |
123 | operator|(_Ios_Openmode __a, _Ios_Openmode __b) |
124 | { return _Ios_Openmode(static_cast<int>(__a) | static_cast<int>(__b)); } | |
125 | ||
ed6814f7 | 126 | inline _Ios_Openmode |
725dc051 BK |
127 | operator^(_Ios_Openmode __a, _Ios_Openmode __b) |
128 | { return _Ios_Openmode(static_cast<int>(__a) ^ static_cast<int>(__b)); } | |
129 | ||
bd80bd9b | 130 | inline _Ios_Openmode& |
725dc051 BK |
131 | operator|=(_Ios_Openmode& __a, _Ios_Openmode __b) |
132 | { return __a = __a | __b; } | |
133 | ||
bd80bd9b | 134 | inline _Ios_Openmode& |
725dc051 BK |
135 | operator&=(_Ios_Openmode& __a, _Ios_Openmode __b) |
136 | { return __a = __a & __b; } | |
137 | ||
bd80bd9b | 138 | inline _Ios_Openmode& |
725dc051 BK |
139 | operator^=(_Ios_Openmode& __a, _Ios_Openmode __b) |
140 | { return __a = __a ^ __b; } | |
141 | ||
ed6814f7 | 142 | inline _Ios_Openmode |
725dc051 BK |
143 | operator~(_Ios_Openmode __a) |
144 | { return _Ios_Openmode(~static_cast<int>(__a)); } | |
145 | ||
146 | ||
bd80bd9b BK |
147 | enum _Ios_Iostate |
148 | { | |
149 | _S_goodbit = 0, | |
150 | _S_badbit = 1L << 0, | |
151 | _S_eofbit = 1L << 1, | |
152 | _S_failbit = 1L << 2, | |
153 | _S_ios_iostate_end = 1L << 16 | |
154 | }; | |
725dc051 | 155 | |
ed6814f7 | 156 | inline _Ios_Iostate |
725dc051 BK |
157 | operator&(_Ios_Iostate __a, _Ios_Iostate __b) |
158 | { return _Ios_Iostate(static_cast<int>(__a) & static_cast<int>(__b)); } | |
159 | ||
ed6814f7 | 160 | inline _Ios_Iostate |
725dc051 BK |
161 | operator|(_Ios_Iostate __a, _Ios_Iostate __b) |
162 | { return _Ios_Iostate(static_cast<int>(__a) | static_cast<int>(__b)); } | |
163 | ||
ed6814f7 | 164 | inline _Ios_Iostate |
725dc051 BK |
165 | operator^(_Ios_Iostate __a, _Ios_Iostate __b) |
166 | { return _Ios_Iostate(static_cast<int>(__a) ^ static_cast<int>(__b)); } | |
167 | ||
bd80bd9b | 168 | inline _Ios_Iostate& |
725dc051 BK |
169 | operator|=(_Ios_Iostate& __a, _Ios_Iostate __b) |
170 | { return __a = __a | __b; } | |
171 | ||
bd80bd9b | 172 | inline _Ios_Iostate& |
725dc051 BK |
173 | operator&=(_Ios_Iostate& __a, _Ios_Iostate __b) |
174 | { return __a = __a & __b; } | |
175 | ||
bd80bd9b | 176 | inline _Ios_Iostate& |
725dc051 BK |
177 | operator^=(_Ios_Iostate& __a, _Ios_Iostate __b) |
178 | { return __a = __a ^ __b; } | |
179 | ||
ed6814f7 | 180 | inline _Ios_Iostate |
725dc051 BK |
181 | operator~(_Ios_Iostate __a) |
182 | { return _Ios_Iostate(~static_cast<int>(__a)); } | |
183 | ||
bd80bd9b BK |
184 | enum _Ios_Seekdir |
185 | { | |
186 | _S_beg = 0, | |
187 | _S_cur = SEEK_CUR, | |
188 | _S_end = SEEK_END, | |
189 | _S_ios_seekdir_end = 1L << 16 | |
190 | }; | |
725dc051 BK |
191 | |
192 | // 27.4.2 Class ios_base | |
840ceb34 | 193 | /** |
00aca6e8 | 194 | * @brief The base of the I/O class hierarchy. |
840ceb34 PE |
195 | * |
196 | * This class defines everything that can be defined about I/O that does | |
197 | * not depend on the type of characters being input or output. Most | |
198 | * people will only see @c ios_base when they need to specify the full | |
199 | * name of the various I/O flags (e.g., the openmodes). | |
200 | */ | |
725dc051 BK |
201 | class ios_base |
202 | { | |
203 | public: | |
ed6814f7 | 204 | |
725dc051 | 205 | // 27.4.2.1.1 Class ios_base::failure |
840ceb34 | 206 | /// These are thrown to indicate problems. Doc me. |
725dc051 BK |
207 | class failure : public exception |
208 | { | |
209 | public: | |
f5677b15 PC |
210 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
211 | // 48. Use of non-existent exception constructor | |
ed6814f7 | 212 | explicit |
d34786e3 | 213 | failure(const string& __str) throw(); |
725dc051 | 214 | |
663653eb BK |
215 | // This declaration is not useless: |
216 | // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 | |
ed6814f7 | 217 | virtual |
d34786e3 | 218 | ~failure() throw(); |
725dc051 | 219 | |
23a5b444 GDR |
220 | virtual const char* |
221 | what() const throw(); | |
ed6814f7 | 222 | |
725dc051 | 223 | private: |
93d04686 | 224 | string _M_msg; |
725dc051 BK |
225 | }; |
226 | ||
227 | // 27.4.2.1.2 Type ios_base::fmtflags | |
840ceb34 PE |
228 | /** |
229 | * @brief This is a bitmask type. | |
230 | * | |
231 | * @c "_Ios_Fmtflags" is implementation-defined, but it is valid to | |
232 | * perform bitwise operations on these values and expect the Right | |
233 | * Thing to happen. Defined objects of type fmtflags are: | |
234 | * - boolalpha | |
235 | * - dec | |
236 | * - fixed | |
237 | * - hex | |
238 | * - internal | |
239 | * - left | |
240 | * - oct | |
241 | * - right | |
242 | * - scientific | |
243 | * - showbase | |
244 | * - showpoint | |
245 | * - showpos | |
246 | * - skipws | |
247 | * - unitbuf | |
248 | * - uppercase | |
249 | * - adjustfield | |
250 | * - basefield | |
251 | * - floatfield | |
252 | */ | |
725dc051 | 253 | typedef _Ios_Fmtflags fmtflags; |
215f9e28 | 254 | |
840ceb34 | 255 | /// Insert/extract @c bool in alphabetic rather than numeric format. |
725dc051 | 256 | static const fmtflags boolalpha = fmtflags(__ios_flags::_S_boolalpha); |
215f9e28 | 257 | |
840ceb34 | 258 | /// Converts integer input or generates integer output in decimal base. |
725dc051 | 259 | static const fmtflags dec = fmtflags(__ios_flags::_S_dec); |
215f9e28 | 260 | |
840ceb34 | 261 | /// Generate floating-point output in fixed-point notation. |
725dc051 | 262 | static const fmtflags fixed = fmtflags(__ios_flags::_S_fixed); |
215f9e28 | 263 | |
840ceb34 | 264 | /// Converts integer input or generates integer output in hexadecimal base. |
725dc051 | 265 | static const fmtflags hex = fmtflags(__ios_flags::_S_hex); |
215f9e28 | 266 | |
840ceb34 PE |
267 | /// Adds fill characters at a designated internal point in certain |
268 | /// generated output, or identical to @c right if no such point is | |
269 | /// designated. | |
725dc051 | 270 | static const fmtflags internal = fmtflags(__ios_flags::_S_internal); |
215f9e28 | 271 | |
840ceb34 PE |
272 | /// Adds fill characters on the right (final positions) of certain |
273 | /// generated output. (I.e., the thing you print is flush left.) | |
725dc051 | 274 | static const fmtflags left = fmtflags(__ios_flags::_S_left); |
215f9e28 | 275 | |
840ceb34 | 276 | /// Converts integer input or generates integer output in octal base. |
725dc051 | 277 | static const fmtflags oct = fmtflags(__ios_flags::_S_oct); |
215f9e28 | 278 | |
840ceb34 PE |
279 | /// Adds fill characters on the left (initial positions) of certain |
280 | /// generated output. (I.e., the thing you print is flush right.) | |
725dc051 | 281 | static const fmtflags right = fmtflags(__ios_flags::_S_right); |
215f9e28 | 282 | |
840ceb34 | 283 | /// Generates floating-point output in scientific notation. |
725dc051 | 284 | static const fmtflags scientific = fmtflags(__ios_flags::_S_scientific); |
215f9e28 | 285 | |
840ceb34 PE |
286 | /// Generates a prefix indicating the numeric base of generated integer |
287 | /// output. | |
725dc051 | 288 | static const fmtflags showbase = fmtflags(__ios_flags::_S_showbase); |
215f9e28 | 289 | |
840ceb34 PE |
290 | /// Generates a decimal-point character unconditionally in generated |
291 | /// floating-point output. | |
725dc051 | 292 | static const fmtflags showpoint = fmtflags(__ios_flags::_S_showpoint); |
215f9e28 | 293 | |
840ceb34 | 294 | /// Generates a + sign in non-negative generated numeric output. |
725dc051 | 295 | static const fmtflags showpos = fmtflags(__ios_flags::_S_showpos); |
215f9e28 | 296 | |
840ceb34 | 297 | /// Skips leading white space before certain input operations. |
725dc051 | 298 | static const fmtflags skipws = fmtflags(__ios_flags::_S_skipws); |
215f9e28 | 299 | |
840ceb34 | 300 | /// Flushes output after each output operation. |
725dc051 | 301 | static const fmtflags unitbuf = fmtflags(__ios_flags::_S_unitbuf); |
215f9e28 | 302 | |
840ceb34 PE |
303 | /// Replaces certain lowercase letters with their uppercase equivalents |
304 | /// in generated output. | |
725dc051 | 305 | static const fmtflags uppercase = fmtflags(__ios_flags::_S_uppercase); |
215f9e28 | 306 | |
840ceb34 | 307 | /// A mask of left|right|internal. Useful for the 2-arg form of @c setf. |
725dc051 | 308 | static const fmtflags adjustfield = fmtflags(__ios_flags::_S_adjustfield); |
215f9e28 | 309 | |
840ceb34 | 310 | /// A mask of dec|oct|hex. Useful for the 2-arg form of @c setf. |
725dc051 | 311 | static const fmtflags basefield = fmtflags(__ios_flags::_S_basefield); |
215f9e28 | 312 | |
840ceb34 | 313 | /// A mask of scientific|fixed. Useful for the 2-arg form of @c setf. |
725dc051 BK |
314 | static const fmtflags floatfield = fmtflags(__ios_flags::_S_floatfield); |
315 | ||
316 | // 27.4.2.1.3 Type ios_base::iostate | |
840ceb34 PE |
317 | /** |
318 | * @brief This is a bitmask type. | |
319 | * | |
320 | * @c "_Ios_Iostate" is implementation-defined, but it is valid to | |
321 | * perform bitwise operations on these values and expect the Right | |
322 | * Thing to happen. Defined objects of type iostate are: | |
323 | * - badbit | |
324 | * - eofbit | |
325 | * - failbit | |
326 | * - goodbit | |
327 | */ | |
725dc051 | 328 | typedef _Ios_Iostate iostate; |
215f9e28 | 329 | |
840ceb34 PE |
330 | /// Indicates a loss of integrity in an input or output sequence (such |
331 | /// as an irrecoverable read error from a file). | |
ed6814f7 | 332 | static const iostate badbit = iostate(__ios_flags::_S_badbit); |
215f9e28 | 333 | |
840ceb34 | 334 | /// Indicates that an input operation reached the end of an input sequence. |
ed6814f7 | 335 | static const iostate eofbit = iostate(__ios_flags::_S_eofbit); |
215f9e28 | 336 | |
840ceb34 PE |
337 | /// Indicates that an input operation failed to read the expected |
338 | /// characters, or that an output operation failed to generate the | |
339 | /// desired characters. | |
ed6814f7 | 340 | static const iostate failbit = iostate(__ios_flags::_S_failbit); |
215f9e28 | 341 | |
840ceb34 | 342 | /// Indicates all is well. |
ed6814f7 | 343 | static const iostate goodbit = iostate(0); |
725dc051 | 344 | |
840ceb34 PE |
345 | // 27.4.2.1.4 Type ios_base::openmode |
346 | /** | |
347 | * @brief This is a bitmask type. | |
348 | * | |
349 | * @c "_Ios_Openmode" is implementation-defined, but it is valid to | |
350 | * perform bitwise operations on these values and expect the Right | |
351 | * Thing to happen. Defined objects of type openmode are: | |
352 | * - app | |
353 | * - ate | |
354 | * - binary | |
355 | * - in | |
356 | * - out | |
357 | * - trunc | |
358 | */ | |
725dc051 | 359 | typedef _Ios_Openmode openmode; |
215f9e28 | 360 | |
840ceb34 | 361 | /// Seek to end before each write. |
ed6814f7 | 362 | static const openmode app = openmode(__ios_flags::_S_app); |
215f9e28 | 363 | |
840ceb34 | 364 | /// Open and seek to end immediately after opening. |
ed6814f7 | 365 | static const openmode ate = openmode(__ios_flags::_S_ate); |
215f9e28 | 366 | |
840ceb34 PE |
367 | /// Perform input and output in binary mode (as opposed to text mode). |
368 | /// This is probably not what you think it is; see | |
369 | /// http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#3 and | |
370 | /// http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#7 for more. | |
ed6814f7 | 371 | static const openmode binary = openmode(__ios_flags::_S_bin); |
215f9e28 | 372 | |
840ceb34 | 373 | /// Open for input. Default for @c ifstream and fstream. |
ed6814f7 | 374 | static const openmode in = openmode(__ios_flags::_S_in); |
215f9e28 | 375 | |
840ceb34 | 376 | /// Open for output. Default for @c ofstream and fstream. |
ed6814f7 | 377 | static const openmode out = openmode(__ios_flags::_S_out); |
215f9e28 | 378 | |
840ceb34 | 379 | /// Open for input. Default for @c ofstream. |
ed6814f7 | 380 | static const openmode trunc = openmode(__ios_flags::_S_trunc); |
725dc051 | 381 | |
840ceb34 PE |
382 | // 27.4.2.1.5 Type ios_base::seekdir |
383 | /** | |
384 | * @brief This is an enumerated type. | |
385 | * | |
386 | * @c "_Ios_Seekdir" is implementation-defined. Defined values | |
387 | * of type seekdir are: | |
388 | * - beg | |
389 | * - cur, equivalent to @c SEEK_CUR in the C standard library. | |
390 | * - end, equivalent to @c SEEK_END in the C standard library. | |
391 | */ | |
725dc051 | 392 | typedef _Ios_Seekdir seekdir; |
215f9e28 | 393 | |
840ceb34 | 394 | /// Request a seek relative to the beginning of the stream. |
ed6814f7 | 395 | static const seekdir beg = seekdir(0); |
215f9e28 | 396 | |
840ceb34 | 397 | /// Request a seek relative to the current position within the sequence. |
ed6814f7 | 398 | static const seekdir cur = seekdir(SEEK_CUR); |
215f9e28 | 399 | |
840ceb34 | 400 | /// Request a seek relative to the current end of the sequence. |
ed6814f7 | 401 | static const seekdir end = seekdir(SEEK_END); |
725dc051 | 402 | |
4df6abc6 | 403 | // Annex D.6 |
725dc051 BK |
404 | typedef int io_state; |
405 | typedef int open_mode; | |
406 | typedef int seek_dir; | |
ed6814f7 | 407 | |
92204597 BK |
408 | typedef std::streampos streampos; |
409 | typedef std::streamoff streamoff; | |
725dc051 BK |
410 | |
411 | // Callbacks; | |
840ceb34 | 412 | /** |
e2fcbaa3 JQ |
413 | * @brief The set of events that may be passed to an event callback. |
414 | * | |
415 | * erase_event is used during ~ios() and copyfmt(). imbue_event is used | |
416 | * during imbue(). copyfmt_event is used during copyfmt(). | |
840ceb34 | 417 | */ |
725dc051 BK |
418 | enum event |
419 | { | |
420 | erase_event, | |
421 | imbue_event, | |
422 | copyfmt_event | |
423 | }; | |
424 | ||
840ceb34 | 425 | /** |
e2fcbaa3 JQ |
426 | * @brief The type of an event callback function. |
427 | * @param event One of the members of the event enum. | |
428 | * @param ios_base Reference to the ios_base object. | |
429 | * @param int The integer provided when the callback was registered. | |
430 | * | |
431 | * Event callbacks are user defined functions that get called during | |
432 | * several ios_base and basic_ios functions, specifically imbue(), | |
433 | * copyfmt(), and ~ios(). | |
840ceb34 | 434 | */ |
725dc051 BK |
435 | typedef void (*event_callback) (event, ios_base&, int); |
436 | ||
840ceb34 | 437 | /** |
e2fcbaa3 JQ |
438 | * @brief Add the callback __fn with parameter __index. |
439 | * @param __fn The function to add. | |
440 | * @param __index The integer to pass to the function when invoked. | |
441 | * | |
442 | * Registers a function as an event callback with an integer parameter to | |
443 | * be passed to the function when invoked. Multiple copies of the | |
444 | * function are allowed. If there are multiple callbacks, they are | |
445 | * invoked in the order they were registered. | |
840ceb34 | 446 | */ |
ed6814f7 | 447 | void |
725dc051 BK |
448 | register_callback(event_callback __fn, int __index); |
449 | ||
450 | protected: | |
840ceb34 PE |
451 | //@{ |
452 | /** | |
453 | * @if maint | |
454 | * ios_base data members (doc me) | |
455 | * @endif | |
456 | */ | |
ed6814f7 BI |
457 | streamsize _M_precision; |
458 | streamsize _M_width; | |
459 | fmtflags _M_flags; | |
460 | iostate _M_exception; | |
461 | iostate _M_streambuf_state; | |
840ceb34 | 462 | //@} |
725dc051 | 463 | |
d9ab8adb | 464 | // 27.4.2.6 Members for callbacks |
725dc051 | 465 | // 27.4.2.6 ios_base callbacks |
725dc051 BK |
466 | struct _Callback_list |
467 | { | |
468 | // Data Members | |
ed6814f7 BI |
469 | _Callback_list* _M_next; |
470 | ios_base::event_callback _M_fn; | |
471 | int _M_index; | |
17325050 | 472 | _Atomic_word _M_refcount; // 0 means one reference. |
ed6814f7 BI |
473 | |
474 | _Callback_list(ios_base::event_callback __fn, int __index, | |
725dc051 BK |
475 | _Callback_list* __cb) |
476 | : _M_next(__cb), _M_fn(__fn), _M_index(__index), _M_refcount(0) { } | |
ed6814f7 BI |
477 | |
478 | void | |
2c5d0ae8 | 479 | _M_add_reference() { __gnu_cxx::__atomic_add(&_M_refcount, 1); } |
17325050 | 480 | |
663653eb | 481 | // 0 => OK to delete. |
ed6814f7 | 482 | int |
2c5d0ae8 BK |
483 | _M_remove_reference() |
484 | { return __gnu_cxx::__exchange_and_add(&_M_refcount, -1); } | |
725dc051 BK |
485 | }; |
486 | ||
ed6814f7 | 487 | _Callback_list* _M_callbacks; |
725dc051 | 488 | |
ed6814f7 | 489 | void |
725dc051 BK |
490 | _M_call_callbacks(event __ev) throw(); |
491 | ||
ed6814f7 | 492 | void |
725dc051 BK |
493 | _M_dispose_callbacks(void); |
494 | ||
d9ab8adb | 495 | // 27.4.2.5 Members for iword/pword storage |
ed6814f7 BI |
496 | struct _Words |
497 | { | |
498 | void* _M_pword; | |
499 | long _M_iword; | |
663653eb | 500 | _Words() : _M_pword(0), _M_iword(0) { } |
725dc051 BK |
501 | }; |
502 | ||
663653eb | 503 | // Only for failed iword/pword calls. |
ed6814f7 | 504 | _Words _M_word_zero; |
663653eb BK |
505 | |
506 | // Guaranteed storage. | |
2e2a38cd | 507 | // The first 5 iword and pword slots are reserved for internal use. |
ed6814f7 BI |
508 | static const int _S_local_word_size = 8; |
509 | _Words _M_local_word[_S_local_word_size]; | |
663653eb BK |
510 | |
511 | // Allocated storage. | |
ed6814f7 BI |
512 | int _M_word_size; |
513 | _Words* _M_word; | |
514 | ||
515 | _Words& | |
2a837cf8 | 516 | _M_grow_words(int __index, bool __iword); |
725dc051 BK |
517 | |
518 | // Members for locale and locale caching. | |
ed6814f7 | 519 | locale _M_ios_locale; |
725dc051 | 520 | |
ed6814f7 | 521 | void |
725dc051 BK |
522 | _M_init(); |
523 | ||
524 | public: | |
d9ab8adb | 525 | |
725dc051 BK |
526 | // 27.4.2.1.6 Class ios_base::Init |
527 | // Used to initialize standard streams. In theory, g++ could use | |
528 | // -finit-priority to order this stuff correctly without going | |
ed6814f7 BI |
529 | // through these machinations. |
530 | class Init | |
725dc051 BK |
531 | { |
532 | friend class ios_base; | |
533 | public: | |
534 | Init(); | |
535 | ~Init(); | |
ed6814f7 | 536 | |
725dc051 | 537 | private: |
fa972243 BK |
538 | static _Atomic_word _S_refcount; |
539 | static bool _S_synced_with_stdio; | |
725dc051 BK |
540 | }; |
541 | ||
840ceb34 PE |
542 | // [27.4.2.2] fmtflags state functions |
543 | /** | |
544 | * @brief Access to format flags. | |
545 | * @return The format control flags for both input and output. | |
546 | */ | |
ed6814f7 | 547 | inline fmtflags |
725dc051 BK |
548 | flags() const { return _M_flags; } |
549 | ||
840ceb34 PE |
550 | /** |
551 | * @brief Setting new format flags all at once. | |
552 | * @param fmtfl The new flags to set. | |
553 | * @return The previous format control flags. | |
554 | * | |
555 | * This function overwrites all the format flags with @a fmtfl. | |
556 | */ | |
ed6814f7 | 557 | inline fmtflags |
725dc051 | 558 | flags(fmtflags __fmtfl) |
ed6814f7 BI |
559 | { |
560 | fmtflags __old = _M_flags; | |
561 | _M_flags = __fmtfl; | |
562 | return __old; | |
725dc051 BK |
563 | } |
564 | ||
840ceb34 PE |
565 | /** |
566 | * @brief Setting new format flags. | |
567 | * @param fmtfl Additional flags to set. | |
568 | * @return The previous format control flags. | |
569 | * | |
570 | * This function sets additional flags in format control. Flags that | |
571 | * were previously set remain set. | |
572 | */ | |
ed6814f7 | 573 | inline fmtflags |
725dc051 | 574 | setf(fmtflags __fmtfl) |
ed6814f7 BI |
575 | { |
576 | fmtflags __old = _M_flags; | |
577 | _M_flags |= __fmtfl; | |
578 | return __old; | |
725dc051 BK |
579 | } |
580 | ||
840ceb34 PE |
581 | /** |
582 | * @brief Setting new format flags. | |
583 | * @param fmtfl Additional flags to set. | |
584 | * @param mask The flags mask for @a fmtfl. | |
585 | * @return The previous format control flags. | |
586 | * | |
587 | * This function clears @a mask in the format flags, then sets | |
588 | * @a fmtfl @c & @a mask. An example mask is @c ios_base::adjustfield. | |
589 | */ | |
ed6814f7 | 590 | inline fmtflags |
725dc051 BK |
591 | setf(fmtflags __fmtfl, fmtflags __mask) |
592 | { | |
593 | fmtflags __old = _M_flags; | |
594 | _M_flags &= ~__mask; | |
595 | _M_flags |= (__fmtfl & __mask); | |
596 | return __old; | |
597 | } | |
598 | ||
840ceb34 PE |
599 | /** |
600 | * @brief Clearing format flags. | |
601 | * @param mask The flags to unset. | |
602 | * | |
603 | * This function clears @a mask in the format flags. | |
604 | */ | |
ed6814f7 | 605 | inline void |
725dc051 BK |
606 | unsetf(fmtflags __mask) { _M_flags &= ~__mask; } |
607 | ||
840ceb34 PE |
608 | /** |
609 | * @brief Flags access. | |
610 | * @return The precision to generate on certain output operations. | |
611 | * | |
612 | * @if maint | |
613 | * Be careful if you try to give a definition of "precision" here; see | |
614 | * DR 189. | |
615 | * @endif | |
616 | */ | |
ed6814f7 | 617 | inline streamsize |
725dc051 BK |
618 | precision() const { return _M_precision; } |
619 | ||
840ceb34 PE |
620 | /** |
621 | * @brief Changing flags. | |
622 | * @param prec The new precision value. | |
623 | * @return The previous value of precision(). | |
624 | */ | |
ed6814f7 | 625 | inline streamsize |
725dc051 | 626 | precision(streamsize __prec) |
ed6814f7 BI |
627 | { |
628 | streamsize __old = _M_precision; | |
629 | _M_precision = __prec; | |
630 | return __old; | |
725dc051 BK |
631 | } |
632 | ||
840ceb34 PE |
633 | /** |
634 | * @brief Flags access. | |
635 | * @return The minimum field width to generate on output operations. | |
636 | * | |
637 | * "Minimum field width" refers to the number of characters. | |
638 | */ | |
ed6814f7 | 639 | inline streamsize |
725dc051 BK |
640 | width() const { return _M_width; } |
641 | ||
840ceb34 PE |
642 | /** |
643 | * @brief Changing flags. | |
644 | * @param wide The new width value. | |
645 | * @return The previous value of width(). | |
646 | */ | |
ed6814f7 | 647 | inline streamsize |
725dc051 | 648 | width(streamsize __wide) |
ed6814f7 BI |
649 | { |
650 | streamsize __old = _M_width; | |
651 | _M_width = __wide; | |
652 | return __old; | |
725dc051 BK |
653 | } |
654 | ||
840ceb34 PE |
655 | // [27.4.2.4] ios_base static members |
656 | /** | |
657 | * @brief Interaction with the standard C I/O objects. | |
658 | * @param sync Whether to synchronize or not. | |
659 | * @return True if the standard streams were previously synchronized. | |
660 | * | |
661 | * The synchronization referred to is @e only that between the standard | |
662 | * C facilities (e.g., stdout) and the standard C++ objects (e.g., | |
663 | * cout). User-declared streams are unaffected. See | |
664 | * http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#8 for more. | |
665 | */ | |
ed6814f7 | 666 | static bool |
725dc051 BK |
667 | sync_with_stdio(bool __sync = true); |
668 | ||
840ceb34 PE |
669 | // [27.4.2.3] ios_base locale functions |
670 | /** | |
671 | * @brief Setting a new locale. | |
672 | * @param loc The new locale. | |
673 | * @return The previous locale. | |
674 | * | |
e2fcbaa3 JQ |
675 | * Sets the new locale for this stream, and then invokes each callback |
676 | * with imbue_event. | |
840ceb34 | 677 | */ |
ed6814f7 | 678 | locale |
725dc051 BK |
679 | imbue(const locale& __loc); |
680 | ||
840ceb34 PE |
681 | /** |
682 | * @brief Locale access | |
215f9e28 | 683 | * @return A copy of the current locale. |
840ceb34 PE |
684 | * |
685 | * If @c imbue(loc) has previously been called, then this function | |
686 | * returns @c loc. Otherwise, it returns a copy of @c std::locale(), | |
687 | * the global C++ locale. | |
688 | */ | |
ed6814f7 | 689 | inline locale |
725dc051 BK |
690 | getloc() const { return _M_ios_locale; } |
691 | ||
215f9e28 BK |
692 | /** |
693 | * @brief Locale access | |
694 | * @return A reference to the current locale. | |
695 | * | |
696 | * Like getloc above, but returns a reference instead of | |
697 | * generating a copy. | |
698 | */ | |
ed6814f7 | 699 | inline const locale& |
215f9e28 BK |
700 | _M_getloc() const { return _M_ios_locale; } |
701 | ||
840ceb34 PE |
702 | // [27.4.2.5] ios_base storage functions |
703 | /** | |
e2fcbaa3 JQ |
704 | * @brief Access to unique indices. |
705 | * @return An integer different from all previous calls. | |
706 | * | |
707 | * This function returns a unique integer every time it is called. It | |
708 | * can be used for any purpose, but is primarily intended to be a unique | |
709 | * index for the iword and pword functions. The expectation is that an | |
710 | * application calls xalloc in order to obtain an index in the iword and | |
711 | * pword arrays that can be used without fear of conflict. | |
712 | * | |
713 | * The implementation maintains a static variable that is incremented and | |
714 | * returned on each invocation. xalloc is guaranteed to return an index | |
715 | * that is safe to use in the iword and pword arrays. | |
840ceb34 | 716 | */ |
ed6814f7 | 717 | static int |
725dc051 BK |
718 | xalloc() throw(); |
719 | ||
840ceb34 | 720 | /** |
e2fcbaa3 JQ |
721 | * @brief Access to integer array. |
722 | * @param __ix Index into the array. | |
723 | * @return A reference to an integer associated with the index. | |
724 | * | |
725 | * The iword function provides access to an array of integers that can be | |
726 | * used for any purpose. The array grows as required to hold the | |
727 | * supplied index. All integers in the array are initialized to 0. | |
728 | * | |
729 | * The implementation reserves several indices. You should use xalloc to | |
730 | * obtain an index that is safe to use. Also note that since the array | |
731 | * can grow dynamically, it is not safe to hold onto the reference. | |
840ceb34 | 732 | */ |
ed6814f7 | 733 | inline long& |
725dc051 BK |
734 | iword(int __ix) |
735 | { | |
ed6814f7 | 736 | _Words& __word = (__ix < _M_word_size) |
2a837cf8 | 737 | ? _M_word[__ix] : _M_grow_words(__ix, true); |
725dc051 BK |
738 | return __word._M_iword; |
739 | } | |
740 | ||
840ceb34 | 741 | /** |
e2fcbaa3 JQ |
742 | * @brief Access to void pointer array. |
743 | * @param __ix Index into the array. | |
744 | * @return A reference to a void* associated with the index. | |
745 | * | |
746 | * The pword function provides access to an array of pointers that can be | |
747 | * used for any purpose. The array grows as required to hold the | |
748 | * supplied index. All pointers in the array are initialized to 0. | |
749 | * | |
750 | * The implementation reserves several indices. You should use xalloc to | |
751 | * obtain an index that is safe to use. Also note that since the array | |
752 | * can grow dynamically, it is not safe to hold onto the reference. | |
840ceb34 | 753 | */ |
ed6814f7 | 754 | inline void*& |
725dc051 BK |
755 | pword(int __ix) |
756 | { | |
ed6814f7 | 757 | _Words& __word = (__ix < _M_word_size) |
2a837cf8 | 758 | ? _M_word[__ix] : _M_grow_words(__ix, false); |
725dc051 BK |
759 | return __word._M_pword; |
760 | } | |
761 | ||
762 | // Destructor | |
840ceb34 | 763 | /** |
e2fcbaa3 JQ |
764 | * Invokes each callback with erase_event. Destroys local storage. |
765 | * | |
766 | * Note that the ios_base object for the standard streams never gets | |
767 | * destroyed. As a result, any callbacks registered with the standard | |
768 | * streams will not get invoked with erase_event (unless copyfmt is | |
769 | * used). | |
840ceb34 | 770 | */ |
cb930542 | 771 | virtual ~ios_base(); |
725dc051 BK |
772 | |
773 | protected: | |
774 | ios_base(); | |
775 | ||
f5677b15 PC |
776 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
777 | // 50. Copy constructor and assignment operator of ios_base | |
725dc051 BK |
778 | private: |
779 | ios_base(const ios_base&); | |
780 | ||
ed6814f7 | 781 | ios_base& |
725dc051 | 782 | operator=(const ios_base&); |
725dc051 | 783 | }; |
ed6814f7 | 784 | |
840ceb34 PE |
785 | // [27.4.5.1] fmtflags manipulators |
786 | /// Calls base.setf(ios_base::boolalpha). | |
ed6814f7 | 787 | inline ios_base& |
725dc051 BK |
788 | boolalpha(ios_base& __base) |
789 | { | |
790 | __base.setf(ios_base::boolalpha); | |
791 | return __base; | |
792 | } | |
793 | ||
840ceb34 | 794 | /// Calls base.unsetf(ios_base::boolalpha). |
ed6814f7 | 795 | inline ios_base& |
725dc051 BK |
796 | noboolalpha(ios_base& __base) |
797 | { | |
798 | __base.unsetf(ios_base::boolalpha); | |
799 | return __base; | |
800 | } | |
801 | ||
840ceb34 | 802 | /// Calls base.setf(ios_base::showbase). |
ed6814f7 | 803 | inline ios_base& |
725dc051 BK |
804 | showbase(ios_base& __base) |
805 | { | |
806 | __base.setf(ios_base::showbase); | |
807 | return __base; | |
808 | } | |
809 | ||
840ceb34 | 810 | /// Calls base.unsetf(ios_base::showbase). |
ed6814f7 | 811 | inline ios_base& |
725dc051 BK |
812 | noshowbase(ios_base& __base) |
813 | { | |
814 | __base.unsetf(ios_base::showbase); | |
815 | return __base; | |
816 | } | |
817 | ||
840ceb34 | 818 | /// Calls base.setf(ios_base::showpoint). |
ed6814f7 | 819 | inline ios_base& |
725dc051 BK |
820 | showpoint(ios_base& __base) |
821 | { | |
822 | __base.setf(ios_base::showpoint); | |
823 | return __base; | |
824 | } | |
825 | ||
840ceb34 | 826 | /// Calls base.unsetf(ios_base::showpoint). |
ed6814f7 | 827 | inline ios_base& |
725dc051 BK |
828 | noshowpoint(ios_base& __base) |
829 | { | |
830 | __base.unsetf(ios_base::showpoint); | |
831 | return __base; | |
832 | } | |
833 | ||
840ceb34 | 834 | /// Calls base.setf(ios_base::showpos). |
ed6814f7 | 835 | inline ios_base& |
725dc051 BK |
836 | showpos(ios_base& __base) |
837 | { | |
838 | __base.setf(ios_base::showpos); | |
839 | return __base; | |
840 | } | |
841 | ||
840ceb34 | 842 | /// Calls base.unsetf(ios_base::showpos). |
ed6814f7 | 843 | inline ios_base& |
725dc051 BK |
844 | noshowpos(ios_base& __base) |
845 | { | |
846 | __base.unsetf(ios_base::showpos); | |
847 | return __base; | |
848 | } | |
849 | ||
840ceb34 | 850 | /// Calls base.setf(ios_base::skipws). |
ed6814f7 | 851 | inline ios_base& |
725dc051 BK |
852 | skipws(ios_base& __base) |
853 | { | |
854 | __base.setf(ios_base::skipws); | |
855 | return __base; | |
856 | } | |
ed6814f7 | 857 | |
840ceb34 | 858 | /// Calls base.unsetf(ios_base::skipws). |
ed6814f7 | 859 | inline ios_base& |
725dc051 BK |
860 | noskipws(ios_base& __base) |
861 | { | |
862 | __base.unsetf(ios_base::skipws); | |
863 | return __base; | |
864 | } | |
865 | ||
840ceb34 | 866 | /// Calls base.setf(ios_base::uppercase). |
ed6814f7 | 867 | inline ios_base& |
725dc051 BK |
868 | uppercase(ios_base& __base) |
869 | { | |
870 | __base.setf(ios_base::uppercase); | |
871 | return __base; | |
872 | } | |
873 | ||
840ceb34 | 874 | /// Calls base.unsetf(ios_base::uppercase). |
ed6814f7 | 875 | inline ios_base& |
725dc051 BK |
876 | nouppercase(ios_base& __base) |
877 | { | |
878 | __base.unsetf(ios_base::uppercase); | |
879 | return __base; | |
880 | } | |
881 | ||
840ceb34 | 882 | /// Calls base.setf(ios_base::unitbuf). |
ed6814f7 | 883 | inline ios_base& |
725dc051 BK |
884 | unitbuf(ios_base& __base) |
885 | { | |
ed6814f7 | 886 | __base.setf(ios_base::unitbuf); |
725dc051 BK |
887 | return __base; |
888 | } | |
889 | ||
840ceb34 | 890 | /// Calls base.unsetf(ios_base::unitbuf). |
ed6814f7 | 891 | inline ios_base& |
725dc051 BK |
892 | nounitbuf(ios_base& __base) |
893 | { | |
894 | __base.unsetf(ios_base::unitbuf); | |
ed6814f7 | 895 | return __base; |
725dc051 BK |
896 | } |
897 | ||
840ceb34 PE |
898 | // [27.4.5.2] adjustfield anipulators |
899 | /// Calls base.setf(ios_base::internal, ios_base::adjustfield). | |
ed6814f7 | 900 | inline ios_base& |
725dc051 BK |
901 | internal(ios_base& __base) |
902 | { | |
903 | __base.setf(ios_base::internal, ios_base::adjustfield); | |
ed6814f7 | 904 | return __base; |
725dc051 BK |
905 | } |
906 | ||
840ceb34 | 907 | /// Calls base.setf(ios_base::left, ios_base::adjustfield). |
ed6814f7 | 908 | inline ios_base& |
725dc051 BK |
909 | left(ios_base& __base) |
910 | { | |
911 | __base.setf(ios_base::left, ios_base::adjustfield); | |
912 | return __base; | |
913 | } | |
ed6814f7 | 914 | |
840ceb34 | 915 | /// Calls base.setf(ios_base::right, ios_base::adjustfield). |
ed6814f7 | 916 | inline ios_base& |
725dc051 BK |
917 | right(ios_base& __base) |
918 | { | |
919 | __base.setf(ios_base::right, ios_base::adjustfield); | |
920 | return __base; | |
921 | } | |
ed6814f7 | 922 | |
840ceb34 PE |
923 | // [27.4.5.3] basefield anipulators |
924 | /// Calls base.setf(ios_base::dec, ios_base::basefield). | |
ed6814f7 | 925 | inline ios_base& |
725dc051 BK |
926 | dec(ios_base& __base) |
927 | { | |
928 | __base.setf(ios_base::dec, ios_base::basefield); | |
929 | return __base; | |
930 | } | |
ed6814f7 | 931 | |
840ceb34 | 932 | /// Calls base.setf(ios_base::hex, ios_base::basefield). |
ed6814f7 | 933 | inline ios_base& |
725dc051 BK |
934 | hex(ios_base& __base) |
935 | { | |
936 | __base.setf(ios_base::hex, ios_base::basefield); | |
937 | return __base; | |
938 | } | |
939 | ||
840ceb34 | 940 | /// Calls base.setf(ios_base::oct, ios_base::basefield). |
ed6814f7 | 941 | inline ios_base& |
725dc051 BK |
942 | oct(ios_base& __base) |
943 | { | |
944 | __base.setf(ios_base::oct, ios_base::basefield); | |
945 | return __base; | |
946 | } | |
ed6814f7 | 947 | |
840ceb34 PE |
948 | // [27.4.5.4] floatfield anipulators |
949 | /// Calls base.setf(ios_base::fixed, ios_base::floatfield). | |
ed6814f7 | 950 | inline ios_base& |
725dc051 BK |
951 | fixed(ios_base& __base) |
952 | { | |
953 | __base.setf(ios_base::fixed, ios_base::floatfield); | |
954 | return __base; | |
955 | } | |
956 | ||
840ceb34 | 957 | /// Calls base.setf(ios_base::scientific, ios_base::floatfield). |
ed6814f7 | 958 | inline ios_base& |
725dc051 BK |
959 | scientific(ios_base& __base) |
960 | { | |
961 | __base.setf(ios_base::scientific, ios_base::floatfield); | |
962 | return __base; | |
963 | } | |
3cbc7af0 BK |
964 | |
965 | _GLIBCXX_END_NAMESPACE | |
725dc051 | 966 | |
3d7c150e | 967 | #endif /* _IOS_BASE_H */ |
725dc051 | 968 |