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.

238 lines
7.2 KiB

  1. /***
  2. *streamb.h - definitions/declarations for the streambuf class
  3. *
  4. * Copyright (c) 1990-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * This file defines the classes, values, macros, and functions
  8. * used by the streambuf class.
  9. * [AT&T C++]
  10. *
  11. * [Public]
  12. *
  13. *Revision History:
  14. * 01-23-92 KRS Ported from 16-bit version.
  15. * 03-02-92 KRS Added locks for multithread support.
  16. * 06-03-92 KRS For convenience, add NULL here too.
  17. * 02-23-93 SKS Update copyright to 1993
  18. * 03-23-93 CFW Modified #pragma warnings.
  19. * 10-12-93 GJF Support NT and Cuda versions. Deleted obsolete
  20. * COMBOINC check. Enclose #pragma-s in #ifdef _MSC_VER
  21. * 01-18-94 SKS Add _mtlockterm() as d-tor version of _mtlockinit()
  22. * 03-03-94 SKS Add __cdecl keyword to _mt*lock* functions.
  23. * _mtlockinit & _mtlockterm are for internal use only.
  24. * Prepend _'s to some parameter names (ANSI compliance)
  25. * 08-12-94 GJF Disable warning 4514 instead of 4505.
  26. * 11-03-94 GJF Changed pack pragma to 8 byte alignment.
  27. * 02-11-95 CFW Add _CRTBLD to avoid users getting wrong headers.
  28. * 02-14-95 CFW Clean up Mac merge.
  29. * 05-11-95 CFW Only for use by C++ programs.
  30. * 12-14-95 JWM Add "#pragma once".
  31. * 04-09-96 SKS Change _CRTIMP to _CRTIMP1 for special iostream build
  32. * 04-15-96 JWM Remove _OLD_IOSTREAMS, add '#pragma comment(lib,"cirt")'.
  33. * 04-16-96 JWM '#include useoldio.h' replaces '#pragma comment(...)'.
  34. * 02-24-97 GJF Cleaned out obsolete support for _NTSDK. Also,
  35. * detab-ed.
  36. * 05-17-99 PML Remove all Macintosh support.
  37. *
  38. ****/
  39. #if _MSC_VER > 1000 /*IFSTRIP=IGN*/
  40. #pragma once
  41. #endif
  42. #ifdef __cplusplus
  43. #ifndef _INC_STREAMB
  44. #define _INC_STREAMB
  45. #if !defined(_WIN32)
  46. #error ERROR: Only Win32 target supported!
  47. #endif
  48. #ifndef _CRTBLD
  49. /* This version of the header files is NOT for user programs.
  50. * It is intended for use when building the C runtimes ONLY.
  51. * The version intended for public use will not have this message.
  52. */
  53. #error ERROR: Use of C runtime library internal header file.
  54. #endif /* _CRTBLD */
  55. #ifdef _MSC_VER
  56. // Currently, all MS C compilers for Win32 platforms default to 8 byte
  57. // alignment.
  58. #pragma pack(push,8)
  59. #include <useoldio.h>
  60. #endif // _MSC_VER
  61. /* Define _CRTIMP */
  62. #ifndef _CRTIMP
  63. #ifdef CRTDLL
  64. #define _CRTIMP __declspec(dllexport)
  65. #else /* ndef CRTDLL */
  66. #ifdef _DLL
  67. #define _CRTIMP __declspec(dllimport)
  68. #else /* ndef _DLL */
  69. #define _CRTIMP
  70. #endif /* _DLL */
  71. #endif /* CRTDLL */
  72. #endif /* _CRTIMP */
  73. #ifndef _INTERNAL_IFSTRIP_
  74. /* Define _CRTIMP1 */
  75. #ifndef _CRTIMP1
  76. #ifdef CRTDLL1
  77. #define _CRTIMP1 __declspec(dllexport)
  78. #else /* ndef CRTDLL1 */
  79. #define _CRTIMP1 _CRTIMP
  80. #endif /* CRTDLL1 */
  81. #endif /* _CRTIMP1 */
  82. #endif /* _INTERNAL_IFSTRIP_ */
  83. #include <ios.h> // need ios::seek_dir definition
  84. #ifndef NULL
  85. #define NULL 0
  86. #endif
  87. #ifndef EOF
  88. #define EOF (-1)
  89. #endif
  90. #ifdef _MSC_VER
  91. // C4514: "unreferenced inline function has been removed"
  92. #pragma warning(disable:4514) // disable C4514 warning
  93. // #pragma warning(default:4514) // use this to reenable, if desired
  94. #endif // _MSC_VER
  95. typedef long streampos, streamoff;
  96. class _CRTIMP1 ios;
  97. class _CRTIMP1 streambuf {
  98. public:
  99. virtual ~streambuf();
  100. inline int in_avail() const;
  101. inline int out_waiting() const;
  102. int sgetc();
  103. int snextc();
  104. int sbumpc();
  105. void stossc();
  106. inline int sputbackc(char);
  107. inline int sputc(int);
  108. inline int sputn(const char *,int);
  109. inline int sgetn(char *,int);
  110. virtual int sync();
  111. virtual streambuf* setbuf(char *, int);
  112. virtual streampos seekoff(streamoff,ios::seek_dir,int =ios::in|ios::out);
  113. virtual streampos seekpos(streampos,int =ios::in|ios::out);
  114. virtual int xsputn(const char *,int);
  115. virtual int xsgetn(char *,int);
  116. virtual int overflow(int =EOF) = 0; // pure virtual function
  117. virtual int underflow() = 0; // pure virtual function
  118. virtual int pbackfail(int);
  119. void dbp();
  120. #ifdef _MT
  121. void setlock() { LockFlg--; } // <0 indicates lock required;
  122. void clrlock() { if (LockFlg <= 0) LockFlg++; }
  123. void lock() { if (LockFlg<0) _mtlock(lockptr()); };
  124. void unlock() { if (LockFlg<0) _mtunlock(lockptr()); }
  125. #else
  126. void lock() { }
  127. void unlock() { }
  128. #endif
  129. protected:
  130. streambuf();
  131. streambuf(char *,int);
  132. inline char * base() const;
  133. inline char * ebuf() const;
  134. inline char * pbase() const;
  135. inline char * pptr() const;
  136. inline char * epptr() const;
  137. inline char * eback() const;
  138. inline char * gptr() const;
  139. inline char * egptr() const;
  140. inline int blen() const;
  141. inline void setp(char *,char *);
  142. inline void setg(char *,char *,char *);
  143. inline void pbump(int);
  144. inline void gbump(int);
  145. void setb(char *,char *,int =0);
  146. inline int unbuffered() const;
  147. inline void unbuffered(int);
  148. int allocate();
  149. virtual int doallocate();
  150. #ifdef _MT
  151. _PCRT_CRITICAL_SECTION lockptr() { return & x_lock; }
  152. #endif
  153. private:
  154. int _fAlloc;
  155. int _fUnbuf;
  156. int x_lastc;
  157. char * _base;
  158. char * _ebuf;
  159. char * _pbase;
  160. char * _pptr;
  161. char * _epptr;
  162. char * _eback;
  163. char * _gptr;
  164. char * _egptr;
  165. #ifdef _MT
  166. int LockFlg; // <0 indicates locking required
  167. _CRT_CRITICAL_SECTION x_lock; // lock needed only for multi-thread operation
  168. #endif
  169. };
  170. inline int streambuf::in_avail() const { return (gptr()<_egptr) ? (int)(_egptr-gptr()) : 0; }
  171. inline int streambuf::out_waiting() const { return (_pptr>=_pbase) ? (int)(_pptr-_pbase) : 0; }
  172. inline int streambuf::sputbackc(char _c){ return (_eback<gptr()) ? *(--_gptr)=_c : pbackfail(_c); }
  173. inline int streambuf::sputc(int _i){ return (_pptr<_epptr) ? (unsigned char)(*(_pptr++)=(char)_i) : overflow(_i); }
  174. inline int streambuf::sputn(const char * _str,int _n) { return xsputn(_str, _n); }
  175. inline int streambuf::sgetn(char * _str,int _n) { return xsgetn(_str, _n); }
  176. inline char * streambuf::base() const { return _base; }
  177. inline char * streambuf::ebuf() const { return _ebuf; }
  178. inline int streambuf::blen() const {return ((_ebuf > _base) ? (int)(_ebuf-_base) : 0); }
  179. inline char * streambuf::pbase() const { return _pbase; }
  180. inline char * streambuf::pptr() const { return _pptr; }
  181. inline char * streambuf::epptr() const { return _epptr; }
  182. inline char * streambuf::eback() const { return _eback; }
  183. inline char * streambuf::gptr() const { return _gptr; }
  184. inline char * streambuf::egptr() const { return _egptr; }
  185. inline void streambuf::gbump(int _n) { if (_egptr) _gptr += _n; }
  186. inline void streambuf::pbump(int _n) { if (_epptr) _pptr += _n; }
  187. inline void streambuf::setg(char * _eb, char * _g, char * _eg) {_eback=_eb; _gptr=_g; _egptr=_eg; x_lastc=EOF; }
  188. inline void streambuf::setp(char * _p, char * _ep) {_pptr=_pbase=_p; _epptr=_ep; }
  189. inline int streambuf::unbuffered() const { return _fUnbuf; }
  190. inline void streambuf::unbuffered(int _f) { _fUnbuf = _f; }
  191. #ifdef _MSC_VER
  192. // Restore previous packing
  193. #pragma pack(pop)
  194. #endif // _MSC_VER
  195. #endif // _INC_STREAMB
  196. #endif /* __cplusplus */