home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stlpt453.zip / STLport-4.5.3 / stlport / stl / _streambuf.c < prev    next >
C/C++ Source or Header  |  2002-02-02  |  6KB  |  217 lines

  1. /*
  2.  * Copyright (c) 1999
  3.  * Silicon Graphics Computer Systems, Inc.
  4.  *
  5.  * Copyright (c) 1999 
  6.  * Boris Fomitchev
  7.  *
  8.  * This material is provided "as is", with absolutely no warranty expressed
  9.  * or implied. Any use is at your own risk.
  10.  *
  11.  * Permission to use or copy this software for any purpose is hereby granted 
  12.  * without fee, provided the above notices are retained on all copies.
  13.  * Permission to modify the code and to distribute modified code is granted,
  14.  * provided the above notices are retained, and a notice that the code was
  15.  * modified is included with the above copyright notice.
  16.  *
  17.  */ 
  18. #ifndef _STLP_STREAMBUF_C
  19. #define _STLP_STREAMBUF_C
  20.  
  21. #ifndef _STLP_INTERNAL_STREAMBUF
  22. # include <stl/_streambuf.h>
  23. #endif
  24.  
  25. # if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION)
  26.  
  27. _STLP_BEGIN_NAMESPACE
  28. //----------------------------------------------------------------------
  29. // Non-inline basic_streambuf<> member functions.
  30.  
  31. template <class _CharT, class _Traits>
  32. basic_streambuf<_CharT, _Traits>::basic_streambuf()
  33.   : _M_gbegin(0), _M_gnext(0), _M_gend(0),
  34.     _M_pbegin(0), _M_pnext(0), _M_pend(0),
  35.     _M_locale()
  36. {
  37.   //  _M_lock._M_initialize();
  38. }
  39.  
  40. template <class _CharT, class _Traits>
  41. basic_streambuf<_CharT, _Traits>::~basic_streambuf() 
  42. {}
  43.  
  44.  
  45. template <class _CharT, class _Traits>
  46. locale 
  47. basic_streambuf<_CharT, _Traits>::pubimbue(const locale& __loc) {
  48.   this->imbue(__loc);
  49.   locale __tmp = _M_locale;
  50.   _M_locale = __loc;
  51.   return __tmp;
  52. }
  53.  
  54. template <class _CharT, class _Traits>
  55. streamsize
  56. basic_streambuf<_CharT, _Traits>::xsgetn(_CharT* __s, streamsize __n)
  57. {
  58.   streamsize __result = 0;
  59.   const int_type __eof = _Traits::eof();
  60.  
  61.   while (__result < __n) {
  62.     if (_M_gnext < _M_gend) {
  63.       size_t __chunk = (min) (__STATIC_CAST(size_t,_M_gend - _M_gnext),
  64.                            __STATIC_CAST(size_t,__n - __result));
  65.       _Traits::copy(__s, _M_gnext, __chunk);
  66.       __result += __chunk;
  67.       __s += __chunk;
  68.       _M_gnext += __chunk;
  69.     }
  70.     else {
  71.       int_type __c = this->sbumpc();
  72.       if (!_Traits::eq_int_type(__c, __eof)) {
  73.         *__s = __c;
  74.         ++__result;
  75.     ++__s;
  76.       }
  77.       else
  78.         break; 
  79.     }
  80.   }
  81.   
  82.   return __result;
  83. }
  84.  
  85. template <class _CharT, class _Traits>
  86. streamsize
  87. basic_streambuf<_CharT, _Traits>::xsputn(const _CharT* __s, streamsize __n)
  88. {
  89.   streamsize __result = 0;
  90.   const int_type __eof = _Traits::eof();
  91.  
  92.   while (__result < __n) {
  93.     if (_M_pnext < _M_pend) {
  94.       size_t __chunk = (min) (__STATIC_CAST(size_t,_M_pend - _M_pnext),
  95.                            __STATIC_CAST(size_t,__n - __result));
  96.       _Traits::copy(_M_pnext, __s, __chunk);
  97.       __result += __chunk;
  98.       __s += __chunk;
  99.       _M_pnext += __chunk;
  100.     }
  101.  
  102.     else if (!_Traits::eq_int_type(this->overflow(_Traits::to_int_type(*__s)),
  103.                                    __eof)) {
  104.       ++__result;
  105.       ++__s;
  106.     }
  107.     else
  108.       break;
  109.   }
  110.   return __result;
  111. }
  112.  
  113. template <class _CharT, class _Traits>
  114. streamsize
  115. basic_streambuf<_CharT, _Traits>::_M_xsputnc(_CharT __c, streamsize __n)
  116. {
  117.   streamsize __result = 0;
  118.   const int_type __eof = _Traits::eof();
  119.  
  120.   while (__result < __n) {
  121.     if (_M_pnext < _M_pend) {
  122.       size_t __chunk = (min) (__STATIC_CAST(size_t,_M_pend - _M_pnext),
  123.                            __STATIC_CAST(size_t,__n - __result));
  124.       _Traits::assign(_M_pnext, __chunk, __c);
  125.       __result += __chunk;
  126.       _M_pnext += __chunk;
  127.     }
  128.  
  129.     else if (!_Traits::eq_int_type(this->overflow(_Traits::to_int_type(__c)),
  130.                                    __eof))
  131.       ++__result;
  132.     else
  133.       break;
  134.   }
  135.   return __result;
  136. }
  137.  
  138. template <class _CharT, class _Traits>
  139. _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type 
  140. basic_streambuf<_CharT, _Traits>::_M_snextc_aux()  
  141. {
  142.   int_type __eof = _Traits::eof();
  143.   if (_M_gend == _M_gnext)
  144.     return _Traits::eq_int_type(this->uflow(), __eof) ? __eof : this->sgetc();
  145.   else {
  146.     _M_gnext = _M_gend;
  147.     return this->underflow();
  148.   }
  149. }
  150.  
  151. template <class _CharT, class _Traits>
  152. _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type 
  153. basic_streambuf<_CharT, _Traits>::pbackfail(int_type) { 
  154.  return _Traits::eof(); 
  155. }
  156.  
  157. template <class _CharT, class _Traits>
  158. _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type 
  159. basic_streambuf<_CharT, _Traits>::overflow(int_type) { 
  160.   return _Traits::eof(); 
  161. }
  162.  
  163. template <class _CharT, class _Traits>
  164. _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type 
  165. basic_streambuf<_CharT, _Traits>::uflow() {
  166.     return ( _Traits::eq_int_type(this->underflow(),_Traits::eof()) ?
  167.              _Traits::eof() :
  168.              _Traits::to_int_type(*_M_gnext++));
  169. }
  170.  
  171. template <class _CharT, class _Traits>
  172. _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type 
  173. basic_streambuf<_CharT, _Traits>::underflow()
  174. { return _Traits::eof(); }
  175.  
  176. template <class _CharT, class _Traits>
  177. streamsize 
  178. basic_streambuf<_CharT, _Traits>::showmanyc()
  179. { return 0; }
  180.  
  181. template <class _CharT, class _Traits>
  182. void 
  183. basic_streambuf<_CharT, _Traits>::imbue(const locale&) {}
  184.  
  185. template <class _CharT, class _Traits>
  186. int
  187. basic_streambuf<_CharT, _Traits>::sync() { return 0; }
  188.  
  189. template <class _CharT, class _Traits>
  190. _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::pos_type 
  191. basic_streambuf<_CharT, _Traits>::seekpos(pos_type, ios_base::openmode)
  192. { return pos_type(-1); }
  193.  
  194. template <class _CharT, class _Traits>
  195. _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::pos_type 
  196. basic_streambuf<_CharT, _Traits>::seekoff(off_type, ios_base::seekdir,
  197.                       ios_base::openmode)
  198. { return pos_type(-1); }
  199.  
  200. template <class _CharT, class _Traits>
  201. basic_streambuf<_CharT, _Traits>* 
  202. basic_streambuf<_CharT, _Traits>:: setbuf(char_type*, streamsize)
  203. { return this; }
  204.  
  205.  
  206. # if defined (_STLP_USE_TEMPLATE_EXPORT)
  207. #  if !defined (_STLP_NO_WCHAR_T)
  208. _STLP_EXPORT_TEMPLATE_CLASS basic_streambuf<wchar_t, char_traits<wchar_t> >;
  209. #  endif
  210. # endif /* _STLP_USE_TEMPLATE_EXPORT */
  211.  
  212. _STLP_END_NAMESPACE
  213.  
  214. # endif /* EXPOSE */
  215.  
  216. #endif
  217.