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