OSDN Git Service

5a5ca869289458bd739eedfab0d8023111c941f8
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / std / std_streambuf.h
1 // Stream buffer classes -*- C++ -*-
2
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
4 // Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library.  This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
10 // any later version.
11
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
16
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING.  If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 // USA.
21
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction.  Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License.  This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
30
31 //
32 // ISO C++ 14882: 27.5  Stream buffers
33 //
34
35 /** @file streambuf
36  *  This is a Standard C++ Library header.
37  */
38
39 #ifndef _GLIBXX_STREAMBUF
40 #define _GLIBXX_STREAMBUF 1
41
42 #pragma GCC system_header
43
44 #include <bits/c++config.h>
45 #include <iosfwd>
46 #include <bits/localefwd.h>
47 #include <bits/ios_base.h>
48 #include <bits/cpp_type_traits.h>
49 #include <ext/type_traits.h>
50
51 _GLIBCXX_BEGIN_NAMESPACE(std)
52
53   /**
54    *  @if maint
55    *  Does stuff.
56    *  @endif
57   */
58   template<typename _CharT, typename _Traits>
59     streamsize
60     __copy_streambufs_eof(basic_streambuf<_CharT, _Traits>*,
61                           basic_streambuf<_CharT, _Traits>*, bool&);
62
63   template<typename _CharT>
64     typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, 
65                                     _CharT*>::__type
66     __copy_aux(istreambuf_iterator<_CharT>,
67                istreambuf_iterator<_CharT>, _CharT*);
68
69   template<typename _CharT>
70     typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value,
71                                     istreambuf_iterator<_CharT> >::__type
72     find(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>,
73          const _CharT&);
74
75   /**
76    *  @brief  The actual work of input and output (interface).
77    *
78    *  This is a base class.  Derived stream buffers each control a
79    *  pair of character sequences:  one for input, and one for output.
80    *
81    *  Section [27.5.1] of the standard describes the requirements and
82    *  behavior of stream buffer classes.  That section (three paragraphs)
83    *  is reproduced here, for simplicity and accuracy.
84    *
85    *  -# Stream buffers can impose various constraints on the sequences
86    *     they control.  Some constraints are:
87    *     - The controlled input sequence can be not readable.
88    *     - The controlled output sequence can be not writable.
89    *     - The controlled sequences can be associated with the contents of
90    *       other representations for character sequences, such as external
91    *       files.
92    *     - The controlled sequences can support operations @e directly to or
93    *       from associated sequences.
94    *     - The controlled sequences can impose limitations on how the
95    *       program can read characters from a sequence, write characters to
96    *       a sequence, put characters back into an input sequence, or alter
97    *       the stream position.
98    *     .
99    *  -# Each sequence is characterized by three pointers which, if non-null,
100    *     all point into the same @c charT array object.  The array object
101    *     represents, at any moment, a (sub)sequence of characters from the
102    *     sequence.  Operations performed on a sequence alter the values
103    *     stored in these pointers, perform reads and writes directly to or
104    *     from associated sequences, and alter "the stream position" and
105    *     conversion state as needed to maintain this subsequence relationship.
106    *     The three pointers are:
107    *     - the <em>beginning pointer</em>, or lowest element address in the
108    *       array (called @e xbeg here);
109    *     - the <em>next pointer</em>, or next element address that is a
110    *       current candidate for reading or writing (called @e xnext here);
111    *     - the <em>end pointer</em>, or first element address beyond the
112    *       end of the array (called @e xend here).
113    *     .
114    *  -# The following semantic constraints shall always apply for any set
115    *     of three pointers for a sequence, using the pointer names given
116    *     immediately above:
117    *     - If @e xnext is not a null pointer, then @e xbeg and @e xend shall
118    *       also be non-null pointers into the same @c charT array, as
119    *       described above; otherwise, @e xbeg and @e xend shall also be null.
120    *     - If @e xnext is not a null pointer and @e xnext < @e xend for an
121    *       output sequence, then a <em>write position</em> is available.
122    *       In this case, @e *xnext shall be assignable as the next element
123    *       to write (to put, or to store a character value, into the sequence).
124    *     - If @e xnext is not a null pointer and @e xbeg < @e xnext for an
125    *       input sequence, then a <em>putback position</em> is available.
126    *       In this case, @e xnext[-1] shall have a defined value and is the
127    *       next (preceding) element to store a character that is put back
128    *       into the input sequence.
129    *     - If @e xnext is not a null pointer and @e xnext< @e xend for an
130    *       input sequence, then a <em>read position</em> is available.
131    *       In this case, @e *xnext shall have a defined value and is the
132    *       next element to read (to get, or to obtain a character value,
133    *       from the sequence).
134   */
135   template<typename _CharT, typename _Traits>
136     class basic_streambuf 
137     {
138     public:
139       //@{
140       /**
141        *  These are standard types.  They permit a standardized way of
142        *  referring to names of (or names dependant on) the template
143        *  parameters, which are specific to the implementation.
144       */
145       typedef _CharT                                    char_type;
146       typedef _Traits                                   traits_type;
147       typedef typename traits_type::int_type            int_type;
148       typedef typename traits_type::pos_type            pos_type;
149       typedef typename traits_type::off_type            off_type;
150       //@}
151
152       //@{
153       /**
154        *  @if maint
155        *  This is a non-standard type.
156        *  @endif
157       */
158       typedef basic_streambuf<char_type, traits_type>   __streambuf_type;
159       //@}
160       
161       friend class basic_ios<char_type, traits_type>;
162       friend class basic_istream<char_type, traits_type>;
163       friend class basic_ostream<char_type, traits_type>;
164       friend class istreambuf_iterator<char_type, traits_type>;
165       friend class ostreambuf_iterator<char_type, traits_type>;
166
167       friend streamsize
168       __copy_streambufs_eof<>(__streambuf_type*, __streambuf_type*, bool&);
169
170       template<typename _CharT2>
171         friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value, 
172                                                _CharT2*>::__type
173         __copy_aux(istreambuf_iterator<_CharT2>,
174                    istreambuf_iterator<_CharT2>, _CharT2*);
175
176       template<typename _CharT2>
177         friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value,
178                                   istreambuf_iterator<_CharT2> >::__type
179         find(istreambuf_iterator<_CharT2>, istreambuf_iterator<_CharT2>,
180              const _CharT2&);
181
182       template<typename _CharT2, typename _Traits2>
183         friend basic_istream<_CharT2, _Traits2>&
184         operator>>(basic_istream<_CharT2, _Traits2>&, _CharT2*);
185
186       template<typename _CharT2, typename _Traits2, typename _Alloc>
187         friend basic_istream<_CharT2, _Traits2>&
188         operator>>(basic_istream<_CharT2, _Traits2>&,
189                    basic_string<_CharT2, _Traits2, _Alloc>&);
190
191       template<typename _CharT2, typename _Traits2, typename _Alloc>
192         friend basic_istream<_CharT2, _Traits2>&
193         getline(basic_istream<_CharT2, _Traits2>&,
194                 basic_string<_CharT2, _Traits2, _Alloc>&, _CharT2);
195
196     protected:
197       //@{
198       /**
199        *  @if maint
200        *  This is based on _IO_FILE, just reordered to be more consistent,
201        *  and is intended to be the most minimal abstraction for an
202        *  internal buffer.
203        *  -  get == input == read
204        *  -  put == output == write
205        *  @endif
206       */
207       char_type*                _M_in_beg;     // Start of get area. 
208       char_type*                _M_in_cur;     // Current read area. 
209       char_type*                _M_in_end;     // End of get area. 
210       char_type*                _M_out_beg;    // Start of put area. 
211       char_type*                _M_out_cur;    // Current put area. 
212       char_type*                _M_out_end;    // End of put area.
213
214       /**
215        *  @if maint
216        *  Current locale setting.
217        *  @endif
218       */
219       locale                    _M_buf_locale;  
220
221   public:
222       /// Destructor deallocates no buffer space.
223       virtual 
224       ~basic_streambuf() 
225       { }
226
227       // [27.5.2.2.1] locales
228       /**
229        *  @brief  Entry point for imbue().
230        *  @param  loc  The new locale.
231        *  @return  The previous locale.
232        *
233        *  Calls the derived imbue(loc).
234       */
235       locale 
236       pubimbue(const locale &__loc)
237       {
238         locale __tmp(this->getloc());
239         this->imbue(__loc);
240         _M_buf_locale = __loc;
241         return __tmp;
242       }
243
244       /**
245        *  @brief  Locale access.
246        *  @return  The current locale in effect.
247        *
248        *  If pubimbue(loc) has been called, then the most recent @c loc
249        *  is returned.  Otherwise the global locale in effect at the time
250        *  of construction is returned.
251       */
252       locale   
253       getloc() const
254       { return _M_buf_locale; } 
255
256       // [27.5.2.2.2] buffer management and positioning
257       //@{
258       /**
259        *  @brief  Entry points for derived buffer functions.
260        *
261        *  The public versions of @c pubfoo dispatch to the protected
262        *  derived @c foo member functions, passing the arguments (if any)
263        *  and returning the result unchanged.
264       */
265       __streambuf_type* 
266       pubsetbuf(char_type* __s, streamsize __n) 
267       { return this->setbuf(__s, __n); }
268
269       pos_type 
270       pubseekoff(off_type __off, ios_base::seekdir __way, 
271                  ios_base::openmode __mode = ios_base::in | ios_base::out)
272       { return this->seekoff(__off, __way, __mode); }
273
274       pos_type 
275       pubseekpos(pos_type __sp,
276                  ios_base::openmode __mode = ios_base::in | ios_base::out)
277       { return this->seekpos(__sp, __mode); }
278
279       int 
280       pubsync() { return this->sync(); }
281       //@}
282
283       // [27.5.2.2.3] get area
284       /**
285        *  @brief  Looking ahead into the stream.
286        *  @return  The number of characters available.
287        *
288        *  If a read position is available, returns the number of characters
289        *  available for reading before the buffer must be refilled.
290        *  Otherwise returns the derived @c showmanyc().
291       */
292       streamsize 
293       in_avail() 
294       { 
295         const streamsize __ret = this->egptr() - this->gptr();
296         return __ret ? __ret : this->showmanyc();
297       }
298
299       /**
300        *  @brief  Getting the next character.
301        *  @return  The next character, or eof.
302        *
303        *  Calls @c sbumpc(), and if that function returns
304        *  @c traits::eof(), so does this function.  Otherwise, @c sgetc().
305       */
306       int_type 
307       snextc()
308       {
309         int_type __ret = traits_type::eof();
310         if (__builtin_expect(!traits_type::eq_int_type(this->sbumpc(), 
311                                                        __ret), true))
312           __ret = this->sgetc();
313         return __ret;
314       }
315
316       /**
317        *  @brief  Getting the next character.
318        *  @return  The next character, or eof.
319        *
320        *  If the input read position is available, returns that character
321        *  and increments the read pointer, otherwise calls and returns
322        *  @c uflow().
323       */
324       int_type 
325       sbumpc()
326       {
327         int_type __ret;
328         if (__builtin_expect(this->gptr() < this->egptr(), true))
329           {
330             __ret = traits_type::to_int_type(*this->gptr());
331             this->gbump(1);
332           }
333         else 
334           __ret = this->uflow();
335         return __ret;
336       }
337
338       /**
339        *  @brief  Getting the next character.
340        *  @return  The next character, or eof.
341        *
342        *  If the input read position is available, returns that character,
343        *  otherwise calls and returns @c underflow().  Does not move the 
344        *  read position after fetching the character.
345       */
346       int_type 
347       sgetc()
348       {
349         int_type __ret;
350         if (__builtin_expect(this->gptr() < this->egptr(), true))
351           __ret = traits_type::to_int_type(*this->gptr());
352         else 
353           __ret = this->underflow();
354         return __ret;
355       }
356
357       /**
358        *  @brief  Entry point for xsgetn.
359        *  @param  s  A buffer area.
360        *  @param  n  A count.
361        *
362        *  Returns xsgetn(s,n).  The effect is to fill @a s[0] through
363        *  @a s[n-1] with characters from the input sequence, if possible.
364       */
365       streamsize 
366       sgetn(char_type* __s, streamsize __n)
367       { return this->xsgetn(__s, __n); }
368
369       // [27.5.2.2.4] putback
370       /**
371        *  @brief  Pushing characters back into the input stream.
372        *  @param  c  The character to push back.
373        *  @return  The previous character, if possible.
374        *
375        *  Similar to sungetc(), but @a c is pushed onto the stream instead
376        *  of "the previous character".  If successful, the next character
377        *  fetched from the input stream will be @a c.
378       */
379       int_type 
380       sputbackc(char_type __c)
381       {
382         int_type __ret;
383         const bool __testpos = this->eback() < this->gptr();
384         if (__builtin_expect(!__testpos || 
385                              !traits_type::eq(__c, this->gptr()[-1]), false))
386           __ret = this->pbackfail(traits_type::to_int_type(__c));
387         else 
388           {
389             this->gbump(-1);
390             __ret = traits_type::to_int_type(*this->gptr());
391           }
392         return __ret;
393       }
394
395       /**
396        *  @brief  Moving backwards in the input stream.
397        *  @return  The previous character, if possible.
398        *
399        *  If a putback position is available, this function decrements the
400        *  input pointer and returns that character.  Otherwise, calls and
401        *  returns pbackfail().  The effect is to "unget" the last character
402        *  "gotten".
403       */
404       int_type 
405       sungetc()
406       {
407         int_type __ret;
408         if (__builtin_expect(this->eback() < this->gptr(), true))
409           {
410             this->gbump(-1);
411             __ret = traits_type::to_int_type(*this->gptr());
412           }
413         else 
414           __ret = this->pbackfail();
415         return __ret;
416       }
417
418       // [27.5.2.2.5] put area
419       /**
420        *  @brief  Entry point for all single-character output functions.
421        *  @param  c  A character to output.
422        *  @return  @a c, if possible.
423        *
424        *  One of two public output functions.
425        *
426        *  If a write position is available for the output sequence (i.e.,
427        *  the buffer is not full), stores @a c in that position, increments
428        *  the position, and returns @c traits::to_int_type(c).  If a write
429        *  position is not available, returns @c overflow(c).
430       */
431       int_type 
432       sputc(char_type __c)
433       {
434         int_type __ret;
435         if (__builtin_expect(this->pptr() < this->epptr(), true))
436           {
437             *this->pptr() = __c;
438             this->pbump(1);
439             __ret = traits_type::to_int_type(__c);
440           }
441         else
442           __ret = this->overflow(traits_type::to_int_type(__c));
443         return __ret;
444       }
445
446       /**
447        *  @brief  Entry point for all single-character output functions.
448        *  @param  s  A buffer read area.
449        *  @param  n  A count.
450        *
451        *  One of two public output functions.
452        *
453        *
454        *  Returns xsputn(s,n).  The effect is to write @a s[0] through
455        *  @a s[n-1] to the output sequence, if possible.
456       */
457       streamsize 
458       sputn(const char_type* __s, streamsize __n)
459       { return this->xsputn(__s, __n); }
460
461     protected:
462       /**
463        *  @brief  Base constructor.
464        *
465        *  Only called from derived constructors, and sets up all the
466        *  buffer data to zero, including the pointers described in the
467        *  basic_streambuf class description.  Note that, as a result,
468        *  - the class starts with no read nor write positions available,
469        *  - this is not an error
470       */
471       basic_streambuf()
472       : _M_in_beg(0), _M_in_cur(0), _M_in_end(0), 
473       _M_out_beg(0), _M_out_cur(0), _M_out_end(0),
474       _M_buf_locale(locale()) 
475       { }
476
477       // [27.5.2.3.1] get area access
478       //@{
479       /**
480        *  @brief  Access to the get area.
481        *
482        *  These functions are only available to other protected functions,
483        *  including derived classes.
484        *
485        *  - eback() returns the beginning pointer for the input sequence
486        *  - gptr() returns the next pointer for the input sequence
487        *  - egptr() returns the end pointer for the input sequence
488       */
489       char_type* 
490       eback() const { return _M_in_beg; }
491
492       char_type* 
493       gptr()  const { return _M_in_cur;  }
494
495       char_type* 
496       egptr() const { return _M_in_end; }
497       //@}
498
499       /**
500        *  @brief  Moving the read position.
501        *  @param  n  The delta by which to move.
502        *
503        *  This just advances the read position without returning any data.
504       */
505       void 
506       gbump(int __n) { _M_in_cur += __n; }
507
508       /**
509        *  @brief  Setting the three read area pointers.
510        *  @param  gbeg  A pointer.
511        *  @param  gnext  A pointer.
512        *  @param  gend  A pointer.
513        *  @post  @a gbeg == @c eback(), @a gnext == @c gptr(), and
514        *         @a gend == @c egptr()
515       */
516       void 
517       setg(char_type* __gbeg, char_type* __gnext, char_type* __gend)
518       {
519         _M_in_beg = __gbeg;
520         _M_in_cur = __gnext;
521         _M_in_end = __gend;
522       }
523
524       // [27.5.2.3.2] put area access
525       //@{
526       /**
527        *  @brief  Access to the put area.
528        *
529        *  These functions are only available to other protected functions,
530        *  including derived classes.
531        *
532        *  - pbase() returns the beginning pointer for the output sequence
533        *  - pptr() returns the next pointer for the output sequence
534        *  - epptr() returns the end pointer for the output sequence
535       */
536       char_type* 
537       pbase() const { return _M_out_beg; }
538
539       char_type* 
540       pptr() const { return _M_out_cur; }
541
542       char_type* 
543       epptr() const { return _M_out_end; }
544       //@}
545
546       /**
547        *  @brief  Moving the write position.
548        *  @param  n  The delta by which to move.
549        *
550        *  This just advances the write position without returning any data.
551       */
552       void 
553       pbump(int __n) { _M_out_cur += __n; }
554
555       /**
556        *  @brief  Setting the three write area pointers.
557        *  @param  pbeg  A pointer.
558        *  @param  pend  A pointer.
559        *  @post  @a pbeg == @c pbase(), @a pbeg == @c pptr(), and
560        *         @a pend == @c epptr()
561       */
562       void 
563       setp(char_type* __pbeg, char_type* __pend)
564       { 
565         _M_out_beg = _M_out_cur = __pbeg; 
566         _M_out_end = __pend;
567       }
568
569       // [27.5.2.4] virtual functions
570       // [27.5.2.4.1] locales
571       /**
572        *  @brief  Changes translations.
573        *  @param  loc  A new locale.
574        *
575        *  Translations done during I/O which depend on the current locale
576        *  are changed by this call.  The standard adds, "Between invocations
577        *  of this function a class derived from streambuf can safely cache
578        *  results of calls to locale functions and to members of facets
579        *  so obtained."
580        *
581        *  @note  Base class version does nothing.
582       */
583       virtual void 
584       imbue(const locale&) 
585       { }
586
587       // [27.5.2.4.2] buffer management and positioning
588       /**
589        *  @brief  Maniuplates the buffer.
590        *
591        *  Each derived class provides its own appropriate behavior.  See
592        *  the next-to-last paragraph of 
593        *  http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#2 for
594        *  more on this function.
595        *
596        *  @note  Base class version does nothing, returns @c this.
597       */
598       virtual basic_streambuf<char_type,_Traits>* 
599       setbuf(char_type*, streamsize)
600       { return this; }
601       
602       /**
603        *  @brief  Alters the stream positions.
604        *
605        *  Each derived class provides its own appropriate behavior.
606        *  @note  Base class version does nothing, returns a @c pos_type
607        *         that represents an invalid stream position.
608       */
609       virtual pos_type 
610       seekoff(off_type, ios_base::seekdir,
611               ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out)
612       { return pos_type(off_type(-1)); } 
613
614       /**
615        *  @brief  Alters the stream positions.
616        *
617        *  Each derived class provides its own appropriate behavior.
618        *  @note  Base class version does nothing, returns a @c pos_type
619        *         that represents an invalid stream position.
620       */
621       virtual pos_type 
622       seekpos(pos_type, 
623               ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out)
624       { return pos_type(off_type(-1)); } 
625
626       /**
627        *  @brief  Synchronizes the buffer arrays with the controlled sequences.
628        *  @return  -1 on failure.
629        *
630        *  Each derived class provides its own appropriate behavior,
631        *  including the definition of "failure".
632        *  @note  Base class version does nothing, returns zero.
633       */
634       virtual int 
635       sync() { return 0; }
636
637       // [27.5.2.4.3] get area
638       /**
639        *  @brief  Investigating the data available.
640        *  @return  An estimate of the number of characters available in the
641        *           input sequence, or -1.
642        *
643        *  "If it returns a positive value, then successive calls to
644        *  @c underflow() will not return @c traits::eof() until at least that
645        *  number of characters have been supplied.  If @c showmanyc()
646        *  returns -1, then calls to @c underflow() or @c uflow() will fail."
647        *  [27.5.2.4.3]/1
648        *
649        *  @note  Base class version does nothing, returns zero.
650        *  @note  The standard adds that "the intention is not only that the
651        *         calls [to underflow or uflow] will not return @c eof() but
652        *         that they will return "immediately".
653        *  @note  The standard adds that "the morphemes of @c showmanyc are
654        *         "es-how-many-see", not "show-manic".
655       */
656       virtual streamsize 
657       showmanyc() { return 0; }
658
659       /**
660        *  @brief  Multiple character extraction.
661        *  @param  s  A buffer area.
662        *  @param  n  Maximum number of characters to assign.
663        *  @return  The number of characters assigned.
664        *
665        *  Fills @a s[0] through @a s[n-1] with characters from the input
666        *  sequence, as if by @c sbumpc().  Stops when either @a n characters
667        *  have been copied, or when @c traits::eof() would be copied.
668        *
669        *  It is expected that derived classes provide a more efficient
670        *  implementation by overriding this definition.
671       */
672       virtual streamsize 
673       xsgetn(char_type* __s, streamsize __n);
674
675       /**
676        *  @brief  Fetches more data from the controlled sequence.
677        *  @return  The first character from the <em>pending sequence</em>.
678        *
679        *  Informally, this function is called when the input buffer is
680        *  exhausted (or does not exist, as buffering need not actually be
681        *  done).  If a buffer exists, it is "refilled".  In either case, the
682        *  next available character is returned, or @c traits::eof() to
683        *  indicate a null pending sequence.
684        *
685        *  For a formal definiton of the pending sequence, see a good text
686        *  such as Langer & Kreft, or [27.5.2.4.3]/7-14.
687        *
688        *  A functioning input streambuf can be created by overriding only
689        *  this function (no buffer area will be used).  For an example, see
690        *  http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#6
691        *
692        *  @note  Base class version does nothing, returns eof().
693       */
694       virtual int_type 
695       underflow()
696       { return traits_type::eof(); }
697
698       /**
699        *  @brief  Fetches more data from the controlled sequence.
700        *  @return  The first character from the <em>pending sequence</em>.
701        *
702        *  Informally, this function does the same thing as @c underflow(),
703        *  and in fact is required to call that function.  It also returns
704        *  the new character, like @c underflow() does.  However, this
705        *  function also moves the read position forward by one.
706       */
707       virtual int_type 
708       uflow() 
709       {
710         int_type __ret = traits_type::eof();
711         const bool __testeof = traits_type::eq_int_type(this->underflow(), 
712                                                         __ret);
713         if (!__testeof)
714           {
715             __ret = traits_type::to_int_type(*this->gptr());
716             this->gbump(1);
717           }
718         return __ret;    
719       }
720
721       // [27.5.2.4.4] putback
722       /**
723        *  @brief  Tries to back up the input sequence.
724        *  @param  c  The character to be inserted back into the sequence.
725        *  @return  eof() on failure, "some other value" on success
726        *  @post  The constraints of @c gptr(), @c eback(), and @c pptr()
727        *         are the same as for @c underflow().
728        *
729        *  @note  Base class version does nothing, returns eof().
730       */
731       virtual int_type 
732       pbackfail(int_type /* __c */  = traits_type::eof())
733       { return traits_type::eof(); }
734
735       // Put area:
736       /**
737        *  @brief  Multiple character insertion.
738        *  @param  s  A buffer area.
739        *  @param  n  Maximum number of characters to write.
740        *  @return  The number of characters written.
741        *
742        *  Writes @a s[0] through @a s[n-1] to the output sequence, as if
743        *  by @c sputc().  Stops when either @a n characters have been
744        *  copied, or when @c sputc() would return @c traits::eof().
745        *
746        *  It is expected that derived classes provide a more efficient
747        *  implementation by overriding this definition.
748       */
749       virtual streamsize 
750       xsputn(const char_type* __s, streamsize __n);
751
752       /**
753        *  @brief  Consumes data from the buffer; writes to the
754        *          controlled sequence.
755        *  @param  c  An additional character to consume.
756        *  @return  eof() to indicate failure, something else (usually
757        *           @a c, or not_eof())
758        *
759        *  Informally, this function is called when the output buffer is full
760        *  (or does not exist, as buffering need not actually be done).  If a
761        *  buffer exists, it is "consumed", with "some effect" on the
762        *  controlled sequence.  (Typically, the buffer is written out to the
763        *  sequence verbatim.)  In either case, the character @a c is also
764        *  written out, if @a c is not @c eof().
765        *
766        *  For a formal definiton of this function, see a good text
767        *  such as Langer & Kreft, or [27.5.2.4.5]/3-7.
768        *
769        *  A functioning output streambuf can be created by overriding only
770        *  this function (no buffer area will be used).
771        *
772        *  @note  Base class version does nothing, returns eof().
773       */
774       virtual int_type 
775       overflow(int_type /* __c */ = traits_type::eof())
776       { return traits_type::eof(); }
777
778 #ifdef _GLIBCXX_DEPRECATED
779     // Annex D.6
780     public:
781       /**
782        *  @brief  Tosses a character.
783        *
784        *  Advances the read pointer, ignoring the character that would have
785        *  been read.
786        *
787        *  See http://gcc.gnu.org/ml/libstdc++/2002-05/msg00168.html
788        *
789        *  @note  This function has been deprecated by the standard.  You
790        *         must define @c _GLIBCXX_DEPRECATED to make this visible; see
791        *         c++config.h.
792       */
793       void 
794       stossc() 
795       {
796         if (this->gptr() < this->egptr()) 
797           this->gbump(1);
798         else 
799           this->uflow();
800       }
801 #endif
802
803     private:
804       // _GLIBCXX_RESOLVE_LIB_DEFECTS
805       // Side effect of DR 50. 
806       basic_streambuf(const __streambuf_type& __sb)
807       : _M_in_beg(__sb._M_in_beg), _M_in_cur(__sb._M_in_cur), 
808       _M_in_end(__sb._M_in_end), _M_out_beg(__sb._M_out_beg), 
809       _M_out_cur(__sb._M_out_cur), _M_out_end(__sb._M_out_cur),
810       _M_buf_locale(__sb._M_buf_locale) 
811       { }
812
813       __streambuf_type& 
814       operator=(const __streambuf_type&) { return *this; };
815     };
816
817   // Explicit specialization declarations, defined in src/streambuf.cc.
818   template<>
819     streamsize
820     __copy_streambufs_eof(basic_streambuf<char>* __sbin,
821                           basic_streambuf<char>* __sbout, bool& __ineof);
822 #ifdef _GLIBCXX_USE_WCHAR_T
823   template<>
824     streamsize
825     __copy_streambufs_eof(basic_streambuf<wchar_t>* __sbin,
826                           basic_streambuf<wchar_t>* __sbout, bool& __ineof);
827 #endif
828
829 _GLIBCXX_END_NAMESPACE
830
831 #ifndef _GLIBCXX_EXPORT_TEMPLATE
832 # include <bits/streambuf.tcc>
833 #endif
834
835 #endif /* _GLIBCXX_STREAMBUF */