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