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