00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __KOKO_STREAM_BASIC_DOT_H
00021 #define __KOKO_STREAM_BASIC_DOT_H
00022
00023 #include <istream>
00024 #include <ostream>
00025 #include <string>
00026 #include <smartptr.h>
00027
00028 #ifdef WIN32
00029 #pragma warning(disable:4251)
00030 #endif
00031
00032 #ifndef _BADOFF
00033 #define _BADOFF 0
00034 #endif
00035
00036
00037
00038
00039
00040
00041
00042
00043 template<
00044 class _Elem,
00045 class _Traits,
00046 class _Alloc
00047 >
00048 class basic_kokobuf
00049 : public std::basic_streambuf<_Elem, _Traits>,
00050 public gutz::Counted
00051 {
00052 public:
00053 typedef _Alloc allocator_type;
00054
00055 typedef std::basic_streambuf<_Elem, _Traits> _Mysb;
00056
00057 typedef std::basic_string<_Elem, _Traits, _Alloc> _Mystr;
00058 typedef std::ios_base::openmode openmode;
00059
00060
00061
00062 explicit basic_kokobuf(int size, openmode _Mode =
00063 std::ios_base::in | std::ios_base::out)
00064
00065 {
00066
00067 _Init(0, 0, _Getstate(_Mode));
00068
00069 if(size < 0) return;
00070
00071 _Elem *_Pnew = _Al.allocate(size);
00072 _Seekhigh = _Pnew;
00073
00074
00075 if (!(_Mystate & _Noread))
00076 _Mysb::setg(_Pnew, _Pnew,
00077 _Pnew + size);
00078
00079 if (!(_Mystate & _Constant))
00080 {
00081 _Mysb::setp(_Pnew, _Pnew + size);
00082 if (_Mysb::gptr() == 0)
00083 _Mysb::setg(_Pnew, 0, _Pnew);
00084 }
00085 _Mystate |= _Allocated;
00086 }
00087
00088
00089
00090 virtual ~basic_kokobuf()
00091 {
00092 _Tidy();
00093 }
00094
00095 enum
00096 {
00097 _Allocated = 1,
00098 _Constant = 2,
00099 _Noread = 4,
00100 _Append = 8,
00101 _Frozen = 16
00102 };
00103 typedef int _Strstate;
00104
00105 typedef typename _Traits::int_type int_type;
00106 typedef typename _Traits::pos_type pos_type;
00107 typedef typename _Traits::off_type off_type;
00108
00109
00110
00111
00112
00113
00114
00115
00116 bool resetStream()
00117 {
00118 if(_Mystate & _Frozen) return true;
00119 _Seekhigh = _Mysb::pbase();
00120
00121 #ifdef WIN32
00122 _Mysb::setp(_Mysb::pbase(), _Mysb::pbase(), _Mysb::epptr());
00123 #else
00124 _Mysb::setp(_Mysb::pbase(), _Mysb::epptr());
00125 #endif
00126
00127 if (_Mystate & _Noread)
00128 {
00129 _Mysb::setg(_Mysb::eback(), 0, _Mysb::epptr());
00130 }
00131 else
00132 {
00133 _Mysb::setg(_Mysb::eback(), _Mysb::eback(), _Mysb::eback()+1);
00134 }
00135 return false;
00136 }
00137
00138
00139
00140
00141
00142
00143 bool makeWritable()
00144 {
00145 if(_Mystate & _Frozen) return true;
00146 _Mystate &= ~(_Constant);
00147 return false;
00148 }
00149
00150
00151
00152
00153
00154 bool makeReadable()
00155 {
00156 if(_Mystate & _Frozen) return true;
00157
00158 _Mystate &= ~(_Noread);
00159 _Mysb::setg(_Mysb::pbase(), _Mysb::pbase(), _Mysb::pptr());
00160 return false;
00161 }
00162
00163
00164
00165
00166 int totalBufferSize() const
00167 {
00168 return (_Mysb::pptr() == 0
00169 ? 0 : _Mysb::epptr() - _Mysb::pbase()) ;
00170 }
00171
00172
00173 int writableSize() const
00174 {
00175 return (_Mysb::pptr() == 0
00176 ? 0 : _Mysb::epptr() - _Mysb::pptr() - 1) ;
00177 }
00178
00179
00180 int writtenSize() const
00181 {
00182 return (_Mysb::pptr() == 0
00183 ? 0 : _Mysb::pptr() - _Mysb::pbase() );
00184 }
00185
00186
00187
00188
00189 _Elem *getCurWritePtr()
00190 {
00191 if(_Mystate & _Constant) return 0;
00192 _Mystate |= _Constant | _Frozen;
00193 #if WIN32
00194 return (_Mysb::_Pninc());
00195 #else
00196 _Elem *_Pret = _M_out_cur;
00197 _M_out_cur_move(1);
00198 return (_Pret);
00199 #endif
00200
00201 }
00202
00203
00204
00205 void setWrittenSize(int size)
00206 {
00207 if(!(_Mystate & _Frozen)) return;
00208 _Mystate &= ~(_Constant | _Frozen);
00209 pbump(size-1);
00210 }
00211
00212
00213
00214 const _Elem *getReadPtr() const
00215 {
00216 if(!(_Mystate & _Constant))
00217 _Mystate |= _Constant | _Frozen;
00218 return _Mysb::eback();
00219 }
00220
00221
00222
00223 const _Elem *getCurReadPtr() const
00224 {
00225 if(!(_Mystate & _Constant))
00226 _Mystate |= _Constant | _Frozen;
00227 return _Mysb::gptr();
00228 }
00229
00230
00231
00232 void setReadSize(int size)
00233 {
00234 if(!(_Mystate & _Frozen))
00235 _Mystate &= ~(_Constant | _Frozen);
00236 gbump(size);
00237 }
00238
00239
00240
00241 void returnReadPtr()
00242 {
00243 if(!(_Mystate & _Frozen)) return;
00244 _Mystate &= ~(_Constant | _Frozen);
00245 }
00246
00247
00248 size_t getReadableSize() const
00249 {
00250 return (_Mysb::pptr() == 0
00251 ? 0 : _Mysb::egptr() - _Mysb::gptr()) ;
00252 }
00253
00254
00255 bool isFrozen() const { return _Mystate & _Frozen; }
00256 bool isConst() const { return _Mystate & (_Constant | _Frozen); }
00257
00258
00259
00260
00261
00262 bool setSize(int size)
00263 {
00264 if(size < 0) return false;
00265
00266 _Elem *_Ptr = 0;
00267 _Ptr = _Al.allocate(_Newsize);
00268 if (_Mystate & _Allocated)
00269 _Al.deallocate(_Mysb::eback(), _Oldsize);
00270 _Mystate |= _Allocated;
00271
00272 _Seekhigh = _Seekhigh - _Mysb::eback() + _Ptr;
00273 _Mysb::setp(_Mysb::pbase() - _Mysb::eback() + _Ptr,
00274 _Mysb::pptr() - _Mysb::eback() + _Ptr, _Ptr + _Newsize);
00275 if (_Mystate & _Noread)
00276 _Mysb::setg(_Ptr, 0, _Ptr);
00277 else
00278 _Mysb::setg(_Ptr,
00279 _Mysb::gptr() - _Mysb::eback() + _Ptr,
00280 _Mysb::pptr() + 1);
00281 return true;
00282 }
00283
00284
00285
00286 _Mystr str() const
00287 {
00288
00289 if (!(_Mystate & _Constant) && _Mysb::pptr() != 0)
00290 {
00291 _Mystr _Str(_Mysb::pbase(), (_Seekhigh < _Mysb::pptr()
00292 ? int(_Mysb::pptr()) : int(_Seekhigh)) - int(_Mysb::pbase()));
00293 return (_Str);
00294 }
00295
00296 else if (!(_Mystate & _Noread) && _Mysb::gptr() != 0)
00297 {
00298 _Mystr _Str(_Mysb::eback(), _Mysb::egptr() - _Mysb::eback());
00299 return (_Str);
00300 }
00301 else
00302 {
00303 _Mystr _Nul;
00304 return (_Nul);
00305 }
00306 }
00307
00308
00309
00310 void str(const _Mystr& _Newstr)
00311 {
00312 if(int(_Newstr.size()) > int(epptr() - pbase()))
00313 {
00314 _Tidy();
00315 _Init(_Newstr.c_str(), _Newstr.size(), _Mystate);
00316 return;
00317 }
00318 resetStream();
00319 _Elem * p = getCurWritePtr();
00320 const _Elem * s = _Newstr.c_str();
00321 for(int i=0; i<int(_Newstr.size()); ++i)
00322 {
00323 p[i] = s[i];
00324 }
00325 setWrittenSize(_Newstr.size());
00326 }
00327
00328
00329
00330
00331
00332 protected:
00333
00334 virtual int_type overflow(int_type _Meta = _Traits::eof())
00335 {
00336 if (_Mystate & _Append
00337 && _Mysb::pptr() != 0 && _Mysb::pptr() < _Seekhigh)
00338 {
00339 #ifdef WIN32
00340 _Mysb::setp(_Mysb::pbase(), _Seekhigh, _Mysb::epptr());
00341 #else
00342 _Mysb::setp(_Mysb::pbase(), _Mysb::epptr());
00343 _M_out_cur_move(_Seekhigh - _Mysb::pbase());
00344 #endif
00345 }
00346 if (_Traits::eq_int_type(_Traits::eof(), _Meta))
00347 return (_Traits::not_eof(_Meta));
00348 else if (_Mysb::pptr() != 0
00349 && _Mysb::pptr() < _Mysb::epptr())
00350 {
00351 #if WIN32
00352 *_Mysb::_Pninc() = _Traits::to_char_type(_Meta);
00353 #else
00354 (*_M_out_cur) = _Traits::to_char_type(_Meta);
00355 _M_out_cur_move(1);
00356 #endif
00357 return (_Meta);
00358 }
00359 else if (_Mystate & _Constant)
00360 return (_Traits::eof());
00361 else
00362 {
00363 size_t _Oldsize = _Mysb::pptr() == 0
00364 ? 0 : _Mysb::epptr() - _Mysb::eback();
00365 size_t _Newsize = _Oldsize;
00366 size_t _Inc = _Newsize / 2 < _MINSIZE
00367 ? _MINSIZE : _Newsize / 2;
00368 _Elem *_Ptr = 0;
00369
00370 while (0 < _Inc && INT_MAX - _Inc < _Newsize)
00371 _Inc /= 2;
00372 if (0 < _Inc)
00373 {
00374 _Newsize += _Inc;
00375 _Ptr = _Al.allocate(_Newsize);
00376 }
00377
00378 if (0 < _Oldsize)
00379 _Traits::copy(_Ptr, _Mysb::eback(), _Oldsize);
00380 if (_Mystate & _Allocated)
00381 _Al.deallocate(_Mysb::eback(), _Oldsize);
00382 _Mystate |= _Allocated;
00383
00384 if (_Oldsize == 0)
00385 {
00386 _Seekhigh = _Ptr;
00387 _Mysb::setp(_Ptr, _Ptr + _Newsize);
00388 if (_Mystate & _Noread)
00389 _Mysb::setg(_Ptr, 0, _Ptr);
00390 else
00391 _Mysb::setg(_Ptr, _Ptr, _Ptr + 1);
00392 }
00393 else
00394 {
00395 _Seekhigh = _Seekhigh - _Mysb::eback() + _Ptr;
00396
00397 #ifdef WIN32
00398 _Mysb::setp(_Mysb::pbase() - _Mysb::eback() + _Ptr,
00399 _Mysb::pptr() - _Mysb::eback() + _Ptr,
00400 _Ptr + _Newsize);
00401 #else
00402 _Mysb::setp(_Mysb::pbase() - _Mysb::eback() + _Ptr,
00403 _Ptr + _Newsize);
00404 _M_out_cur_move(_Mysb::pptr() - _Mysb::eback() + _Ptr - _Mysb::pbase());
00405 #endif
00406 if (_Mystate & _Noread)
00407 _Mysb::setg(_Ptr, 0, _Ptr);
00408 else
00409 _Mysb::setg(_Ptr,
00410 _Mysb::gptr() - _Mysb::eback() + _Ptr,
00411 _Mysb::pptr() + 1);
00412 }
00413 #if WIN32
00414 *_Mysb::_Pninc() = _Traits::to_char_type(_Meta);
00415 #else
00416 (*_M_out_cur) = _Traits::to_char_type(_Meta);
00417 _M_out_cur_move(1);
00418 #endif
00419
00420 return (_Meta);
00421 }
00422 }
00423
00424 virtual int_type pbackfail(int_type _Meta = _Traits::eof())
00425 {
00426 if (_Mysb::gptr() == 0
00427 || _Mysb::gptr() <= _Mysb::eback()
00428 || !_Traits::eq_int_type(_Traits::eof(), _Meta)
00429 && !_Traits::eq(_Traits::to_char_type(_Meta), _Mysb::gptr()[-1])
00430 && _Mystate & _Constant)
00431 return (_Traits::eof());
00432 else
00433 {
00434 _Mysb::gbump(-1);
00435 if (!_Traits::eq_int_type(_Traits::eof(), _Meta))
00436 *_Mysb::gptr() = _Traits::to_char_type(_Meta);
00437 return (_Traits::not_eof(_Meta));
00438 }
00439 }
00440
00441 virtual int_type underflow()
00442 {
00443 if (_Mysb::gptr() == 0)
00444 return (_Traits::eof());
00445 else if (_Mysb::gptr() < _Mysb::egptr())
00446 return (_Traits::to_int_type(*_Mysb::gptr()));
00447 else if (_Mystate & _Noread || _Mysb::pptr() == 0
00448 || _Mysb::pptr() <= _Mysb::gptr() && _Seekhigh <= _Mysb::gptr())
00449 return (_Traits::eof());
00450 else
00451 {
00452 if (_Seekhigh < _Mysb::pptr())
00453 _Seekhigh = _Mysb::pptr();
00454 _Mysb::setg(_Mysb::eback(), _Mysb::gptr(), _Seekhigh);
00455 return (_Traits::to_int_type(*_Mysb::gptr()));
00456 }
00457 }
00458
00459 virtual pos_type seekoff(off_type _Off,
00460 std::ios_base::seekdir _Way,
00461 openmode _Which = std::ios_base::in | std::ios_base::out)
00462 {
00463 if (_Mysb::pptr() != 0 && _Seekhigh < _Mysb::pptr())
00464 _Seekhigh = _Mysb::pptr();
00465
00466
00467 if (_Which & std::ios_base::in && _Mysb::gptr() != 0)
00468 {
00469 if (_Way == std::ios_base::end)
00470 _Off += (off_type)(_Seekhigh - _Mysb::eback());
00471 else if (_Way == std::ios_base::cur
00472 && (_Which & std::ios_base::out) == 0)
00473 _Off += (off_type)(_Mysb::gptr() - _Mysb::eback());
00474 else if (_Way != std::ios_base::beg)
00475 _Off = _BADOFF;
00476
00477 if ( (0 <= _Off) && (_Off <= (_Seekhigh - _Mysb::eback())) )
00478 {
00479 _Mysb::gbump( int( _Mysb::eback() - _Mysb::gptr() + _Off ) );
00480 if ( _Which & std::ios_base::out && _Mysb::pptr() != 0 )
00481 {
00482 #ifdef WIN32
00483 _Mysb::setp(_Mysb::pbase(), _Mysb::gptr(),
00484 _Mysb::epptr());
00485 #else
00486 _Mysb::setp(_Mysb::pbase(), _Mysb::epptr());
00487 _M_out_cur_move(_Mysb::gptr() - _Mysb::pbase());
00488 #endif
00489 }
00490 }
00491 else
00492 _Off = _BADOFF;
00493 }
00494
00495 else if (_Which & std::ios_base::out && _Mysb::pptr() != 0)
00496 {
00497 if (_Way == std::ios_base::end)
00498 _Off += (off_type)(_Seekhigh - _Mysb::eback());
00499 else if (_Way == std::ios_base::cur)
00500 _Off += (off_type)(_Mysb::pptr() - _Mysb::eback());
00501 else if (_Way != std::ios_base::beg)
00502 _Off = _BADOFF;
00503
00504 if (0 <= _Off && _Off <= _Seekhigh - _Mysb::eback())
00505 _Mysb::pbump((int)(_Mysb::eback()
00506 - _Mysb::pptr() + _Off));
00507 else
00508 _Off = _BADOFF;
00509 }
00510 else
00511 _Off = _BADOFF;
00512 return (pos_type(_Off));
00513 }
00514
00515 virtual pos_type seekpos(pos_type _Ptr,
00516 openmode _Mode = std::ios_base::in | std::ios_base::out)
00517 {
00518 std::streamoff _Off = (std::streamoff)_Ptr;
00519 if (_Mysb::pptr() != 0 && _Seekhigh < _Mysb::pptr())
00520 _Seekhigh = _Mysb::pptr();
00521
00522 if (_Off == int(_BADOFF))
00523 ;
00524 else if (_Mode & std::ios_base::in && _Mysb::gptr() != 0)
00525 {
00526 if (0 <= _Off && _Off <= _Seekhigh - _Mysb::eback())
00527 {
00528 _Mysb::gbump((int)(_Mysb::eback() - _Mysb::gptr() + _Off));
00529 if (_Mode & std::ios_base::out && _Mysb::pptr() != 0)
00530 #ifdef WIN32
00531 _Mysb::setp(_Mysb::pbase(), _Mysb::gptr(),
00532 _Mysb::epptr());
00533 #else
00534 _Mysb::setp(_Mysb::pbase(), _Mysb::epptr());
00535 _M_out_cur_move(_Mysb::gptr() - _Mysb::pbase());
00536 #endif
00537 }
00538 else
00539 _Off = _BADOFF;
00540 }
00541 else if (_Mode & std::ios_base::out && _Mysb::pptr() != 0)
00542 {
00543 if (0 <= _Off && _Off <= _Seekhigh - _Mysb::eback())
00544 _Mysb::pbump((int)(_Mysb::eback()
00545 - _Mysb::pptr() + _Off));
00546 else
00547 _Off = _BADOFF;
00548 }
00549 else
00550 _Off = _BADOFF;
00551 return (std::streampos(_Off));
00552 }
00553
00554 void _Init(const _Elem *_Ptr,
00555 size_t _Count, _Strstate _State)
00556 {
00557 _Seekhigh = 0;
00558 _Mystate = _State;
00559
00560 if (_Count != 0
00561 && (_Mystate & (_Noread | _Constant)) != (_Noread | _Constant))
00562 {
00563 _Elem *_Pnew = _Al.allocate(_Count);
00564 _Traits::copy(_Pnew, _Ptr, _Count);
00565 _Seekhigh = _Pnew + _Count;
00566
00567
00568 if (!(_Mystate & _Noread))
00569 _Mysb::setg(_Pnew, _Pnew,
00570 _Pnew + _Count);
00571
00572 if (!(_Mystate & _Constant))
00573 {
00574 _Mysb::setp(_Pnew, _Pnew + _Count);
00575 if (_Mysb::gptr() == 0)
00576 _Mysb::setg(_Pnew, 0, _Pnew);
00577 }
00578 _Mystate |= _Allocated;
00579 }
00580 }
00581
00582 void _Tidy()
00583 {
00584 if (_Mystate & _Allocated)
00585 _Al.deallocate(_Mysb::eback(),
00586 (_Mysb::pptr() != 0 ? _Mysb::epptr()
00587 : _Mysb::egptr()) - _Mysb::eback());
00588 _Mysb::setg(0, 0, 0);
00589 _Mysb::setp(0, 0);
00590 _Seekhigh = 0;
00591 _Mystate &= ~_Allocated;
00592 }
00593
00594 protected:
00595 enum
00596 {
00597 _MINSIZE = 32
00598 };
00599
00600 _Strstate _Getstate(openmode _Mode)
00601 {
00602 _Strstate _State = (_Strstate)0;
00603 if (!(_Mode & std::ios_base::in))
00604 _State |= _Noread;
00605 if (!(_Mode & std::ios_base::out))
00606 _State |= _Constant;
00607 if (_Mode & std::ios_base::app)
00608 _State |= _Append;
00609 return (_State);
00610 }
00611
00612 _Elem *_Seekhigh;
00613 _Strstate _Mystate;
00614 allocator_type _Al;
00615 };
00616
00617
00618 typedef basic_kokobuf< char, std::char_traits<char>, std::allocator<char> >
00619 kokobuf;
00620
00621 typedef gutz::SmartPtr<kokobuf> kokobufSP;
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643 template<
00644 class _Elem,
00645 class _Traits,
00646 class _Alloc
00647 >
00648 class basic_ikokostream
00649 : public std::basic_istream<_Elem, _Traits>
00650 {
00651 public:
00652 typedef _Alloc allocator_type;
00653
00654 typedef basic_kokobuf<_Elem, _Traits, _Alloc> _Mysb;
00655
00656 typedef std::basic_string<_Elem, _Traits, _Alloc> _Mystr;
00657
00658
00659
00660 explicit basic_ikokostream(_Mysb *sb)
00661 : std::basic_istream<_Elem, _Traits>(sb),
00662 _kokobuffer(sb)
00663 {
00664 }
00665
00666
00667
00668 virtual ~basic_ikokostream()
00669 {
00670 }
00671
00672
00673
00674 void setStreamBuffer(_Mysb *sb)
00675 {
00676 _kokobuffer = sb;
00677 clear();
00678 std::basic_istream<_Elem, _Traits>::basic_istream<_Elem,_Traits>((_Mysb*)_kokobuffer);
00679 }
00680
00681
00682 gutz::SmartPtr<_Mysb> getStreamBuffer() { return _kokobuffer; }
00683
00684
00685
00686 _Mysb *rdbuf() const
00687 {
00688 return (_kokobuffer.getPtr());
00689 }
00690
00691
00692
00693 _Mystr str() const
00694 {
00695 return (_kokobuffer->str());
00696 }
00697
00698
00699
00700 void str(const _Mystr& _Newstr)
00701 {
00702 _kokobuffer->str(_Newstr);
00703 }
00704
00705 protected:
00706 gutz::SmartPtr<_Mysb> _kokobuffer;
00707 };
00708
00709
00710 typedef basic_ikokostream<char, std::char_traits<char>, std::allocator<char> >
00711 ikokostream;
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733 template<
00734 class _Elem,
00735 class _Traits,
00736 class _Alloc
00737 >
00738 class basic_okokostream
00739 : public std::basic_ostream<_Elem, _Traits>
00740 {
00741 public:
00742 typedef _Alloc allocator_type;
00743 typedef basic_kokobuf<_Elem, _Traits, _Alloc> _Mysb;
00744 typedef std::basic_string<_Elem, _Traits, _Alloc> _Mystr;
00745
00746 explicit basic_okokostream(_Mysb *sb)
00747 : std::basic_ostream<_Elem, _Traits>(sb),
00748 _kokobuffer(sb)
00749 {
00750
00751 }
00752
00753 virtual ~basic_okokostream()
00754 {
00755 }
00756
00757 void setStreamBuffer(_Mysb *sb)
00758 {
00759 _kokobuffer = sb;
00760 clear();
00761 std::basic_ostream<_Elem, _Traits>::basic_ostream<_Elem, _Traits>((_Mysb*)_kokobuffer);
00762 }
00763
00764
00765 gutz::SmartPtr<_Mysb> getStreamBuffer() { return _kokobuffer; }
00766
00767 _Mysb *rdbuf() const
00768 {
00769 return (_kokobuffer.getPtr());
00770 }
00771
00772 _Mystr str() const
00773 {
00774 return (_kokobuffer->str());
00775 }
00776
00777 void str(const _Mystr& _Newstr)
00778 {
00779 _kokobuffer->str(_Newstr);
00780 }
00781
00782 protected:
00783 gutz::SmartPtr<_Mysb> _kokobuffer;
00784 };
00785
00786 typedef basic_okokostream<char, std::char_traits<char>, std::allocator<char> >
00787 okokostream;
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807 template<
00808 class _Elem,
00809 class _Traits,
00810 class _Alloc
00811 >
00812 class basic_kokostream
00813 : public std::basic_iostream<_Elem, _Traits>
00814 {
00815 public:
00816 typedef _Elem char_type;
00817 typedef _Traits traits_type;
00818 typedef _Alloc allocator_type;
00819 typedef typename _Traits::int_type int_type;
00820 typedef typename _Traits::pos_type pos_type;
00821 typedef typename _Traits::off_type off_type;
00822 typedef basic_kokobuf<_Elem, _Traits, _Alloc> _Mysb;
00823 typedef std::basic_string<_Elem, _Traits, _Alloc> _Mystr;
00824
00825 explicit basic_kokostream(_Mysb *sb)
00826 : std::basic_iostream<_Elem, _Traits>(sb),
00827 _kokobuffer(sb)
00828 {
00829 }
00830
00831 virtual ~basic_kokostream()
00832 {
00833 }
00834
00835 void setStreamBuffer(_Mysb *sp)
00836 {
00837 _kokobuffer = sp;
00838 clear();
00839 std::basic_iostream<_Elem, _Traits>::basic_iostream<_Elem, _Traits>(_kokobuffer);
00840 }
00841
00842
00843
00844 gutz::SmartPtr<_Mysb> getStreamBuffer() { return _kokobuffer; }
00845
00846 _Mysb *rdbuf() const
00847 {
00848 return (_kokobuffer.getPtr());
00849 }
00850
00851 _Mystr str() const
00852 {
00853 return (_kokobuffer->str());
00854 }
00855
00856 void str(const _Mystr& _Newstr)
00857 {
00858 _kokobuffer->str(_Newstr);
00859 }
00860
00861 protected:
00862 gutz::SmartPtr<_Mysb> _kokobuffer;
00863 };
00864
00865 typedef basic_kokostream<char, std::char_traits<char>, std::allocator<char> >
00866 kokostream;
00867
00868
00869
00870
00871
00872
00873
00874
00875 #endif // catch include
00876