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