libstdc++
ios_base.h
Go to the documentation of this file.
00001 // Iostreams base classes -*- C++ -*-
00002 
00003 // Copyright (C) 1997-2015 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 3, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License and
00021 // a copy of the GCC Runtime Library Exception along with this program;
00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023 // <http://www.gnu.org/licenses/>.
00024 
00025 /** @file bits/ios_base.h
00026  *  This is an internal header file, included by other library headers.
00027  *  Do not attempt to use it directly. @headername{ios}
00028  */
00029 
00030 //
00031 // ISO C++ 14882: 27.4  Iostreams base classes
00032 //
00033 
00034 #ifndef _IOS_BASE_H
00035 #define _IOS_BASE_H 1
00036 
00037 #pragma GCC system_header
00038 
00039 #include <ext/atomicity.h>
00040 #include <bits/localefwd.h>
00041 #include <bits/locale_classes.h>
00042 
00043 #if __cplusplus < 201103L
00044 # include <stdexcept>
00045 #else
00046 # include <system_error>
00047 #endif
00048 
00049 namespace std _GLIBCXX_VISIBILITY(default)
00050 {
00051 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00052 
00053   // The following definitions of bitmask types are enums, not ints,
00054   // as permitted (but not required) in the standard, in order to provide
00055   // better type safety in iostream calls.  A side effect is that
00056   // expressions involving them are no longer compile-time constants.
00057   enum _Ios_Fmtflags 
00058     { 
00059       _S_boolalpha      = 1L << 0,
00060       _S_dec            = 1L << 1,
00061       _S_fixed          = 1L << 2,
00062       _S_hex            = 1L << 3,
00063       _S_internal       = 1L << 4,
00064       _S_left           = 1L << 5,
00065       _S_oct            = 1L << 6,
00066       _S_right          = 1L << 7,
00067       _S_scientific     = 1L << 8,
00068       _S_showbase       = 1L << 9,
00069       _S_showpoint      = 1L << 10,
00070       _S_showpos        = 1L << 11,
00071       _S_skipws         = 1L << 12,
00072       _S_unitbuf        = 1L << 13,
00073       _S_uppercase      = 1L << 14,
00074       _S_adjustfield    = _S_left | _S_right | _S_internal,
00075       _S_basefield      = _S_dec | _S_oct | _S_hex,
00076       _S_floatfield     = _S_scientific | _S_fixed,
00077       _S_ios_fmtflags_end = 1L << 16,
00078       _S_ios_fmtflags_max = __INT_MAX__,
00079       _S_ios_fmtflags_min = ~__INT_MAX__
00080     };
00081 
00082   inline _GLIBCXX_CONSTEXPR _Ios_Fmtflags
00083   operator&(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
00084   { return _Ios_Fmtflags(static_cast<int>(__a) & static_cast<int>(__b)); }
00085 
00086   inline _GLIBCXX_CONSTEXPR _Ios_Fmtflags
00087   operator|(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
00088   { return _Ios_Fmtflags(static_cast<int>(__a) | static_cast<int>(__b)); }
00089 
00090   inline _GLIBCXX_CONSTEXPR _Ios_Fmtflags
00091   operator^(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
00092   { return _Ios_Fmtflags(static_cast<int>(__a) ^ static_cast<int>(__b)); }
00093 
00094   inline _GLIBCXX_CONSTEXPR _Ios_Fmtflags
00095   operator~(_Ios_Fmtflags __a)
00096   { return _Ios_Fmtflags(~static_cast<int>(__a)); }
00097 
00098   inline const _Ios_Fmtflags&
00099   operator|=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b)
00100   { return __a = __a | __b; }
00101 
00102   inline const _Ios_Fmtflags&
00103   operator&=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b)
00104   { return __a = __a & __b; }
00105 
00106   inline const _Ios_Fmtflags&
00107   operator^=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b)
00108   { return __a = __a ^ __b; }
00109 
00110 
00111   enum _Ios_Openmode 
00112     { 
00113       _S_app            = 1L << 0,
00114       _S_ate            = 1L << 1,
00115       _S_bin            = 1L << 2,
00116       _S_in             = 1L << 3,
00117       _S_out            = 1L << 4,
00118       _S_trunc          = 1L << 5,
00119       _S_ios_openmode_end = 1L << 16,
00120       _S_ios_openmode_max = __INT_MAX__,
00121       _S_ios_openmode_min = ~__INT_MAX__
00122     };
00123 
00124   inline _GLIBCXX_CONSTEXPR _Ios_Openmode
00125   operator&(_Ios_Openmode __a, _Ios_Openmode __b)
00126   { return _Ios_Openmode(static_cast<int>(__a) & static_cast<int>(__b)); }
00127 
00128   inline _GLIBCXX_CONSTEXPR _Ios_Openmode
00129   operator|(_Ios_Openmode __a, _Ios_Openmode __b)
00130   { return _Ios_Openmode(static_cast<int>(__a) | static_cast<int>(__b)); }
00131 
00132   inline _GLIBCXX_CONSTEXPR _Ios_Openmode
00133   operator^(_Ios_Openmode __a, _Ios_Openmode __b)
00134   { return _Ios_Openmode(static_cast<int>(__a) ^ static_cast<int>(__b)); }
00135 
00136   inline _GLIBCXX_CONSTEXPR _Ios_Openmode
00137   operator~(_Ios_Openmode __a)
00138   { return _Ios_Openmode(~static_cast<int>(__a)); }
00139 
00140   inline const _Ios_Openmode&
00141   operator|=(_Ios_Openmode& __a, _Ios_Openmode __b)
00142   { return __a = __a | __b; }
00143 
00144   inline const _Ios_Openmode&
00145   operator&=(_Ios_Openmode& __a, _Ios_Openmode __b)
00146   { return __a = __a & __b; }
00147 
00148   inline const _Ios_Openmode&
00149   operator^=(_Ios_Openmode& __a, _Ios_Openmode __b)
00150   { return __a = __a ^ __b; }
00151 
00152 
00153   enum _Ios_Iostate
00154     { 
00155       _S_goodbit                = 0,
00156       _S_badbit                 = 1L << 0,
00157       _S_eofbit                 = 1L << 1,
00158       _S_failbit                = 1L << 2,
00159       _S_ios_iostate_end = 1L << 16,
00160       _S_ios_iostate_max = __INT_MAX__,
00161       _S_ios_iostate_min = ~__INT_MAX__
00162     };
00163 
00164   inline _GLIBCXX_CONSTEXPR _Ios_Iostate
00165   operator&(_Ios_Iostate __a, _Ios_Iostate __b)
00166   { return _Ios_Iostate(static_cast<int>(__a) & static_cast<int>(__b)); }
00167 
00168   inline _GLIBCXX_CONSTEXPR _Ios_Iostate
00169   operator|(_Ios_Iostate __a, _Ios_Iostate __b)
00170   { return _Ios_Iostate(static_cast<int>(__a) | static_cast<int>(__b)); }
00171 
00172   inline _GLIBCXX_CONSTEXPR _Ios_Iostate
00173   operator^(_Ios_Iostate __a, _Ios_Iostate __b)
00174   { return _Ios_Iostate(static_cast<int>(__a) ^ static_cast<int>(__b)); }
00175 
00176   inline _GLIBCXX_CONSTEXPR _Ios_Iostate
00177   operator~(_Ios_Iostate __a)
00178   { return _Ios_Iostate(~static_cast<int>(__a)); }
00179 
00180   inline const _Ios_Iostate&
00181   operator|=(_Ios_Iostate& __a, _Ios_Iostate __b)
00182   { return __a = __a | __b; }
00183 
00184   inline const _Ios_Iostate&
00185   operator&=(_Ios_Iostate& __a, _Ios_Iostate __b)
00186   { return __a = __a & __b; }
00187 
00188   inline const  _Ios_Iostate&
00189   operator^=(_Ios_Iostate& __a, _Ios_Iostate __b)
00190   { return __a = __a ^ __b; }
00191 
00192 
00193   enum _Ios_Seekdir 
00194     { 
00195       _S_beg = 0,
00196       _S_cur = _GLIBCXX_STDIO_SEEK_CUR,
00197       _S_end = _GLIBCXX_STDIO_SEEK_END,
00198       _S_ios_seekdir_end = 1L << 16 
00199     };
00200 
00201 #if __cplusplus >= 201103L
00202   /// I/O error code
00203   enum class io_errc { stream = 1 };
00204 
00205   template <> struct is_error_code_enum<io_errc> : public true_type { };
00206 
00207   const error_category& iostream_category() noexcept;
00208 
00209   inline error_code
00210   make_error_code(io_errc e) noexcept
00211   { return error_code(static_cast<int>(e), iostream_category()); }
00212 
00213   inline error_condition
00214   make_error_condition(io_errc e) noexcept
00215   { return error_condition(static_cast<int>(e), iostream_category()); }
00216 #endif
00217 
00218   // 27.4.2  Class ios_base
00219   /**
00220    *  @brief  The base of the I/O class hierarchy.
00221    *  @ingroup io
00222    *
00223    *  This class defines everything that can be defined about I/O that does
00224    *  not depend on the type of characters being input or output.  Most
00225    *  people will only see @c ios_base when they need to specify the full
00226    *  name of the various I/O flags (e.g., the openmodes).
00227   */
00228   class ios_base
00229   {
00230 #if _GLIBCXX_USE_CXX11_ABI
00231 #if __cplusplus < 201103L
00232     // Type that is layout-compatible with std::system_error
00233     struct system_error : std::runtime_error
00234     {
00235       // Type that is layout-compatible with std::error_code
00236       struct error_code
00237       {
00238         error_code() { }
00239       private:
00240         int             _M_value;
00241         const void*     _M_cat;
00242       } _M_code;
00243     };
00244 #endif
00245 #endif
00246   public:
00247 
00248     /** 
00249      *  @brief These are thrown to indicate problems with io.
00250      *  @ingroup exceptions
00251      *
00252      *  27.4.2.1.1  Class ios_base::failure
00253      */
00254 #if _GLIBCXX_USE_CXX11_ABI
00255     class _GLIBCXX_ABI_TAG_CXX11 failure : public system_error
00256     {
00257     public:
00258       explicit
00259       failure(const string& __str);
00260 
00261 #if __cplusplus >= 201103L
00262       explicit
00263       failure(const string&, const error_code&);
00264 
00265       explicit
00266       failure(const char*, const error_code& = io_errc::stream);
00267 #endif
00268 
00269       virtual
00270       ~failure() throw();
00271 
00272       virtual const char*
00273       what() const throw();
00274     };
00275 #else
00276     class failure : public exception
00277     {
00278     public:
00279       // _GLIBCXX_RESOLVE_LIB_DEFECTS
00280       // 48.  Use of non-existent exception constructor
00281       explicit
00282       failure(const string& __str) throw();
00283 
00284       // This declaration is not useless:
00285       // http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Vague-Linkage.html
00286       virtual
00287       ~failure() throw();
00288 
00289       virtual const char*
00290       what() const throw();
00291 
00292     private:
00293       string _M_msg;
00294     };
00295 #endif
00296 
00297     // 27.4.2.1.2  Type ios_base::fmtflags
00298     /**
00299      *  @brief This is a bitmask type.
00300      *
00301      *  @c @a _Ios_Fmtflags is implementation-defined, but it is valid to
00302      *  perform bitwise operations on these values and expect the Right
00303      *  Thing to happen.  Defined objects of type fmtflags are:
00304      *  - boolalpha
00305      *  - dec
00306      *  - fixed
00307      *  - hex
00308      *  - internal
00309      *  - left
00310      *  - oct
00311      *  - right
00312      *  - scientific
00313      *  - showbase
00314      *  - showpoint
00315      *  - showpos
00316      *  - skipws
00317      *  - unitbuf
00318      *  - uppercase
00319      *  - adjustfield
00320      *  - basefield
00321      *  - floatfield
00322     */
00323     typedef _Ios_Fmtflags fmtflags;
00324 
00325     /// Insert/extract @c bool in alphabetic rather than numeric format.
00326     static const fmtflags boolalpha =   _S_boolalpha;
00327 
00328     /// Converts integer input or generates integer output in decimal base.
00329     static const fmtflags dec =         _S_dec;
00330 
00331     /// Generate floating-point output in fixed-point notation.
00332     static const fmtflags fixed =       _S_fixed;
00333 
00334     /// Converts integer input or generates integer output in hexadecimal base.
00335     static const fmtflags hex =         _S_hex;
00336 
00337     /// Adds fill characters at a designated internal point in certain
00338     /// generated output, or identical to @c right if no such point is
00339     /// designated.
00340     static const fmtflags internal =    _S_internal;
00341 
00342     /// Adds fill characters on the right (final positions) of certain
00343     /// generated output.  (I.e., the thing you print is flush left.)
00344     static const fmtflags left =        _S_left;
00345 
00346     /// Converts integer input or generates integer output in octal base.
00347     static const fmtflags oct =         _S_oct;
00348 
00349     /// Adds fill characters on the left (initial positions) of certain
00350     /// generated output.  (I.e., the thing you print is flush right.)
00351     static const fmtflags right =       _S_right;
00352 
00353     /// Generates floating-point output in scientific notation.
00354     static const fmtflags scientific =  _S_scientific;
00355 
00356     /// Generates a prefix indicating the numeric base of generated integer
00357     /// output.
00358     static const fmtflags showbase =    _S_showbase;
00359 
00360     /// Generates a decimal-point character unconditionally in generated
00361     /// floating-point output.
00362     static const fmtflags showpoint =   _S_showpoint;
00363 
00364     /// Generates a + sign in non-negative generated numeric output.
00365     static const fmtflags showpos =     _S_showpos;
00366 
00367     /// Skips leading white space before certain input operations.
00368     static const fmtflags skipws =      _S_skipws;
00369 
00370     /// Flushes output after each output operation.
00371     static const fmtflags unitbuf =     _S_unitbuf;
00372 
00373     /// Replaces certain lowercase letters with their uppercase equivalents
00374     /// in generated output.
00375     static const fmtflags uppercase =   _S_uppercase;
00376 
00377     /// A mask of left|right|internal.  Useful for the 2-arg form of @c setf.
00378     static const fmtflags adjustfield = _S_adjustfield;
00379 
00380     /// A mask of dec|oct|hex.  Useful for the 2-arg form of @c setf.
00381     static const fmtflags basefield =   _S_basefield;
00382 
00383     /// A mask of scientific|fixed.  Useful for the 2-arg form of @c setf.
00384     static const fmtflags floatfield =  _S_floatfield;
00385 
00386     // 27.4.2.1.3  Type ios_base::iostate
00387     /**
00388      *  @brief This is a bitmask type.
00389      *
00390      *  @c @a _Ios_Iostate is implementation-defined, but it is valid to
00391      *  perform bitwise operations on these values and expect the Right
00392      *  Thing to happen.  Defined objects of type iostate are:
00393      *  - badbit
00394      *  - eofbit
00395      *  - failbit
00396      *  - goodbit
00397     */
00398     typedef _Ios_Iostate iostate;
00399 
00400     /// Indicates a loss of integrity in an input or output sequence (such
00401     /// as an irrecoverable read error from a file).
00402     static const iostate badbit =       _S_badbit;
00403 
00404     /// Indicates that an input operation reached the end of an input sequence.
00405     static const iostate eofbit =       _S_eofbit;
00406 
00407     /// Indicates that an input operation failed to read the expected
00408     /// characters, or that an output operation failed to generate the
00409     /// desired characters.
00410     static const iostate failbit =      _S_failbit;
00411 
00412     /// Indicates all is well.
00413     static const iostate goodbit =      _S_goodbit;
00414 
00415     // 27.4.2.1.4  Type ios_base::openmode
00416     /**
00417      *  @brief This is a bitmask type.
00418      *
00419      *  @c @a _Ios_Openmode is implementation-defined, but it is valid to
00420      *  perform bitwise operations on these values and expect the Right
00421      *  Thing to happen.  Defined objects of type openmode are:
00422      *  - app
00423      *  - ate
00424      *  - binary
00425      *  - in
00426      *  - out
00427      *  - trunc
00428     */
00429     typedef _Ios_Openmode openmode;
00430 
00431     /// Seek to end before each write.
00432     static const openmode app =         _S_app;
00433 
00434     /// Open and seek to end immediately after opening.
00435     static const openmode ate =         _S_ate;
00436 
00437     /// Perform input and output in binary mode (as opposed to text mode).
00438     /// This is probably not what you think it is; see
00439     /// https://gcc.gnu.org/onlinedocs/libstdc++/manual/fstreams.html#std.io.filestreams.binary
00440     static const openmode binary =      _S_bin;
00441 
00442     /// Open for input.  Default for @c ifstream and fstream.
00443     static const openmode in =          _S_in;
00444 
00445     /// Open for output.  Default for @c ofstream and fstream.
00446     static const openmode out =         _S_out;
00447 
00448     /// Open for input.  Default for @c ofstream.
00449     static const openmode trunc =       _S_trunc;
00450 
00451     // 27.4.2.1.5  Type ios_base::seekdir
00452     /**
00453      *  @brief This is an enumerated type.
00454      *
00455      *  @c @a _Ios_Seekdir is implementation-defined.  Defined values
00456      *  of type seekdir are:
00457      *  - beg
00458      *  - cur, equivalent to @c SEEK_CUR in the C standard library.
00459      *  - end, equivalent to @c SEEK_END in the C standard library.
00460     */
00461     typedef _Ios_Seekdir seekdir;
00462 
00463     /// Request a seek relative to the beginning of the stream.
00464     static const seekdir beg =          _S_beg;
00465 
00466     /// Request a seek relative to the current position within the sequence.
00467     static const seekdir cur =          _S_cur;
00468 
00469     /// Request a seek relative to the current end of the sequence.
00470     static const seekdir end =          _S_end;
00471 
00472     // Annex D.6
00473     typedef int io_state;
00474     typedef int open_mode;
00475     typedef int seek_dir;
00476 
00477     typedef std::streampos streampos;
00478     typedef std::streamoff streamoff;
00479 
00480     // Callbacks;
00481     /**
00482      *  @brief  The set of events that may be passed to an event callback.
00483      *
00484      *  erase_event is used during ~ios() and copyfmt().  imbue_event is used
00485      *  during imbue().  copyfmt_event is used during copyfmt().
00486     */
00487     enum event
00488     {
00489       erase_event,
00490       imbue_event,
00491       copyfmt_event
00492     };
00493 
00494     /**
00495      *  @brief  The type of an event callback function.
00496      *  @param  __e  One of the members of the event enum.
00497      *  @param  __b  Reference to the ios_base object.
00498      *  @param  __i  The integer provided when the callback was registered.
00499      *
00500      *  Event callbacks are user defined functions that get called during
00501      *  several ios_base and basic_ios functions, specifically imbue(),
00502      *  copyfmt(), and ~ios().
00503     */
00504     typedef void (*event_callback) (event __e, ios_base& __b, int __i);
00505 
00506     /**
00507      *  @brief  Add the callback __fn with parameter __index.
00508      *  @param  __fn  The function to add.
00509      *  @param  __index  The integer to pass to the function when invoked.
00510      *
00511      *  Registers a function as an event callback with an integer parameter to
00512      *  be passed to the function when invoked.  Multiple copies of the
00513      *  function are allowed.  If there are multiple callbacks, they are
00514      *  invoked in the order they were registered.
00515     */
00516     void
00517     register_callback(event_callback __fn, int __index);
00518 
00519   protected:
00520     streamsize          _M_precision;
00521     streamsize          _M_width;
00522     fmtflags            _M_flags;
00523     iostate             _M_exception;
00524     iostate             _M_streambuf_state;
00525 
00526     // 27.4.2.6  Members for callbacks
00527     // 27.4.2.6  ios_base callbacks
00528     struct _Callback_list
00529     {
00530       // Data Members
00531       _Callback_list*           _M_next;
00532       ios_base::event_callback  _M_fn;
00533       int                       _M_index;
00534       _Atomic_word              _M_refcount;  // 0 means one reference.
00535 
00536       _Callback_list(ios_base::event_callback __fn, int __index,
00537                      _Callback_list* __cb)
00538       : _M_next(__cb), _M_fn(__fn), _M_index(__index), _M_refcount(0) { }
00539 
00540       void
00541       _M_add_reference() { __gnu_cxx::__atomic_add_dispatch(&_M_refcount, 1); }
00542 
00543       // 0 => OK to delete.
00544       int
00545       _M_remove_reference() 
00546       {
00547         // Be race-detector-friendly.  For more info see bits/c++config.
00548         _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_refcount);
00549         int __res = __gnu_cxx::__exchange_and_add_dispatch(&_M_refcount, -1);
00550         if (__res == 0)
00551           {
00552             _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&_M_refcount);
00553           }
00554         return __res;
00555       }
00556     };
00557 
00558      _Callback_list*    _M_callbacks;
00559 
00560     void
00561     _M_call_callbacks(event __ev) throw();
00562 
00563     void
00564     _M_dispose_callbacks(void) throw();
00565 
00566     // 27.4.2.5  Members for iword/pword storage
00567     struct _Words
00568     {
00569       void*     _M_pword;
00570       long      _M_iword;
00571       _Words() : _M_pword(0), _M_iword(0) { }
00572     };
00573 
00574     // Only for failed iword/pword calls.
00575     _Words              _M_word_zero;
00576 
00577     // Guaranteed storage.
00578     // The first 5 iword and pword slots are reserved for internal use.
00579     enum { _S_local_word_size = 8 };
00580     _Words              _M_local_word[_S_local_word_size];
00581 
00582     // Allocated storage.
00583     int                 _M_word_size;
00584     _Words*             _M_word;
00585 
00586     _Words&
00587     _M_grow_words(int __index, bool __iword);
00588 
00589     // Members for locale and locale caching.
00590     locale              _M_ios_locale;
00591 
00592     void
00593     _M_init() throw();
00594 
00595   public:
00596 
00597     // 27.4.2.1.6  Class ios_base::Init
00598     // Used to initialize standard streams. In theory, g++ could use
00599     // -finit-priority to order this stuff correctly without going
00600     // through these machinations.
00601     class Init
00602     {
00603       friend class ios_base;
00604     public:
00605       Init();
00606       ~Init();
00607 
00608     private:
00609       static _Atomic_word       _S_refcount;
00610       static bool               _S_synced_with_stdio;
00611     };
00612 
00613     // [27.4.2.2] fmtflags state functions
00614     /**
00615      *  @brief  Access to format flags.
00616      *  @return  The format control flags for both input and output.
00617     */
00618     fmtflags
00619     flags() const
00620     { return _M_flags; }
00621 
00622     /**
00623      *  @brief  Setting new format flags all at once.
00624      *  @param  __fmtfl  The new flags to set.
00625      *  @return  The previous format control flags.
00626      *
00627      *  This function overwrites all the format flags with @a __fmtfl.
00628     */
00629     fmtflags
00630     flags(fmtflags __fmtfl)
00631     {
00632       fmtflags __old = _M_flags;
00633       _M_flags = __fmtfl;
00634       return __old;
00635     }
00636 
00637     /**
00638      *  @brief  Setting new format flags.
00639      *  @param  __fmtfl  Additional flags to set.
00640      *  @return  The previous format control flags.
00641      *
00642      *  This function sets additional flags in format control.  Flags that
00643      *  were previously set remain set.
00644     */
00645     fmtflags
00646     setf(fmtflags __fmtfl)
00647     {
00648       fmtflags __old = _M_flags;
00649       _M_flags |= __fmtfl;
00650       return __old;
00651     }
00652 
00653     /**
00654      *  @brief  Setting new format flags.
00655      *  @param  __fmtfl  Additional flags to set.
00656      *  @param  __mask  The flags mask for @a fmtfl.
00657      *  @return  The previous format control flags.
00658      *
00659      *  This function clears @a mask in the format flags, then sets
00660      *  @a fmtfl @c & @a mask.  An example mask is @c ios_base::adjustfield.
00661     */
00662     fmtflags
00663     setf(fmtflags __fmtfl, fmtflags __mask)
00664     {
00665       fmtflags __old = _M_flags;
00666       _M_flags &= ~__mask;
00667       _M_flags |= (__fmtfl & __mask);
00668       return __old;
00669     }
00670 
00671     /**
00672      *  @brief  Clearing format flags.
00673      *  @param  __mask  The flags to unset.
00674      *
00675      *  This function clears @a __mask in the format flags.
00676     */
00677     void
00678     unsetf(fmtflags __mask)
00679     { _M_flags &= ~__mask; }
00680 
00681     /**
00682      *  @brief  Flags access.
00683      *  @return  The precision to generate on certain output operations.
00684      *
00685      *  Be careful if you try to give a definition of @a precision here; see
00686      *  DR 189.
00687     */
00688     streamsize
00689     precision() const
00690     { return _M_precision; }
00691 
00692     /**
00693      *  @brief  Changing flags.
00694      *  @param  __prec  The new precision value.
00695      *  @return  The previous value of precision().
00696     */
00697     streamsize
00698     precision(streamsize __prec)
00699     {
00700       streamsize __old = _M_precision;
00701       _M_precision = __prec;
00702       return __old;
00703     }
00704 
00705     /**
00706      *  @brief  Flags access.
00707      *  @return  The minimum field width to generate on output operations.
00708      *
00709      *  <em>Minimum field width</em> refers to the number of characters.
00710     */
00711     streamsize
00712     width() const
00713     { return _M_width; }
00714 
00715     /**
00716      *  @brief  Changing flags.
00717      *  @param  __wide  The new width value.
00718      *  @return  The previous value of width().
00719     */
00720     streamsize
00721     width(streamsize __wide)
00722     {
00723       streamsize __old = _M_width;
00724       _M_width = __wide;
00725       return __old;
00726     }
00727 
00728     // [27.4.2.4] ios_base static members
00729     /**
00730      *  @brief  Interaction with the standard C I/O objects.
00731      *  @param  __sync  Whether to synchronize or not.
00732      *  @return  True if the standard streams were previously synchronized.
00733      *
00734      *  The synchronization referred to is @e only that between the standard
00735      *  C facilities (e.g., stdout) and the standard C++ objects (e.g.,
00736      *  cout).  User-declared streams are unaffected.  See
00737      *  https://gcc.gnu.org/onlinedocs/libstdc++/manual/fstreams.html#std.io.filestreams.binary
00738     */
00739     static bool
00740     sync_with_stdio(bool __sync = true);
00741 
00742     // [27.4.2.3] ios_base locale functions
00743     /**
00744      *  @brief  Setting a new locale.
00745      *  @param  __loc  The new locale.
00746      *  @return  The previous locale.
00747      *
00748      *  Sets the new locale for this stream, and then invokes each callback
00749      *  with imbue_event.
00750     */
00751     locale
00752     imbue(const locale& __loc) throw();
00753 
00754     /**
00755      *  @brief  Locale access
00756      *  @return  A copy of the current locale.
00757      *
00758      *  If @c imbue(loc) has previously been called, then this function
00759      *  returns @c loc.  Otherwise, it returns a copy of @c std::locale(),
00760      *  the global C++ locale.
00761     */
00762     locale
00763     getloc() const
00764     { return _M_ios_locale; }
00765 
00766     /**
00767      *  @brief  Locale access
00768      *  @return  A reference to the current locale.
00769      *
00770      *  Like getloc above, but returns a reference instead of
00771      *  generating a copy.
00772     */
00773     const locale&
00774     _M_getloc() const
00775     { return _M_ios_locale; }
00776 
00777     // [27.4.2.5] ios_base storage functions
00778     /**
00779      *  @brief  Access to unique indices.
00780      *  @return  An integer different from all previous calls.
00781      *
00782      *  This function returns a unique integer every time it is called.  It
00783      *  can be used for any purpose, but is primarily intended to be a unique
00784      *  index for the iword and pword functions.  The expectation is that an
00785      *  application calls xalloc in order to obtain an index in the iword and
00786      *  pword arrays that can be used without fear of conflict.
00787      *
00788      *  The implementation maintains a static variable that is incremented and
00789      *  returned on each invocation.  xalloc is guaranteed to return an index
00790      *  that is safe to use in the iword and pword arrays.
00791     */
00792     static int
00793     xalloc() throw();
00794 
00795     /**
00796      *  @brief  Access to integer array.
00797      *  @param  __ix  Index into the array.
00798      *  @return  A reference to an integer associated with the index.
00799      *
00800      *  The iword function provides access to an array of integers that can be
00801      *  used for any purpose.  The array grows as required to hold the
00802      *  supplied index.  All integers in the array are initialized to 0.
00803      *
00804      *  The implementation reserves several indices.  You should use xalloc to
00805      *  obtain an index that is safe to use.  Also note that since the array
00806      *  can grow dynamically, it is not safe to hold onto the reference.
00807     */
00808     long&
00809     iword(int __ix)
00810     {
00811       _Words& __word = (__ix < _M_word_size)
00812                         ? _M_word[__ix] : _M_grow_words(__ix, true);
00813       return __word._M_iword;
00814     }
00815 
00816     /**
00817      *  @brief  Access to void pointer array.
00818      *  @param  __ix  Index into the array.
00819      *  @return  A reference to a void* associated with the index.
00820      *
00821      *  The pword function provides access to an array of pointers that can be
00822      *  used for any purpose.  The array grows as required to hold the
00823      *  supplied index.  All pointers in the array are initialized to 0.
00824      *
00825      *  The implementation reserves several indices.  You should use xalloc to
00826      *  obtain an index that is safe to use.  Also note that since the array
00827      *  can grow dynamically, it is not safe to hold onto the reference.
00828     */
00829     void*&
00830     pword(int __ix)
00831     {
00832       _Words& __word = (__ix < _M_word_size)
00833                         ? _M_word[__ix] : _M_grow_words(__ix, false);
00834       return __word._M_pword;
00835     }
00836 
00837     // Destructor
00838     /**
00839      *  Invokes each callback with erase_event.  Destroys local storage.
00840      *
00841      *  Note that the ios_base object for the standard streams never gets
00842      *  destroyed.  As a result, any callbacks registered with the standard
00843      *  streams will not get invoked with erase_event (unless copyfmt is
00844      *  used).
00845     */
00846     virtual ~ios_base();
00847 
00848   protected:
00849     ios_base() throw ();
00850 
00851 #if __cplusplus < 201103L
00852   // _GLIBCXX_RESOLVE_LIB_DEFECTS
00853   // 50.  Copy constructor and assignment operator of ios_base
00854   private:
00855     ios_base(const ios_base&);
00856 
00857     ios_base&
00858     operator=(const ios_base&);
00859 #else
00860   public:
00861     ios_base(const ios_base&) = delete;
00862 
00863     ios_base&
00864     operator=(const ios_base&) = delete;
00865 
00866   protected:
00867     void
00868     _M_move(ios_base&) noexcept;
00869 
00870     void
00871     _M_swap(ios_base& __rhs) noexcept;
00872 #endif
00873   };
00874 
00875   // [27.4.5.1] fmtflags manipulators
00876   /// Calls base.setf(ios_base::boolalpha).
00877   inline ios_base&
00878   boolalpha(ios_base& __base)
00879   {
00880     __base.setf(ios_base::boolalpha);
00881     return __base;
00882   }
00883 
00884   /// Calls base.unsetf(ios_base::boolalpha).
00885   inline ios_base&
00886   noboolalpha(ios_base& __base)
00887   {
00888     __base.unsetf(ios_base::boolalpha);
00889     return __base;
00890   }
00891 
00892   /// Calls base.setf(ios_base::showbase).
00893   inline ios_base&
00894   showbase(ios_base& __base)
00895   {
00896     __base.setf(ios_base::showbase);
00897     return __base;
00898   }
00899 
00900   /// Calls base.unsetf(ios_base::showbase).
00901   inline ios_base&
00902   noshowbase(ios_base& __base)
00903   {
00904     __base.unsetf(ios_base::showbase);
00905     return __base;
00906   }
00907 
00908   /// Calls base.setf(ios_base::showpoint).
00909   inline ios_base&
00910   showpoint(ios_base& __base)
00911   {
00912     __base.setf(ios_base::showpoint);
00913     return __base;
00914   }
00915 
00916   /// Calls base.unsetf(ios_base::showpoint).
00917   inline ios_base&
00918   noshowpoint(ios_base& __base)
00919   {
00920     __base.unsetf(ios_base::showpoint);
00921     return __base;
00922   }
00923 
00924   /// Calls base.setf(ios_base::showpos).
00925   inline ios_base&
00926   showpos(ios_base& __base)
00927   {
00928     __base.setf(ios_base::showpos);
00929     return __base;
00930   }
00931 
00932   /// Calls base.unsetf(ios_base::showpos).
00933   inline ios_base&
00934   noshowpos(ios_base& __base)
00935   {
00936     __base.unsetf(ios_base::showpos);
00937     return __base;
00938   }
00939 
00940   /// Calls base.setf(ios_base::skipws).
00941   inline ios_base&
00942   skipws(ios_base& __base)
00943   {
00944     __base.setf(ios_base::skipws);
00945     return __base;
00946   }
00947 
00948   /// Calls base.unsetf(ios_base::skipws).
00949   inline ios_base&
00950   noskipws(ios_base& __base)
00951   {
00952     __base.unsetf(ios_base::skipws);
00953     return __base;
00954   }
00955 
00956   /// Calls base.setf(ios_base::uppercase).
00957   inline ios_base&
00958   uppercase(ios_base& __base)
00959   {
00960     __base.setf(ios_base::uppercase);
00961     return __base;
00962   }
00963 
00964   /// Calls base.unsetf(ios_base::uppercase).
00965   inline ios_base&
00966   nouppercase(ios_base& __base)
00967   {
00968     __base.unsetf(ios_base::uppercase);
00969     return __base;
00970   }
00971 
00972   /// Calls base.setf(ios_base::unitbuf).
00973   inline ios_base&
00974   unitbuf(ios_base& __base)
00975   {
00976      __base.setf(ios_base::unitbuf);
00977      return __base;
00978   }
00979 
00980   /// Calls base.unsetf(ios_base::unitbuf).
00981   inline ios_base&
00982   nounitbuf(ios_base& __base)
00983   {
00984      __base.unsetf(ios_base::unitbuf);
00985      return __base;
00986   }
00987 
00988   // [27.4.5.2] adjustfield manipulators
00989   /// Calls base.setf(ios_base::internal, ios_base::adjustfield).
00990   inline ios_base&
00991   internal(ios_base& __base)
00992   {
00993      __base.setf(ios_base::internal, ios_base::adjustfield);
00994      return __base;
00995   }
00996 
00997   /// Calls base.setf(ios_base::left, ios_base::adjustfield).
00998   inline ios_base&
00999   left(ios_base& __base)
01000   {
01001     __base.setf(ios_base::left, ios_base::adjustfield);
01002     return __base;
01003   }
01004 
01005   /// Calls base.setf(ios_base::right, ios_base::adjustfield).
01006   inline ios_base&
01007   right(ios_base& __base)
01008   {
01009     __base.setf(ios_base::right, ios_base::adjustfield);
01010     return __base;
01011   }
01012 
01013   // [27.4.5.3] basefield manipulators
01014   /// Calls base.setf(ios_base::dec, ios_base::basefield).
01015   inline ios_base&
01016   dec(ios_base& __base)
01017   {
01018     __base.setf(ios_base::dec, ios_base::basefield);
01019     return __base;
01020   }
01021 
01022   /// Calls base.setf(ios_base::hex, ios_base::basefield).
01023   inline ios_base&
01024   hex(ios_base& __base)
01025   {
01026     __base.setf(ios_base::hex, ios_base::basefield);
01027     return __base;
01028   }
01029 
01030   /// Calls base.setf(ios_base::oct, ios_base::basefield).
01031   inline ios_base&
01032   oct(ios_base& __base)
01033   {
01034     __base.setf(ios_base::oct, ios_base::basefield);
01035     return __base;
01036   }
01037 
01038   // [27.4.5.4] floatfield manipulators
01039   /// Calls base.setf(ios_base::fixed, ios_base::floatfield).
01040   inline ios_base&
01041   fixed(ios_base& __base)
01042   {
01043     __base.setf(ios_base::fixed, ios_base::floatfield);
01044     return __base;
01045   }
01046 
01047   /// Calls base.setf(ios_base::scientific, ios_base::floatfield).
01048   inline ios_base&
01049   scientific(ios_base& __base)
01050   {
01051     __base.setf(ios_base::scientific, ios_base::floatfield);
01052     return __base;
01053   }
01054 
01055 #if __cplusplus >= 201103L
01056   // New C++11 floatfield manipulators
01057 
01058   /// Calls
01059   /// base.setf(ios_base::fixed|ios_base::scientific, ios_base::floatfield)
01060   inline ios_base&
01061   hexfloat(ios_base& __base)
01062   {
01063     __base.setf(ios_base::fixed | ios_base::scientific, ios_base::floatfield);
01064     return __base;
01065   }
01066 
01067   /// Calls @c base.unsetf(ios_base::floatfield)
01068   inline ios_base&
01069   defaultfloat(ios_base& __base)
01070   {
01071     __base.unsetf(ios_base::floatfield);
01072     return __base;
01073   }
01074 #endif
01075 
01076 _GLIBCXX_END_NAMESPACE_VERSION
01077 } // namespace
01078 
01079 #endif /* _IOS_BASE_H */