Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

210 lines
6.1 KiB

  1. // streambuf standard header
  2. #ifndef _STREAMBUF_
  3. #define _STREAMBUF_
  4. #include <xlocnum>
  5. #ifdef _MSC_VER
  6. #pragma pack(push,8)
  7. #endif /* _MSC_VER */
  8. _STD_BEGIN
  9. // TEMPLATE CLASS basic_streambuf
  10. template<class _E, class _Tr = char_traits<_E> >
  11. class basic_streambuf {
  12. protected:
  13. basic_streambuf()
  14. : _Loc() {_Init(); }
  15. basic_streambuf(_Uninitialized)
  16. : _Loc(_Noinit) {}
  17. public:
  18. typedef basic_streambuf<_E, _Tr> _Myt;
  19. typedef _E char_type;
  20. typedef _Tr traits_type;
  21. virtual ~basic_streambuf()
  22. {}
  23. typedef _Tr::int_type int_type;
  24. typedef _Tr::pos_type pos_type;
  25. typedef _Tr::off_type off_type;
  26. pos_type pubseekoff(off_type _O, ios_base::seekdir _W,
  27. ios_base::openmode _M = ios_base::in | ios_base::out)
  28. {return (seekoff(_O, _W, _M)); }
  29. pos_type pubseekoff(off_type _O, ios_base::seek_dir _W,
  30. ios_base::open_mode _M)
  31. {return (pubseekoff(_O, (ios_base::seekdir)_W,
  32. (ios_base::openmode)_M)); }
  33. pos_type pubseekpos(pos_type _P,
  34. ios_base::openmode _M = ios_base::in | ios_base::out)
  35. {return (seekpos(_P, _M)); }
  36. pos_type pubseekpos(pos_type _P, ios_base::open_mode _M)
  37. {return (seekpos(_P, (ios_base::openmode)_M)); }
  38. _Myt *pubsetbuf(_E *_S, streamsize _N)
  39. {return (setbuf(_S, _N)); }
  40. locale pubimbue(const locale &_Ln)
  41. {locale _Lo = _Loc;
  42. imbue(_Ln);
  43. _Loc = _Ln;
  44. return (_Lo); }
  45. locale getloc()
  46. {return (_Loc); }
  47. streamsize in_avail()
  48. {return (gptr() != 0 && gptr() < egptr()
  49. ? egptr() - gptr() : showmanyc()); }
  50. int pubsync()
  51. {return (sync()); }
  52. int_type sbumpc()
  53. {return (gptr() != 0 && gptr() < egptr()
  54. ? _Tr::to_int_type(*_Gninc()) : uflow()); }
  55. int_type sgetc()
  56. {return (gptr() != 0 && gptr() < egptr()
  57. ? _Tr::to_int_type(*gptr()) : underflow()); }
  58. streamsize sgetn(_E *_S, streamsize _N)
  59. {return (xsgetn(_S, _N)); }
  60. int_type snextc()
  61. {return (_Tr::eq_int_type(_Tr::eof(), sbumpc())
  62. ? _Tr::eof() : sgetc()); }
  63. int_type sputbackc(_E _C)
  64. {return (gptr() != 0 && eback() < gptr()
  65. && _Tr::eq(_C, gptr()[-1])
  66. ? _Tr::to_int_type(*_Gndec())
  67. : pbackfail(_Tr::to_int_type(_C))); }
  68. void stossc()
  69. {if (gptr() != 0 && gptr() < egptr())
  70. _Gninc();
  71. else
  72. uflow(); }
  73. int_type sungetc()
  74. {return (gptr() != 0 && eback() < gptr()
  75. ? _Tr::to_int_type(*_Gndec()) : pbackfail()); }
  76. int_type sputc(_E _C)
  77. {return (pptr() != 0 && pptr() < epptr()
  78. ? _Tr::to_int_type(*_Pninc() = _C)
  79. : overflow(_Tr::to_int_type(_C))); }
  80. streamsize sputn(const _E *_S, streamsize _N)
  81. {return (xsputn(_S, _N)); }
  82. protected:
  83. _E *eback() const
  84. {return (*_IGbeg); }
  85. _E *gptr() const
  86. {return (*_IGnext); }
  87. _E *pbase() const
  88. {return (*_IPbeg); }
  89. _E *pptr() const
  90. {return (*_IPnext); }
  91. _E *egptr() const
  92. {return (*_IGnext + *_IGcnt); }
  93. void gbump(int _N)
  94. {*_IGcnt -= _N;
  95. *_IGnext += _N; }
  96. void setg(_E *_B, _E *_N, _E *_L)
  97. {*_IGbeg = _B, *_IGnext = _N, *_IGcnt = (int) (_L - _N); }
  98. _E *epptr() const
  99. {return (*_IPnext + *_IPcnt); }
  100. _E *_Gndec()
  101. {++*_IGcnt;
  102. return (--*_IGnext); }
  103. _E *_Gninc()
  104. {--*_IGcnt;
  105. return ((*_IGnext)++); }
  106. void pbump(int _N)
  107. {*_IPcnt -= _N;
  108. *_IPnext += _N; }
  109. void setp(_E *_B, _E *_L)
  110. {*_IPbeg = _B, *_IPnext = _B, *_IPcnt = (int) (_L - _B); }
  111. void setp(_E *_B, _E *_N, _E *_L)
  112. {*_IPbeg = _B, *_IPnext = _N, *_IPcnt = (int) (_L - _N); }
  113. _E *_Pninc()
  114. {--*_IPcnt;
  115. return ((*_IPnext)++); }
  116. void _Init()
  117. {_IGbeg = &_Gbeg, _IPbeg = &_Pbeg;
  118. _IGnext = &_Gnext, _IPnext = &_Pnext;
  119. _IGcnt = &_Gcnt, _IPcnt = &_Pcnt;
  120. setp(0, 0), setg(0, 0, 0); }
  121. void _Init(_E **_Gb, _E **_Gn, int *_Gc,
  122. _E **_Pb, _E **_Pn, int *_Pc)
  123. {_IGbeg = _Gb, _IPbeg = _Pb;
  124. _IGnext = _Gn, _IPnext = _Pn;
  125. _IGcnt = _Gc, _IPcnt = _Pc; }
  126. virtual int_type overflow(int_type = _Tr::eof())
  127. {return (_Tr::eof()); }
  128. virtual int_type pbackfail(int_type = _Tr::eof())
  129. {return (_Tr::eof()); }
  130. virtual int showmanyc()
  131. {return (0); }
  132. virtual int_type underflow()
  133. {return (_Tr::eof()); }
  134. virtual int_type uflow()
  135. {return (_Tr::eq_int_type(_Tr::eof(), underflow())
  136. ? _Tr::eof() : _Tr::to_int_type(*_Gninc())); }
  137. virtual streamsize xsgetn(_E * _S, streamsize _N)
  138. {int_type _C;
  139. streamsize _M, _Ns;
  140. for (_Ns = 0; 0 < _N; )
  141. if (gptr() != 0 && 0 < (_M = (streamsize) (egptr() - gptr())))
  142. {if (_N < _M)
  143. _M = _N;
  144. _Tr::copy(_S, gptr(), _M);
  145. _S += _M, _Ns += _M, _N -= _M, gbump((int)_M); }
  146. else if (_Tr::eq_int_type(_Tr::eof(), _C = uflow()))
  147. break;
  148. else
  149. *_S++ = _Tr::to_char_type(_C), ++_Ns, --_N;
  150. return (_Ns); }
  151. virtual streamsize xsputn(const _E *_S, streamsize _N)
  152. {streamsize _M, _Ns;
  153. for (_Ns = 0; 0 < _N; )
  154. if (pptr() != 0 && 0 < (_M = (streamsize) (epptr() - pptr())))
  155. {if (_N < _M)
  156. _M = _N;
  157. _Tr::copy(pptr(), _S, _M);
  158. _S += _M, _Ns += _M, _N -= _M, pbump((int)_M); }
  159. else if (_Tr::eq_int_type(_Tr::eof(),
  160. overflow(_Tr::to_int_type(*_S))))
  161. break;
  162. else
  163. ++_S, ++_Ns, --_N;
  164. return (_Ns); }
  165. virtual pos_type seekoff(off_type, ios_base::seekdir,
  166. ios_base::openmode = ios_base::in | ios_base::out)
  167. {return (streampos(_BADOFF)); }
  168. virtual pos_type seekpos(pos_type,
  169. ios_base::openmode = ios_base::in | ios_base::out)
  170. {return (streampos(_BADOFF)); }
  171. virtual _Myt *setbuf(_E *, streamsize)
  172. {return (this); }
  173. virtual int sync()
  174. {return (0); }
  175. virtual void imbue(const locale& _Loc)
  176. {}
  177. private:
  178. _E *_Gbeg, *_Pbeg;
  179. _E **_IGbeg, **_IPbeg;
  180. _E *_Gnext, *_Pnext;
  181. _E **_IGnext, **_IPnext;
  182. int _Gcnt, _Pcnt;
  183. int *_IGcnt, *_IPcnt;
  184. locale _Loc;
  185. };
  186. #ifdef _DLL
  187. #ifdef __FORCE_INSTANCE
  188. template class _CRTIMP2 basic_streambuf<char, char_traits<char> >;
  189. template class _CRTIMP2 basic_streambuf<wchar_t, char_traits<wchar_t> >;
  190. #else // __FORCE_INSTANCE
  191. #pragma warning(disable:4231) /* the extern before template is a non-standard extension */
  192. extern template class _CRTIMP2 basic_streambuf<char, char_traits<char> >;
  193. extern template class _CRTIMP2 basic_streambuf<wchar_t, char_traits<wchar_t> >;
  194. #pragma warning(default:4231) /* restore previous warning */
  195. #endif // __FORCE_INSTANCE
  196. #endif // _DLL
  197. _STD_END
  198. #ifdef _MSC_VER
  199. #pragma pack(pop)
  200. #endif /* _MSC_VER */
  201. #endif /* _STREAMBUF_ */
  202. /*
  203. * Copyright (c) 1994 by P.J. Plauger. ALL RIGHTS RESERVED.
  204. * Consult your license regarding permissions and restrictions.
  205. */