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