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