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