# streambuf

Go to the documentation of this file.

    00001 // Stream buffer classes -*- C++ -*-
    00002
    00003 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
    00004 // Free Software Foundation, Inc.
    00005 //
    00006 // This file is part of the GNU ISO C++ Library.  This library is free
    00007 // software; you can redistribute it and/or modify it under the
    00008 // terms of the GNU General Public License as published by the
    00009 // Free Software Foundation; either version 2, or (at your option)
    00010 // any later version.
    00011
    00012 // This library is distributed in the hope that it will be useful,
    00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00015 // GNU General Public License for more details.
    00016
    00017 // You should have received a copy of the GNU General Public License along
    00018 // with this library; see the file COPYING.  If not, write to the Free
    00019 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
    00020 // USA.
    00021
    00022 // As a special exception, you may use this file as part of a free software
    00023 // library without restriction.  Specifically, if other files instantiate
    00024 // templates or use macros or inline functions from this file, or you compile
    00025 // this file and link it with other files to produce an executable, this
    00026 // file does not by itself cause the resulting executable to be covered by
    00027 // the GNU General Public License.  This exception does not however
    00028 // invalidate any other reasons why the executable file might be covered by
    00029 // the GNU General Public License.
    00030
    00031 //
    00032 // ISO C++ 14882: 27.5  Stream buffers
    00033 //
    00034
    00035 /** @file streambuf
    00036  *  This is a Standard C++ Library header.
    00037  */
    00038
    00039 #ifndef _GLIBXX_STREAMBUF
    00040 #define _GLIBXX_STREAMBUF 1
    00041
    00042 #pragma GCC system_header
    00043
    00044 #include <bits/c++config.h>
    00045 #include <iosfwd>
    00046 #include <bits/localefwd.h>
    00047 #include <bits/ios_base.h>
    00048
    00049 namespace std
    00050 {
    00051   /**
    00052    *  @if maint
    00053    *  Does stuff.
    00054    *  @endif
    00055   */
    00056   template<typename _CharT, typename _Traits>
    00057     streamsize
    00058     __copy_streambufs(basic_streambuf<_CharT, _Traits>* __sbin,
    00059               basic_streambuf<_CharT, _Traits>* __sbout);
    00060
    00061   /**
    00062    *  @brief  The actual work of input and output (interface).
    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 "the stream position" 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 dependant 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       /**
    00140        *  @if maint
    00141        *  This is a non-standard type.
    00142        *  @endif
    00143       */
    00144       typedef basic_streambuf<char_type, traits_type>   __streambuf_type;
    00145       //@}
    00146
    00147       friend class basic_ios<char_type, traits_type>;
    00148       friend class basic_istream<char_type, traits_type>;
    00149       friend class basic_ostream<char_type, traits_type>;
    00150       friend class istreambuf_iterator<char_type, traits_type>;
    00151       friend class ostreambuf_iterator<char_type, traits_type>;
    00152
    00153       friend streamsize
    00154       __copy_streambufs<>(__streambuf_type* __sbin,
    00155               __streambuf_type* __sbout);
    00156
    00157       template<typename _CharT2, typename _Traits2, typename _Alloc>
    00158         friend basic_istream<_CharT2, _Traits2>&
    00159         getline(basic_istream<_CharT2, _Traits2>&,
    00160         basic_string<_CharT2, _Traits2, _Alloc>&, _CharT2);
    00161
    00162     protected:
    00163       //@{
    00164       /**
    00165        *  @if maint
    00166        *  This is based on _IO_FILE, just reordered to be more consistent,
    00167        *  and is intended to be the most minimal abstraction for an
    00168        *  internal buffer.
    00169        *  -  get == input == read
    00170        *  -  put == output == write
    00171        *  @endif
    00172       */
    00173       char_type*        _M_in_beg;     // Start of get area.
    00174       char_type*        _M_in_cur;     // Current read area.
    00175       char_type*        _M_in_end;     // End of get area.
    00176       char_type*        _M_out_beg;    // Start of put area.
    00177       char_type*        _M_out_cur;    // Current put area.
    00178       char_type*        _M_out_end;    // End of put area.
    00179
    00180       /**
    00181        *  @if maint
    00182        *  Current locale setting.
    00183        *  @endif
    00184       */
    00185       locale            _M_buf_locale;
    00186
    00187   public:
    00188       /// Destructor deallocates no buffer space.
    00189       virtual
    00190       ~basic_streambuf()
    00191       { }
    00192
    00193       // [27.5.2.2.1] locales
    00194       /**
    00195        *  @brief  Entry point for imbue().
    00196        *  @param  loc  The new locale.
    00197        *  @return  The previous locale.
    00198        *
    00199        *  Calls the derived imbue(loc).
    00200       */
    00201       locale
    00202       pubimbue(const locale &__loc)
    00203       {
    00204     locale __tmp(this->getloc());
    00205     this->imbue(__loc);
    00206     _M_buf_locale = __loc;
    00207     return __tmp;
    00208       }
    00209
    00210       /**
    00211        *  @brief  Locale access.
    00212        *  @return  The current locale in effect.
    00213        *
    00214        *  If pubimbue(loc) has been called, then the most recent @c loc
    00215        *  is returned.  Otherwise the global locale in effect at the time
    00216        *  of construction is returned.
    00217       */
    00218       locale
    00219       getloc() const
    00220       { return _M_buf_locale; }
    00221
    00222       // [27.5.2.2.2] buffer management and positioning
    00223       //@{
    00224       /**
    00225        *  @brief  Entry points for derived buffer functions.
    00226        *
    00227        *  The public versions of @c pubfoo dispatch to the protected
    00228        *  derived @c foo member functions, passing the arguments (if any)
    00229        *  and returning the result unchanged.
    00230       */
    00231       __streambuf_type*
    00232       pubsetbuf(char_type* __s, streamsize __n)
    00233       { return this->setbuf(__s, __n); }
    00234
    00235       pos_type
    00236       pubseekoff(off_type __off, ios_base::seekdir __way,
    00237          ios_base::openmode __mode = ios_base::in | ios_base::out)
    00238       { return this->seekoff(__off, __way, __mode); }
    00239
    00240       pos_type
    00241       pubseekpos(pos_type __sp,
    00242          ios_base::openmode __mode = ios_base::in | ios_base::out)
    00243       { return this->seekpos(__sp, __mode); }
    00244
    00245       int
    00246       pubsync() { return this->sync(); }
    00247       //@}
    00248
    00249       // [27.5.2.2.3] get area
    00250       /**
    00251        *  @brief  Looking ahead into the stream.
    00252        *  @return  The number of characters available.
    00253        *
    00254        *  If a read position is available, returns the number of characters
    00255        *  available for reading before the buffer must be refilled.
    00256        *  Otherwise returns the derived @c showmanyc().
    00257       */
    00258       streamsize
    00259       in_avail()
    00260       {
    00261     const streamsize __ret = this->egptr() - this->gptr();
    00262     return __ret ? __ret : this->showmanyc();
    00263       }
    00264
    00265       /**
    00266        *  @brief  Getting the next character.
    00267        *  @return  The next character, or eof.
    00268        *
    00269        *  Calls @c sbumpc(), and if that function returns
    00270        *  @c traits::eof(), so does this function.  Otherwise, @c sgetc().
    00271       */
    00272       int_type
    00273       snextc()
    00274       {
    00275     int_type __ret = traits_type::eof();
    00276     if (__builtin_expect(!traits_type::eq_int_type(this->sbumpc(),
    00277                                __ret), true))
    00278       __ret = this->sgetc();
    00279     return __ret;
    00280       }
    00281
    00282       /**
    00283        *  @brief  Getting the next character.
    00284        *  @return  The next character, or eof.
    00285        *
    00286        *  If the input read position is available, returns that character
    00287        *  and increments the read pointer, otherwise calls and returns
    00288        *  @c uflow().
    00289       */
    00290       int_type
    00291       sbumpc()
    00292       {
    00293     int_type __ret;
    00294     if (__builtin_expect(this->gptr() < this->egptr(), true))
    00295       {
    00296         __ret = traits_type::to_int_type(*this->gptr());
    00297         this->gbump(1);
    00298       }
    00299     else
    00300       __ret = this->uflow();
    00301     return __ret;
    00302       }
    00303
    00304       /**
    00305        *  @brief  Getting the next character.
    00306        *  @return  The next character, or eof.
    00307        *
    00308        *  If the input read position is available, returns that character,
    00309        *  otherwise calls and returns @c underflow().  Does not move the
    00310        *  read position after fetching the character.
    00311       */
    00312       int_type
    00313       sgetc()
    00314       {
    00315     int_type __ret;
    00316     if (__builtin_expect(this->gptr() < this->egptr(), true))
    00317       __ret = traits_type::to_int_type(*this->gptr());
    00318     else
    00319       __ret = this->underflow();
    00320     return __ret;
    00321       }
    00322
    00323       /**
    00324        *  @brief  Entry point for xsgetn.
    00325        *  @param  s  A buffer area.
    00326        *  @param  n  A count.
    00327        *
    00328        *  Returns xsgetn(s,n).  The effect is to fill @a s[0] through
    00329        *  @a s[n-1] with characters from the input sequence, if possible.
    00330       */
    00331       streamsize
    00332       sgetn(char_type* __s, streamsize __n)
    00333       { return this->xsgetn(__s, __n); }
    00334
    00335       // [27.5.2.2.4] putback
    00336       /**
    00337        *  @brief  Pushing characters back into the input stream.
    00338        *  @param  c  The character to push back.
    00339        *  @return  The previous character, if possible.
    00340        *
    00341        *  Similar to sungetc(), but @a c is pushed onto the stream instead
    00342        *  of "the previous character".  If successful, the next character
    00343        *  fetched from the input stream will be @a c.
    00344       */
    00345       int_type
    00346       sputbackc(char_type __c)
    00347       {
    00348     int_type __ret;
    00349     const bool __testpos = this->eback() < this->gptr();
    00350     if (__builtin_expect(!__testpos ||
    00351                  !traits_type::eq(__c, this->gptr()[-1]), false))
    00352       __ret = this->pbackfail(traits_type::to_int_type(__c));
    00353     else
    00354       {
    00355         this->gbump(-1);
    00356         __ret = traits_type::to_int_type(*this->gptr());
    00357       }
    00358     return __ret;
    00359       }
    00360
    00361       /**
    00362        *  @brief  Moving backwards in the input stream.
    00363        *  @return  The previous character, if possible.
    00364        *
    00365        *  If a putback position is available, this function decrements the
    00366        *  input pointer and returns that character.  Otherwise, calls and
    00367        *  returns pbackfail().  The effect is to "unget" the last character
    00368        *  "gotten".
    00369       */
    00370       int_type
    00371       sungetc()
    00372       {
    00373     int_type __ret;
    00374     if (__builtin_expect(this->eback() < this->gptr(), true))
    00375       {
    00376         this->gbump(-1);
    00377         __ret = traits_type::to_int_type(*this->gptr());
    00378       }
    00379     else
    00380       __ret = this->pbackfail();
    00381     return __ret;
    00382       }
    00383
    00384       // [27.5.2.2.5] put area
    00385       /**
    00386        *  @brief  Entry point for all single-character output functions.
    00387        *  @param  c  A character to output.
    00388        *  @return  @a c, if possible.
    00389        *
    00390        *  One of two public output functions.
    00391        *
    00392        *  If a write position is available for the output sequence (i.e.,
    00393        *  the buffer is not full), stores @a c in that position, increments
    00394        *  the position, and returns @c traits::to_int_type(c).  If a write
    00395        *  position is not available, returns @c overflow(c).
    00396       */
    00397       int_type
    00398       sputc(char_type __c)
    00399       {
    00400     int_type __ret;
    00401     if (__builtin_expect(this->pptr() < this->epptr(), true))
    00402       {
    00403         *this->pptr() = __c;
    00404         this->pbump(1);
    00405         __ret = traits_type::to_int_type(__c);
    00406       }
    00407     else
    00408       __ret = this->overflow(traits_type::to_int_type(__c));
    00409     return __ret;
    00410       }
    00411
    00412       /**
    00413        *  @brief  Entry point for all single-character output functions.
    00414        *  @param  s  A buffer read area.
    00415        *  @param  n  A count.
    00416        *
    00417        *  One of two public output functions.
    00418        *
    00419        *
    00420        *  Returns xsputn(s,n).  The effect is to write @a s[0] through
    00421        *  @a s[n-1] to the output sequence, if possible.
    00422       */
    00423       streamsize
    00424       sputn(const char_type* __s, streamsize __n)
    00425       { return this->xsputn(__s, __n); }
    00426
    00427     protected:
    00428       /**
    00429        *  @brief  Base constructor.
    00430        *
    00431        *  Only called from derived constructors, and sets up all the
    00432        *  buffer data to zero, including the pointers described in the
    00433        *  basic_streambuf class description.  Note that, as a result,
    00434        *  - the class starts with no read nor write positions available,
    00435        *  - this is not an error
    00436       */
    00437       basic_streambuf()
    00438       : _M_in_beg(0), _M_in_cur(0), _M_in_end(0),
    00439       _M_out_beg(0), _M_out_cur(0), _M_out_end(0),
    00440       _M_buf_locale(locale())
    00441       { }
    00442
    00443       // [27.5.2.3.1] get area access
    00444       //@{
    00445       /**
    00446        *  @brief  Access to the get area.
    00447        *
    00448        *  These functions are only available to other protected functions,
    00449        *  including derived classes.
    00450        *
    00451        *  - eback() returns the beginning pointer for the input sequence
    00452        *  - gptr() returns the next pointer for the input sequence
    00453        *  - egptr() returns the end pointer for the input sequence
    00454       */
    00455       char_type*
    00456       eback() const { return _M_in_beg; }
    00457
    00458       char_type*
    00459       gptr()  const { return _M_in_cur;  }
    00460
    00461       char_type*
    00462       egptr() const { return _M_in_end; }
    00463       //@}
    00464
    00465       /**
    00466        *  @brief  Moving the read position.
    00467        *  @param  n  The delta by which to move.
    00468        *
    00469        *  This just advances the read position without returning any data.
    00470       */
    00471       void
    00472       gbump(int __n) { _M_in_cur += __n; }
    00473
    00474       /**
    00475        *  @brief  Setting the three read area pointers.
    00476        *  @param  gbeg  A pointer.
    00477        *  @param  gnext  A pointer.
    00478        *  @param  gend  A pointer.
    00479        *  @post  @a gbeg == @c eback(), @a gnext == @c gptr(), and
    00480        *         @a gend == @c egptr()
    00481       */
    00482       void
    00483       setg(char_type* __gbeg, char_type* __gnext, char_type* __gend)
    00484       {
    00485     _M_in_beg = __gbeg;
    00486     _M_in_cur = __gnext;
    00487     _M_in_end = __gend;
    00488       }
    00489
    00490       // [27.5.2.3.2] put area access
    00491       //@{
    00492       /**
    00493        *  @brief  Access to the put area.
    00494        *
    00495        *  These functions are only available to other protected functions,
    00496        *  including derived classes.
    00497        *
    00498        *  - pbase() returns the beginning pointer for the output sequence
    00499        *  - pptr() returns the next pointer for the output sequence
    00500        *  - epptr() returns the end pointer for the output sequence
    00501       */
    00502       char_type*
    00503       pbase() const { return _M_out_beg; }
    00504
    00505       char_type*
    00506       pptr() const { return _M_out_cur; }
    00507
    00508       char_type*
    00509       epptr() const { return _M_out_end; }
    00510       //@}
    00511
    00512       /**
    00513        *  @brief  Moving the write position.
    00514        *  @param  n  The delta by which to move.
    00515        *
    00516        *  This just advances the write position without returning any data.
    00517       */
    00518       void
    00519       pbump(int __n) { _M_out_cur += __n; }
    00520
    00521       /**
    00522        *  @brief  Setting the three write area pointers.
    00523        *  @param  pbeg  A pointer.
    00524        *  @param  pend  A pointer.
    00525        *  @post  @a pbeg == @c pbase(), @a pbeg == @c pptr(), and
    00526        *         @a pend == @c epptr()
    00527       */
    00528       void
    00529       setp(char_type* __pbeg, char_type* __pend)
    00530       {
    00531     _M_out_beg = _M_out_cur = __pbeg;
    00532     _M_out_end = __pend;
    00533       }
    00534
    00535       // [27.5.2.4] virtual functions
    00536       // [27.5.2.4.1] locales
    00537       /**
    00538        *  @brief  Changes translations.
    00539        *  @param  loc  A new locale.
    00540        *
    00541        *  Translations done during I/O which depend on the current locale
    00542        *  are changed by this call.  The standard adds, "Between invocations
    00543        *  of this function a class derived from streambuf can safely cache
    00544        *  results of calls to locale functions and to members of facets
    00545        *  so obtained."
    00546        *
    00547        *  @note  Base class version does nothing.
    00548       */
    00549       virtual void
    00550       imbue(const locale&)
    00551       { }
    00552
    00553       // [27.5.2.4.2] buffer management and positioning
    00554       /**
    00555        *  @brief  Maniuplates the buffer.
    00556        *
    00557        *  Each derived class provides its own appropriate behavior.  See
    00558        *  the next-to-last paragraph of
    00559        *  http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#2 for
    00560        *  more on this function.
    00561        *
    00562        *  @note  Base class version does nothing, returns @c this.
    00563       */
    00564       virtual basic_streambuf<char_type,_Traits>*
    00565       setbuf(char_type*, streamsize)
    00566       { return this; }
    00567
    00568       /**
    00569        *  @brief  Alters the stream positions.
    00570        *
    00571        *  Each derived class provides its own appropriate behavior.
    00572        *  @note  Base class version does nothing, returns a @c pos_type
    00573        *         that represents an invalid stream position.
    00574       */
    00575       virtual pos_type
    00576       seekoff(off_type, ios_base::seekdir,
    00577           ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out)
    00578       { return pos_type(off_type(-1)); }
    00579
    00580       /**
    00581        *  @brief  Alters the stream positions.
    00582        *
    00583        *  Each derived class provides its own appropriate behavior.
    00584        *  @note  Base class version does nothing, returns a @c pos_type
    00585        *         that represents an invalid stream position.
    00586       */
    00587       virtual pos_type
    00588       seekpos(pos_type,
    00589           ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out)
    00590       { return pos_type(off_type(-1)); }
    00591
    00592       /**
    00593        *  @brief  Synchronizes the buffer arrays with the controlled sequences.
    00594        *  @return  -1 on failure.
    00595        *
    00596        *  Each derived class provides its own appropriate behavior,
    00597        *  including the definition of "failure".
    00598        *  @note  Base class version does nothing, returns zero.
    00599       */
    00600       virtual int
    00601       sync() { return 0; }
    00602
    00603       // [27.5.2.4.3] get area
    00604       /**
    00605        *  @brief  Investigating the data available.
    00606        *  @return  An estimate of the number of characters available in the
    00607        *           input sequence, or -1.
    00608        *
    00609        *  "If it returns a positive value, then successive calls to
    00610        *  @c underflow() will not return @c traits::eof() until at least that
    00611        *  number of characters have been supplied.  If @c showmanyc()
    00612        *  returns -1, then calls to @c underflow() or @c uflow() will fail."
    00613        *  [27.5.2.4.3]/1
    00614        *
    00615        *  @note  Base class version does nothing, returns zero.
    00616        *  @note  The standard adds that "the intention is not only that the
    00617        *         calls [to underflow or uflow] will not return @c eof() but
    00618        *         that they will return "immediately".
    00619        *  @note  The standard adds that "the morphemes of @c showmanyc are
    00620        *         "es-how-many-see", not "show-manic".
    00621       */
    00622       virtual streamsize
    00623       showmanyc() { return 0; }
    00624
    00625       /**
    00626        *  @brief  Multiple character extraction.
    00627        *  @param  s  A buffer area.
    00628        *  @param  n  Maximum number of characters to assign.
    00629        *  @return  The number of characters assigned.
    00630        *
    00631        *  Fills @a s[0] through @a s[n-1] with characters from the input
    00632        *  sequence, as if by @c sbumpc().  Stops when either @a n characters
    00633        *  have been copied, or when @c traits::eof() would be copied.
    00634        *
    00635        *  It is expected that derived classes provide a more efficient
    00636        *  implementation by overriding this definition.
    00637       */
    00638       virtual streamsize
    00639       xsgetn(char_type* __s, streamsize __n);
    00640
    00641       /**
    00642        *  @brief  Fetches more data from the controlled sequence.
    00643        *  @return  The first character from the <em>pending sequence</em>.
    00644        *
    00645        *  Informally, this function is called when the input buffer is
    00646        *  exhausted (or does not exist, as buffering need not actually be
    00647        *  done).  If a buffer exists, it is "refilled".  In either case, the
    00648        *  next available character is returned, or @c traits::eof() to
    00649        *  indicate a null pending sequence.
    00650        *
    00651        *  For a formal definiton of the pending sequence, see a good text
    00652        *  such as Langer & Kreft, or [27.5.2.4.3]/7-14.
    00653        *
    00654        *  A functioning input streambuf can be created by overriding only
    00655        *  this function (no buffer area will be used).  For an example, see
    00656        *  http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#6
    00657        *
    00658        *  @note  Base class version does nothing, returns eof().
    00659       */
    00660       virtual int_type
    00661       underflow()
    00662       { return traits_type::eof(); }
    00663
    00664       /**
    00665        *  @brief  Fetches more data from the controlled sequence.
    00666        *  @return  The first character from the <em>pending sequence</em>.
    00667        *
    00668        *  Informally, this function does the same thing as @c underflow(),
    00669        *  and in fact is required to call that function.  It also returns
    00670        *  the new character, like @c underflow() does.  However, this
    00671        *  function also moves the read position forward by one.
    00672       */
    00673       virtual int_type
    00674       uflow()
    00675       {
    00676     int_type __ret = traits_type::eof();
    00677     const bool __testeof = traits_type::eq_int_type(this->underflow(),
    00678                             __ret);
    00679     if (!__testeof)
    00680       {
    00681         __ret = traits_type::to_int_type(*this->gptr());
    00682         this->gbump(1);
    00683       }
    00684     return __ret;
    00685       }
    00686
    00687       // [27.5.2.4.4] putback
    00688       /**
    00689        *  @brief  Tries to back up the input sequence.
    00690        *  @param  c  The character to be inserted back into the sequence.
    00691        *  @return  eof() on failure, "some other value" on success
    00692        *  @post  The constraints of @c gptr(), @c eback(), and @c pptr()
    00693        *         are the same as for @c underflow().
    00694        *
    00695        *  @note  Base class version does nothing, returns eof().
    00696       */
    00697       virtual int_type
    00698       pbackfail(int_type /* __c */  = traits_type::eof())
    00699       { return traits_type::eof(); }
    00700
    00701       // Put area:
    00702       /**
    00703        *  @brief  Multiple character insertion.
    00704        *  @param  s  A buffer area.
    00705        *  @param  n  Maximum number of characters to write.
    00706        *  @return  The number of characters written.
    00707        *
    00708        *  Writes @a s[0] through @a s[n-1] to the output sequence, as if
    00709        *  by @c sputc().  Stops when either @a n characters have been
    00710        *  copied, or when @c sputc() would return @c traits::eof().
    00711        *
    00712        *  It is expected that derived classes provide a more efficient
    00713        *  implementation by overriding this definition.
    00714       */
    00715       virtual streamsize
    00716       xsputn(const char_type* __s, streamsize __n);
    00717
    00718       /**
    00719        *  @brief  Consumes data from the buffer; writes to the
    00720        *          controlled sequence.
    00721        *  @param  c  An additional character to consume.
    00722        *  @return  eof() to indicate failure, something else (usually
    00723        *           @a c, or not_eof())
    00724        *
    00725        *  Informally, this function is called when the output buffer is full
    00726        *  (or does not exist, as buffering need not actually be done).  If a
    00727        *  buffer exists, it is "consumed", with "some effect" on the
    00728        *  controlled sequence.  (Typically, the buffer is written out to the
    00729        *  sequence verbatim.)  In either case, the character @a c is also
    00730        *  written out, if @a c is not @c eof().
    00731        *
    00732        *  For a formal definiton of this function, see a good text
    00733        *  such as Langer & Kreft, or [27.5.2.4.5]/3-7.
    00734        *
    00735        *  A functioning output streambuf can be created by overriding only
    00736        *  this function (no buffer area will be used).
    00737        *
    00738        *  @note  Base class version does nothing, returns eof().
    00739       */
    00740       virtual int_type
    00741       overflow(int_type /* __c */ = traits_type::eof())
    00742       { return traits_type::eof(); }
    00743
    00744 #ifdef _GLIBCXX_DEPRECATED
    00745     // Annex D.6
    00746     public:
    00747       /**
    00748        *  @brief  Tosses a character.
    00749        *
    00750        *  Advances the read pointer, ignoring the character that would have
    00751        *  been read.
    00752        *
    00753        *  See http://gcc.gnu.org/ml/libstdc++/2002-05/msg00168.html
    00754        *
    00755        *  @note  This function has been deprecated by the standard.  You
    00756        *         must define @c _GLIBCXX_DEPRECATED to make this visible; see
    00757        *         c++config.h.
    00758       */
    00759       void
    00760       stossc()
    00761       {
    00762     if (this->gptr() < this->egptr())
    00763       this->gbump(1);
    00764     else
    00765       this->uflow();
    00766       }
    00767 #endif
    00768
    00769     private:
    00770       // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00771       // Side effect of DR 50.
    00772       basic_streambuf(const __streambuf_type& __sb)
    00773       : _M_in_beg(__sb._M_in_beg), _M_in_cur(__sb._M_in_cur),
    00774       _M_in_end(__sb._M_in_end), _M_out_beg(__sb._M_out_beg),
    00775       _M_out_cur(__sb._M_out_cur), _M_out_end(__sb._M_out_cur),
    00776       _M_buf_locale(__sb._M_buf_locale)
    00777       { }
    00778
    00779       __streambuf_type&
    00780       operator=(const __streambuf_type&) { return *this; };
    00781     };
    00782
    00783   // Explicit specialization declarations, defined in src/streambuf.cc.
    00784   template<>
    00785     streamsize
    00786     __copy_streambufs(basic_streambuf<char>* __sbin,
    00787               basic_streambuf<char>* __sbout);
    00788 #ifdef _GLIBCXX_USE_WCHAR_T
    00789   template<>
    00790     streamsize
    00791     __copy_streambufs(basic_streambuf<wchar_t>* __sbin,
    00792               basic_streambuf<wchar_t>* __sbout);
    00793 #endif
    00794 } // namespace std
    00795
    00796 #ifndef _GLIBCXX_EXPORT_TEMPLATE
    00797 # include <bits/streambuf.tcc>
    00798 #endif
    00799
    00800 #endif /* _GLIBCXX_STREAMBUF */