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