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