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

Generated on Thu Jul 23 21:16:24 2009 for libstdc++ by  doxygen 1.5.8