libstdc++
|
00001 // Stream buffer classes -*- C++ -*- 00002 00003 // Copyright (C) 1997-2015 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /** @file include/streambuf 00026 * This is a Standard C++ Library header. 00027 */ 00028 00029 // 00030 // ISO C++ 14882: 27.5 Stream buffers 00031 // 00032 00033 #ifndef _GLIBXX_STREAMBUF 00034 #define _GLIBXX_STREAMBUF 1 00035 00036 #pragma GCC system_header 00037 00038 #include <bits/c++config.h> 00039 #include <iosfwd> 00040 #include <bits/localefwd.h> 00041 #include <bits/ios_base.h> 00042 #include <bits/cpp_type_traits.h> 00043 #include <ext/type_traits.h> 00044 00045 namespace std _GLIBCXX_VISIBILITY(default) 00046 { 00047 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00048 00049 template<typename _CharT, typename _Traits> 00050 streamsize 00051 __copy_streambufs_eof(basic_streambuf<_CharT, _Traits>*, 00052 basic_streambuf<_CharT, _Traits>*, bool&); 00053 00054 /** 00055 * @brief The actual work of input and output (interface). 00056 * @ingroup io 00057 * 00058 * @tparam _CharT Type of character stream. 00059 * @tparam _Traits Traits for character type, defaults to 00060 * char_traits<_CharT>. 00061 * 00062 * This is a base class. Derived stream buffers each control a 00063 * pair of character sequences: one for input, and one for output. 00064 * 00065 * Section [27.5.1] of the standard describes the requirements and 00066 * behavior of stream buffer classes. That section (three paragraphs) 00067 * is reproduced here, for simplicity and accuracy. 00068 * 00069 * -# Stream buffers can impose various constraints on the sequences 00070 * they control. Some constraints are: 00071 * - The controlled input sequence can be not readable. 00072 * - The controlled output sequence can be not writable. 00073 * - The controlled sequences can be associated with the contents of 00074 * other representations for character sequences, such as external 00075 * files. 00076 * - The controlled sequences can support operations @e directly to or 00077 * from associated sequences. 00078 * - The controlled sequences can impose limitations on how the 00079 * program can read characters from a sequence, write characters to 00080 * a sequence, put characters back into an input sequence, or alter 00081 * the stream position. 00082 * . 00083 * -# Each sequence is characterized by three pointers which, if non-null, 00084 * all point into the same @c charT array object. The array object 00085 * represents, at any moment, a (sub)sequence of characters from the 00086 * sequence. Operations performed on a sequence alter the values 00087 * stored in these pointers, perform reads and writes directly to or 00088 * from associated sequences, and alter <em>the stream position</em> and 00089 * conversion state as needed to maintain this subsequence relationship. 00090 * The three pointers are: 00091 * - the <em>beginning pointer</em>, or lowest element address in the 00092 * array (called @e xbeg here); 00093 * - the <em>next pointer</em>, or next element address that is a 00094 * current candidate for reading or writing (called @e xnext here); 00095 * - the <em>end pointer</em>, or first element address beyond the 00096 * end of the array (called @e xend here). 00097 * . 00098 * -# The following semantic constraints shall always apply for any set 00099 * of three pointers for a sequence, using the pointer names given 00100 * immediately above: 00101 * - If @e xnext is not a null pointer, then @e xbeg and @e xend shall 00102 * also be non-null pointers into the same @c charT array, as 00103 * described above; otherwise, @e xbeg and @e xend shall also be null. 00104 * - If @e xnext is not a null pointer and @e xnext < @e xend for an 00105 * output sequence, then a <em>write position</em> is available. 00106 * In this case, @e *xnext shall be assignable as the next element 00107 * to write (to put, or to store a character value, into the sequence). 00108 * - If @e xnext is not a null pointer and @e xbeg < @e xnext for an 00109 * input sequence, then a <em>putback position</em> is available. 00110 * In this case, @e xnext[-1] shall have a defined value and is the 00111 * next (preceding) element to store a character that is put back 00112 * into the input sequence. 00113 * - If @e xnext is not a null pointer and @e xnext< @e xend for an 00114 * input sequence, then a <em>read position</em> is available. 00115 * In this case, @e *xnext shall have a defined value and is the 00116 * next element to read (to get, or to obtain a character value, 00117 * from the sequence). 00118 */ 00119 template<typename _CharT, typename _Traits> 00120 class basic_streambuf 00121 { 00122 public: 00123 //@{ 00124 /** 00125 * These are standard types. They permit a standardized way of 00126 * referring to names of (or names dependent on) the template 00127 * parameters, which are specific to the implementation. 00128 */ 00129 typedef _CharT char_type; 00130 typedef _Traits traits_type; 00131 typedef typename traits_type::int_type int_type; 00132 typedef typename traits_type::pos_type pos_type; 00133 typedef typename traits_type::off_type off_type; 00134 //@} 00135 00136 //@{ 00137 /// This is a non-standard type. 00138 typedef basic_streambuf<char_type, traits_type> __streambuf_type; 00139 //@} 00140 00141 friend class basic_ios<char_type, traits_type>; 00142 friend class basic_istream<char_type, traits_type>; 00143 friend class basic_ostream<char_type, traits_type>; 00144 friend class istreambuf_iterator<char_type, traits_type>; 00145 friend class ostreambuf_iterator<char_type, traits_type>; 00146 00147 friend streamsize 00148 __copy_streambufs_eof<>(basic_streambuf*, basic_streambuf*, bool&); 00149 00150 template<bool _IsMove, typename _CharT2> 00151 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value, 00152 _CharT2*>::__type 00153 __copy_move_a2(istreambuf_iterator<_CharT2>, 00154 istreambuf_iterator<_CharT2>, _CharT2*); 00155 00156 template<typename _CharT2> 00157 friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value, 00158 istreambuf_iterator<_CharT2> >::__type 00159 find(istreambuf_iterator<_CharT2>, istreambuf_iterator<_CharT2>, 00160 const _CharT2&); 00161 00162 template<typename _CharT2, typename _Traits2> 00163 friend basic_istream<_CharT2, _Traits2>& 00164 operator>>(basic_istream<_CharT2, _Traits2>&, _CharT2*); 00165 00166 template<typename _CharT2, typename _Traits2, typename _Alloc> 00167 friend basic_istream<_CharT2, _Traits2>& 00168 operator>>(basic_istream<_CharT2, _Traits2>&, 00169 basic_string<_CharT2, _Traits2, _Alloc>&); 00170 00171 template<typename _CharT2, typename _Traits2, typename _Alloc> 00172 friend basic_istream<_CharT2, _Traits2>& 00173 getline(basic_istream<_CharT2, _Traits2>&, 00174 basic_string<_CharT2, _Traits2, _Alloc>&, _CharT2); 00175 00176 protected: 00177 /* 00178 * This is based on _IO_FILE, just reordered to be more consistent, 00179 * and is intended to be the most minimal abstraction for an 00180 * internal buffer. 00181 * - get == input == read 00182 * - put == output == write 00183 */ 00184 char_type* _M_in_beg; ///< Start of get area. 00185 char_type* _M_in_cur; ///< Current read area. 00186 char_type* _M_in_end; ///< End of get area. 00187 char_type* _M_out_beg; ///< Start of put area. 00188 char_type* _M_out_cur; ///< Current put area. 00189 char_type* _M_out_end; ///< End of put area. 00190 00191 /// Current locale setting. 00192 locale _M_buf_locale; 00193 00194 public: 00195 /// Destructor deallocates no buffer space. 00196 virtual 00197 ~basic_streambuf() 00198 { } 00199 00200 // [27.5.2.2.1] locales 00201 /** 00202 * @brief Entry point for imbue(). 00203 * @param __loc The new locale. 00204 * @return The previous locale. 00205 * 00206 * Calls the derived imbue(__loc). 00207 */ 00208 locale 00209 pubimbue(const locale& __loc) 00210 { 00211 locale __tmp(this->getloc()); 00212 this->imbue(__loc); 00213 _M_buf_locale = __loc; 00214 return __tmp; 00215 } 00216 00217 /** 00218 * @brief Locale access. 00219 * @return The current locale in effect. 00220 * 00221 * If pubimbue(loc) has been called, then the most recent @c loc 00222 * is returned. Otherwise the global locale in effect at the time 00223 * of construction is returned. 00224 */ 00225 locale 00226 getloc() const 00227 { return _M_buf_locale; } 00228 00229 // [27.5.2.2.2] buffer management and positioning 00230 //@{ 00231 /** 00232 * @brief Entry points for derived buffer functions. 00233 * 00234 * The public versions of @c pubfoo dispatch to the protected 00235 * derived @c foo member functions, passing the arguments (if any) 00236 * and returning the result unchanged. 00237 */ 00238 basic_streambuf* 00239 pubsetbuf(char_type* __s, streamsize __n) 00240 { return this->setbuf(__s, __n); } 00241 00242 /** 00243 * @brief Alters the stream position. 00244 * @param __off Offset. 00245 * @param __way Value for ios_base::seekdir. 00246 * @param __mode Value for ios_base::openmode. 00247 * 00248 * Calls virtual seekoff function. 00249 */ 00250 pos_type 00251 pubseekoff(off_type __off, ios_base::seekdir __way, 00252 ios_base::openmode __mode = ios_base::in | ios_base::out) 00253 { return this->seekoff(__off, __way, __mode); } 00254 00255 /** 00256 * @brief Alters the stream position. 00257 * @param __sp Position 00258 * @param __mode Value for ios_base::openmode. 00259 * 00260 * Calls virtual seekpos function. 00261 */ 00262 pos_type 00263 pubseekpos(pos_type __sp, 00264 ios_base::openmode __mode = ios_base::in | ios_base::out) 00265 { return this->seekpos(__sp, __mode); } 00266 00267 /** 00268 * @brief Calls virtual sync function. 00269 */ 00270 int 00271 pubsync() { return this->sync(); } 00272 //@} 00273 00274 // [27.5.2.2.3] get area 00275 /** 00276 * @brief Looking ahead into the stream. 00277 * @return The number of characters available. 00278 * 00279 * If a read position is available, returns the number of characters 00280 * available for reading before the buffer must be refilled. 00281 * Otherwise returns the derived @c showmanyc(). 00282 */ 00283 streamsize 00284 in_avail() 00285 { 00286 const streamsize __ret = this->egptr() - this->gptr(); 00287 return __ret ? __ret : this->showmanyc(); 00288 } 00289 00290 /** 00291 * @brief Getting the next character. 00292 * @return The next character, or eof. 00293 * 00294 * Calls @c sbumpc(), and if that function returns 00295 * @c traits::eof(), so does this function. Otherwise, @c sgetc(). 00296 */ 00297 int_type 00298 snextc() 00299 { 00300 int_type __ret = traits_type::eof(); 00301 if (__builtin_expect(!traits_type::eq_int_type(this->sbumpc(), 00302 __ret), true)) 00303 __ret = this->sgetc(); 00304 return __ret; 00305 } 00306 00307 /** 00308 * @brief Getting the next character. 00309 * @return The next character, or eof. 00310 * 00311 * If the input read position is available, returns that character 00312 * and increments the read pointer, otherwise calls and returns 00313 * @c uflow(). 00314 */ 00315 int_type 00316 sbumpc() 00317 { 00318 int_type __ret; 00319 if (__builtin_expect(this->gptr() < this->egptr(), true)) 00320 { 00321 __ret = traits_type::to_int_type(*this->gptr()); 00322 this->gbump(1); 00323 } 00324 else 00325 __ret = this->uflow(); 00326 return __ret; 00327 } 00328 00329 /** 00330 * @brief Getting the next character. 00331 * @return The next character, or eof. 00332 * 00333 * If the input read position is available, returns that character, 00334 * otherwise calls and returns @c underflow(). Does not move the 00335 * read position after fetching the character. 00336 */ 00337 int_type 00338 sgetc() 00339 { 00340 int_type __ret; 00341 if (__builtin_expect(this->gptr() < this->egptr(), true)) 00342 __ret = traits_type::to_int_type(*this->gptr()); 00343 else 00344 __ret = this->underflow(); 00345 return __ret; 00346 } 00347 00348 /** 00349 * @brief Entry point for xsgetn. 00350 * @param __s A buffer area. 00351 * @param __n A count. 00352 * 00353 * Returns xsgetn(__s,__n). The effect is to fill @a __s[0] through 00354 * @a __s[__n-1] with characters from the input sequence, if possible. 00355 */ 00356 streamsize 00357 sgetn(char_type* __s, streamsize __n) 00358 { return this->xsgetn(__s, __n); } 00359 00360 // [27.5.2.2.4] putback 00361 /** 00362 * @brief Pushing characters back into the input stream. 00363 * @param __c The character to push back. 00364 * @return The previous character, if possible. 00365 * 00366 * Similar to sungetc(), but @a __c is pushed onto the stream 00367 * instead of <em>the previous character.</em> If successful, 00368 * the next character fetched from the input stream will be @a 00369 * __c. 00370 */ 00371 int_type 00372 sputbackc(char_type __c) 00373 { 00374 int_type __ret; 00375 const bool __testpos = this->eback() < this->gptr(); 00376 if (__builtin_expect(!__testpos || 00377 !traits_type::eq(__c, this->gptr()[-1]), false)) 00378 __ret = this->pbackfail(traits_type::to_int_type(__c)); 00379 else 00380 { 00381 this->gbump(-1); 00382 __ret = traits_type::to_int_type(*this->gptr()); 00383 } 00384 return __ret; 00385 } 00386 00387 /** 00388 * @brief Moving backwards in the input stream. 00389 * @return The previous character, if possible. 00390 * 00391 * If a putback position is available, this function decrements 00392 * the input pointer and returns that character. Otherwise, 00393 * calls and returns pbackfail(). The effect is to @a unget 00394 * the last character @a gotten. 00395 */ 00396 int_type 00397 sungetc() 00398 { 00399 int_type __ret; 00400 if (__builtin_expect(this->eback() < this->gptr(), true)) 00401 { 00402 this->gbump(-1); 00403 __ret = traits_type::to_int_type(*this->gptr()); 00404 } 00405 else 00406 __ret = this->pbackfail(); 00407 return __ret; 00408 } 00409 00410 // [27.5.2.2.5] put area 00411 /** 00412 * @brief Entry point for all single-character output functions. 00413 * @param __c A character to output. 00414 * @return @a __c, if possible. 00415 * 00416 * One of two public output functions. 00417 * 00418 * If a write position is available for the output sequence (i.e., 00419 * the buffer is not full), stores @a __c in that position, increments 00420 * the position, and returns @c traits::to_int_type(__c). If a write 00421 * position is not available, returns @c overflow(__c). 00422 */ 00423 int_type 00424 sputc(char_type __c) 00425 { 00426 int_type __ret; 00427 if (__builtin_expect(this->pptr() < this->epptr(), true)) 00428 { 00429 *this->pptr() = __c; 00430 this->pbump(1); 00431 __ret = traits_type::to_int_type(__c); 00432 } 00433 else 00434 __ret = this->overflow(traits_type::to_int_type(__c)); 00435 return __ret; 00436 } 00437 00438 /** 00439 * @brief Entry point for all single-character output functions. 00440 * @param __s A buffer read area. 00441 * @param __n A count. 00442 * 00443 * One of two public output functions. 00444 * 00445 * 00446 * Returns xsputn(__s,__n). The effect is to write @a __s[0] through 00447 * @a __s[__n-1] to the output sequence, if possible. 00448 */ 00449 streamsize 00450 sputn(const char_type* __s, streamsize __n) 00451 { return this->xsputn(__s, __n); } 00452 00453 protected: 00454 /** 00455 * @brief Base constructor. 00456 * 00457 * Only called from derived constructors, and sets up all the 00458 * buffer data to zero, including the pointers described in the 00459 * basic_streambuf class description. Note that, as a result, 00460 * - the class starts with no read nor write positions available, 00461 * - this is not an error 00462 */ 00463 basic_streambuf() 00464 : _M_in_beg(0), _M_in_cur(0), _M_in_end(0), 00465 _M_out_beg(0), _M_out_cur(0), _M_out_end(0), 00466 _M_buf_locale(locale()) 00467 { } 00468 00469 // [27.5.2.3.1] get area access 00470 //@{ 00471 /** 00472 * @brief Access to the get area. 00473 * 00474 * These functions are only available to other protected functions, 00475 * including derived classes. 00476 * 00477 * - eback() returns the beginning pointer for the input sequence 00478 * - gptr() returns the next pointer for the input sequence 00479 * - egptr() returns the end pointer for the input sequence 00480 */ 00481 char_type* 00482 eback() const { return _M_in_beg; } 00483 00484 char_type* 00485 gptr() const { return _M_in_cur; } 00486 00487 char_type* 00488 egptr() const { return _M_in_end; } 00489 //@} 00490 00491 /** 00492 * @brief Moving the read position. 00493 * @param __n The delta by which to move. 00494 * 00495 * This just advances the read position without returning any data. 00496 */ 00497 void 00498 gbump(int __n) { _M_in_cur += __n; } 00499 00500 /** 00501 * @brief Setting the three read area pointers. 00502 * @param __gbeg A pointer. 00503 * @param __gnext A pointer. 00504 * @param __gend A pointer. 00505 * @post @a __gbeg == @c eback(), @a __gnext == @c gptr(), and 00506 * @a __gend == @c egptr() 00507 */ 00508 void 00509 setg(char_type* __gbeg, char_type* __gnext, char_type* __gend) 00510 { 00511 _M_in_beg = __gbeg; 00512 _M_in_cur = __gnext; 00513 _M_in_end = __gend; 00514 } 00515 00516 // [27.5.2.3.2] put area access 00517 //@{ 00518 /** 00519 * @brief Access to the put area. 00520 * 00521 * These functions are only available to other protected functions, 00522 * including derived classes. 00523 * 00524 * - pbase() returns the beginning pointer for the output sequence 00525 * - pptr() returns the next pointer for the output sequence 00526 * - epptr() returns the end pointer for the output sequence 00527 */ 00528 char_type* 00529 pbase() const { return _M_out_beg; } 00530 00531 char_type* 00532 pptr() const { return _M_out_cur; } 00533 00534 char_type* 00535 epptr() const { return _M_out_end; } 00536 //@} 00537 00538 /** 00539 * @brief Moving the write position. 00540 * @param __n The delta by which to move. 00541 * 00542 * This just advances the write position without returning any data. 00543 */ 00544 void 00545 pbump(int __n) { _M_out_cur += __n; } 00546 00547 /** 00548 * @brief Setting the three write area pointers. 00549 * @param __pbeg A pointer. 00550 * @param __pend A pointer. 00551 * @post @a __pbeg == @c pbase(), @a __pbeg == @c pptr(), and 00552 * @a __pend == @c epptr() 00553 */ 00554 void 00555 setp(char_type* __pbeg, char_type* __pend) 00556 { 00557 _M_out_beg = _M_out_cur = __pbeg; 00558 _M_out_end = __pend; 00559 } 00560 00561 // [27.5.2.4] virtual functions 00562 // [27.5.2.4.1] locales 00563 /** 00564 * @brief Changes translations. 00565 * @param __loc A new locale. 00566 * 00567 * Translations done during I/O which depend on the current 00568 * locale are changed by this call. The standard adds, 00569 * <em>Between invocations of this function a class derived 00570 * from streambuf can safely cache results of calls to locale 00571 * functions and to members of facets so obtained.</em> 00572 * 00573 * @note Base class version does nothing. 00574 */ 00575 virtual void 00576 imbue(const locale& __loc) 00577 { } 00578 00579 // [27.5.2.4.2] buffer management and positioning 00580 /** 00581 * @brief Manipulates the buffer. 00582 * 00583 * Each derived class provides its own appropriate behavior. See 00584 * the next-to-last paragraph of 00585 * https://gcc.gnu.org/onlinedocs/libstdc++/manual/streambufs.html#io.streambuf.buffering 00586 * for more on this function. 00587 * 00588 * @note Base class version does nothing, returns @c this. 00589 */ 00590 virtual basic_streambuf<char_type,_Traits>* 00591 setbuf(char_type*, streamsize) 00592 { return this; } 00593 00594 /** 00595 * @brief Alters the stream positions. 00596 * 00597 * Each derived class provides its own appropriate behavior. 00598 * @note Base class version does nothing, returns a @c pos_type 00599 * that represents an invalid stream position. 00600 */ 00601 virtual pos_type 00602 seekoff(off_type, ios_base::seekdir, 00603 ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out) 00604 { return pos_type(off_type(-1)); } 00605 00606 /** 00607 * @brief Alters the stream positions. 00608 * 00609 * Each derived class provides its own appropriate behavior. 00610 * @note Base class version does nothing, returns a @c pos_type 00611 * that represents an invalid stream position. 00612 */ 00613 virtual pos_type 00614 seekpos(pos_type, 00615 ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out) 00616 { return pos_type(off_type(-1)); } 00617 00618 /** 00619 * @brief Synchronizes the buffer arrays with the controlled sequences. 00620 * @return -1 on failure. 00621 * 00622 * Each derived class provides its own appropriate behavior, 00623 * including the definition of @a failure. 00624 * @note Base class version does nothing, returns zero. 00625 */ 00626 virtual int 00627 sync() { return 0; } 00628 00629 // [27.5.2.4.3] get area 00630 /** 00631 * @brief Investigating the data available. 00632 * @return An estimate of the number of characters available in the 00633 * input sequence, or -1. 00634 * 00635 * <em>If it returns a positive value, then successive calls to 00636 * @c underflow() will not return @c traits::eof() until at 00637 * least that number of characters have been supplied. If @c 00638 * showmanyc() returns -1, then calls to @c underflow() or @c 00639 * uflow() will fail.</em> [27.5.2.4.3]/1 00640 * 00641 * @note Base class version does nothing, returns zero. 00642 * @note The standard adds that <em>the intention is not only that the 00643 * calls [to underflow or uflow] will not return @c eof() but 00644 * that they will return immediately.</em> 00645 * @note The standard adds that <em>the morphemes of @c showmanyc are 00646 * @b es-how-many-see, not @b show-manic.</em> 00647 */ 00648 virtual streamsize 00649 showmanyc() { return 0; } 00650 00651 /** 00652 * @brief Multiple character extraction. 00653 * @param __s A buffer area. 00654 * @param __n Maximum number of characters to assign. 00655 * @return The number of characters assigned. 00656 * 00657 * Fills @a __s[0] through @a __s[__n-1] with characters from the input 00658 * sequence, as if by @c sbumpc(). Stops when either @a __n characters 00659 * have been copied, or when @c traits::eof() would be copied. 00660 * 00661 * It is expected that derived classes provide a more efficient 00662 * implementation by overriding this definition. 00663 */ 00664 virtual streamsize 00665 xsgetn(char_type* __s, streamsize __n); 00666 00667 /** 00668 * @brief Fetches more data from the controlled sequence. 00669 * @return The first character from the <em>pending sequence</em>. 00670 * 00671 * Informally, this function is called when the input buffer is 00672 * exhausted (or does not exist, as buffering need not actually be 00673 * done). If a buffer exists, it is @a refilled. In either case, the 00674 * next available character is returned, or @c traits::eof() to 00675 * indicate a null pending sequence. 00676 * 00677 * For a formal definition of the pending sequence, see a good text 00678 * such as Langer & Kreft, or [27.5.2.4.3]/7-14. 00679 * 00680 * A functioning input streambuf can be created by overriding only 00681 * this function (no buffer area will be used). For an example, see 00682 * https://gcc.gnu.org/onlinedocs/libstdc++/manual/streambufs.html 00683 * 00684 * @note Base class version does nothing, returns eof(). 00685 */ 00686 virtual int_type 00687 underflow() 00688 { return traits_type::eof(); } 00689 00690 /** 00691 * @brief Fetches more data from the controlled sequence. 00692 * @return The first character from the <em>pending sequence</em>. 00693 * 00694 * Informally, this function does the same thing as @c underflow(), 00695 * and in fact is required to call that function. It also returns 00696 * the new character, like @c underflow() does. However, this 00697 * function also moves the read position forward by one. 00698 */ 00699 virtual int_type 00700 uflow() 00701 { 00702 int_type __ret = traits_type::eof(); 00703 const bool __testeof = traits_type::eq_int_type(this->underflow(), 00704 __ret); 00705 if (!__testeof) 00706 { 00707 __ret = traits_type::to_int_type(*this->gptr()); 00708 this->gbump(1); 00709 } 00710 return __ret; 00711 } 00712 00713 // [27.5.2.4.4] putback 00714 /** 00715 * @brief Tries to back up the input sequence. 00716 * @param __c The character to be inserted back into the sequence. 00717 * @return eof() on failure, <em>some other value</em> on success 00718 * @post The constraints of @c gptr(), @c eback(), and @c pptr() 00719 * are the same as for @c underflow(). 00720 * 00721 * @note Base class version does nothing, returns eof(). 00722 */ 00723 virtual int_type 00724 pbackfail(int_type __c = traits_type::eof()) 00725 { return traits_type::eof(); } 00726 00727 // Put area: 00728 /** 00729 * @brief Multiple character insertion. 00730 * @param __s A buffer area. 00731 * @param __n Maximum number of characters to write. 00732 * @return The number of characters written. 00733 * 00734 * Writes @a __s[0] through @a __s[__n-1] to the output sequence, as if 00735 * by @c sputc(). Stops when either @a n characters have been 00736 * copied, or when @c sputc() would return @c traits::eof(). 00737 * 00738 * It is expected that derived classes provide a more efficient 00739 * implementation by overriding this definition. 00740 */ 00741 virtual streamsize 00742 xsputn(const char_type* __s, streamsize __n); 00743 00744 /** 00745 * @brief Consumes data from the buffer; writes to the 00746 * controlled sequence. 00747 * @param __c An additional character to consume. 00748 * @return eof() to indicate failure, something else (usually 00749 * @a __c, or not_eof()) 00750 * 00751 * Informally, this function is called when the output buffer 00752 * is full (or does not exist, as buffering need not actually 00753 * be done). If a buffer exists, it is @a consumed, with 00754 * <em>some effect</em> on the controlled sequence. 00755 * (Typically, the buffer is written out to the sequence 00756 * verbatim.) In either case, the character @a c is also 00757 * written out, if @a __c is not @c eof(). 00758 * 00759 * For a formal definition of this function, see a good text 00760 * such as Langer & Kreft, or [27.5.2.4.5]/3-7. 00761 * 00762 * A functioning output streambuf can be created by overriding only 00763 * this function (no buffer area will be used). 00764 * 00765 * @note Base class version does nothing, returns eof(). 00766 */ 00767 virtual int_type 00768 overflow(int_type __c = traits_type::eof()) 00769 { return traits_type::eof(); } 00770 00771 #if _GLIBCXX_USE_DEPRECATED 00772 // Annex D.6 00773 public: 00774 /** 00775 * @brief Tosses a character. 00776 * 00777 * Advances the read pointer, ignoring the character that would have 00778 * been read. 00779 * 00780 * See http://gcc.gnu.org/ml/libstdc++/2002-05/msg00168.html 00781 */ 00782 void 00783 stossc() 00784 { 00785 if (this->gptr() < this->egptr()) 00786 this->gbump(1); 00787 else 00788 this->uflow(); 00789 } 00790 #endif 00791 00792 // Also used by specializations for char and wchar_t in src. 00793 void 00794 __safe_gbump(streamsize __n) { _M_in_cur += __n; } 00795 00796 void 00797 __safe_pbump(streamsize __n) { _M_out_cur += __n; } 00798 00799 #if __cplusplus < 201103L 00800 private: 00801 #else 00802 protected: 00803 #endif 00804 basic_streambuf(const basic_streambuf&); 00805 00806 basic_streambuf& 00807 operator=(const basic_streambuf&); 00808 00809 #if __cplusplus >= 201103L 00810 void 00811 swap(basic_streambuf& __sb) 00812 { 00813 std::swap(_M_in_beg, __sb._M_in_beg); 00814 std::swap(_M_in_cur, __sb._M_in_cur); 00815 std::swap(_M_in_end, __sb._M_in_end); 00816 std::swap(_M_out_beg, __sb._M_out_beg); 00817 std::swap(_M_out_cur, __sb._M_out_cur); 00818 std::swap(_M_out_end, __sb._M_out_end); 00819 std::swap(_M_buf_locale, __sb._M_buf_locale); 00820 } 00821 #endif 00822 }; 00823 00824 #if __cplusplus >= 201103L 00825 template<typename _CharT, typename _Traits> 00826 std::basic_streambuf<_CharT, _Traits>:: 00827 basic_streambuf(const basic_streambuf&) = default; 00828 00829 template<typename _CharT, typename _Traits> 00830 std::basic_streambuf<_CharT, _Traits>& 00831 std::basic_streambuf<_CharT, _Traits>:: 00832 operator=(const basic_streambuf&) = default; 00833 #endif 00834 00835 // Explicit specialization declarations, defined in src/streambuf.cc. 00836 template<> 00837 streamsize 00838 __copy_streambufs_eof(basic_streambuf<char>* __sbin, 00839 basic_streambuf<char>* __sbout, bool& __ineof); 00840 #ifdef _GLIBCXX_USE_WCHAR_T 00841 template<> 00842 streamsize 00843 __copy_streambufs_eof(basic_streambuf<wchar_t>* __sbin, 00844 basic_streambuf<wchar_t>* __sbout, bool& __ineof); 00845 #endif 00846 00847 _GLIBCXX_END_NAMESPACE_VERSION 00848 } // namespace 00849 00850 #include <bits/streambuf.tcc> 00851 00852 #endif /* _GLIBCXX_STREAMBUF */