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