libstdc++
streambuf
Go to the documentation of this file.
00001 // Stream buffer classes -*- C++ -*-
00002 
00003 // Copyright (C) 1997-2019 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 include/streambuf
00026  *  This is a Standard C++ Library header.
00027  */
00028 
00029 //
00030 // ISO C++ 14882: 27.5  Stream buffers
00031 //
00032 
00033 #ifndef _GLIBXX_STREAMBUF
00034 #define _GLIBXX_STREAMBUF 1
00035 
00036 #pragma GCC system_header
00037 
00038 #include <bits/c++config.h>
00039 #include <iosfwd>
00040 #include <bits/localefwd.h>
00041 #include <bits/ios_base.h>
00042 #include <bits/cpp_type_traits.h>
00043 #include <ext/type_traits.h>
00044 
00045 namespace std _GLIBCXX_VISIBILITY(default)
00046 {
00047 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00048 
00049 #define _IsUnused __attribute__ ((__unused__))
00050 
00051   template<typename _CharT, typename _Traits>
00052     streamsize
00053     __copy_streambufs_eof(basic_streambuf<_CharT, _Traits>*,
00054                           basic_streambuf<_CharT, _Traits>*, bool&);
00055 
00056   /**
00057    *  @brief  The actual work of input and output (interface).
00058    *  @ingroup io
00059    *
00060    *  @tparam _CharT  Type of character stream.
00061    *  @tparam _Traits  Traits for character type, defaults to
00062    *                   char_traits<_CharT>.
00063    *
00064    *  This is a base class.  Derived stream buffers each control a
00065    *  pair of character sequences:  one for input, and one for output.
00066    *
00067    *  Section [27.5.1] of the standard describes the requirements and
00068    *  behavior of stream buffer classes.  That section (three paragraphs)
00069    *  is reproduced here, for simplicity and accuracy.
00070    *
00071    *  -# Stream buffers can impose various constraints on the sequences
00072    *     they control.  Some constraints are:
00073    *     - The controlled input sequence can be not readable.
00074    *     - The controlled output sequence can be not writable.
00075    *     - The controlled sequences can be associated with the contents of
00076    *       other representations for character sequences, such as external
00077    *       files.
00078    *     - The controlled sequences can support operations @e directly to or
00079    *       from associated sequences.
00080    *     - The controlled sequences can impose limitations on how the
00081    *       program can read characters from a sequence, write characters to
00082    *       a sequence, put characters back into an input sequence, or alter
00083    *       the stream position.
00084    *     .
00085    *  -# Each sequence is characterized by three pointers which, if non-null,
00086    *     all point into the same @c charT array object.  The array object
00087    *     represents, at any moment, a (sub)sequence of characters from the
00088    *     sequence.  Operations performed on a sequence alter the values
00089    *     stored in these pointers, perform reads and writes directly to or
00090    *     from associated sequences, and alter <em>the stream position</em> and
00091    *     conversion state as needed to maintain this subsequence relationship.
00092    *     The three pointers are:
00093    *     - the <em>beginning pointer</em>, or lowest element address in the
00094    *       array (called @e xbeg here);
00095    *     - the <em>next pointer</em>, or next element address that is a
00096    *       current candidate for reading or writing (called @e xnext here);
00097    *     - the <em>end pointer</em>, or first element address beyond the
00098    *       end of the array (called @e xend here).
00099    *     .
00100    *  -# The following semantic constraints shall always apply for any set
00101    *     of three pointers for a sequence, using the pointer names given
00102    *     immediately above:
00103    *     - If @e xnext is not a null pointer, then @e xbeg and @e xend shall
00104    *       also be non-null pointers into the same @c charT array, as
00105    *       described above; otherwise, @e xbeg and @e xend shall also be null.
00106    *     - If @e xnext is not a null pointer and @e xnext < @e xend for an
00107    *       output sequence, then a <em>write position</em> is available.
00108    *       In this case, @e *xnext shall be assignable as the next element
00109    *       to write (to put, or to store a character value, into the sequence).
00110    *     - If @e xnext is not a null pointer and @e xbeg < @e xnext for an
00111    *       input sequence, then a <em>putback position</em> is available.
00112    *       In this case, @e xnext[-1] shall have a defined value and is the
00113    *       next (preceding) element to store a character that is put back
00114    *       into the input sequence.
00115    *     - If @e xnext is not a null pointer and @e xnext< @e xend for an
00116    *       input sequence, then a <em>read position</em> is available.
00117    *       In this case, @e *xnext shall have a defined value and is the
00118    *       next element to read (to get, or to obtain a character value,
00119    *       from the sequence).
00120   */
00121   template<typename _CharT, typename _Traits>
00122     class basic_streambuf
00123     {
00124     public:
00125       //@{
00126       /**
00127        *  These are standard types.  They permit a standardized way of
00128        *  referring to names of (or names dependent on) the template
00129        *  parameters, which are specific to the implementation.
00130       */
00131       typedef _CharT                                    char_type;
00132       typedef _Traits                                   traits_type;
00133       typedef typename traits_type::int_type            int_type;
00134       typedef typename traits_type::pos_type            pos_type;
00135       typedef typename traits_type::off_type            off_type;
00136       //@}
00137 
00138       //@{
00139       /// This is a non-standard type.
00140       typedef basic_streambuf<char_type, traits_type>   __streambuf_type;
00141       //@}
00142 
00143       friend class basic_ios<char_type, traits_type>;
00144       friend class basic_istream<char_type, traits_type>;
00145       friend class basic_ostream<char_type, traits_type>;
00146       friend class istreambuf_iterator<char_type, traits_type>;
00147       friend class ostreambuf_iterator<char_type, traits_type>;
00148 
00149       friend streamsize
00150       __copy_streambufs_eof<>(basic_streambuf*, basic_streambuf*, bool&);
00151 
00152       template<bool _IsMove, typename _CharT2>
00153         friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
00154                                                _CharT2*>::__type
00155         __copy_move_a2(istreambuf_iterator<_CharT2>,
00156                        istreambuf_iterator<_CharT2>, _CharT2*);
00157 
00158       template<typename _CharT2>
00159         friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
00160                                   istreambuf_iterator<_CharT2> >::__type
00161         find(istreambuf_iterator<_CharT2>, istreambuf_iterator<_CharT2>,
00162              const _CharT2&);
00163 
00164       template<typename _CharT2, typename _Distance>
00165         friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
00166                                                void>::__type
00167         advance(istreambuf_iterator<_CharT2>&, _Distance);
00168 
00169       template<typename _CharT2, typename _Traits2>
00170         friend basic_istream<_CharT2, _Traits2>&
00171         operator>>(basic_istream<_CharT2, _Traits2>&, _CharT2*);
00172 
00173       template<typename _CharT2, typename _Traits2, typename _Alloc>
00174         friend basic_istream<_CharT2, _Traits2>&
00175         operator>>(basic_istream<_CharT2, _Traits2>&,
00176                    basic_string<_CharT2, _Traits2, _Alloc>&);
00177 
00178       template<typename _CharT2, typename _Traits2, typename _Alloc>
00179         friend basic_istream<_CharT2, _Traits2>&
00180         getline(basic_istream<_CharT2, _Traits2>&,
00181                 basic_string<_CharT2, _Traits2, _Alloc>&, _CharT2);
00182 
00183     protected:
00184       /*
00185        *  This is based on _IO_FILE, just reordered to be more consistent,
00186        *  and is intended to be the most minimal abstraction for an
00187        *  internal buffer.
00188        *  -  get == input == read
00189        *  -  put == output == write
00190       */
00191       char_type*                _M_in_beg;     ///< Start of get area.
00192       char_type*                _M_in_cur;     ///< Current read area.
00193       char_type*                _M_in_end;     ///< End of get area.
00194       char_type*                _M_out_beg;    ///< Start of put area.
00195       char_type*                _M_out_cur;    ///< Current put area.
00196       char_type*                _M_out_end;    ///< End of put area.
00197 
00198       /// Current locale setting.
00199       locale                    _M_buf_locale;
00200 
00201   public:
00202       /// Destructor deallocates no buffer space.
00203       virtual
00204       ~basic_streambuf()
00205       { }
00206 
00207       // [27.5.2.2.1] locales
00208       /**
00209        *  @brief  Entry point for imbue().
00210        *  @param  __loc  The new locale.
00211        *  @return  The previous locale.
00212        *
00213        *  Calls the derived imbue(__loc).
00214       */
00215       locale
00216       pubimbue(const locale& __loc)
00217       {
00218         locale __tmp(this->getloc());
00219         this->imbue(__loc);
00220         _M_buf_locale = __loc;
00221         return __tmp;
00222       }
00223 
00224       /**
00225        *  @brief  Locale access.
00226        *  @return  The current locale in effect.
00227        *
00228        *  If pubimbue(loc) has been called, then the most recent @c loc
00229        *  is returned.  Otherwise the global locale in effect at the time
00230        *  of construction is returned.
00231       */
00232       locale
00233       getloc() const
00234       { return _M_buf_locale; }
00235 
00236       // [27.5.2.2.2] buffer management and positioning
00237       //@{
00238       /**
00239        *  @brief  Entry points for derived buffer functions.
00240        *
00241        *  The public versions of @c pubfoo dispatch to the protected
00242        *  derived @c foo member functions, passing the arguments (if any)
00243        *  and returning the result unchanged.
00244       */
00245       basic_streambuf*
00246       pubsetbuf(char_type* __s, streamsize __n)
00247       { return this->setbuf(__s, __n); }
00248 
00249       /**
00250        *  @brief  Alters the stream position.
00251        *  @param  __off  Offset.
00252        *  @param  __way  Value for ios_base::seekdir.
00253        *  @param  __mode Value for ios_base::openmode.
00254        *
00255        *  Calls virtual seekoff function.
00256       */
00257       pos_type
00258       pubseekoff(off_type __off, ios_base::seekdir __way,
00259                  ios_base::openmode __mode = ios_base::in | ios_base::out)
00260       { return this->seekoff(__off, __way, __mode); }
00261 
00262       /**
00263        *  @brief  Alters the stream position.
00264        *  @param  __sp  Position
00265        *  @param  __mode Value for ios_base::openmode.
00266        *
00267        *  Calls virtual seekpos function.
00268       */
00269       pos_type
00270       pubseekpos(pos_type __sp,
00271                  ios_base::openmode __mode = ios_base::in | ios_base::out)
00272       { return this->seekpos(__sp, __mode); }
00273 
00274       /**
00275        *  @brief  Calls virtual sync function.
00276       */
00277       int
00278       pubsync() { return this->sync(); }
00279       //@}
00280 
00281       // [27.5.2.2.3] get area
00282       /**
00283        *  @brief  Looking ahead into the stream.
00284        *  @return  The number of characters available.
00285        *
00286        *  If a read position is available, returns the number of characters
00287        *  available for reading before the buffer must be refilled.
00288        *  Otherwise returns the derived @c showmanyc().
00289       */
00290       streamsize
00291       in_avail()
00292       {
00293         const streamsize __ret = this->egptr() - this->gptr();
00294         return __ret ? __ret : this->showmanyc();
00295       }
00296 
00297       /**
00298        *  @brief  Getting the next character.
00299        *  @return  The next character, or eof.
00300        *
00301        *  Calls @c sbumpc(), and if that function returns
00302        *  @c traits::eof(), so does this function.  Otherwise, @c sgetc().
00303       */
00304       int_type
00305       snextc()
00306       {
00307         int_type __ret = traits_type::eof();
00308         if (__builtin_expect(!traits_type::eq_int_type(this->sbumpc(),
00309                                                        __ret), true))
00310           __ret = this->sgetc();
00311         return __ret;
00312       }
00313 
00314       /**
00315        *  @brief  Getting the next character.
00316        *  @return  The next character, or eof.
00317        *
00318        *  If the input read position is available, returns that character
00319        *  and increments the read pointer, otherwise calls and returns
00320        *  @c uflow().
00321       */
00322       int_type
00323       sbumpc()
00324       {
00325         int_type __ret;
00326         if (__builtin_expect(this->gptr() < this->egptr(), true))
00327           {
00328             __ret = traits_type::to_int_type(*this->gptr());
00329             this->gbump(1);
00330           }
00331         else
00332           __ret = this->uflow();
00333         return __ret;
00334       }
00335 
00336       /**
00337        *  @brief  Getting the next character.
00338        *  @return  The next character, or eof.
00339        *
00340        *  If the input read position is available, returns that character,
00341        *  otherwise calls and returns @c underflow().  Does not move the
00342        *  read position after fetching the character.
00343       */
00344       int_type
00345       sgetc()
00346       {
00347         int_type __ret;
00348         if (__builtin_expect(this->gptr() < this->egptr(), true))
00349           __ret = traits_type::to_int_type(*this->gptr());
00350         else
00351           __ret = this->underflow();
00352         return __ret;
00353       }
00354 
00355       /**
00356        *  @brief  Entry point for xsgetn.
00357        *  @param  __s  A buffer area.
00358        *  @param  __n  A count.
00359        *
00360        *  Returns xsgetn(__s,__n).  The effect is to fill @a __s[0] through
00361        *  @a __s[__n-1] with characters from the input sequence, if possible.
00362       */
00363       streamsize
00364       sgetn(char_type* __s, streamsize __n)
00365       { return this->xsgetn(__s, __n); }
00366 
00367       // [27.5.2.2.4] putback
00368       /**
00369        *  @brief  Pushing characters back into the input stream.
00370        *  @param  __c  The character to push back.
00371        *  @return  The previous character, if possible.
00372        *
00373        *  Similar to sungetc(), but @a __c is pushed onto the stream
00374        *  instead of <em>the previous character.</em> If successful,
00375        *  the next character fetched from the input stream will be @a
00376        *  __c.
00377       */
00378       int_type
00379       sputbackc(char_type __c)
00380       {
00381         int_type __ret;
00382         const bool __testpos = this->eback() < this->gptr();
00383         if (__builtin_expect(!__testpos ||
00384                              !traits_type::eq(__c, this->gptr()[-1]), false))
00385           __ret = this->pbackfail(traits_type::to_int_type(__c));
00386         else
00387           {
00388             this->gbump(-1);
00389             __ret = traits_type::to_int_type(*this->gptr());
00390           }
00391         return __ret;
00392       }
00393 
00394       /**
00395        *  @brief  Moving backwards in the input stream.
00396        *  @return  The previous character, if possible.
00397        *
00398        *  If a putback position is available, this function decrements
00399        *  the input pointer and returns that character.  Otherwise,
00400        *  calls and returns pbackfail().  The effect is to @a unget
00401        *  the last character @a gotten.
00402       */
00403       int_type
00404       sungetc()
00405       {
00406         int_type __ret;
00407         if (__builtin_expect(this->eback() < this->gptr(), true))
00408           {
00409             this->gbump(-1);
00410             __ret = traits_type::to_int_type(*this->gptr());
00411           }
00412         else
00413           __ret = this->pbackfail();
00414         return __ret;
00415       }
00416 
00417       // [27.5.2.2.5] put area
00418       /**
00419        *  @brief  Entry point for all single-character output functions.
00420        *  @param  __c  A character to output.
00421        *  @return  @a __c, if possible.
00422        *
00423        *  One of two public output functions.
00424        *
00425        *  If a write position is available for the output sequence (i.e.,
00426        *  the buffer is not full), stores @a __c in that position, increments
00427        *  the position, and returns @c traits::to_int_type(__c).  If a write
00428        *  position is not available, returns @c overflow(__c).
00429       */
00430       int_type
00431       sputc(char_type __c)
00432       {
00433         int_type __ret;
00434         if (__builtin_expect(this->pptr() < this->epptr(), true))
00435           {
00436             *this->pptr() = __c;
00437             this->pbump(1);
00438             __ret = traits_type::to_int_type(__c);
00439           }
00440         else
00441           __ret = this->overflow(traits_type::to_int_type(__c));
00442         return __ret;
00443       }
00444 
00445       /**
00446        *  @brief  Entry point for all single-character output functions.
00447        *  @param  __s  A buffer read area.
00448        *  @param  __n  A count.
00449        *
00450        *  One of two public output functions.
00451        *
00452        *
00453        *  Returns xsputn(__s,__n).  The effect is to write @a __s[0] through
00454        *  @a __s[__n-1] to the output sequence, if possible.
00455       */
00456       streamsize
00457       sputn(const char_type* __s, streamsize __n)
00458       { return this->xsputn(__s, __n); }
00459 
00460     protected:
00461       /**
00462        *  @brief  Base constructor.
00463        *
00464        *  Only called from derived constructors, and sets up all the
00465        *  buffer data to zero, including the pointers described in the
00466        *  basic_streambuf class description.  Note that, as a result,
00467        *  - the class starts with no read nor write positions available,
00468        *  - this is not an error
00469       */
00470       basic_streambuf()
00471       : _M_in_beg(0), _M_in_cur(0), _M_in_end(0),
00472       _M_out_beg(0), _M_out_cur(0), _M_out_end(0),
00473       _M_buf_locale(locale())
00474       { }
00475 
00476       // [27.5.2.3.1] get area access
00477       //@{
00478       /**
00479        *  @brief  Access to the get area.
00480        *
00481        *  These functions are only available to other protected functions,
00482        *  including derived classes.
00483        *
00484        *  - eback() returns the beginning pointer for the input sequence
00485        *  - gptr() returns the next pointer for the input sequence
00486        *  - egptr() returns the end pointer for the input sequence
00487       */
00488       char_type*
00489       eback() const { return _M_in_beg; }
00490 
00491       char_type*
00492       gptr()  const { return _M_in_cur;  }
00493 
00494       char_type*
00495       egptr() const { return _M_in_end; }
00496       //@}
00497 
00498       /**
00499        *  @brief  Moving the read position.
00500        *  @param  __n  The delta by which to move.
00501        *
00502        *  This just advances the read position without returning any data.
00503       */
00504       void
00505       gbump(int __n) { _M_in_cur += __n; }
00506 
00507       /**
00508        *  @brief  Setting the three read area pointers.
00509        *  @param  __gbeg  A pointer.
00510        *  @param  __gnext  A pointer.
00511        *  @param  __gend  A pointer.
00512        *  @post  @a __gbeg == @c eback(), @a __gnext == @c gptr(), and
00513        *         @a __gend == @c egptr()
00514       */
00515       void
00516       setg(char_type* __gbeg, char_type* __gnext, char_type* __gend)
00517       {
00518         _M_in_beg = __gbeg;
00519         _M_in_cur = __gnext;
00520         _M_in_end = __gend;
00521       }
00522 
00523       // [27.5.2.3.2] put area access
00524       //@{
00525       /**
00526        *  @brief  Access to the put area.
00527        *
00528        *  These functions are only available to other protected functions,
00529        *  including derived classes.
00530        *
00531        *  - pbase() returns the beginning pointer for the output sequence
00532        *  - pptr() returns the next pointer for the output sequence
00533        *  - epptr() returns the end pointer for the output sequence
00534       */
00535       char_type*
00536       pbase() const { return _M_out_beg; }
00537 
00538       char_type*
00539       pptr() const { return _M_out_cur; }
00540 
00541       char_type*
00542       epptr() const { return _M_out_end; }
00543       //@}
00544 
00545       /**
00546        *  @brief  Moving the write position.
00547        *  @param  __n  The delta by which to move.
00548        *
00549        *  This just advances the write position without returning any data.
00550       */
00551       void
00552       pbump(int __n) { _M_out_cur += __n; }
00553 
00554       /**
00555        *  @brief  Setting the three write area pointers.
00556        *  @param  __pbeg  A pointer.
00557        *  @param  __pend  A pointer.
00558        *  @post  @a __pbeg == @c pbase(), @a __pbeg == @c pptr(), and
00559        *         @a __pend == @c epptr()
00560       */
00561       void
00562       setp(char_type* __pbeg, char_type* __pend)
00563       {
00564         _M_out_beg = _M_out_cur = __pbeg;
00565         _M_out_end = __pend;
00566       }
00567 
00568       // [27.5.2.4] virtual functions
00569       // [27.5.2.4.1] locales
00570       /**
00571        *  @brief  Changes translations.
00572        *  @param  __loc  A new locale.
00573        *
00574        *  Translations done during I/O which depend on the current
00575        *  locale are changed by this call.  The standard adds,
00576        *  <em>Between invocations of this function a class derived
00577        *  from streambuf can safely cache results of calls to locale
00578        *  functions and to members of facets so obtained.</em>
00579        *
00580        *  @note  Base class version does nothing.
00581       */
00582       virtual void
00583       imbue(const locale& __loc _IsUnused)
00584       { }
00585 
00586       // [27.5.2.4.2] buffer management and positioning
00587       /**
00588        *  @brief  Manipulates the buffer.
00589        *
00590        *  Each derived class provides its own appropriate behavior.  See
00591        *  the next-to-last paragraph of
00592        *  https://gcc.gnu.org/onlinedocs/libstdc++/manual/streambufs.html#io.streambuf.buffering
00593        *  for more on this function.
00594        *
00595        *  @note  Base class version does nothing, returns @c this.
00596       */
00597       virtual basic_streambuf<char_type,_Traits>*
00598       setbuf(char_type*, streamsize)
00599       { return this; }
00600 
00601       /**
00602        *  @brief  Alters the stream positions.
00603        *
00604        *  Each derived class provides its own appropriate behavior.
00605        *  @note  Base class version does nothing, returns a @c pos_type
00606        *         that represents an invalid stream position.
00607       */
00608       virtual pos_type
00609       seekoff(off_type, ios_base::seekdir,
00610               ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out)
00611       { return pos_type(off_type(-1)); }
00612 
00613       /**
00614        *  @brief  Alters the stream positions.
00615        *
00616        *  Each derived class provides its own appropriate behavior.
00617        *  @note  Base class version does nothing, returns a @c pos_type
00618        *         that represents an invalid stream position.
00619       */
00620       virtual pos_type
00621       seekpos(pos_type,
00622               ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out)
00623       { return pos_type(off_type(-1)); }
00624 
00625       /**
00626        *  @brief  Synchronizes the buffer arrays with the controlled sequences.
00627        *  @return  -1 on failure.
00628        *
00629        *  Each derived class provides its own appropriate behavior,
00630        *  including the definition of @a failure.
00631        *  @note  Base class version does nothing, returns zero.
00632       */
00633       virtual int
00634       sync() { return 0; }
00635 
00636       // [27.5.2.4.3] get area
00637       /**
00638        *  @brief  Investigating the data available.
00639        *  @return  An estimate of the number of characters available in the
00640        *           input sequence, or -1.
00641        *
00642        *  <em>If it returns a positive value, then successive calls to
00643        *  @c underflow() will not return @c traits::eof() until at
00644        *  least that number of characters have been supplied.  If @c
00645        *  showmanyc() returns -1, then calls to @c underflow() or @c
00646        *  uflow() will fail.</em> [27.5.2.4.3]/1
00647        *
00648        *  @note  Base class version does nothing, returns zero.
00649        *  @note  The standard adds that <em>the intention is not only that the
00650        *         calls [to underflow or uflow] will not return @c eof() but
00651        *         that they will return immediately.</em>
00652        *  @note  The standard adds that <em>the morphemes of @c showmanyc are
00653        *         @b es-how-many-see, not @b show-manic.</em>
00654       */
00655       virtual streamsize
00656       showmanyc() { return 0; }
00657 
00658       /**
00659        *  @brief  Multiple character extraction.
00660        *  @param  __s  A buffer area.
00661        *  @param  __n  Maximum number of characters to assign.
00662        *  @return  The number of characters assigned.
00663        *
00664        *  Fills @a __s[0] through @a __s[__n-1] with characters from the input
00665        *  sequence, as if by @c sbumpc().  Stops when either @a __n characters
00666        *  have been copied, or when @c traits::eof() would be copied.
00667        *
00668        *  It is expected that derived classes provide a more efficient
00669        *  implementation by overriding this definition.
00670       */
00671       virtual streamsize
00672       xsgetn(char_type* __s, streamsize __n);
00673 
00674       /**
00675        *  @brief  Fetches more data from the controlled sequence.
00676        *  @return  The first character from the <em>pending sequence</em>.
00677        *
00678        *  Informally, this function is called when the input buffer is
00679        *  exhausted (or does not exist, as buffering need not actually be
00680        *  done).  If a buffer exists, it is @a refilled.  In either case, the
00681        *  next available character is returned, or @c traits::eof() to
00682        *  indicate a null pending sequence.
00683        *
00684        *  For a formal definition of the pending sequence, see a good text
00685        *  such as Langer & Kreft, or [27.5.2.4.3]/7-14.
00686        *
00687        *  A functioning input streambuf can be created by overriding only
00688        *  this function (no buffer area will be used).  For an example, see
00689        *  https://gcc.gnu.org/onlinedocs/libstdc++/manual/streambufs.html
00690        *
00691        *  @note  Base class version does nothing, returns eof().
00692       */
00693       virtual int_type
00694       underflow()
00695       { return traits_type::eof(); }
00696 
00697       /**
00698        *  @brief  Fetches more data from the controlled sequence.
00699        *  @return  The first character from the <em>pending sequence</em>.
00700        *
00701        *  Informally, this function does the same thing as @c underflow(),
00702        *  and in fact is required to call that function.  It also returns
00703        *  the new character, like @c underflow() does.  However, this
00704        *  function also moves the read position forward by one.
00705       */
00706       virtual int_type
00707       uflow()
00708       {
00709         int_type __ret = traits_type::eof();
00710         const bool __testeof = traits_type::eq_int_type(this->underflow(),
00711                                                         __ret);
00712         if (!__testeof)
00713           {
00714             __ret = traits_type::to_int_type(*this->gptr());
00715             this->gbump(1);
00716           }
00717         return __ret;
00718       }
00719 
00720       // [27.5.2.4.4] putback
00721       /**
00722        *  @brief  Tries to back up the input sequence.
00723        *  @param  __c  The character to be inserted back into the sequence.
00724        *  @return  eof() on failure, <em>some other value</em> on success
00725        *  @post  The constraints of @c gptr(), @c eback(), and @c pptr()
00726        *         are the same as for @c underflow().
00727        *
00728        *  @note  Base class version does nothing, returns eof().
00729       */
00730       virtual int_type
00731       pbackfail(int_type __c _IsUnused  = traits_type::eof())
00732       { return traits_type::eof(); }
00733 
00734       // Put area:
00735       /**
00736        *  @brief  Multiple character insertion.
00737        *  @param  __s  A buffer area.
00738        *  @param  __n  Maximum number of characters to write.
00739        *  @return  The number of characters written.
00740        *
00741        *  Writes @a __s[0] through @a __s[__n-1] to the output sequence, as if
00742        *  by @c sputc().  Stops when either @a n characters have been
00743        *  copied, or when @c sputc() would return @c traits::eof().
00744        *
00745        *  It is expected that derived classes provide a more efficient
00746        *  implementation by overriding this definition.
00747       */
00748       virtual streamsize
00749       xsputn(const char_type* __s, streamsize __n);
00750 
00751       /**
00752        *  @brief  Consumes data from the buffer; writes to the
00753        *          controlled sequence.
00754        *  @param  __c  An additional character to consume.
00755        *  @return  eof() to indicate failure, something else (usually
00756        *           @a __c, or not_eof())
00757        *
00758        *  Informally, this function is called when the output buffer
00759        *  is full (or does not exist, as buffering need not actually
00760        *  be done).  If a buffer exists, it is @a consumed, with
00761        *  <em>some effect</em> on the controlled sequence.
00762        *  (Typically, the buffer is written out to the sequence
00763        *  verbatim.)  In either case, the character @a c is also
00764        *  written out, if @a __c is not @c eof().
00765        *
00766        *  For a formal definition of this function, see a good text
00767        *  such as Langer & Kreft, or [27.5.2.4.5]/3-7.
00768        *
00769        *  A functioning output streambuf can be created by overriding only
00770        *  this function (no buffer area will be used).
00771        *
00772        *  @note  Base class version does nothing, returns eof().
00773       */
00774       virtual int_type
00775       overflow(int_type __c _IsUnused  = traits_type::eof())
00776       { return traits_type::eof(); }
00777 
00778 #if _GLIBCXX_USE_DEPRECATED && __cplusplus <= 201402L
00779     // Annex D.6 (removed in C++17)
00780     public:
00781       /**
00782        *  @brief  Tosses a character.
00783        *
00784        *  Advances the read pointer, ignoring the character that would have
00785        *  been read.
00786        *
00787        *  See http://gcc.gnu.org/ml/libstdc++/2002-05/msg00168.html
00788        */
00789 #if __cplusplus >= 201103L
00790       [[__deprecated__("stossc is deprecated, use sbumpc instead")]]
00791 #endif
00792       void
00793       stossc()
00794       {
00795         if (this->gptr() < this->egptr())
00796           this->gbump(1);
00797         else
00798           this->uflow();
00799       }
00800 #endif
00801 
00802       // Also used by specializations for char and wchar_t in src.
00803       void
00804       __safe_gbump(streamsize __n) { _M_in_cur += __n; }
00805 
00806       void
00807       __safe_pbump(streamsize __n) { _M_out_cur += __n; }
00808 
00809 #if __cplusplus < 201103L
00810     private:
00811 #else
00812     protected:
00813 #endif
00814       basic_streambuf(const basic_streambuf&);
00815 
00816       basic_streambuf&
00817       operator=(const basic_streambuf&);
00818 
00819 #if __cplusplus >= 201103L
00820       void
00821       swap(basic_streambuf& __sb)
00822       {
00823         std::swap(_M_in_beg, __sb._M_in_beg);
00824         std::swap(_M_in_cur, __sb._M_in_cur);
00825         std::swap(_M_in_end, __sb._M_in_end);
00826         std::swap(_M_out_beg, __sb._M_out_beg);
00827         std::swap(_M_out_cur, __sb._M_out_cur);
00828         std::swap(_M_out_end, __sb._M_out_end);
00829         std::swap(_M_buf_locale, __sb._M_buf_locale);
00830       }
00831 #endif
00832     };
00833 
00834 #if __cplusplus >= 201103L
00835   template<typename _CharT, typename _Traits>
00836     std::basic_streambuf<_CharT, _Traits>::
00837     basic_streambuf(const basic_streambuf&) = default;
00838 
00839   template<typename _CharT, typename _Traits>
00840     std::basic_streambuf<_CharT, _Traits>&
00841     std::basic_streambuf<_CharT, _Traits>::
00842     operator=(const basic_streambuf&) = default;
00843 #endif
00844 
00845   // Explicit specialization declarations, defined in src/streambuf.cc.
00846   template<>
00847     streamsize
00848     __copy_streambufs_eof(basic_streambuf<char>* __sbin,
00849                           basic_streambuf<char>* __sbout, bool& __ineof);
00850 #ifdef _GLIBCXX_USE_WCHAR_T
00851   template<>
00852     streamsize
00853     __copy_streambufs_eof(basic_streambuf<wchar_t>* __sbin,
00854                           basic_streambuf<wchar_t>* __sbout, bool& __ineof);
00855 #endif
00856 
00857 #undef _IsUnused
00858 
00859 _GLIBCXX_END_NAMESPACE_VERSION
00860 } // namespace
00861 
00862 #include <bits/streambuf.tcc>
00863 
00864 #endif /* _GLIBCXX_STREAMBUF */