00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00040 #ifndef _CLIBXX_STREAMBUF
00041 #define _CLIBXX_STREAMBUF 1
00042
00043 #pragma GCC system_header
00044
00045 #include <bits/c++config.h>
00046 #include <iosfwd>
00047 #include <bits/localefwd.h>
00048 #include <bits/ios_base.h>
00049
00050 namespace std
00051 {
00057 template<typename _CharT, typename _Traits>
00058 streamsize
00059 __copy_streambufs(basic_streambuf<_CharT, _Traits>* __sbin,
00060 basic_streambuf<_CharT, _Traits>* __sbout);
00061
00122 template<typename _CharT, typename _Traits>
00123 class basic_streambuf
00124 {
00125 public:
00127
00132 typedef _CharT char_type;
00133 typedef _Traits traits_type;
00134 typedef typename traits_type::int_type int_type;
00135 typedef typename traits_type::pos_type pos_type;
00136 typedef typename traits_type::off_type off_type;
00138
00140
00145 typedef basic_streambuf<char_type, traits_type> __streambuf_type;
00147
00148 friend class basic_ios<char_type, traits_type>;
00149 friend class basic_istream<char_type, traits_type>;
00150 friend class basic_ostream<char_type, traits_type>;
00151 friend class istreambuf_iterator<char_type, traits_type>;
00152 friend class ostreambuf_iterator<char_type, traits_type>;
00153
00154 friend streamsize
00155 __copy_streambufs<>(__streambuf_type* __sbin,
00156 __streambuf_type* __sbout);
00157
00158 protected:
00160
00169 char_type* _M_in_beg;
00170 char_type* _M_in_cur;
00171 char_type* _M_in_end;
00172 char_type* _M_out_beg;
00173 char_type* _M_out_cur;
00174 char_type* _M_out_end;
00175
00181 locale _M_buf_locale;
00182
00183 public:
00185 virtual
00186 ~basic_streambuf()
00187 { }
00188
00189
00197 locale
00198 pubimbue(const locale &__loc)
00199 {
00200 locale __tmp(this->getloc());
00201 this->imbue(__loc);
00202 _M_buf_locale = __loc;
00203 return __tmp;
00204 }
00205
00214 locale
00215 getloc() const
00216 { return _M_buf_locale; }
00217
00218
00220
00227 __streambuf_type*
00228 pubsetbuf(char_type* __s, streamsize __n)
00229 { return this->setbuf(__s, __n); }
00230
00231 pos_type
00232 pubseekoff(off_type __off, ios_base::seekdir __way,
00233 ios_base::openmode __mode = ios_base::in | ios_base::out)
00234 { return this->seekoff(__off, __way, __mode); }
00235
00236 pos_type
00237 pubseekpos(pos_type __sp,
00238 ios_base::openmode __mode = ios_base::in | ios_base::out)
00239 { return this->seekpos(__sp, __mode); }
00240
00241 int
00242 pubsync() { return this->sync(); }
00244
00245
00254 streamsize
00255 in_avail()
00256 {
00257 const streamsize __ret = this->egptr() - this->gptr();
00258 return __ret ? __ret : this->showmanyc();
00259 }
00260
00268 int_type
00269 snextc()
00270 {
00271 int_type __ret = traits_type::eof();
00272 if (__builtin_expect(!traits_type::eq_int_type(this->sbumpc(),
00273 __ret), true))
00274 __ret = this->sgetc();
00275 return __ret;
00276 }
00277
00286 int_type
00287 sbumpc()
00288 {
00289 int_type __ret;
00290 if (__builtin_expect(this->gptr() < this->egptr(), true))
00291 {
00292 __ret = traits_type::to_int_type(*this->gptr());
00293 this->gbump(1);
00294 }
00295 else
00296 __ret = this->uflow();
00297 return __ret;
00298 }
00299
00308 int_type
00309 sgetc()
00310 {
00311 int_type __ret;
00312 if (__builtin_expect(this->gptr() < this->egptr(), true))
00313 __ret = traits_type::to_int_type(*this->gptr());
00314 else
00315 __ret = this->underflow();
00316 return __ret;
00317 }
00318
00327 streamsize
00328 sgetn(char_type* __s, streamsize __n)
00329 { return this->xsgetn(__s, __n); }
00330
00331
00341 int_type
00342 sputbackc(char_type __c)
00343 {
00344 int_type __ret;
00345 const bool __testpos = this->eback() < this->gptr();
00346 if (__builtin_expect(!__testpos ||
00347 !traits_type::eq(__c, this->gptr()[-1]), false))
00348 __ret = this->pbackfail(traits_type::to_int_type(__c));
00349 else
00350 {
00351 this->gbump(-1);
00352 __ret = traits_type::to_int_type(*this->gptr());
00353 }
00354 return __ret;
00355 }
00356
00366 int_type
00367 sungetc()
00368 {
00369 int_type __ret;
00370 if (__builtin_expect(this->eback() < this->gptr(), true))
00371 {
00372 this->gbump(-1);
00373 __ret = traits_type::to_int_type(*this->gptr());
00374 }
00375 else
00376 __ret = this->pbackfail();
00377 return __ret;
00378 }
00379
00380
00393 int_type
00394 sputc(char_type __c)
00395 {
00396 int_type __ret;
00397 if (__builtin_expect(this->pptr() < this->epptr(), true))
00398 {
00399 *this->pptr() = __c;
00400 this->pbump(1);
00401 __ret = traits_type::to_int_type(__c);
00402 }
00403 else
00404 __ret = this->overflow(traits_type::to_int_type(__c));
00405 return __ret;
00406 }
00407
00419 streamsize
00420 sputn(const char_type* __s, streamsize __n)
00421 { return this->xsputn(__s, __n); }
00422
00423 protected:
00433 basic_streambuf()
00434 : _M_in_beg(0), _M_in_cur(0), _M_in_end(0),
00435 _M_out_beg(0), _M_out_cur(0), _M_out_end(0),
00436 _M_buf_locale(locale())
00437 { }
00438
00439
00441
00451 char_type*
00452 eback() const { return _M_in_beg; }
00453
00454 char_type*
00455 gptr() const { return _M_in_cur; }
00456
00457 char_type*
00458 egptr() const { return _M_in_end; }
00460
00467 void
00468 gbump(int __n) { _M_in_cur += __n; }
00469
00478 void
00479 setg(char_type* __gbeg, char_type* __gnext, char_type* __gend)
00480 {
00481 _M_in_beg = __gbeg;
00482 _M_in_cur = __gnext;
00483 _M_in_end = __gend;
00484 }
00485
00486
00488
00498 char_type*
00499 pbase() const { return _M_out_beg; }
00500
00501 char_type*
00502 pptr() const { return _M_out_cur; }
00503
00504 char_type*
00505 epptr() const { return _M_out_end; }
00507
00514 void
00515 pbump(int __n) { _M_out_cur += __n; }
00516
00524 void
00525 setp(char_type* __pbeg, char_type* __pend)
00526 {
00527 _M_out_beg = _M_out_cur = __pbeg;
00528 _M_out_end = __pend;
00529 }
00530
00531
00532
00545 virtual void
00546 imbue(const locale&)
00547 { }
00548
00549
00560 virtual basic_streambuf<char_type,_Traits>*
00561 setbuf(char_type*, streamsize)
00562 { return this; }
00563
00571 virtual pos_type
00572 seekoff(off_type, ios_base::seekdir,
00573 ios_base::openmode = ios_base::in | ios_base::out)
00574 { return pos_type(off_type(-1)); }
00575
00583 virtual pos_type
00584 seekpos(pos_type,
00585 ios_base::openmode = ios_base::in | ios_base::out)
00586 { return pos_type(off_type(-1)); }
00587
00596 virtual int
00597 sync() { return 0; }
00598
00599
00618 virtual streamsize
00619 showmanyc() { return 0; }
00620
00634 virtual streamsize
00635 xsgetn(char_type* __s, streamsize __n);
00636
00656 virtual int_type
00657 underflow()
00658 { return traits_type::eof(); }
00659
00669 virtual int_type
00670 uflow()
00671 {
00672 int_type __ret = traits_type::eof();
00673 const bool __testeof = traits_type::eq_int_type(this->underflow(),
00674 __ret);
00675 if (!__testeof)
00676 {
00677 __ret = traits_type::to_int_type(*this->gptr());
00678 this->gbump(1);
00679 }
00680 return __ret;
00681 }
00682
00683
00693 virtual int_type
00694 pbackfail(int_type = traits_type::eof())
00695 { return traits_type::eof(); }
00696
00697
00711 virtual streamsize
00712 xsputn(const char_type* __s, streamsize __n);
00713
00736 virtual int_type
00737 overflow(int_type = traits_type::eof())
00738 { return traits_type::eof(); }
00739
00740 #ifdef _GLIBCXX_DEPRECATED
00741
00742 public:
00755 void
00756 stossc()
00757 {
00758 if (this->gptr() < this->egptr())
00759 this->gbump(1);
00760 else
00761 this->uflow();
00762 }
00763 #endif
00764
00765 private:
00766
00767
00768 basic_streambuf(const __streambuf_type& __sb)
00769 : _M_in_beg(__sb._M_in_beg), _M_in_cur(__sb._M_in_cur),
00770 _M_in_end(__sb._M_in_end), _M_out_beg(__sb._M_out_beg),
00771 _M_out_cur(__sb._M_out_cur), _M_out_end(__sb._M_out_cur),
00772 _M_buf_locale(__sb._M_buf_locale)
00773 { }
00774
00775 __streambuf_type&
00776 operator=(const __streambuf_type&) { return *this; };
00777 };
00778 }
00779
00780 #ifndef _GLIBCXX_EXPORT_TEMPLATE
00781 # include <bits/streambuf.tcc>
00782 #endif
00783
00784 #endif