_streambuf.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. #ifndef _STLP_INTERNAL_STREAMBUF
  21. # include <stl/_streambuf.h>
  22. #endif
  23. _STLP_BEGIN_NAMESPACE
  24. //----------------------------------------------------------------------
  25. // Non-inline basic_streambuf<> member functions.
  26. #if !defined (_STLP_MSVC) || (_STLP_MSVC >= 1300) || !defined (_STLP_USE_STATIC_LIB)
  27. template <class _CharT, class _Traits>
  28. basic_streambuf<_CharT, _Traits>::basic_streambuf()
  29. : _M_gbegin(0), _M_gnext(0), _M_gend(0),
  30. _M_pbegin(0), _M_pnext(0), _M_pend(0),
  31. _M_locale() {
  32. // _M_lock._M_initialize();
  33. }
  34. #endif
  35. template <class _CharT, class _Traits>
  36. basic_streambuf<_CharT, _Traits>::~basic_streambuf()
  37. {}
  38. template <class _CharT, class _Traits>
  39. locale
  40. basic_streambuf<_CharT, _Traits>::pubimbue(const locale& __loc) {
  41. this->imbue(__loc);
  42. locale __tmp = _M_locale;
  43. _M_locale = __loc;
  44. return __tmp;
  45. }
  46. template <class _CharT, class _Traits>
  47. streamsize
  48. basic_streambuf<_CharT, _Traits>::xsgetn(_CharT* __s, streamsize __n) {
  49. streamsize __result = 0;
  50. const int_type __eof = _Traits::eof();
  51. while (__result < __n) {
  52. if (_M_gnext < _M_gend) {
  53. size_t __chunk = (min) (__STATIC_CAST(size_t,_M_gend - _M_gnext),
  54. __STATIC_CAST(size_t,__n - __result));
  55. _Traits::copy(__s, _M_gnext, __chunk);
  56. __result += __chunk;
  57. __s += __chunk;
  58. _M_gnext += __chunk;
  59. }
  60. else {
  61. int_type __c = this->sbumpc();
  62. if (!_Traits::eq_int_type(__c, __eof)) {
  63. *__s = _Traits::to_char_type(__c);
  64. ++__result;
  65. ++__s;
  66. }
  67. else
  68. break;
  69. }
  70. }
  71. return __result;
  72. }
  73. template <class _CharT, class _Traits>
  74. streamsize
  75. basic_streambuf<_CharT, _Traits>::xsputn(const _CharT* __s, streamsize __n)
  76. {
  77. streamsize __result = 0;
  78. const int_type __eof = _Traits::eof();
  79. while (__result < __n) {
  80. if (_M_pnext < _M_pend) {
  81. size_t __chunk = (min) (__STATIC_CAST(size_t,_M_pend - _M_pnext),
  82. __STATIC_CAST(size_t,__n - __result));
  83. _Traits::copy(_M_pnext, __s, __chunk);
  84. __result += __chunk;
  85. __s += __chunk;
  86. _M_pnext += __chunk;
  87. }
  88. else if (!_Traits::eq_int_type(this->overflow(_Traits::to_int_type(*__s)),
  89. __eof)) {
  90. ++__result;
  91. ++__s;
  92. }
  93. else
  94. break;
  95. }
  96. return __result;
  97. }
  98. template <class _CharT, class _Traits>
  99. streamsize
  100. basic_streambuf<_CharT, _Traits>::_M_xsputnc(_CharT __c, streamsize __n)
  101. {
  102. streamsize __result = 0;
  103. const int_type __eof = _Traits::eof();
  104. while (__result < __n) {
  105. if (_M_pnext < _M_pend) {
  106. size_t __chunk = (min) (__STATIC_CAST(size_t,_M_pend - _M_pnext),
  107. __STATIC_CAST(size_t,__n - __result));
  108. _Traits::assign(_M_pnext, __chunk, __c);
  109. __result += __chunk;
  110. _M_pnext += __chunk;
  111. }
  112. else if (!_Traits::eq_int_type(this->overflow(_Traits::to_int_type(__c)),
  113. __eof))
  114. ++__result;
  115. else
  116. break;
  117. }
  118. return __result;
  119. }
  120. template <class _CharT, class _Traits>
  121. _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type
  122. basic_streambuf<_CharT, _Traits>::_M_snextc_aux()
  123. {
  124. int_type __eof = _Traits::eof();
  125. if (_M_gend == _M_gnext)
  126. return _Traits::eq_int_type(this->uflow(), __eof) ? __eof : this->sgetc();
  127. else {
  128. _M_gnext = _M_gend;
  129. return this->underflow();
  130. }
  131. }
  132. template <class _CharT, class _Traits>
  133. _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type
  134. basic_streambuf<_CharT, _Traits>::pbackfail(int_type) {
  135. return _Traits::eof();
  136. }
  137. template <class _CharT, class _Traits>
  138. _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type
  139. basic_streambuf<_CharT, _Traits>::overflow(int_type) {
  140. return _Traits::eof();
  141. }
  142. template <class _CharT, class _Traits>
  143. _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type
  144. basic_streambuf<_CharT, _Traits>::uflow() {
  145. return ( _Traits::eq_int_type(this->underflow(),_Traits::eof()) ?
  146. _Traits::eof() :
  147. _Traits::to_int_type(*_M_gnext++));
  148. }
  149. template <class _CharT, class _Traits>
  150. _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type
  151. basic_streambuf<_CharT, _Traits>::underflow()
  152. { return _Traits::eof(); }
  153. template <class _CharT, class _Traits>
  154. streamsize
  155. basic_streambuf<_CharT, _Traits>::showmanyc()
  156. { return 0; }
  157. template <class _CharT, class _Traits>
  158. void
  159. basic_streambuf<_CharT, _Traits>::imbue(const locale&) {}
  160. template <class _CharT, class _Traits>
  161. int
  162. basic_streambuf<_CharT, _Traits>::sync() { return 0; }
  163. template <class _CharT, class _Traits>
  164. _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::pos_type
  165. basic_streambuf<_CharT, _Traits>::seekpos(pos_type, ios_base::openmode)
  166. { return pos_type(-1); }
  167. template <class _CharT, class _Traits>
  168. _STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::pos_type
  169. basic_streambuf<_CharT, _Traits>::seekoff(off_type, ios_base::seekdir,
  170. ios_base::openmode)
  171. { return pos_type(-1); }
  172. template <class _CharT, class _Traits>
  173. basic_streambuf<_CharT, _Traits>*
  174. basic_streambuf<_CharT, _Traits>:: setbuf(char_type*, streamsize)
  175. { return this; }
  176. _STLP_END_NAMESPACE
  177. #endif
  178. // Local Variables:
  179. // mode:C++
  180. // End: