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

Generated on Fri May 6 01:09:13 2005 for libstdc++-v3 Source by  doxygen 1.4.2