libstdc++
ios_base.h
Go to the documentation of this file.
00001 // Iostreams base classes -*- C++ -*-
00002 
00003 // Copyright (C) 1997-2018 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 in C++98
00056   // expressions involving them are not 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 #if __cplusplus <= 201402L
00473     // Annex D.6 (removed in C++17)
00474     typedef int io_state;
00475     typedef int open_mode;
00476     typedef int seek_dir;
00477 
00478     typedef std::streampos streampos;
00479     typedef std::streamoff streamoff;
00480 #endif
00481 
00482     // Callbacks;
00483     /**
00484      *  @brief  The set of events that may be passed to an event callback.
00485      *
00486      *  erase_event is used during ~ios() and copyfmt().  imbue_event is used
00487      *  during imbue().  copyfmt_event is used during copyfmt().
00488     */
00489     enum event
00490     {
00491       erase_event,
00492       imbue_event,
00493       copyfmt_event
00494     };
00495 
00496     /**
00497      *  @brief  The type of an event callback function.
00498      *  @param  __e  One of the members of the event enum.
00499      *  @param  __b  Reference to the ios_base object.
00500      *  @param  __i  The integer provided when the callback was registered.
00501      *
00502      *  Event callbacks are user defined functions that get called during
00503      *  several ios_base and basic_ios functions, specifically imbue(),
00504      *  copyfmt(), and ~ios().
00505     */
00506     typedef void (*event_callback) (event __e, ios_base& __b, int __i);
00507 
00508     /**
00509      *  @brief  Add the callback __fn with parameter __index.
00510      *  @param  __fn  The function to add.
00511      *  @param  __index  The integer to pass to the function when invoked.
00512      *
00513      *  Registers a function as an event callback with an integer parameter to
00514      *  be passed to the function when invoked.  Multiple copies of the
00515      *  function are allowed.  If there are multiple callbacks, they are
00516      *  invoked in the order they were registered.
00517     */
00518     void
00519     register_callback(event_callback __fn, int __index);
00520 
00521   protected:
00522     streamsize          _M_precision;
00523     streamsize          _M_width;
00524     fmtflags            _M_flags;
00525     iostate             _M_exception;
00526     iostate             _M_streambuf_state;
00527 
00528     // 27.4.2.6  Members for callbacks
00529     // 27.4.2.6  ios_base callbacks
00530     struct _Callback_list
00531     {
00532       // Data Members
00533       _Callback_list*           _M_next;
00534       ios_base::event_callback  _M_fn;
00535       int                       _M_index;
00536       _Atomic_word              _M_refcount;  // 0 means one reference.
00537 
00538       _Callback_list(ios_base::event_callback __fn, int __index,
00539                      _Callback_list* __cb)
00540       : _M_next(__cb), _M_fn(__fn), _M_index(__index), _M_refcount(0) { }
00541 
00542       void
00543       _M_add_reference() { __gnu_cxx::__atomic_add_dispatch(&_M_refcount, 1); }
00544 
00545       // 0 => OK to delete.
00546       int
00547       _M_remove_reference() 
00548       {
00549         // Be race-detector-friendly.  For more info see bits/c++config.
00550         _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_refcount);
00551         int __res = __gnu_cxx::__exchange_and_add_dispatch(&_M_refcount, -1);
00552         if (__res == 0)
00553           {
00554             _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&_M_refcount);
00555           }
00556         return __res;
00557       }
00558     };
00559 
00560      _Callback_list*    _M_callbacks;
00561 
00562     void
00563     _M_call_callbacks(event __ev) throw();
00564 
00565     void
00566     _M_dispose_callbacks(void) throw();
00567 
00568     // 27.4.2.5  Members for iword/pword storage
00569     struct _Words
00570     {
00571       void*     _M_pword;
00572       long      _M_iword;
00573       _Words() : _M_pword(0), _M_iword(0) { }
00574     };
00575 
00576     // Only for failed iword/pword calls.
00577     _Words              _M_word_zero;
00578 
00579     // Guaranteed storage.
00580     // The first 5 iword and pword slots are reserved for internal use.
00581     enum { _S_local_word_size = 8 };
00582     _Words              _M_local_word[_S_local_word_size];
00583 
00584     // Allocated storage.
00585     int                 _M_word_size;
00586     _Words*             _M_word;
00587 
00588     _Words&
00589     _M_grow_words(int __index, bool __iword);
00590 
00591     // Members for locale and locale caching.
00592     locale              _M_ios_locale;
00593 
00594     void
00595     _M_init() throw();
00596 
00597   public:
00598 
00599     // 27.4.2.1.6  Class ios_base::Init
00600     // Used to initialize standard streams. In theory, g++ could use
00601     // -finit-priority to order this stuff correctly without going
00602     // through these machinations.
00603     class Init
00604     {
00605       friend class ios_base;
00606     public:
00607       Init();
00608       ~Init();
00609 
00610     private:
00611       static _Atomic_word       _S_refcount;
00612       static bool               _S_synced_with_stdio;
00613     };
00614 
00615     // [27.4.2.2] fmtflags state functions
00616     /**
00617      *  @brief  Access to format flags.
00618      *  @return  The format control flags for both input and output.
00619     */
00620     fmtflags
00621     flags() const
00622     { return _M_flags; }
00623 
00624     /**
00625      *  @brief  Setting new format flags all at once.
00626      *  @param  __fmtfl  The new flags to set.
00627      *  @return  The previous format control flags.
00628      *
00629      *  This function overwrites all the format flags with @a __fmtfl.
00630     */
00631     fmtflags
00632     flags(fmtflags __fmtfl)
00633     {
00634       fmtflags __old = _M_flags;
00635       _M_flags = __fmtfl;
00636       return __old;
00637     }
00638 
00639     /**
00640      *  @brief  Setting new format flags.
00641      *  @param  __fmtfl  Additional flags to set.
00642      *  @return  The previous format control flags.
00643      *
00644      *  This function sets additional flags in format control.  Flags that
00645      *  were previously set remain set.
00646     */
00647     fmtflags
00648     setf(fmtflags __fmtfl)
00649     {
00650       fmtflags __old = _M_flags;
00651       _M_flags |= __fmtfl;
00652       return __old;
00653     }
00654 
00655     /**
00656      *  @brief  Setting new format flags.
00657      *  @param  __fmtfl  Additional flags to set.
00658      *  @param  __mask  The flags mask for @a fmtfl.
00659      *  @return  The previous format control flags.
00660      *
00661      *  This function clears @a mask in the format flags, then sets
00662      *  @a fmtfl @c & @a mask.  An example mask is @c ios_base::adjustfield.
00663     */
00664     fmtflags
00665     setf(fmtflags __fmtfl, fmtflags __mask)
00666     {
00667       fmtflags __old = _M_flags;
00668       _M_flags &= ~__mask;
00669       _M_flags |= (__fmtfl & __mask);
00670       return __old;
00671     }
00672 
00673     /**
00674      *  @brief  Clearing format flags.
00675      *  @param  __mask  The flags to unset.
00676      *
00677      *  This function clears @a __mask in the format flags.
00678     */
00679     void
00680     unsetf(fmtflags __mask)
00681     { _M_flags &= ~__mask; }
00682 
00683     /**
00684      *  @brief  Flags access.
00685      *  @return  The precision to generate on certain output operations.
00686      *
00687      *  Be careful if you try to give a definition of @a precision here; see
00688      *  DR 189.
00689     */
00690     streamsize
00691     precision() const
00692     { return _M_precision; }
00693 
00694     /**
00695      *  @brief  Changing flags.
00696      *  @param  __prec  The new precision value.
00697      *  @return  The previous value of precision().
00698     */
00699     streamsize
00700     precision(streamsize __prec)
00701     {
00702       streamsize __old = _M_precision;
00703       _M_precision = __prec;
00704       return __old;
00705     }
00706 
00707     /**
00708      *  @brief  Flags access.
00709      *  @return  The minimum field width to generate on output operations.
00710      *
00711      *  <em>Minimum field width</em> refers to the number of characters.
00712     */
00713     streamsize
00714     width() const
00715     { return _M_width; }
00716 
00717     /**
00718      *  @brief  Changing flags.
00719      *  @param  __wide  The new width value.
00720      *  @return  The previous value of width().
00721     */
00722     streamsize
00723     width(streamsize __wide)
00724     {
00725       streamsize __old = _M_width;
00726       _M_width = __wide;
00727       return __old;
00728     }
00729 
00730     // [27.4.2.4] ios_base static members
00731     /**
00732      *  @brief  Interaction with the standard C I/O objects.
00733      *  @param  __sync  Whether to synchronize or not.
00734      *  @return  True if the standard streams were previously synchronized.
00735      *
00736      *  The synchronization referred to is @e only that between the standard
00737      *  C facilities (e.g., stdout) and the standard C++ objects (e.g.,
00738      *  cout).  User-declared streams are unaffected.  See
00739      *  https://gcc.gnu.org/onlinedocs/libstdc++/manual/fstreams.html#std.io.filestreams.binary
00740     */
00741     static bool
00742     sync_with_stdio(bool __sync = true);
00743 
00744     // [27.4.2.3] ios_base locale functions
00745     /**
00746      *  @brief  Setting a new locale.
00747      *  @param  __loc  The new locale.
00748      *  @return  The previous locale.
00749      *
00750      *  Sets the new locale for this stream, and then invokes each callback
00751      *  with imbue_event.
00752     */
00753     locale
00754     imbue(const locale& __loc) throw();
00755 
00756     /**
00757      *  @brief  Locale access
00758      *  @return  A copy of the current locale.
00759      *
00760      *  If @c imbue(loc) has previously been called, then this function
00761      *  returns @c loc.  Otherwise, it returns a copy of @c std::locale(),
00762      *  the global C++ locale.
00763     */
00764     locale
00765     getloc() const
00766     { return _M_ios_locale; }
00767 
00768     /**
00769      *  @brief  Locale access
00770      *  @return  A reference to the current locale.
00771      *
00772      *  Like getloc above, but returns a reference instead of
00773      *  generating a copy.
00774     */
00775     const locale&
00776     _M_getloc() const
00777     { return _M_ios_locale; }
00778 
00779     // [27.4.2.5] ios_base storage functions
00780     /**
00781      *  @brief  Access to unique indices.
00782      *  @return  An integer different from all previous calls.
00783      *
00784      *  This function returns a unique integer every time it is called.  It
00785      *  can be used for any purpose, but is primarily intended to be a unique
00786      *  index for the iword and pword functions.  The expectation is that an
00787      *  application calls xalloc in order to obtain an index in the iword and
00788      *  pword arrays that can be used without fear of conflict.
00789      *
00790      *  The implementation maintains a static variable that is incremented and
00791      *  returned on each invocation.  xalloc is guaranteed to return an index
00792      *  that is safe to use in the iword and pword arrays.
00793     */
00794     static int
00795     xalloc() throw();
00796 
00797     /**
00798      *  @brief  Access to integer array.
00799      *  @param  __ix  Index into the array.
00800      *  @return  A reference to an integer associated with the index.
00801      *
00802      *  The iword function provides access to an array of integers that can be
00803      *  used for any purpose.  The array grows as required to hold the
00804      *  supplied index.  All integers in the array are initialized to 0.
00805      *
00806      *  The implementation reserves several indices.  You should use xalloc to
00807      *  obtain an index that is safe to use.  Also note that since the array
00808      *  can grow dynamically, it is not safe to hold onto the reference.
00809     */
00810     long&
00811     iword(int __ix)
00812     {
00813       _Words& __word = (__ix < _M_word_size)
00814                         ? _M_word[__ix] : _M_grow_words(__ix, true);
00815       return __word._M_iword;
00816     }
00817 
00818     /**
00819      *  @brief  Access to void pointer array.
00820      *  @param  __ix  Index into the array.
00821      *  @return  A reference to a void* associated with the index.
00822      *
00823      *  The pword function provides access to an array of pointers that can be
00824      *  used for any purpose.  The array grows as required to hold the
00825      *  supplied index.  All pointers in the array are initialized to 0.
00826      *
00827      *  The implementation reserves several indices.  You should use xalloc to
00828      *  obtain an index that is safe to use.  Also note that since the array
00829      *  can grow dynamically, it is not safe to hold onto the reference.
00830     */
00831     void*&
00832     pword(int __ix)
00833     {
00834       _Words& __word = (__ix < _M_word_size)
00835                         ? _M_word[__ix] : _M_grow_words(__ix, false);
00836       return __word._M_pword;
00837     }
00838 
00839     // Destructor
00840     /**
00841      *  Invokes each callback with erase_event.  Destroys local storage.
00842      *
00843      *  Note that the ios_base object for the standard streams never gets
00844      *  destroyed.  As a result, any callbacks registered with the standard
00845      *  streams will not get invoked with erase_event (unless copyfmt is
00846      *  used).
00847     */
00848     virtual ~ios_base();
00849 
00850   protected:
00851     ios_base() throw ();
00852 
00853 #if __cplusplus < 201103L
00854   // _GLIBCXX_RESOLVE_LIB_DEFECTS
00855   // 50.  Copy constructor and assignment operator of ios_base
00856   private:
00857     ios_base(const ios_base&);
00858 
00859     ios_base&
00860     operator=(const ios_base&);
00861 #else
00862   public:
00863     ios_base(const ios_base&) = delete;
00864 
00865     ios_base&
00866     operator=(const ios_base&) = delete;
00867 
00868   protected:
00869     void
00870     _M_move(ios_base&) noexcept;
00871 
00872     void
00873     _M_swap(ios_base& __rhs) noexcept;
00874 #endif
00875   };
00876 
00877   // [27.4.5.1] fmtflags manipulators
00878   /// Calls base.setf(ios_base::boolalpha).
00879   inline ios_base&
00880   boolalpha(ios_base& __base)
00881   {
00882     __base.setf(ios_base::boolalpha);
00883     return __base;
00884   }
00885 
00886   /// Calls base.unsetf(ios_base::boolalpha).
00887   inline ios_base&
00888   noboolalpha(ios_base& __base)
00889   {
00890     __base.unsetf(ios_base::boolalpha);
00891     return __base;
00892   }
00893 
00894   /// Calls base.setf(ios_base::showbase).
00895   inline ios_base&
00896   showbase(ios_base& __base)
00897   {
00898     __base.setf(ios_base::showbase);
00899     return __base;
00900   }
00901 
00902   /// Calls base.unsetf(ios_base::showbase).
00903   inline ios_base&
00904   noshowbase(ios_base& __base)
00905   {
00906     __base.unsetf(ios_base::showbase);
00907     return __base;
00908   }
00909 
00910   /// Calls base.setf(ios_base::showpoint).
00911   inline ios_base&
00912   showpoint(ios_base& __base)
00913   {
00914     __base.setf(ios_base::showpoint);
00915     return __base;
00916   }
00917 
00918   /// Calls base.unsetf(ios_base::showpoint).
00919   inline ios_base&
00920   noshowpoint(ios_base& __base)
00921   {
00922     __base.unsetf(ios_base::showpoint);
00923     return __base;
00924   }
00925 
00926   /// Calls base.setf(ios_base::showpos).
00927   inline ios_base&
00928   showpos(ios_base& __base)
00929   {
00930     __base.setf(ios_base::showpos);
00931     return __base;
00932   }
00933 
00934   /// Calls base.unsetf(ios_base::showpos).
00935   inline ios_base&
00936   noshowpos(ios_base& __base)
00937   {
00938     __base.unsetf(ios_base::showpos);
00939     return __base;
00940   }
00941 
00942   /// Calls base.setf(ios_base::skipws).
00943   inline ios_base&
00944   skipws(ios_base& __base)
00945   {
00946     __base.setf(ios_base::skipws);
00947     return __base;
00948   }
00949 
00950   /// Calls base.unsetf(ios_base::skipws).
00951   inline ios_base&
00952   noskipws(ios_base& __base)
00953   {
00954     __base.unsetf(ios_base::skipws);
00955     return __base;
00956   }
00957 
00958   /// Calls base.setf(ios_base::uppercase).
00959   inline ios_base&
00960   uppercase(ios_base& __base)
00961   {
00962     __base.setf(ios_base::uppercase);
00963     return __base;
00964   }
00965 
00966   /// Calls base.unsetf(ios_base::uppercase).
00967   inline ios_base&
00968   nouppercase(ios_base& __base)
00969   {
00970     __base.unsetf(ios_base::uppercase);
00971     return __base;
00972   }
00973 
00974   /// Calls base.setf(ios_base::unitbuf).
00975   inline ios_base&
00976   unitbuf(ios_base& __base)
00977   {
00978      __base.setf(ios_base::unitbuf);
00979      return __base;
00980   }
00981 
00982   /// Calls base.unsetf(ios_base::unitbuf).
00983   inline ios_base&
00984   nounitbuf(ios_base& __base)
00985   {
00986      __base.unsetf(ios_base::unitbuf);
00987      return __base;
00988   }
00989 
00990   // [27.4.5.2] adjustfield manipulators
00991   /// Calls base.setf(ios_base::internal, ios_base::adjustfield).
00992   inline ios_base&
00993   internal(ios_base& __base)
00994   {
00995      __base.setf(ios_base::internal, ios_base::adjustfield);
00996      return __base;
00997   }
00998 
00999   /// Calls base.setf(ios_base::left, ios_base::adjustfield).
01000   inline ios_base&
01001   left(ios_base& __base)
01002   {
01003     __base.setf(ios_base::left, ios_base::adjustfield);
01004     return __base;
01005   }
01006 
01007   /// Calls base.setf(ios_base::right, ios_base::adjustfield).
01008   inline ios_base&
01009   right(ios_base& __base)
01010   {
01011     __base.setf(ios_base::right, ios_base::adjustfield);
01012     return __base;
01013   }
01014 
01015   // [27.4.5.3] basefield manipulators
01016   /// Calls base.setf(ios_base::dec, ios_base::basefield).
01017   inline ios_base&
01018   dec(ios_base& __base)
01019   {
01020     __base.setf(ios_base::dec, ios_base::basefield);
01021     return __base;
01022   }
01023 
01024   /// Calls base.setf(ios_base::hex, ios_base::basefield).
01025   inline ios_base&
01026   hex(ios_base& __base)
01027   {
01028     __base.setf(ios_base::hex, ios_base::basefield);
01029     return __base;
01030   }
01031 
01032   /// Calls base.setf(ios_base::oct, ios_base::basefield).
01033   inline ios_base&
01034   oct(ios_base& __base)
01035   {
01036     __base.setf(ios_base::oct, ios_base::basefield);
01037     return __base;
01038   }
01039 
01040   // [27.4.5.4] floatfield manipulators
01041   /// Calls base.setf(ios_base::fixed, ios_base::floatfield).
01042   inline ios_base&
01043   fixed(ios_base& __base)
01044   {
01045     __base.setf(ios_base::fixed, ios_base::floatfield);
01046     return __base;
01047   }
01048 
01049   /// Calls base.setf(ios_base::scientific, ios_base::floatfield).
01050   inline ios_base&
01051   scientific(ios_base& __base)
01052   {
01053     __base.setf(ios_base::scientific, ios_base::floatfield);
01054     return __base;
01055   }
01056 
01057 #if __cplusplus >= 201103L
01058   // New C++11 floatfield manipulators
01059 
01060   /// Calls
01061   /// base.setf(ios_base::fixed|ios_base::scientific, ios_base::floatfield)
01062   inline ios_base&
01063   hexfloat(ios_base& __base)
01064   {
01065     __base.setf(ios_base::fixed | ios_base::scientific, ios_base::floatfield);
01066     return __base;
01067   }
01068 
01069   /// Calls @c base.unsetf(ios_base::floatfield)
01070   inline ios_base&
01071   defaultfloat(ios_base& __base)
01072   {
01073     __base.unsetf(ios_base::floatfield);
01074     return __base;
01075   }
01076 #endif
01077 
01078 _GLIBCXX_END_NAMESPACE_VERSION
01079 } // namespace
01080 
01081 #endif /* _IOS_BASE_H */