]>
Commit | Line | Data |
---|---|---|
725dc051 BK |
1 | // Iostreams base classes -*- C++ -*- |
2 | ||
2e2a38cd | 3 | // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003 |
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 | |
19 | // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
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 | // | |
32 | // ISO C++ 14882: 27.8 File-based streams | |
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 | ||
725dc051 BK |
40 | #ifndef _CPP_BITS_IOSBASE_H |
41 | #define _CPP_BITS_IOSBASE_H 1 | |
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 | |
d53d7f6e PE |
49 | 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. | |
655d7821 | 55 | enum _Ios_Fmtflags { _S_ios_fmtflags_end = 1L << 16 }; |
725dc051 BK |
56 | |
57 | inline _Ios_Fmtflags | |
58 | operator&(_Ios_Fmtflags __a, _Ios_Fmtflags __b) | |
59 | { return _Ios_Fmtflags(static_cast<int>(__a) & static_cast<int>(__b)); } | |
60 | ||
61 | inline _Ios_Fmtflags | |
62 | operator|(_Ios_Fmtflags __a, _Ios_Fmtflags __b) | |
63 | { return _Ios_Fmtflags(static_cast<int>(__a) | static_cast<int>(__b)); } | |
64 | ||
65 | inline _Ios_Fmtflags | |
66 | operator^(_Ios_Fmtflags __a, _Ios_Fmtflags __b) | |
67 | { return _Ios_Fmtflags(static_cast<int>(__a) ^ static_cast<int>(__b)); } | |
68 | ||
69 | inline _Ios_Fmtflags | |
70 | operator|=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) | |
71 | { return __a = __a | __b; } | |
72 | ||
73 | inline _Ios_Fmtflags | |
74 | operator&=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) | |
75 | { return __a = __a & __b; } | |
76 | ||
77 | inline _Ios_Fmtflags | |
78 | operator^=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) | |
79 | { return __a = __a ^ __b; } | |
80 | ||
81 | inline _Ios_Fmtflags | |
82 | operator~(_Ios_Fmtflags __a) | |
83 | { return _Ios_Fmtflags(~static_cast<int>(__a)); } | |
84 | ||
85 | ||
655d7821 | 86 | enum _Ios_Openmode { _S_ios_openmode_end = 1L << 16 }; |
725dc051 BK |
87 | |
88 | inline _Ios_Openmode | |
89 | operator&(_Ios_Openmode __a, _Ios_Openmode __b) | |
90 | { return _Ios_Openmode(static_cast<int>(__a) & static_cast<int>(__b)); } | |
91 | ||
92 | inline _Ios_Openmode | |
93 | operator|(_Ios_Openmode __a, _Ios_Openmode __b) | |
94 | { return _Ios_Openmode(static_cast<int>(__a) | static_cast<int>(__b)); } | |
95 | ||
96 | inline _Ios_Openmode | |
97 | operator^(_Ios_Openmode __a, _Ios_Openmode __b) | |
98 | { return _Ios_Openmode(static_cast<int>(__a) ^ static_cast<int>(__b)); } | |
99 | ||
100 | inline _Ios_Openmode | |
101 | operator|=(_Ios_Openmode& __a, _Ios_Openmode __b) | |
102 | { return __a = __a | __b; } | |
103 | ||
104 | inline _Ios_Openmode | |
105 | operator&=(_Ios_Openmode& __a, _Ios_Openmode __b) | |
106 | { return __a = __a & __b; } | |
107 | ||
108 | inline _Ios_Openmode | |
109 | operator^=(_Ios_Openmode& __a, _Ios_Openmode __b) | |
110 | { return __a = __a ^ __b; } | |
111 | ||
112 | inline _Ios_Openmode | |
113 | operator~(_Ios_Openmode __a) | |
114 | { return _Ios_Openmode(~static_cast<int>(__a)); } | |
115 | ||
116 | ||
655d7821 | 117 | enum _Ios_Iostate { _S_ios_iostate_end = 1L << 16 }; |
725dc051 BK |
118 | |
119 | inline _Ios_Iostate | |
120 | operator&(_Ios_Iostate __a, _Ios_Iostate __b) | |
121 | { return _Ios_Iostate(static_cast<int>(__a) & static_cast<int>(__b)); } | |
122 | ||
123 | inline _Ios_Iostate | |
124 | operator|(_Ios_Iostate __a, _Ios_Iostate __b) | |
125 | { return _Ios_Iostate(static_cast<int>(__a) | static_cast<int>(__b)); } | |
126 | ||
127 | inline _Ios_Iostate | |
128 | operator^(_Ios_Iostate __a, _Ios_Iostate __b) | |
129 | { return _Ios_Iostate(static_cast<int>(__a) ^ static_cast<int>(__b)); } | |
130 | ||
131 | inline _Ios_Iostate | |
132 | operator|=(_Ios_Iostate& __a, _Ios_Iostate __b) | |
133 | { return __a = __a | __b; } | |
134 | ||
135 | inline _Ios_Iostate | |
136 | operator&=(_Ios_Iostate& __a, _Ios_Iostate __b) | |
137 | { return __a = __a & __b; } | |
138 | ||
139 | inline _Ios_Iostate | |
140 | operator^=(_Ios_Iostate& __a, _Ios_Iostate __b) | |
141 | { return __a = __a ^ __b; } | |
142 | ||
143 | inline _Ios_Iostate | |
144 | operator~(_Ios_Iostate __a) | |
145 | { return _Ios_Iostate(~static_cast<int>(__a)); } | |
146 | ||
655d7821 | 147 | enum _Ios_Seekdir { _S_ios_seekdir_end = 1L << 16 }; |
725dc051 | 148 | |
6067bea4 BK |
149 | class __locale_cache_base; |
150 | ||
725dc051 | 151 | // 27.4.2 Class ios_base |
840ceb34 PE |
152 | /** |
153 | * @brief The very top of the I/O class hierarchy. | |
154 | * | |
155 | * This class defines everything that can be defined about I/O that does | |
156 | * not depend on the type of characters being input or output. Most | |
157 | * people will only see @c ios_base when they need to specify the full | |
158 | * name of the various I/O flags (e.g., the openmodes). | |
159 | */ | |
725dc051 BK |
160 | class ios_base |
161 | { | |
162 | public: | |
d358ecd0 | 163 | |
725dc051 | 164 | // 27.4.2.1.1 Class ios_base::failure |
840ceb34 | 165 | /// These are thrown to indicate problems. Doc me. |
725dc051 BK |
166 | class failure : public exception |
167 | { | |
168 | public: | |
169 | #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS | |
77cd227e | 170 | //48. Use of non-existent exception constructor |
725dc051 | 171 | explicit |
d34786e3 | 172 | failure(const string& __str) throw(); |
725dc051 | 173 | |
663653eb BK |
174 | // This declaration is not useless: |
175 | // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 | |
725dc051 | 176 | virtual |
d34786e3 | 177 | ~failure() throw(); |
725dc051 | 178 | |
23a5b444 GDR |
179 | virtual const char* |
180 | what() const throw(); | |
725dc051 BK |
181 | |
182 | private: | |
655d7821 BK |
183 | enum { _S_bufsize = 256 }; |
184 | char _M_name[_S_bufsize]; | |
725dc051 BK |
185 | #endif |
186 | }; | |
187 | ||
188 | // 27.4.2.1.2 Type ios_base::fmtflags | |
840ceb34 PE |
189 | /** |
190 | * @brief This is a bitmask type. | |
191 | * | |
192 | * @c "_Ios_Fmtflags" is implementation-defined, but it is valid to | |
193 | * perform bitwise operations on these values and expect the Right | |
194 | * Thing to happen. Defined objects of type fmtflags are: | |
195 | * - boolalpha | |
196 | * - dec | |
197 | * - fixed | |
198 | * - hex | |
199 | * - internal | |
200 | * - left | |
201 | * - oct | |
202 | * - right | |
203 | * - scientific | |
204 | * - showbase | |
205 | * - showpoint | |
206 | * - showpos | |
207 | * - skipws | |
208 | * - unitbuf | |
209 | * - uppercase | |
210 | * - adjustfield | |
211 | * - basefield | |
212 | * - floatfield | |
213 | */ | |
725dc051 | 214 | typedef _Ios_Fmtflags fmtflags; |
840ceb34 | 215 | /// Insert/extract @c bool in alphabetic rather than numeric format. |
725dc051 | 216 | static const fmtflags boolalpha = fmtflags(__ios_flags::_S_boolalpha); |
840ceb34 | 217 | /// Converts integer input or generates integer output in decimal base. |
725dc051 | 218 | static const fmtflags dec = fmtflags(__ios_flags::_S_dec); |
840ceb34 | 219 | /// Generate floating-point output in fixed-point notation. |
725dc051 | 220 | static const fmtflags fixed = fmtflags(__ios_flags::_S_fixed); |
840ceb34 | 221 | /// Converts integer input or generates integer output in hexadecimal base. |
725dc051 | 222 | static const fmtflags hex = fmtflags(__ios_flags::_S_hex); |
840ceb34 PE |
223 | /// Adds fill characters at a designated internal point in certain |
224 | /// generated output, or identical to @c right if no such point is | |
225 | /// designated. | |
725dc051 | 226 | static const fmtflags internal = fmtflags(__ios_flags::_S_internal); |
840ceb34 PE |
227 | /// Adds fill characters on the right (final positions) of certain |
228 | /// generated output. (I.e., the thing you print is flush left.) | |
725dc051 | 229 | static const fmtflags left = fmtflags(__ios_flags::_S_left); |
840ceb34 | 230 | /// Converts integer input or generates integer output in octal base. |
725dc051 | 231 | static const fmtflags oct = fmtflags(__ios_flags::_S_oct); |
840ceb34 PE |
232 | /// Adds fill characters on the left (initial positions) of certain |
233 | /// generated output. (I.e., the thing you print is flush right.) | |
725dc051 | 234 | static const fmtflags right = fmtflags(__ios_flags::_S_right); |
840ceb34 | 235 | /// Generates floating-point output in scientific notation. |
725dc051 | 236 | static const fmtflags scientific = fmtflags(__ios_flags::_S_scientific); |
840ceb34 PE |
237 | /// Generates a prefix indicating the numeric base of generated integer |
238 | /// output. | |
725dc051 | 239 | static const fmtflags showbase = fmtflags(__ios_flags::_S_showbase); |
840ceb34 PE |
240 | /// Generates a decimal-point character unconditionally in generated |
241 | /// floating-point output. | |
725dc051 | 242 | static const fmtflags showpoint = fmtflags(__ios_flags::_S_showpoint); |
840ceb34 | 243 | /// Generates a + sign in non-negative generated numeric output. |
725dc051 | 244 | static const fmtflags showpos = fmtflags(__ios_flags::_S_showpos); |
840ceb34 | 245 | /// Skips leading white space before certain input operations. |
725dc051 | 246 | static const fmtflags skipws = fmtflags(__ios_flags::_S_skipws); |
840ceb34 | 247 | /// Flushes output after each output operation. |
725dc051 | 248 | static const fmtflags unitbuf = fmtflags(__ios_flags::_S_unitbuf); |
840ceb34 PE |
249 | /// Replaces certain lowercase letters with their uppercase equivalents |
250 | /// in generated output. | |
725dc051 | 251 | static const fmtflags uppercase = fmtflags(__ios_flags::_S_uppercase); |
840ceb34 | 252 | /// A mask of left|right|internal. Useful for the 2-arg form of @c setf. |
725dc051 | 253 | static const fmtflags adjustfield = fmtflags(__ios_flags::_S_adjustfield); |
840ceb34 | 254 | /// A mask of dec|oct|hex. Useful for the 2-arg form of @c setf. |
725dc051 | 255 | static const fmtflags basefield = fmtflags(__ios_flags::_S_basefield); |
840ceb34 | 256 | /// A mask of scientific|fixed. Useful for the 2-arg form of @c setf. |
725dc051 BK |
257 | static const fmtflags floatfield = fmtflags(__ios_flags::_S_floatfield); |
258 | ||
259 | // 27.4.2.1.3 Type ios_base::iostate | |
840ceb34 PE |
260 | /** |
261 | * @brief This is a bitmask type. | |
262 | * | |
263 | * @c "_Ios_Iostate" is implementation-defined, but it is valid to | |
264 | * perform bitwise operations on these values and expect the Right | |
265 | * Thing to happen. Defined objects of type iostate are: | |
266 | * - badbit | |
267 | * - eofbit | |
268 | * - failbit | |
269 | * - goodbit | |
270 | */ | |
725dc051 | 271 | typedef _Ios_Iostate iostate; |
840ceb34 PE |
272 | /// Indicates a loss of integrity in an input or output sequence (such |
273 | /// as an irrecoverable read error from a file). | |
725dc051 | 274 | static const iostate badbit = iostate(__ios_flags::_S_badbit); |
840ceb34 | 275 | /// Indicates that an input operation reached the end of an input sequence. |
725dc051 | 276 | static const iostate eofbit = iostate(__ios_flags::_S_eofbit); |
840ceb34 PE |
277 | /// Indicates that an input operation failed to read the expected |
278 | /// characters, or that an output operation failed to generate the | |
279 | /// desired characters. | |
725dc051 | 280 | static const iostate failbit = iostate(__ios_flags::_S_failbit); |
840ceb34 | 281 | /// Indicates all is well. |
725dc051 BK |
282 | static const iostate goodbit = iostate(0); |
283 | ||
840ceb34 PE |
284 | // 27.4.2.1.4 Type ios_base::openmode |
285 | /** | |
286 | * @brief This is a bitmask type. | |
287 | * | |
288 | * @c "_Ios_Openmode" is implementation-defined, but it is valid to | |
289 | * perform bitwise operations on these values and expect the Right | |
290 | * Thing to happen. Defined objects of type openmode are: | |
291 | * - app | |
292 | * - ate | |
293 | * - binary | |
294 | * - in | |
295 | * - out | |
296 | * - trunc | |
297 | */ | |
725dc051 | 298 | typedef _Ios_Openmode openmode; |
840ceb34 | 299 | /// Seek to end before each write. |
725dc051 | 300 | static const openmode app = openmode(__ios_flags::_S_app); |
840ceb34 | 301 | /// Open and seek to end immediately after opening. |
725dc051 | 302 | static const openmode ate = openmode(__ios_flags::_S_ate); |
840ceb34 PE |
303 | /// Perform input and output in binary mode (as opposed to text mode). |
304 | /// This is probably not what you think it is; see | |
305 | /// http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#3 and | |
306 | /// http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#7 for more. | |
725dc051 | 307 | static const openmode binary = openmode(__ios_flags::_S_bin); |
840ceb34 | 308 | /// Open for input. Default for @c ifstream and fstream. |
725dc051 | 309 | static const openmode in = openmode(__ios_flags::_S_in); |
840ceb34 | 310 | /// Open for output. Default for @c ofstream and fstream. |
725dc051 | 311 | static const openmode out = openmode(__ios_flags::_S_out); |
840ceb34 | 312 | /// Open for input. Default for @c ofstream. |
725dc051 BK |
313 | static const openmode trunc = openmode(__ios_flags::_S_trunc); |
314 | ||
840ceb34 PE |
315 | // 27.4.2.1.5 Type ios_base::seekdir |
316 | /** | |
317 | * @brief This is an enumerated type. | |
318 | * | |
319 | * @c "_Ios_Seekdir" is implementation-defined. Defined values | |
320 | * of type seekdir are: | |
321 | * - beg | |
322 | * - cur, equivalent to @c SEEK_CUR in the C standard library. | |
323 | * - end, equivalent to @c SEEK_END in the C standard library. | |
324 | */ | |
725dc051 | 325 | typedef _Ios_Seekdir seekdir; |
840ceb34 | 326 | /// Request a seek relative to the beginning of the stream. |
725dc051 | 327 | static const seekdir beg = seekdir(0); |
840ceb34 | 328 | /// Request a seek relative to the current position within the sequence. |
725dc051 | 329 | static const seekdir cur = seekdir(SEEK_CUR); |
840ceb34 | 330 | /// Request a seek relative to the current end of the sequence. |
725dc051 BK |
331 | static const seekdir end = seekdir(SEEK_END); |
332 | ||
78d58962 | 333 | #ifdef _GLIBCPP_DEPRECATED |
4df6abc6 | 334 | // Annex D.6 |
725dc051 BK |
335 | typedef int io_state; |
336 | typedef int open_mode; | |
337 | typedef int seek_dir; | |
92204597 BK |
338 | |
339 | typedef std::streampos streampos; | |
340 | typedef std::streamoff streamoff; | |
725dc051 BK |
341 | #endif |
342 | ||
343 | // Callbacks; | |
840ceb34 PE |
344 | /** |
345 | * @doctodo | |
346 | */ | |
725dc051 BK |
347 | enum event |
348 | { | |
349 | erase_event, | |
350 | imbue_event, | |
351 | copyfmt_event | |
352 | }; | |
353 | ||
840ceb34 PE |
354 | /** |
355 | * @doctodo | |
356 | */ | |
725dc051 BK |
357 | typedef void (*event_callback) (event, ios_base&, int); |
358 | ||
840ceb34 PE |
359 | /** |
360 | * @doctodo | |
361 | */ | |
725dc051 BK |
362 | void |
363 | register_callback(event_callback __fn, int __index); | |
364 | ||
365 | protected: | |
840ceb34 PE |
366 | //@{ |
367 | /** | |
368 | * @if maint | |
369 | * ios_base data members (doc me) | |
370 | * @endif | |
371 | */ | |
725dc051 BK |
372 | streamsize _M_precision; |
373 | streamsize _M_width; | |
374 | fmtflags _M_flags; | |
663653eb BK |
375 | iostate _M_exception; |
376 | iostate _M_streambuf_state; | |
840ceb34 | 377 | //@} |
725dc051 | 378 | |
d9ab8adb | 379 | // 27.4.2.6 Members for callbacks |
725dc051 | 380 | // 27.4.2.6 ios_base callbacks |
725dc051 BK |
381 | struct _Callback_list |
382 | { | |
383 | // Data Members | |
384 | _Callback_list* _M_next; | |
385 | ios_base::event_callback _M_fn; | |
386 | int _M_index; | |
17325050 | 387 | _Atomic_word _M_refcount; // 0 means one reference. |
725dc051 BK |
388 | |
389 | _Callback_list(ios_base::event_callback __fn, int __index, | |
390 | _Callback_list* __cb) | |
391 | : _M_next(__cb), _M_fn(__fn), _M_index(__index), _M_refcount(0) { } | |
392 | ||
393 | void | |
17325050 AP |
394 | _M_add_reference() { __atomic_add(&_M_refcount, 1); } |
395 | ||
663653eb | 396 | // 0 => OK to delete. |
725dc051 | 397 | int |
17325050 | 398 | _M_remove_reference() { return __exchange_and_add(&_M_refcount, -1); } |
725dc051 BK |
399 | }; |
400 | ||
401 | _Callback_list* _M_callbacks; | |
402 | ||
403 | void | |
404 | _M_call_callbacks(event __ev) throw(); | |
405 | ||
406 | void | |
407 | _M_dispose_callbacks(void); | |
408 | ||
d9ab8adb | 409 | // 27.4.2.5 Members for iword/pword storage |
725dc051 BK |
410 | struct _Words |
411 | { | |
412 | void* _M_pword; | |
413 | long _M_iword; | |
663653eb | 414 | _Words() : _M_pword(0), _M_iword(0) { } |
725dc051 BK |
415 | }; |
416 | ||
663653eb BK |
417 | // Only for failed iword/pword calls. |
418 | _Words _M_word_zero; | |
419 | ||
420 | // Guaranteed storage. | |
2e2a38cd | 421 | // The first 5 iword and pword slots are reserved for internal use. |
663653eb BK |
422 | static const int _S_local_word_size = 8; |
423 | _Words _M_local_word[_S_local_word_size]; | |
424 | ||
425 | // Allocated storage. | |
426 | int _M_word_size; | |
427 | _Words* _M_word; | |
725dc051 BK |
428 | |
429 | _Words& | |
430 | _M_grow_words(int __index); | |
431 | ||
432 | // Members for locale and locale caching. | |
433 | locale _M_ios_locale; | |
434 | ||
6067bea4 BK |
435 | // Cache of locale and facet data. |
436 | // Cast this to __locale_cache<_CharT>* | |
437 | auto_ptr<__locale_cache_base> _M_locale_cache; | |
438 | ||
725dc051 BK |
439 | void |
440 | _M_init(); | |
441 | ||
442 | public: | |
d9ab8adb | 443 | |
725dc051 BK |
444 | // 27.4.2.1.6 Class ios_base::Init |
445 | // Used to initialize standard streams. In theory, g++ could use | |
446 | // -finit-priority to order this stuff correctly without going | |
447 | // through these machinations. | |
725dc051 BK |
448 | class Init |
449 | { | |
450 | friend class ios_base; | |
451 | public: | |
452 | Init(); | |
453 | ~Init(); | |
12764462 | 454 | |
0530d3b0 CW |
455 | // NB: Allows debugger applications use of the standard streams |
456 | // from operator new. _S_ios_base_init must be incremented in | |
457 | // _S_ios_create _after_ initialization is completed. | |
458 | static bool | |
459 | _S_initialized() { return _S_ios_base_init; } | |
460 | ||
725dc051 BK |
461 | private: |
462 | static int _S_ios_base_init; | |
469550eb | 463 | static bool _S_synced_with_stdio; |
725dc051 BK |
464 | }; |
465 | ||
840ceb34 PE |
466 | // [27.4.2.2] fmtflags state functions |
467 | /** | |
468 | * @brief Access to format flags. | |
469 | * @return The format control flags for both input and output. | |
470 | */ | |
725dc051 BK |
471 | inline fmtflags |
472 | flags() const { return _M_flags; } | |
473 | ||
840ceb34 PE |
474 | /** |
475 | * @brief Setting new format flags all at once. | |
476 | * @param fmtfl The new flags to set. | |
477 | * @return The previous format control flags. | |
478 | * | |
479 | * This function overwrites all the format flags with @a fmtfl. | |
480 | */ | |
725dc051 BK |
481 | inline fmtflags |
482 | flags(fmtflags __fmtfl) | |
483 | { | |
484 | fmtflags __old = _M_flags; | |
485 | _M_flags = __fmtfl; | |
486 | return __old; | |
487 | } | |
488 | ||
840ceb34 PE |
489 | /** |
490 | * @brief Setting new format flags. | |
491 | * @param fmtfl Additional flags to set. | |
492 | * @return The previous format control flags. | |
493 | * | |
494 | * This function sets additional flags in format control. Flags that | |
495 | * were previously set remain set. | |
496 | */ | |
725dc051 BK |
497 | inline fmtflags |
498 | setf(fmtflags __fmtfl) | |
499 | { | |
500 | fmtflags __old = _M_flags; | |
501 | _M_flags |= __fmtfl; | |
502 | return __old; | |
503 | } | |
504 | ||
840ceb34 PE |
505 | /** |
506 | * @brief Setting new format flags. | |
507 | * @param fmtfl Additional flags to set. | |
508 | * @param mask The flags mask for @a fmtfl. | |
509 | * @return The previous format control flags. | |
510 | * | |
511 | * This function clears @a mask in the format flags, then sets | |
512 | * @a fmtfl @c & @a mask. An example mask is @c ios_base::adjustfield. | |
513 | */ | |
725dc051 BK |
514 | inline fmtflags |
515 | setf(fmtflags __fmtfl, fmtflags __mask) | |
516 | { | |
517 | fmtflags __old = _M_flags; | |
518 | _M_flags &= ~__mask; | |
519 | _M_flags |= (__fmtfl & __mask); | |
520 | return __old; | |
521 | } | |
522 | ||
840ceb34 PE |
523 | /** |
524 | * @brief Clearing format flags. | |
525 | * @param mask The flags to unset. | |
526 | * | |
527 | * This function clears @a mask in the format flags. | |
528 | */ | |
725dc051 BK |
529 | inline void |
530 | unsetf(fmtflags __mask) { _M_flags &= ~__mask; } | |
531 | ||
840ceb34 PE |
532 | /** |
533 | * @brief Flags access. | |
534 | * @return The precision to generate on certain output operations. | |
535 | * | |
536 | * @if maint | |
537 | * Be careful if you try to give a definition of "precision" here; see | |
538 | * DR 189. | |
539 | * @endif | |
540 | */ | |
725dc051 BK |
541 | inline streamsize |
542 | precision() const { return _M_precision; } | |
543 | ||
840ceb34 PE |
544 | /** |
545 | * @brief Changing flags. | |
546 | * @param prec The new precision value. | |
547 | * @return The previous value of precision(). | |
548 | */ | |
725dc051 BK |
549 | inline streamsize |
550 | precision(streamsize __prec) | |
551 | { | |
552 | streamsize __old = _M_precision; | |
553 | _M_precision = __prec; | |
554 | return __old; | |
555 | } | |
556 | ||
840ceb34 PE |
557 | /** |
558 | * @brief Flags access. | |
559 | * @return The minimum field width to generate on output operations. | |
560 | * | |
561 | * "Minimum field width" refers to the number of characters. | |
562 | */ | |
725dc051 BK |
563 | inline streamsize |
564 | width() const { return _M_width; } | |
565 | ||
840ceb34 PE |
566 | /** |
567 | * @brief Changing flags. | |
568 | * @param wide The new width value. | |
569 | * @return The previous value of width(). | |
570 | */ | |
725dc051 BK |
571 | inline streamsize |
572 | width(streamsize __wide) | |
573 | { | |
574 | streamsize __old = _M_width; | |
575 | _M_width = __wide; | |
576 | return __old; | |
577 | } | |
578 | ||
840ceb34 PE |
579 | // [27.4.2.4] ios_base static members |
580 | /** | |
581 | * @brief Interaction with the standard C I/O objects. | |
582 | * @param sync Whether to synchronize or not. | |
583 | * @return True if the standard streams were previously synchronized. | |
584 | * | |
585 | * The synchronization referred to is @e only that between the standard | |
586 | * C facilities (e.g., stdout) and the standard C++ objects (e.g., | |
587 | * cout). User-declared streams are unaffected. See | |
588 | * http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#8 for more. | |
589 | */ | |
725dc051 BK |
590 | static bool |
591 | sync_with_stdio(bool __sync = true); | |
592 | ||
840ceb34 PE |
593 | // [27.4.2.3] ios_base locale functions |
594 | /** | |
595 | * @brief Setting a new locale. | |
596 | * @param loc The new locale. | |
597 | * @return The previous locale. | |
598 | * | |
599 | * Sets the new locale for this stream, and | |
600 | * [XXX does something with callbacks]. | |
601 | */ | |
725dc051 BK |
602 | locale |
603 | imbue(const locale& __loc); | |
604 | ||
840ceb34 PE |
605 | /** |
606 | * @brief Locale access | |
607 | * @return The locale currently in effect. | |
608 | * | |
609 | * If @c imbue(loc) has previously been called, then this function | |
610 | * returns @c loc. Otherwise, it returns a copy of @c std::locale(), | |
611 | * the global C++ locale. | |
612 | */ | |
725dc051 BK |
613 | inline locale |
614 | getloc() const { return _M_ios_locale; } | |
615 | ||
840ceb34 PE |
616 | // [27.4.2.5] ios_base storage functions |
617 | /** | |
618 | * @doctodo | |
619 | */ | |
725dc051 BK |
620 | static int |
621 | xalloc() throw(); | |
622 | ||
840ceb34 PE |
623 | /** |
624 | * @doctodo | |
625 | */ | |
725dc051 BK |
626 | inline long& |
627 | iword(int __ix) | |
628 | { | |
663653eb BK |
629 | _Words& __word = (__ix < _M_word_size) |
630 | ? _M_word[__ix] : _M_grow_words(__ix); | |
725dc051 BK |
631 | return __word._M_iword; |
632 | } | |
633 | ||
840ceb34 PE |
634 | /** |
635 | * @doctodo | |
636 | */ | |
725dc051 BK |
637 | inline void*& |
638 | pword(int __ix) | |
639 | { | |
663653eb BK |
640 | _Words& __word = (__ix < _M_word_size) |
641 | ? _M_word[__ix] : _M_grow_words(__ix); | |
725dc051 BK |
642 | return __word._M_pword; |
643 | } | |
644 | ||
6067bea4 BK |
645 | // Access to the cache. Not safe to call until basic_ios::_M_init() has |
646 | // happened. | |
647 | __locale_cache_base& | |
648 | _M_cache() { return *_M_locale_cache; } | |
649 | ||
725dc051 | 650 | // Destructor |
840ceb34 PE |
651 | /** |
652 | * Destroys local storage and | |
653 | * [XXX does something with callbacks]. | |
654 | */ | |
cb930542 | 655 | virtual ~ios_base(); |
725dc051 BK |
656 | |
657 | protected: | |
658 | ios_base(); | |
659 | ||
660 | #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS | |
77cd227e | 661 | //50. Copy constructor and assignment operator of ios_base |
725dc051 BK |
662 | private: |
663 | ios_base(const ios_base&); | |
664 | ||
665 | ios_base& | |
666 | operator=(const ios_base&); | |
667 | #endif | |
668 | }; | |
669 | ||
840ceb34 PE |
670 | // [27.4.5.1] fmtflags manipulators |
671 | /// Calls base.setf(ios_base::boolalpha). | |
725dc051 BK |
672 | inline ios_base& |
673 | boolalpha(ios_base& __base) | |
674 | { | |
675 | __base.setf(ios_base::boolalpha); | |
676 | return __base; | |
677 | } | |
678 | ||
840ceb34 | 679 | /// Calls base.unsetf(ios_base::boolalpha). |
725dc051 BK |
680 | inline ios_base& |
681 | noboolalpha(ios_base& __base) | |
682 | { | |
683 | __base.unsetf(ios_base::boolalpha); | |
684 | return __base; | |
685 | } | |
686 | ||
840ceb34 | 687 | /// Calls base.setf(ios_base::showbase). |
725dc051 BK |
688 | inline ios_base& |
689 | showbase(ios_base& __base) | |
690 | { | |
691 | __base.setf(ios_base::showbase); | |
692 | return __base; | |
693 | } | |
694 | ||
840ceb34 | 695 | /// Calls base.unsetf(ios_base::showbase). |
725dc051 BK |
696 | inline ios_base& |
697 | noshowbase(ios_base& __base) | |
698 | { | |
699 | __base.unsetf(ios_base::showbase); | |
700 | return __base; | |
701 | } | |
702 | ||
840ceb34 | 703 | /// Calls base.setf(ios_base::showpoint). |
725dc051 BK |
704 | inline ios_base& |
705 | showpoint(ios_base& __base) | |
706 | { | |
707 | __base.setf(ios_base::showpoint); | |
708 | return __base; | |
709 | } | |
710 | ||
840ceb34 | 711 | /// Calls base.unsetf(ios_base::showpoint). |
725dc051 BK |
712 | inline ios_base& |
713 | noshowpoint(ios_base& __base) | |
714 | { | |
715 | __base.unsetf(ios_base::showpoint); | |
716 | return __base; | |
717 | } | |
718 | ||
840ceb34 | 719 | /// Calls base.setf(ios_base::showpos). |
725dc051 BK |
720 | inline ios_base& |
721 | showpos(ios_base& __base) | |
722 | { | |
723 | __base.setf(ios_base::showpos); | |
724 | return __base; | |
725 | } | |
726 | ||
840ceb34 | 727 | /// Calls base.unsetf(ios_base::showpos). |
725dc051 BK |
728 | inline ios_base& |
729 | noshowpos(ios_base& __base) | |
730 | { | |
731 | __base.unsetf(ios_base::showpos); | |
732 | return __base; | |
733 | } | |
734 | ||
840ceb34 | 735 | /// Calls base.setf(ios_base::skipws). |
725dc051 BK |
736 | inline ios_base& |
737 | skipws(ios_base& __base) | |
738 | { | |
739 | __base.setf(ios_base::skipws); | |
740 | return __base; | |
741 | } | |
742 | ||
840ceb34 | 743 | /// Calls base.unsetf(ios_base::skipws). |
725dc051 BK |
744 | inline ios_base& |
745 | noskipws(ios_base& __base) | |
746 | { | |
747 | __base.unsetf(ios_base::skipws); | |
748 | return __base; | |
749 | } | |
750 | ||
840ceb34 | 751 | /// Calls base.setf(ios_base::uppercase). |
725dc051 BK |
752 | inline ios_base& |
753 | uppercase(ios_base& __base) | |
754 | { | |
755 | __base.setf(ios_base::uppercase); | |
756 | return __base; | |
757 | } | |
758 | ||
840ceb34 | 759 | /// Calls base.unsetf(ios_base::uppercase). |
725dc051 BK |
760 | inline ios_base& |
761 | nouppercase(ios_base& __base) | |
762 | { | |
763 | __base.unsetf(ios_base::uppercase); | |
764 | return __base; | |
765 | } | |
766 | ||
840ceb34 | 767 | /// Calls base.setf(ios_base::unitbuf). |
725dc051 BK |
768 | inline ios_base& |
769 | unitbuf(ios_base& __base) | |
770 | { | |
771 | __base.setf(ios_base::unitbuf); | |
772 | return __base; | |
773 | } | |
774 | ||
840ceb34 | 775 | /// Calls base.unsetf(ios_base::unitbuf). |
725dc051 BK |
776 | inline ios_base& |
777 | nounitbuf(ios_base& __base) | |
778 | { | |
779 | __base.unsetf(ios_base::unitbuf); | |
780 | return __base; | |
781 | } | |
782 | ||
840ceb34 PE |
783 | // [27.4.5.2] adjustfield anipulators |
784 | /// Calls base.setf(ios_base::internal, ios_base::adjustfield). | |
725dc051 BK |
785 | inline ios_base& |
786 | internal(ios_base& __base) | |
787 | { | |
788 | __base.setf(ios_base::internal, ios_base::adjustfield); | |
789 | return __base; | |
790 | } | |
791 | ||
840ceb34 | 792 | /// Calls base.setf(ios_base::left, ios_base::adjustfield). |
725dc051 BK |
793 | inline ios_base& |
794 | left(ios_base& __base) | |
795 | { | |
796 | __base.setf(ios_base::left, ios_base::adjustfield); | |
797 | return __base; | |
798 | } | |
799 | ||
840ceb34 | 800 | /// Calls base.setf(ios_base::right, ios_base::adjustfield). |
725dc051 BK |
801 | inline ios_base& |
802 | right(ios_base& __base) | |
803 | { | |
804 | __base.setf(ios_base::right, ios_base::adjustfield); | |
805 | return __base; | |
806 | } | |
807 | ||
840ceb34 PE |
808 | // [27.4.5.3] basefield anipulators |
809 | /// Calls base.setf(ios_base::dec, ios_base::basefield). | |
725dc051 BK |
810 | inline ios_base& |
811 | dec(ios_base& __base) | |
812 | { | |
813 | __base.setf(ios_base::dec, ios_base::basefield); | |
814 | return __base; | |
815 | } | |
816 | ||
840ceb34 | 817 | /// Calls base.setf(ios_base::hex, ios_base::basefield). |
725dc051 BK |
818 | inline ios_base& |
819 | hex(ios_base& __base) | |
820 | { | |
821 | __base.setf(ios_base::hex, ios_base::basefield); | |
822 | return __base; | |
823 | } | |
824 | ||
840ceb34 | 825 | /// Calls base.setf(ios_base::oct, ios_base::basefield). |
725dc051 BK |
826 | inline ios_base& |
827 | oct(ios_base& __base) | |
828 | { | |
829 | __base.setf(ios_base::oct, ios_base::basefield); | |
830 | return __base; | |
831 | } | |
832 | ||
840ceb34 PE |
833 | // [27.4.5.4] floatfield anipulators |
834 | /// Calls base.setf(ios_base::fixed, ios_base::floatfield). | |
725dc051 BK |
835 | inline ios_base& |
836 | fixed(ios_base& __base) | |
837 | { | |
838 | __base.setf(ios_base::fixed, ios_base::floatfield); | |
839 | return __base; | |
840 | } | |
841 | ||
840ceb34 | 842 | /// Calls base.setf(ios_base::scientific, ios_base::floatfield). |
725dc051 BK |
843 | inline ios_base& |
844 | scientific(ios_base& __base) | |
845 | { | |
846 | __base.setf(ios_base::scientific, ios_base::floatfield); | |
847 | return __base; | |
848 | } | |
849 | ||
850 | } // namespace std | |
851 | ||
852 | #endif /* _CPP_BITS_IOSBASE_H */ | |
853 |