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