OSDN Git Service

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