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 /** 00241 * @brief Alters the stream position. 00242 * @param __off Offset. 00243 * @param __way Value for ios_base::seekdir. 00244 * @param __mode Value for ios_base::openmode. 00245 * 00246 * Calls virtual seekoff function. 00247 */ 00248 pos_type 00249 pubseekoff(off_type __off, ios_base::seekdir __way, 00250 ios_base::openmode __mode = ios_base::in | ios_base::out) 00251 { return this->seekoff(__off, __way, __mode); } 00252 00253 /** 00254 * @brief Alters the stream position. 00255 * @param __sp Position 00256 * @param __mode Value for ios_base::openmode. 00257 * 00258 * Calls virtual seekpos function. 00259 */ 00260 pos_type 00261 pubseekpos(pos_type __sp, 00262 ios_base::openmode __mode = ios_base::in | ios_base::out) 00263 { return this->seekpos(__sp, __mode); } 00264 00265 /** 00266 * @brief Calls virtual sync function. 00267 */ 00268 int 00269 pubsync() { return this->sync(); } 00270 //@} 00271 00272 // [27.5.2.2.3] get area 00273 /** 00274 * @brief Looking ahead into the stream. 00275 * @return The number of characters available. 00276 * 00277 * If a read position is available, returns the number of characters 00278 * available for reading before the buffer must be refilled. 00279 * Otherwise returns the derived @c showmanyc(). 00280 */ 00281 streamsize 00282 in_avail() 00283 { 00284 const streamsize __ret = this->egptr() - this->gptr(); 00285 return __ret ? __ret : this->showmanyc(); 00286 } 00287 00288 /** 00289 * @brief Getting the next character. 00290 * @return The next character, or eof. 00291 * 00292 * Calls @c sbumpc(), and if that function returns 00293 * @c traits::eof(), so does this function. Otherwise, @c sgetc(). 00294 */ 00295 int_type 00296 snextc() 00297 { 00298 int_type __ret = traits_type::eof(); 00299 if (__builtin_expect(!traits_type::eq_int_type(this->sbumpc(), 00300 __ret), true)) 00301 __ret = this->sgetc(); 00302 return __ret; 00303 } 00304 00305 /** 00306 * @brief Getting the next character. 00307 * @return The next character, or eof. 00308 * 00309 * If the input read position is available, returns that character 00310 * and increments the read pointer, otherwise calls and returns 00311 * @c uflow(). 00312 */ 00313 int_type 00314 sbumpc() 00315 { 00316 int_type __ret; 00317 if (__builtin_expect(this->gptr() < this->egptr(), true)) 00318 { 00319 __ret = traits_type::to_int_type(*this->gptr()); 00320 this->gbump(1); 00321 } 00322 else 00323 __ret = this->uflow(); 00324 return __ret; 00325 } 00326 00327 /** 00328 * @brief Getting the next character. 00329 * @return The next character, or eof. 00330 * 00331 * If the input read position is available, returns that character, 00332 * otherwise calls and returns @c underflow(). Does not move the 00333 * read position after fetching the character. 00334 */ 00335 int_type 00336 sgetc() 00337 { 00338 int_type __ret; 00339 if (__builtin_expect(this->gptr() < this->egptr(), true)) 00340 __ret = traits_type::to_int_type(*this->gptr()); 00341 else 00342 __ret = this->underflow(); 00343 return __ret; 00344 } 00345 00346 /** 00347 * @brief Entry point for xsgetn. 00348 * @param __s A buffer area. 00349 * @param __n A count. 00350 * 00351 * Returns xsgetn(__s,__n). The effect is to fill @a __s[0] through 00352 * @a __s[__n-1] with characters from the input sequence, if possible. 00353 */ 00354 streamsize 00355 sgetn(char_type* __s, streamsize __n) 00356 { return this->xsgetn(__s, __n); } 00357 00358 // [27.5.2.2.4] putback 00359 /** 00360 * @brief Pushing characters back into the input stream. 00361 * @param __c The character to push back. 00362 * @return The previous character, if possible. 00363 * 00364 * Similar to sungetc(), but @a __c is pushed onto the stream 00365 * instead of <em>the previous character.</em> If successful, 00366 * the next character fetched from the input stream will be @a 00367 * __c. 00368 */ 00369 int_type 00370 sputbackc(char_type __c) 00371 { 00372 int_type __ret; 00373 const bool __testpos = this->eback() < this->gptr(); 00374 if (__builtin_expect(!__testpos || 00375 !traits_type::eq(__c, this->gptr()[-1]), false)) 00376 __ret = this->pbackfail(traits_type::to_int_type(__c)); 00377 else 00378 { 00379 this->gbump(-1); 00380 __ret = traits_type::to_int_type(*this->gptr()); 00381 } 00382 return __ret; 00383 } 00384 00385 /** 00386 * @brief Moving backwards in the input stream. 00387 * @return The previous character, if possible. 00388 * 00389 * If a putback position is available, this function decrements 00390 * the input pointer and returns that character. Otherwise, 00391 * calls and returns pbackfail(). The effect is to @a unget 00392 * the last character @a gotten. 00393 */ 00394 int_type 00395 sungetc() 00396 { 00397 int_type __ret; 00398 if (__builtin_expect(this->eback() < this->gptr(), true)) 00399 { 00400 this->gbump(-1); 00401 __ret = traits_type::to_int_type(*this->gptr()); 00402 } 00403 else 00404 __ret = this->pbackfail(); 00405 return __ret; 00406 } 00407 00408 // [27.5.2.2.5] put area 00409 /** 00410 * @brief Entry point for all single-character output functions. 00411 * @param __c A character to output. 00412 * @return @a __c, if possible. 00413 * 00414 * One of two public output functions. 00415 * 00416 * If a write position is available for the output sequence (i.e., 00417 * the buffer is not full), stores @a __c in that position, increments 00418 * the position, and returns @c traits::to_int_type(__c). If a write 00419 * position is not available, returns @c overflow(__c). 00420 */ 00421 int_type 00422 sputc(char_type __c) 00423 { 00424 int_type __ret; 00425 if (__builtin_expect(this->pptr() < this->epptr(), true)) 00426 { 00427 *this->pptr() = __c; 00428 this->pbump(1); 00429 __ret = traits_type::to_int_type(__c); 00430 } 00431 else 00432 __ret = this->overflow(traits_type::to_int_type(__c)); 00433 return __ret; 00434 } 00435 00436 /** 00437 * @brief Entry point for all single-character output functions. 00438 * @param __s A buffer read area. 00439 * @param __n A count. 00440 * 00441 * One of two public output functions. 00442 * 00443 * 00444 * Returns xsputn(__s,__n). The effect is to write @a __s[0] through 00445 * @a __s[__n-1] to the output sequence, if possible. 00446 */ 00447 streamsize 00448 sputn(const char_type* __s, streamsize __n) 00449 { return this->xsputn(__s, __n); } 00450 00451 protected: 00452 /** 00453 * @brief Base constructor. 00454 * 00455 * Only called from derived constructors, and sets up all the 00456 * buffer data to zero, including the pointers described in the 00457 * basic_streambuf class description. Note that, as a result, 00458 * - the class starts with no read nor write positions available, 00459 * - this is not an error 00460 */ 00461 basic_streambuf() 00462 : _M_in_beg(0), _M_in_cur(0), _M_in_end(0), 00463 _M_out_beg(0), _M_out_cur(0), _M_out_end(0), 00464 _M_buf_locale(locale()) 00465 { } 00466 00467 // [27.5.2.3.1] get area access 00468 //@{ 00469 /** 00470 * @brief Access to the get area. 00471 * 00472 * These functions are only available to other protected functions, 00473 * including derived classes. 00474 * 00475 * - eback() returns the beginning pointer for the input sequence 00476 * - gptr() returns the next pointer for the input sequence 00477 * - egptr() returns the end pointer for the input sequence 00478 */ 00479 char_type* 00480 eback() const { return _M_in_beg; } 00481 00482 char_type* 00483 gptr() const { return _M_in_cur; } 00484 00485 char_type* 00486 egptr() const { return _M_in_end; } 00487 //@} 00488 00489 /** 00490 * @brief Moving the read position. 00491 * @param __n The delta by which to move. 00492 * 00493 * This just advances the read position without returning any data. 00494 */ 00495 void 00496 gbump(int __n) { _M_in_cur += __n; } 00497 00498 /** 00499 * @brief Setting the three read area pointers. 00500 * @param __gbeg A pointer. 00501 * @param __gnext A pointer. 00502 * @param __gend A pointer. 00503 * @post @a __gbeg == @c eback(), @a __gnext == @c gptr(), and 00504 * @a __gend == @c egptr() 00505 */ 00506 void 00507 setg(char_type* __gbeg, char_type* __gnext, char_type* __gend) 00508 { 00509 _M_in_beg = __gbeg; 00510 _M_in_cur = __gnext; 00511 _M_in_end = __gend; 00512 } 00513 00514 // [27.5.2.3.2] put area access 00515 //@{ 00516 /** 00517 * @brief Access to the put area. 00518 * 00519 * These functions are only available to other protected functions, 00520 * including derived classes. 00521 * 00522 * - pbase() returns the beginning pointer for the output sequence 00523 * - pptr() returns the next pointer for the output sequence 00524 * - epptr() returns the end pointer for the output sequence 00525 */ 00526 char_type* 00527 pbase() const { return _M_out_beg; } 00528 00529 char_type* 00530 pptr() const { return _M_out_cur; } 00531 00532 char_type* 00533 epptr() const { return _M_out_end; } 00534 //@} 00535 00536 /** 00537 * @brief Moving the write position. 00538 * @param __n The delta by which to move. 00539 * 00540 * This just advances the write position without returning any data. 00541 */ 00542 void 00543 pbump(int __n) { _M_out_cur += __n; } 00544 00545 /** 00546 * @brief Setting the three write area pointers. 00547 * @param __pbeg A pointer. 00548 * @param __pend A pointer. 00549 * @post @a __pbeg == @c pbase(), @a __pbeg == @c pptr(), and 00550 * @a __pend == @c epptr() 00551 */ 00552 void 00553 setp(char_type* __pbeg, char_type* __pend) 00554 { 00555 _M_out_beg = _M_out_cur = __pbeg; 00556 _M_out_end = __pend; 00557 } 00558 00559 // [27.5.2.4] virtual functions 00560 // [27.5.2.4.1] locales 00561 /** 00562 * @brief Changes translations. 00563 * @param __loc A new locale. 00564 * 00565 * Translations done during I/O which depend on the current 00566 * locale are changed by this call. The standard adds, 00567 * <em>Between invocations of this function a class derived 00568 * from streambuf can safely cache results of calls to locale 00569 * functions and to members of facets so obtained.</em> 00570 * 00571 * @note Base class version does nothing. 00572 */ 00573 virtual void 00574 imbue(const locale& __loc) 00575 { } 00576 00577 // [27.5.2.4.2] buffer management and positioning 00578 /** 00579 * @brief Manipulates the buffer. 00580 * 00581 * Each derived class provides its own appropriate behavior. See 00582 * the next-to-last paragraph of 00583 * http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt11ch25s02.html 00584 * for more on this function. 00585 * 00586 * @note Base class version does nothing, returns @c this. 00587 */ 00588 virtual basic_streambuf<char_type,_Traits>* 00589 setbuf(char_type*, streamsize) 00590 { return this; } 00591 00592 /** 00593 * @brief Alters the stream positions. 00594 * 00595 * Each derived class provides its own appropriate behavior. 00596 * @note Base class version does nothing, returns a @c pos_type 00597 * that represents an invalid stream position. 00598 */ 00599 virtual pos_type 00600 seekoff(off_type, ios_base::seekdir, 00601 ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out) 00602 { return pos_type(off_type(-1)); } 00603 00604 /** 00605 * @brief Alters the stream positions. 00606 * 00607 * Each derived class provides its own appropriate behavior. 00608 * @note Base class version does nothing, returns a @c pos_type 00609 * that represents an invalid stream position. 00610 */ 00611 virtual pos_type 00612 seekpos(pos_type, 00613 ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out) 00614 { return pos_type(off_type(-1)); } 00615 00616 /** 00617 * @brief Synchronizes the buffer arrays with the controlled sequences. 00618 * @return -1 on failure. 00619 * 00620 * Each derived class provides its own appropriate behavior, 00621 * including the definition of @a failure. 00622 * @note Base class version does nothing, returns zero. 00623 */ 00624 virtual int 00625 sync() { return 0; } 00626 00627 // [27.5.2.4.3] get area 00628 /** 00629 * @brief Investigating the data available. 00630 * @return An estimate of the number of characters available in the 00631 * input sequence, or -1. 00632 * 00633 * <em>If it returns a positive value, then successive calls to 00634 * @c underflow() will not return @c traits::eof() until at 00635 * least that number of characters have been supplied. If @c 00636 * showmanyc() returns -1, then calls to @c underflow() or @c 00637 * uflow() will fail.</em> [27.5.2.4.3]/1 00638 * 00639 * @note Base class version does nothing, returns zero. 00640 * @note The standard adds that <em>the intention is not only that the 00641 * calls [to underflow or uflow] will not return @c eof() but 00642 * that they will return immediately.</em> 00643 * @note The standard adds that <em>the morphemes of @c showmanyc are 00644 * @b es-how-many-see, not @b show-manic.</em> 00645 */ 00646 virtual streamsize 00647 showmanyc() { return 0; } 00648 00649 /** 00650 * @brief Multiple character extraction. 00651 * @param __s A buffer area. 00652 * @param __n Maximum number of characters to assign. 00653 * @return The number of characters assigned. 00654 * 00655 * Fills @a __s[0] through @a __s[__n-1] with characters from the input 00656 * sequence, as if by @c sbumpc(). Stops when either @a __n characters 00657 * have been copied, or when @c traits::eof() would be copied. 00658 * 00659 * It is expected that derived classes provide a more efficient 00660 * implementation by overriding this definition. 00661 */ 00662 virtual streamsize 00663 xsgetn(char_type* __s, streamsize __n); 00664 00665 /** 00666 * @brief Fetches more data from the controlled sequence. 00667 * @return The first character from the <em>pending sequence</em>. 00668 * 00669 * Informally, this function is called when the input buffer is 00670 * exhausted (or does not exist, as buffering need not actually be 00671 * done). If a buffer exists, it is @a refilled. In either case, the 00672 * next available character is returned, or @c traits::eof() to 00673 * indicate a null pending sequence. 00674 * 00675 * For a formal definition of the pending sequence, see a good text 00676 * such as Langer & Kreft, or [27.5.2.4.3]/7-14. 00677 * 00678 * A functioning input streambuf can be created by overriding only 00679 * this function (no buffer area will be used). For an example, see 00680 * http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt11ch25.html 00681 * 00682 * @note Base class version does nothing, returns eof(). 00683 */ 00684 virtual int_type 00685 underflow() 00686 { return traits_type::eof(); } 00687 00688 /** 00689 * @brief Fetches more data from the controlled sequence. 00690 * @return The first character from the <em>pending sequence</em>. 00691 * 00692 * Informally, this function does the same thing as @c underflow(), 00693 * and in fact is required to call that function. It also returns 00694 * the new character, like @c underflow() does. However, this 00695 * function also moves the read position forward by one. 00696 */ 00697 virtual int_type 00698 uflow() 00699 { 00700 int_type __ret = traits_type::eof(); 00701 const bool __testeof = traits_type::eq_int_type(this->underflow(), 00702 __ret); 00703 if (!__testeof) 00704 { 00705 __ret = traits_type::to_int_type(*this->gptr()); 00706 this->gbump(1); 00707 } 00708 return __ret; 00709 } 00710 00711 // [27.5.2.4.4] putback 00712 /** 00713 * @brief Tries to back up the input sequence. 00714 * @param __c The character to be inserted back into the sequence. 00715 * @return eof() on failure, <em>some other value</em> on success 00716 * @post The constraints of @c gptr(), @c eback(), and @c pptr() 00717 * are the same as for @c underflow(). 00718 * 00719 * @note Base class version does nothing, returns eof(). 00720 */ 00721 virtual int_type 00722 pbackfail(int_type __c = traits_type::eof()) 00723 { return traits_type::eof(); } 00724 00725 // Put area: 00726 /** 00727 * @brief Multiple character insertion. 00728 * @param __s A buffer area. 00729 * @param __n Maximum number of characters to write. 00730 * @return The number of characters written. 00731 * 00732 * Writes @a __s[0] through @a __s[__n-1] to the output sequence, as if 00733 * by @c sputc(). Stops when either @a n characters have been 00734 * copied, or when @c sputc() would return @c traits::eof(). 00735 * 00736 * It is expected that derived classes provide a more efficient 00737 * implementation by overriding this definition. 00738 */ 00739 virtual streamsize 00740 xsputn(const char_type* __s, streamsize __n); 00741 00742 /** 00743 * @brief Consumes data from the buffer; writes to the 00744 * controlled sequence. 00745 * @param __c An additional character to consume. 00746 * @return eof() to indicate failure, something else (usually 00747 * @a __c, or not_eof()) 00748 * 00749 * Informally, this function is called when the output buffer 00750 * is full (or does not exist, as buffering need not actually 00751 * be done). If a buffer exists, it is @a consumed, with 00752 * <em>some effect</em> on the controlled sequence. 00753 * (Typically, the buffer is written out to the sequence 00754 * verbatim.) In either case, the character @a c is also 00755 * written out, if @a __c is not @c eof(). 00756 * 00757 * For a formal definition of this function, see a good text 00758 * such as Langer & Kreft, or [27.5.2.4.5]/3-7. 00759 * 00760 * A functioning output streambuf can be created by overriding only 00761 * this function (no buffer area will be used). 00762 * 00763 * @note Base class version does nothing, returns eof(). 00764 */ 00765 virtual int_type 00766 overflow(int_type __c = traits_type::eof()) 00767 { return traits_type::eof(); } 00768 00769 #if _GLIBCXX_USE_DEPRECATED 00770 // Annex D.6 00771 public: 00772 /** 00773 * @brief Tosses a character. 00774 * 00775 * Advances the read pointer, ignoring the character that would have 00776 * been read. 00777 * 00778 * See http://gcc.gnu.org/ml/libstdc++/2002-05/msg00168.html 00779 */ 00780 void 00781 stossc() 00782 { 00783 if (this->gptr() < this->egptr()) 00784 this->gbump(1); 00785 else 00786 this->uflow(); 00787 } 00788 #endif 00789 00790 // Also used by specializations for char and wchar_t in src. 00791 void 00792 __safe_gbump(streamsize __n) { _M_in_cur += __n; } 00793 00794 void 00795 __safe_pbump(streamsize __n) { _M_out_cur += __n; } 00796 00797 private: 00798 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00799 // Side effect of DR 50. 00800 basic_streambuf(const __streambuf_type& __sb) 00801 : _M_in_beg(__sb._M_in_beg), _M_in_cur(__sb._M_in_cur), 00802 _M_in_end(__sb._M_in_end), _M_out_beg(__sb._M_out_beg), 00803 _M_out_cur(__sb._M_out_cur), _M_out_end(__sb._M_out_cur), 00804 _M_buf_locale(__sb._M_buf_locale) 00805 { } 00806 00807 __streambuf_type& 00808 operator=(const __streambuf_type&) { return *this; }; 00809 }; 00810 00811 // Explicit specialization declarations, defined in src/streambuf.cc. 00812 template<> 00813 streamsize 00814 __copy_streambufs_eof(basic_streambuf<char>* __sbin, 00815 basic_streambuf<char>* __sbout, bool& __ineof); 00816 #ifdef _GLIBCXX_USE_WCHAR_T 00817 template<> 00818 streamsize 00819 __copy_streambufs_eof(basic_streambuf<wchar_t>* __sbin, 00820 basic_streambuf<wchar_t>* __sbout, bool& __ineof); 00821 #endif 00822 00823 _GLIBCXX_END_NAMESPACE_VERSION 00824 } // namespace 00825 00826 #include <bits/streambuf.tcc> 00827 00828 #endif /* _GLIBCXX_STREAMBUF */