TODO: Note change in clause 27 docs.
[official-gcc.git] / libstdc++-v3 / include / std / std_streambuf.h
blob883401bf6eeef509224cea6da44b134e284eb62b
1 // Stream buffer classes -*- C++ -*-
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
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.
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.
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.
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.
32 // ISO C++ 14882: 27.5 Stream buffers
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.
40 #ifndef _CPP_STREAMBUF
41 #define _CPP_STREAMBUF 1
43 #pragma GCC system_header
45 #include <bits/c++config.h>
46 #include <iosfwd>
47 #include <cstdio> // For SEEK_SET, SEEK_CUR, SEEK_END
48 #include <bits/localefwd.h>
49 #include <bits/ios_base.h>
51 namespace std
53 /**
54 * @if maint
55 * Does stuff.
56 * @endif
58 template<typename _CharT, typename _Traits>
59 streamsize
60 __copy_streambufs(basic_ios<_CharT, _Traits>& _ios,
61 basic_streambuf<_CharT, _Traits>* __sbin,
62 basic_streambuf<_CharT, _Traits>* __sbout);
64 /**
65 * @brief The actual work of input and output (interface).
67 * This is a base class. Derived stream buffers each control a
68 * pair of character sequences: one for input, and one for output.
70 * Section [27.5.1] of the standard describes the requirements and
71 * behavior of stream buffer classes. That section (three paragraphs)
72 * is reproduced here, for simplicity and accuracy.
74 * -# Stream buffers can impose various constraints on the sequences
75 * they control. Some constraints are:
76 * - The controlled input sequence can be not readable.
77 * - The controlled output sequence can be not writable.
78 * - The controlled sequences can be associated with the contents of
79 * other representations for character sequences, such as external
80 * files.
81 * - The controlled sequences can support operations @e directly to or
82 * from associated sequences.
83 * - The controlled sequences can impose limitations on how the
84 * program can read characters from a sequence, write characters to
85 * a sequence, put characters back into an input sequence, or alter
86 * the stream position.
87 * .
88 * -# Each sequence is characterized by three pointers which, if non-null,
89 * all point into the same @c charT array object. The array object
90 * represents, at any moment, a (sub)sequence of characters from the
91 * sequence. Operations performed on a sequence alter the values
92 * stored in these pointers, perform reads and writes directly to or
93 * from associated sequences, and alter "the stream position" and
94 * conversion state as needed to maintain this subsequence relationship.
95 * The three pointers are:
96 * - the <em>beginning pointer</em>, or lowest element address in the
97 * array (called @e xbeg here);
98 * - the <em>next pointer</em>, or next element address that is a
99 * current candidate for reading or writing (called @e xnext here);
100 * - the <em>end pointer</em>, or first element address beyond the
101 * end of the array (called @e xend here).
103 * -# The following semantic constraints shall always apply for any set
104 * of three pointers for a sequence, using the pointer names given
105 * immediately above:
106 * - If @e xnext is not a null pointer, then @e xbeg and @e xend shall
107 * also be non-null pointers into the same @c charT array, as
108 * described above; otherwise, @e xbeg and @e xend shall also be null.
109 * - If @e xnext is not a null pointer and @e xnext < @e xend for an
110 * output sequence, then a <em>write position</em> is available.
111 * In this case, @e *xnext shall be assignable as the next element
112 * to write (to put, or to store a character value, into the sequence).
113 * - If @e xnext is not a null pointer and @e xbeg < @e xnext for an
114 * input sequence, then a <em>putback position</em> is available.
115 * In this case, @e xnext[-1] shall have a defined value and is the
116 * next (preceding) element to store a character that is put back
117 * into the input sequence.
118 * - If @e xnext is not a null pointer and @e xnext< @e xend for an
119 * input sequence, then a <em>read position</em> is available.
120 * In this case, @e *xnext shall have a defined value and is the
121 * next element to read (to get, or to obtain a character value,
122 * from the sequence).
124 template<typename _CharT, typename _Traits>
125 class basic_streambuf
127 public:
128 //@{
130 * These are standard types. They permit a standardized way of
131 * referring to names of (or names dependant on) the template
132 * parameters, which are specific to the implementation.
134 typedef _CharT char_type;
135 typedef _Traits traits_type;
136 typedef typename traits_type::int_type int_type;
137 typedef typename traits_type::pos_type pos_type;
138 typedef typename traits_type::off_type off_type;
139 //@}
141 //@{
143 * @if maint
144 * These are non-standard types.
145 * @endif
147 typedef ctype<char_type> __ctype_type;
148 typedef basic_streambuf<char_type, traits_type> __streambuf_type;
149 typedef typename traits_type::state_type __state_type;
150 //@}
152 friend class basic_ios<char_type, traits_type>;
153 friend class basic_istream<char_type, traits_type>;
154 friend class basic_ostream<char_type, traits_type>;
155 friend class istreambuf_iterator<char_type, traits_type>;
156 friend class ostreambuf_iterator<char_type, traits_type>;
158 friend streamsize
159 __copy_streambufs<>(basic_ios<char_type, traits_type>& __ios,
160 __streambuf_type* __sbin,__streambuf_type* __sbout);
162 protected:
164 * @if maint
165 * Pointer to the beginning of internally-allocated space. Filebuf
166 * manually allocates/deallocates this, whereas stringstreams attempt
167 * to use the built-in intelligence of the string class. If you are
168 * managing memory, set this. If not, leave it NULL.
169 * @endif
171 char_type* _M_buf;
174 * @if maint
175 * Actual size of allocated internal buffer, in bytes.
176 * @endif
178 size_t _M_buf_size;
181 * @if maint
182 * Optimal or preferred size of internal buffer, in bytes.
183 * @endif
185 size_t _M_buf_size_opt;
188 * @if maint
189 * True iff _M_in_* and _M_out_* buffers should always point to
190 * the same place. True for fstreams, false for sstreams.
191 * @endif
193 bool _M_buf_unified;
195 //@{
197 * @if maint
198 * This is based on _IO_FILE, just reordered to be more consistent,
199 * and is intended to be the most minimal abstraction for an
200 * internal buffer.
201 * - get == input == read
202 * - put == output == write
203 * @endif
205 char_type* _M_in_beg; // Start of get area.
206 char_type* _M_in_cur; // Current read area.
207 char_type* _M_in_end; // End of get area.
208 char_type* _M_out_beg; // Start of put area.
209 char_type* _M_out_cur; // Current put area.
210 char_type* _M_out_end; // End of put area.
211 //@}
214 * @if maint
215 * Place to stash in || out || in | out settings for current streambuf.
216 * @endif
218 ios_base::openmode _M_mode;
221 * @if maint
222 * Current locale setting.
223 * @endif
225 locale _M_buf_locale;
228 * @if maint
229 * True iff locale is initialized.
230 * @endif
232 bool _M_buf_locale_init;
234 //@{
236 * @if maint
237 * Necessary bits for putback buffer management. Only used in
238 * the basic_filebuf class, as necessary for the standard
239 * requirements. The only basic_streambuf member function that
240 * needs access to these data members is in_avail...
242 * @note pbacks of over one character are not currently supported.
243 * @endif
245 static const size_t _S_pback_size = 1;
246 char_type _M_pback[_S_pback_size];
247 char_type* _M_pback_cur_save;
248 char_type* _M_pback_end_save;
249 bool _M_pback_init;
250 //@}
253 * @if maint
254 * Yet unused.
255 * @endif
257 fpos<__state_type> _M_pos;
259 // Initializes pback buffers, and moves normal buffers to safety.
260 // Assumptions:
261 // _M_in_cur has already been moved back
262 void
263 _M_pback_create()
265 if (!_M_pback_init)
267 size_t __dist = _M_in_end - _M_in_cur;
268 size_t __len = min(_S_pback_size, __dist);
269 traits_type::copy(_M_pback, _M_in_cur, __len);
270 _M_pback_cur_save = _M_in_cur;
271 _M_pback_end_save = _M_in_end;
272 this->setg(_M_pback, _M_pback, _M_pback + __len);
273 _M_pback_init = true;
277 // Deactivates pback buffer contents, and restores normal buffer.
278 // Assumptions:
279 // The pback buffer has only moved forward.
280 void
281 _M_pback_destroy()
283 if (_M_pback_init)
285 // Length _M_in_cur moved in the pback buffer.
286 size_t __off_cur = _M_in_cur - _M_pback;
288 // For in | out buffers, the end can be pushed back...
289 size_t __off_end = 0;
290 size_t __pback_len = _M_in_end - _M_pback;
291 size_t __save_len = _M_pback_end_save - _M_buf;
292 if (__pback_len > __save_len)
293 __off_end = __pback_len - __save_len;
295 this->setg(_M_buf, _M_pback_cur_save + __off_cur,
296 _M_pback_end_save + __off_end);
297 _M_pback_cur_save = NULL;
298 _M_pback_end_save = NULL;
299 _M_pback_init = false;
303 // Correctly sets the _M_in_cur pointer, and bumps the
304 // _M_out_cur pointer as well if necessary.
305 void
306 _M_in_cur_move(off_type __n) // argument needs to be +-
308 bool __testout = _M_out_cur;
309 _M_in_cur += __n;
310 if (__testout && _M_buf_unified)
311 _M_out_cur += __n;
314 // Correctly sets the _M_out_cur pointer, and bumps the
315 // appropriate _M_*_end pointers as well. Necessary for the
316 // un-tied stringbufs, in in|out mode.
317 // Invariant:
318 // __n + _M_out_[cur, end] <= _M_buf + _M_buf_size
319 // Assuming all _M_*_[beg, cur, end] pointers are operating on
320 // the same range:
321 // _M_buf <= _M_*_ <= _M_buf + _M_buf_size
322 void
323 _M_out_cur_move(off_type __n) // argument needs to be +-
325 bool __testin = _M_in_cur;
327 _M_out_cur += __n;
328 if (__testin && _M_buf_unified)
329 _M_in_cur += __n;
330 if (_M_out_cur > _M_out_end)
332 _M_out_end = _M_out_cur;
333 // NB: in | out buffers drag the _M_in_end pointer along...
334 if (__testin)
335 _M_in_end += __n;
339 // Return the size of the output buffer. This depends on the
340 // buffer in use: allocated buffers have a stored size in
341 // _M_buf_size and setbuf() buffers don't.
342 off_type
343 _M_out_buf_size()
345 off_type __ret = 0;
346 if (_M_out_cur)
348 // Using allocated buffer.
349 if (_M_out_beg == _M_buf)
350 __ret = _M_out_beg + _M_buf_size - _M_out_cur;
351 // Using non-allocated buffer.
352 else
353 __ret = _M_out_end - _M_out_cur;
355 return __ret;
358 public:
359 /// Destructor deallocates no buffer space.
360 virtual
361 ~basic_streambuf()
363 _M_buf_unified = false;
364 _M_buf_size = 0;
365 _M_buf_size_opt = 0;
366 _M_mode = ios_base::openmode(0);
367 _M_buf_locale_init = false;
370 // [27.5.2.2.1] locales
372 * @brief Entry point for imbue().
373 * @param loc The new locale.
374 * @return The previous locale.
376 * Calls the derived imbue(loc).
378 locale
379 pubimbue(const locale &__loc)
381 locale __tmp(this->getloc());
382 this->imbue(__loc);
383 return __tmp;
387 * @brief Locale access.
388 * @return The current locale in effect.
390 * If pubimbue(loc) has been called, then the most recent @c loc
391 * is returned. Otherwise the global locale in effect at the time
392 * of construction is returned.
394 locale
395 getloc() const
397 if (_M_buf_locale_init)
398 return _M_buf_locale;
399 else
400 return locale();
403 // [27.5.2.2.2] buffer management and positioning
404 //@{
406 * @brief Entry points for derived buffer functions.
408 * The public versions of @c pubfoo dispatch to the protected
409 * derived @c foo member functions, passing the arguments (if any)
410 * and returning the result unchanged.
412 __streambuf_type*
413 pubsetbuf(char_type* __s, streamsize __n)
414 { return this->setbuf(__s, __n); }
416 pos_type
417 pubseekoff(off_type __off, ios_base::seekdir __way,
418 ios_base::openmode __mode = ios_base::in | ios_base::out)
419 { return this->seekoff(__off, __way, __mode); }
421 pos_type
422 pubseekpos(pos_type __sp,
423 ios_base::openmode __mode = ios_base::in | ios_base::out)
424 { return this->seekpos(__sp, __mode); }
426 int
427 pubsync() { return this->sync(); }
428 //@}
430 // [27.5.2.2.3] get area
432 * @brief Looking ahead into the stream.
433 * @return The number of characters available.
435 * If a read position is available, returns the number of characters
436 * available for reading before the buffer must be refilled.
437 * Otherwise returns the derived @c showmanyc().
439 streamsize
440 in_avail()
442 streamsize __ret;
443 if (_M_in_cur && _M_in_cur < _M_in_end)
445 if (_M_pback_init)
447 size_t __save_len = _M_pback_end_save - _M_pback_cur_save;
448 size_t __pback_len = _M_in_cur - _M_pback;
449 __ret = __save_len - __pback_len;
451 else
452 __ret = this->egptr() - this->gptr();
454 else
455 __ret = this->showmanyc();
456 return __ret;
460 * @brief Getting the next character.
461 * @return The next character, or eof.
463 * Calls @c sbumpc(), and if that function returns
464 * @c traits::eof(), so does this function. Otherwise, @c sgetc().
466 int_type
467 snextc()
469 int_type __eof = traits_type::eof();
470 return (traits_type::eq_int_type(this->sbumpc(), __eof)
471 ? __eof : this->sgetc());
475 * @brief Getting the next character.
476 * @return The next character, or eof.
478 * If the input read position is available, returns that character
479 * and increments the read pointer, otherwise calls and returns
480 * @c uflow().
482 int_type
483 sbumpc();
486 * @brief Getting the next character.
487 * @return The next character, or eof.
489 * If the input read position is available, returns that character,
490 * otherwise calls and returns @c underflow(). Does not move the
491 * read position after fetching the character.
493 int_type
494 sgetc()
496 int_type __ret;
497 if (_M_in_cur && _M_in_cur < _M_in_end)
498 __ret = traits_type::to_int_type(*(this->gptr()));
499 else
500 __ret = this->underflow();
501 return __ret;
505 * @brief Entry point for xsgetn.
506 * @param s A buffer area.
507 * @param n A count.
509 * Returns xsgetn(s,n). The effect is to fill @a s[0] through
510 * @a s[n-1] with characters from the input sequence, if possible.
512 streamsize
513 sgetn(char_type* __s, streamsize __n)
514 { return this->xsgetn(__s, __n); }
516 // [27.5.2.2.4] putback
518 * @brief Pushing characters back into the input stream.
519 * @param c The character to push back.
520 * @return The previous character, if possible.
522 * Similar to sungetc(), but @a c is pushed onto the stream instead
523 * of "the previous character". If successful, the next character
524 * fetched from the input stream will be @a c.
526 int_type
527 sputbackc(char_type __c);
530 * @brief Moving backwards in the input stream.
531 * @return The previous character, if possible.
533 * If a putback position is available, this function decrements the
534 * input pointer and returns that character. Otherwise, calls and
535 * returns pbackfail(). The effect is to "unget" the last character
536 * "gotten".
538 int_type
539 sungetc();
541 // [27.5.2.2.5] put area
543 * @brief Entry point for all single-character output functions.
544 * @param c A character to output.
545 * @return @a c, if possible.
547 * One of two public output functions.
549 * If a write position is available for the output sequence (i.e.,
550 * the buffer is not full), stores @a c in that position, increments
551 * the position, and returns @c traits::to_int_type(c). If a write
552 * position is not available, returns @c overflow(c).
554 int_type
555 sputc(char_type __c);
558 * @brief Entry point for all single-character output functions.
559 * @param s A buffer read area.
560 * @param n A count.
562 * One of two public output functions.
565 * Returns xsputn(s,n). The effect is to write @a s[0] through
566 * @a s[n-1] to the output sequence, if possible.
568 streamsize
569 sputn(const char_type* __s, streamsize __n)
570 { return this->xsputn(__s, __n); }
572 protected:
574 * @brief Base constructor.
576 * Only called from derived constructors, and sets up all the
577 * buffer data to zero, including the pointers described in the
578 * basic_streambuf class description. Note that, as a result,
579 * - the class starts with no read nor write positions available,
580 * - this is not an error
582 basic_streambuf()
583 : _M_buf(NULL), _M_buf_size(0), _M_buf_size_opt(BUFSIZ),
584 _M_buf_unified(false), _M_in_beg(0), _M_in_cur(0), _M_in_end(0),
585 _M_out_beg(0), _M_out_cur(0), _M_out_end(0),
586 _M_mode(ios_base::openmode(0)), _M_buf_locale(locale()),
587 _M_buf_locale_init(false), _M_pback_cur_save(0), _M_pback_end_save(0),
588 _M_pback_init(false)
591 // [27.5.2.3.1] get area access
592 //@{
594 * @brief Access to the get area.
596 * These functions are only available to other protected functions,
597 * including derived classes.
599 * - eback() returns the beginning pointer for the input sequence
600 * - gptr() returns the next pointer for the input sequence
601 * - egptr() returns the end pointer for the input sequence
603 char_type*
604 eback() const { return _M_in_beg; }
606 char_type*
607 gptr() const { return _M_in_cur; }
609 char_type*
610 egptr() const { return _M_in_end; }
611 //@}
614 * @brief Moving the read position.
615 * @param n The delta by which to move.
617 * This just advances the read position without returning any data.
619 void
620 gbump(int __n) { _M_in_cur += __n; }
623 * @brief Setting the three read area pointers.
624 * @param gbeg A pointer.
625 * @param gnext A pointer.
626 * @param gend A pointer.
627 * @post @a gbeg == @c eback(), @a gnext == @c gptr(), and
628 * @a gend == @c egptr()
630 void
631 setg(char_type* __gbeg, char_type* __gnext, char_type* __gend)
633 _M_in_beg = __gbeg;
634 _M_in_cur = __gnext;
635 _M_in_end = __gend;
636 if (!(_M_mode & ios_base::in) && __gbeg && __gnext && __gend)
637 _M_mode = _M_mode | ios_base::in;
640 // [27.5.2.3.2] put area access
641 //@{
643 * @brief Access to the put area.
645 * These functions are only available to other protected functions,
646 * including derived classes.
648 * - pbase() returns the beginning pointer for the output sequence
649 * - pptr() returns the next pointer for the output sequence
650 * - epptr() returns the end pointer for the output sequence
652 char_type*
653 pbase() const { return _M_out_beg; }
655 char_type*
656 pptr() const { return _M_out_cur; }
658 char_type*
659 epptr() const { return _M_out_end; }
660 //@}
663 * @brief Moving the write position.
664 * @param n The delta by which to move.
666 * This just advances the write position without returning any data.
668 void
669 pbump(int __n) { _M_out_cur += __n; }
672 * @brief Setting the three write area pointers.
673 * @param pbeg A pointer.
674 * @param pend A pointer.
675 * @post @a pbeg == @c pbase(), @a pbeg == @c pptr(), and
676 * @a pend == @c epptr()
678 void
679 setp(char_type* __pbeg, char_type* __pend)
681 _M_out_beg = _M_out_cur = __pbeg;
682 _M_out_end = __pend;
683 if (!(_M_mode & ios_base::out) && __pbeg && __pend)
684 _M_mode = _M_mode | ios_base::out;
687 // [27.5.2.4] virtual functions
688 // [27.5.2.4.1] locales
690 * @brief Changes translations.
691 * @param loc A new locale.
693 * Translations done during I/O which depend on the current locale
694 * are changed by this call. The standard adds, "Between invocations
695 * of this function a class derived from streambuf can safely cache
696 * results of calls to locale functions and to members of facets
697 * so obtained." This function simply stores the new locale for use
698 * by derived classes.
700 virtual void
701 imbue(const locale& __loc)
703 _M_buf_locale_init = true;
704 if (_M_buf_locale != __loc)
705 _M_buf_locale = __loc;
708 // [27.5.2.4.2] buffer management and positioning
710 * @brief Maniuplates the buffer.
712 * Each derived class provides its own appropriate behavior. See
713 * the next-to-last paragraph of
714 * http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#2 for
715 * more on this function.
717 * @note Base class version does nothing, returns @c this.
719 virtual basic_streambuf<char_type,_Traits>*
720 setbuf(char_type*, streamsize)
721 { return this; }
724 * @brief Alters the stream positions.
726 * Each derived class provides its own appropriate behavior.
727 * @note Base class version does nothing, returns a @c pos_type
728 * that represents an invalid stream position.
730 virtual pos_type
731 seekoff(off_type, ios_base::seekdir,
732 ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out)
733 { return pos_type(off_type(-1)); }
736 * @brief Alters the stream positions.
738 * Each derived class provides its own appropriate behavior.
739 * @note Base class version does nothing, returns a @c pos_type
740 * that represents an invalid stream position.
742 virtual pos_type
743 seekpos(pos_type,
744 ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out)
745 { return pos_type(off_type(-1)); }
748 * @brief Synchronizes the buffer arrays with the controlled sequences.
749 * @return -1 on failure.
751 * Each derived class provides its own appropriate behavior,
752 * including the definition of "failure".
753 * @note Base class version does nothing, returns zero.
755 virtual int
756 sync() { return 0; }
758 // [27.5.2.4.3] get area
760 * @brief Investigating the data available.
761 * @return An estimate of the number of characters available in the
762 * input sequence, or -1.
764 * "If it returns a positive value, then successive calls to
765 * @c underflow() will not return @c traits::eof() until at least that
766 * number of characters have been supplied. If @c showmanyc()
767 * returns -1, then calls to @c underflow() or @c uflow() will fail."
768 * [27.5.2.4.3]/1
770 * @note Base class version does nothing, returns zero.
771 * @note The standard adds that "the intention is not only that the
772 * calls [to underflow or uflow] will not return @c eof() but
773 * that they will return "immediately".
774 * @note The standard adds that "the morphemes of @c showmanyc are
775 * "es-how-many-see", not "show-manic".
777 virtual streamsize
778 showmanyc() { return 0; }
781 * @brief Multiple character extraction.
782 * @param s A buffer area.
783 * @param n Maximum number of characters to assign.
784 * @return The number of characters assigned.
786 * Fills @a s[0] through @a s[n-1] with characters from the input
787 * sequence, as if by @c sbumpc(). Stops when either @a n characters
788 * have been copied, or when @c traits::eof() would be copied.
790 * It is expected that derived classes provide a more efficient
791 * implementation by overriding this definition.
793 virtual streamsize
794 xsgetn(char_type* __s, streamsize __n);
797 * @brief Fetches more data from the controlled sequence.
798 * @return The first character from the <em>pending sequence</em>.
800 * Informally, this function is called when the input buffer is
801 * exhausted (or does not exist, as buffering need not actually be
802 * done). If a buffer exists, it is "refilled". In either case, the
803 * next available character is returned, or @c traits::eof() to
804 * indicate a null pending sequence.
806 * For a formal definiton of the pending sequence, see a good text
807 * such as Langer & Kreft, or [27.5.2.4.3]/7-14.
809 * A functioning input streambuf can be created by overriding only
810 * this function (no buffer area will be used). For an example, see
811 * http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#6
813 * @note Base class version does nothing, returns eof().
815 virtual int_type
816 underflow()
817 { return traits_type::eof(); }
820 * @brief Fetches more data from the controlled sequence.
821 * @return The first character from the <em>pending sequence</em>.
823 * Informally, this function does the same thing as @c underflow(),
824 * and in fact is required to call that function. It also returns
825 * the new character, like @c underflow() does. However, this
826 * function also moves the read position forward by one.
828 virtual int_type
829 uflow()
831 int_type __ret = traits_type::eof();
832 bool __testeof = traits_type::eq_int_type(this->underflow(), __ret);
833 bool __testpending = _M_in_cur && _M_in_cur < _M_in_end;
834 if (!__testeof && __testpending)
836 __ret = traits_type::to_int_type(*_M_in_cur);
837 ++_M_in_cur;
838 if (_M_buf_unified && _M_mode & ios_base::out)
839 ++_M_out_cur;
841 return __ret;
844 // [27.5.2.4.4] putback
846 * @brief Tries to back up the input sequence.
847 * @param c The character to be inserted back into the sequence.
848 * @return eof() on failure, "some other value" on success
849 * @post The constraints of @c gptr(), @c eback(), and @c pptr()
850 * are the same as for @c underflow().
852 * @note Base class version does nothing, returns eof().
854 virtual int_type
855 pbackfail(int_type /* __c */ = traits_type::eof())
856 { return traits_type::eof(); }
858 // Put area:
860 * @brief Multiple character insertion.
861 * @param s A buffer area.
862 * @param n Maximum number of characters to write.
863 * @return The number of characters written.
865 * Writes @a s[0] through @a s[n-1] to the output sequence, as if
866 * by @c sputc(). Stops when either @a n characters have been
867 * copied, or when @c sputc() would return @c traits::eof().
869 * It is expected that derived classes provide a more efficient
870 * implementation by overriding this definition.
872 virtual streamsize
873 xsputn(const char_type* __s, streamsize __n);
876 * @brief Consumes data from the buffer; writes to the
877 * controlled sequence.
878 * @param c An additional character to consume.
879 * @return eof() to indicate failure, something else (usually
880 * @a c, or not_eof())
882 * Informally, this function is called when the output buffer is full
883 * (or does not exist, as buffering need not actually be done). If a
884 * buffer exists, it is "consumed", with "some effect" on the
885 * controlled sequence. (Typically, the buffer is written out to the
886 * sequence verbatim.) In either case, the character @a c is also
887 * written out, if @a c is not @c eof().
889 * For a formal definiton of this function, see a good text
890 * such as Langer & Kreft, or [27.5.2.4.5]/3-7.
892 * A functioning output streambuf can be created by overriding only
893 * this function (no buffer area will be used).
895 * @note Base class version does nothing, returns eof().
897 virtual int_type
898 overflow(int_type /* __c */ = traits_type::eof())
899 { return traits_type::eof(); }
901 #ifdef _GLIBCPP_DEPRECATED
902 // Annex D.6
903 public:
905 * @brief Tosses a character.
907 * Advances the read pointer, ignoring the character that would have
908 * been read.
910 * See http://gcc.gnu.org/ml/libstdc++/2002-05/msg00168.html
912 * @note This function has been deprecated by the standard. You
913 * must define @c _GLIBCPP_DEPRECATED to make this visible; see
914 * c++config.h.
916 void
917 stossc()
919 if (_M_in_cur < _M_in_end)
920 ++_M_in_cur;
921 else
922 this->uflow();
924 #endif
926 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
927 // Side effect of DR 50.
928 private:
929 basic_streambuf(const __streambuf_type&) { };
931 __streambuf_type&
932 operator=(const __streambuf_type&) { return *this; };
933 #endif
935 } // namespace std
937 #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
938 # define export
939 #endif
940 #ifdef _GLIBCPP_FULLY_COMPLIANT_HEADERS
941 #include <bits/streambuf.tcc>
942 #endif
944 #endif