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