00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _STLP_INTERNAL_STREAMBUF
00019 #define _STLP_INTERNAL_STREAMBUF
00020
00021 #ifndef _STLP_IOS_BASE_H
00022 #include <stl/_ios_base.h>
00023
00024 #endif
00025
00026 #ifndef _STLP_STDIO_FILE_H
00027 #include <stl/_stdio_file.h>
00028
00029 #endif
00030
00031 _STLP_BEGIN_NAMESPACE
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 template <class _CharT, class _Traits>
00054 class basic_streambuf
00055 {
00056 friend class basic_istream<_CharT, _Traits>;
00057 friend class basic_ostream<_CharT, _Traits>;
00058
00059 public:
00060 typedef _CharT char_type;
00061 typedef typename _Traits::int_type int_type;
00062 typedef typename _Traits::pos_type pos_type;
00063 typedef typename _Traits::off_type off_type;
00064 typedef _Traits traits_type;
00065
00066 private:
00067
00068 char_type* _M_gbegin;
00069 char_type* _M_gnext;
00070 char_type* _M_gend;
00071
00072 char_type* _M_pbegin;
00073 char_type* _M_pnext;
00074 char_type* _M_pend;
00075
00076 locale _M_locale;
00077
00078 public:
00079 _STLP_mutex _M_lock;
00080
00081 public:
00082 virtual ~basic_streambuf();
00083
00084 protected:
00085 basic_streambuf();
00086
00087 protected:
00088 char_type* eback() const { return _M_gbegin; }
00089 char_type* gptr() const { return _M_gnext; }
00090 char_type* egptr() const { return _M_gend; }
00091
00092 void gbump(int __n) { _M_gnext += __n; }
00093 void setg(char_type* __gbegin, char_type* __gnext, char_type* __gend) {
00094 _M_gbegin = __gbegin;
00095 _M_gnext = __gnext;
00096 _M_gend = __gend;
00097 }
00098
00099 public:
00100
00101
00102
00103
00104 char_type* _M_eback() const { return eback(); }
00105 char_type* _M_gptr() const { return gptr(); }
00106 char_type* _M_egptr() const { return egptr(); }
00107 void _M_gbump(int __n) { gbump(__n); }
00108 void _M_setg(char_type* __gbegin, char_type* __gnext, char_type* __gend)
00109 { setg(__gbegin, __gnext, __gend); }
00110
00111 protected:
00112
00113 char_type* pbase() const { return _M_pbegin; }
00114 char_type* pptr() const { return _M_pnext; }
00115 char_type* epptr() const { return _M_pend; }
00116
00117 void pbump(int __n) { _M_pnext += __n; }
00118 void setp(char_type* __pbegin, char_type* __pend) {
00119 _M_pbegin = __pbegin;
00120 _M_pnext = __pbegin;
00121 _M_pend = __pend;
00122 }
00123
00124 protected:
00125
00126 virtual basic_streambuf<_CharT, _Traits>* setbuf(char_type*, streamsize);
00127
00128
00129
00130 virtual pos_type seekoff(off_type, ios_base::seekdir,
00131 ios_base::openmode = ios_base::in | ios_base::out);
00132
00133
00134
00135 virtual pos_type
00136 seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out);
00137
00138
00139
00140 virtual int sync();
00141
00142
00143 public:
00144 basic_streambuf<_CharT, _Traits>* pubsetbuf(char_type* __s, streamsize __n)
00145 { return this->setbuf(__s, __n); }
00146
00147 pos_type pubseekoff(off_type __offset, ios_base::seekdir __way,
00148 ios_base::openmode __mod = ios_base::in | ios_base::out)
00149 { return this->seekoff(__offset, __way, __mod); }
00150
00151 pos_type pubseekpos(pos_type __sp,
00152 ios_base::openmode __mod = ios_base::in | ios_base::out)
00153 { return this->seekpos(__sp, __mod); }
00154
00155 int pubsync() { return this->sync(); }
00156
00157 protected:
00158
00159
00160
00161
00162
00163 virtual streamsize showmanyc();
00164
00165
00166
00167 virtual streamsize xsgetn(char_type* __s, streamsize __n);
00168
00169
00170
00171
00172 virtual int_type underflow();
00173
00174
00175
00176 virtual int_type uflow();
00177
00178
00179
00180
00181 virtual int_type pbackfail(int_type = traits_type::eof());
00182
00183 protected:
00184
00185
00186
00187
00188 virtual streamsize xsputn(const char_type* __s, streamsize __n);
00189
00190
00191
00192 virtual streamsize _M_xsputnc(char_type __c, streamsize __n);
00193
00194
00195
00196 virtual int_type overflow(int_type = traits_type::eof());
00197
00198 public:
00199
00200 int_type sputc(char_type __c) {
00201 return ((_M_pnext < _M_pend) ? _Traits::to_int_type(*_M_pnext++ = __c)
00202 : this->overflow(_Traits::to_int_type(__c)));
00203 }
00204
00205
00206 streamsize sputn(const char_type* __s, streamsize __n)
00207 { return this->xsputn(__s, __n); }
00208
00209
00210 streamsize _M_sputnc(char_type __c, streamsize __n)
00211 { return this->_M_xsputnc(__c, __n); }
00212
00213 private:
00214 int_type _M_snextc_aux();
00215
00216
00217 public:
00218 streamsize in_avail() {
00219 return (_M_gnext < _M_gend) ? (_M_gend - _M_gnext) : this->showmanyc();
00220 }
00221
00222
00223 int_type snextc() {
00224 return ( _M_gend - _M_gnext > 1 ?
00225 _Traits::to_int_type(*++_M_gnext) :
00226 this->_M_snextc_aux());
00227 }
00228
00229
00230 int_type sbumpc() {
00231 return _M_gnext < _M_gend ? _Traits::to_int_type(*_M_gnext++)
00232 : this->uflow();
00233 }
00234
00235
00236 int_type sgetc() {
00237 return _M_gnext < _M_gend ? _Traits::to_int_type(*_M_gnext)
00238 : this->underflow();
00239 }
00240
00241 streamsize sgetn(char_type* __s, streamsize __n)
00242 { return this->xsgetn(__s, __n); }
00243
00244 int_type sputbackc(char_type __c) {
00245 return ((_M_gbegin < _M_gnext) && _Traits::eq(__c, *(_M_gnext - 1)))
00246 ? _Traits::to_int_type(*--_M_gnext)
00247 : this->pbackfail(_Traits::to_int_type(__c));
00248 }
00249
00250 int_type sungetc() {
00251 return (_M_gbegin < _M_gnext)
00252 ? _Traits::to_int_type(*--_M_gnext)
00253 : this->pbackfail();
00254 }
00255
00256 protected:
00257
00258
00259
00260
00261
00262 virtual void imbue(const locale&);
00263
00264 public:
00265 locale pubimbue(const locale&);
00266 locale getloc() const { return _M_locale; }
00267
00268 # ifndef _STLP_NO_ANACHRONISMS
00269 void stossc() { this->sbumpc(); }
00270 # endif
00271 #if defined(__MVS__) || defined(__OS400__)
00272 private:
00273
00274 char_type* _M_gbegin;
00275 char_type* _M_gnext;
00276 char_type* _M_gend;
00277
00278 char_type* _M_pbegin;
00279 char_type* _M_pnext;
00280 char_type* _M_pend;
00281 #endif
00282 };
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313 _STLP_TEMPLATE_NULL
00314 class _STLP_CLASS_DECLSPEC basic_streambuf<char, char_traits<char> >
00315 {
00316 friend class basic_istream<char, char_traits<char> >;
00317 friend class basic_ostream<char, char_traits<char> >;
00318 public:
00319 typedef char char_type;
00320 typedef char_traits<char>::int_type int_type;
00321 typedef char_traits<char>::pos_type pos_type;
00322 typedef char_traits<char>::off_type off_type;
00323 typedef char_traits<char> traits_type;
00324
00325 private:
00326
00327 FILE& _M_get;
00328 FILE& _M_put;
00329
00330 #if defined(__hpux)
00331 _FILEX _M_default_get;
00332 _FILEX _M_default_put;
00333 #else
00334 FILE _M_default_get;
00335 FILE _M_default_put;
00336 #endif
00337
00338 locale _M_locale;
00339
00340 public:
00341 _STLP_mutex _M_lock;
00342
00343 public:
00344 virtual ~basic_streambuf _STLP_PSPEC2(char, char_traits<char>) ();
00345
00346 protected:
00347
00348
00349 basic_streambuf _STLP_PSPEC2(char, char_traits<char>) ()
00350 # if defined(__MVS__) || defined(__OS400__)
00351 : _M_get(_M_default_get),
00352 _M_put(_M_default_put), _M_locale()
00353 {
00354
00355
00356 _FILE_I_set(_M_get, 0, 0, 0);
00357 _FILE_O_set(_M_put, 0, 0, 0);
00358 }
00359 # else
00360 ;
00361 # endif
00362
00363
00364 basic_streambuf _STLP_PSPEC2(char, char_traits<char>) (FILE* __get, FILE* __put);
00365
00366 protected:
00367 char_type* eback() const { return _FILE_I_begin(_M_get); }
00368 char_type* gptr() const { return _FILE_I_next(_M_get); }
00369 char_type* egptr() const { return _FILE_I_end(_M_get); }
00370 void gbump(int __n) { _FILE_I_bump(_M_get, __n); }
00371 void setg(char_type* __gbegin, char_type* __gnext, char_type* __gend)
00372 { _FILE_I_set(_M_get, __gbegin, __gnext, __gend); }
00373
00374 public:
00375
00376
00377
00378
00379 char_type* _M_eback() const { return _FILE_I_begin(_M_get); }
00380 char_type* _M_gptr() const { return _FILE_I_next(_M_get); }
00381 char_type* _M_egptr() const { return _FILE_I_end(_M_get); }
00382
00383 void _M_gbump(int __n) { _FILE_I_bump(_M_get, __n); }
00384 void _M_setg(char_type* __gbegin, char_type* __gnext, char_type* __gend)
00385 { _FILE_I_set(_M_get, __gbegin, __gnext, __gend); }
00386
00387 protected:
00388 char_type* pbase() const { return _FILE_O_begin(_M_put); }
00389 char_type* pptr() const { return _FILE_O_next(_M_put); }
00390 char_type* epptr() const { return _FILE_O_end(_M_put); }
00391
00392 void pbump(int __n) { _FILE_O_bump(_M_put, __n); }
00393 void setp(char_type* __pbegin, char_type* __pend)
00394 { _FILE_O_set(_M_put, __pbegin, __pbegin, __pend); }
00395
00396 protected:
00397 virtual basic_streambuf<char, char_traits<char> >* setbuf(char_type*, streamsize);
00398 virtual pos_type seekoff(off_type, ios_base::seekdir,
00399 ios_base::openmode = ios_base::in | ios_base::out);
00400 virtual pos_type
00401 seekpos(pos_type, ios_base::openmode = ios_base::in | ios_base::out);
00402 virtual int sync();
00403
00404 public:
00405 basic_streambuf<char, char_traits<char> >* pubsetbuf(char_type* __s, streamsize __n)
00406 { return this->setbuf(__s, __n); }
00407
00408 pos_type pubseekoff(off_type __offset, ios_base::seekdir __way,
00409 ios_base::openmode __mod = ios_base::in | ios_base::out)
00410 { return this->seekoff(__offset, __way, __mod); }
00411
00412 pos_type pubseekpos(pos_type __sp,
00413 ios_base::openmode __mod = ios_base::in | ios_base::out)
00414 { return this->seekpos(__sp, __mod); }
00415
00416 int pubsync() { return this->sync(); }
00417
00418 protected:
00419 virtual streamsize showmanyc();
00420 virtual streamsize xsgetn(char_type* __s, streamsize __n);
00421 virtual int_type underflow();
00422 virtual int_type uflow();
00423 virtual int_type pbackfail(int_type __c = traits_type::eof());
00424
00425 protected:
00426 virtual streamsize xsputn(const char_type* __s, streamsize __n);
00427 virtual streamsize _M_xsputnc(char_type __c, streamsize __n);
00428 virtual int_type overflow(int_type = traits_type::eof());
00429
00430 public:
00431
00432 int_type sputc(char_type __c) {
00433 int_type __res;
00434 if( _FILE_O_avail(_M_put) > 0 )
00435 {
00436 _FILE_O_postincr(_M_put) = __c;
00437 __res = traits_type::to_int_type(__c);
00438 }
00439 else
00440 __res = this->overflow(traits_type::to_int_type(__c));
00441 return __res;
00442 }
00443
00444
00445 streamsize sputn(const char_type* __s, streamsize __n)
00446 { return this->xsputn(__s, __n); }
00447
00448
00449 streamsize _M_sputnc(char_type __c, streamsize __n)
00450 { return this->_M_xsputnc(__c, __n); }
00451
00452 private:
00453 int_type _M_snextc_aux();
00454
00455 public:
00456 streamsize in_avail()
00457 { return _FILE_I_avail(_M_get) > 0 ? _FILE_I_avail(_M_get)
00458 : this->showmanyc(); }
00459
00460
00461 int_type snextc() {
00462 return _FILE_I_avail(_M_get) > 1
00463 ? traits_type::to_int_type(_FILE_I_preincr(_M_get))
00464 : this->_M_snextc_aux();
00465 }
00466
00467
00468 int_type sbumpc() {
00469 return _FILE_I_avail(_M_get) > 0
00470 ? traits_type::to_int_type(_FILE_I_postincr(_M_get))
00471 : this->uflow();
00472 }
00473
00474
00475 int_type sgetc() {
00476 return _FILE_I_avail(_M_get) > 0
00477 ? traits_type::to_int_type(*_FILE_I_next(_M_get))
00478 : this->underflow();
00479 }
00480
00481 streamsize sgetn(char_type* __s, streamsize __n)
00482 { return this->xsgetn(__s, __n); }
00483
00484 int_type sputbackc(char_type __c) {
00485 return _FILE_I_begin(_M_get) < _FILE_I_next(_M_get) &&
00486 __c == *(_FILE_I_next(_M_get) - 1)
00487 ? traits_type::to_int_type(_FILE_I_predecr(_M_get))
00488 : this->pbackfail(traits_type::to_int_type(__c));
00489 }
00490
00491 int_type sungetc() {
00492 return _FILE_I_begin(_M_get) < _FILE_I_next(_M_get)
00493 ? traits_type::to_int_type(_FILE_I_predecr(_M_get))
00494 : this->pbackfail();
00495 }
00496
00497 protected:
00498 virtual void imbue(const locale&);
00499
00500 public:
00501 locale pubimbue(const locale&);
00502 locale getloc() const { return _M_locale; }
00503
00504 # ifndef _STLP_NO_ANACHRONISMS
00505 public:
00506 void stossc() { this->sbumpc(); }
00507 # endif
00508
00509 #if defined(__MVS__) || defined(__OS400__)
00510 private:
00511
00512 char_type* _M_gbegin;
00513 char_type* _M_gnext;
00514 char_type* _M_gend;
00515
00516 char_type* _M_pbegin;
00517 char_type* _M_pnext;
00518 char_type* _M_pend;
00519 #endif
00520
00521 };
00522 _STLP_END_NAMESPACE
00523
00524 # if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
00525 # include <stl/_streambuf.c>
00526 # endif
00527
00528 #endif
00529
00530
00531