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