Leaked source code of windows server 2003
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.

191 lines
5.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. ****/
  14. #if _MSC_VER > 1000
  15. #pragma once
  16. #endif
  17. #ifdef __cplusplus
  18. #ifndef _INC_STREAMB
  19. #define _INC_STREAMB
  20. #if !defined(_WIN32)
  21. #error ERROR: Only Win32 target supported!
  22. #endif
  23. #ifdef _MSC_VER
  24. // Currently, all MS C compilers for Win32 platforms default to 8 byte
  25. // alignment.
  26. #pragma pack(push,8)
  27. #include <useoldio.h>
  28. #endif // _MSC_VER
  29. /* Define _CRTIMP */
  30. #ifndef _CRTIMP
  31. #ifdef _DLL
  32. #define _CRTIMP __declspec(dllimport)
  33. #else /* ndef _DLL */
  34. #define _CRTIMP
  35. #endif /* _DLL */
  36. #endif /* _CRTIMP */
  37. #include <ios.h> // need ios::seek_dir definition
  38. #ifndef NULL
  39. #define NULL 0
  40. #endif
  41. #ifndef EOF
  42. #define EOF (-1)
  43. #endif
  44. #ifdef _MSC_VER
  45. // C4514: "unreferenced inline function has been removed"
  46. #pragma warning(disable:4514) // disable C4514 warning
  47. // #pragma warning(default:4514) // use this to reenable, if desired
  48. #endif // _MSC_VER
  49. typedef long streampos, streamoff;
  50. class _CRTIMP ios;
  51. class _CRTIMP streambuf {
  52. public:
  53. virtual ~streambuf();
  54. inline int in_avail() const;
  55. inline int out_waiting() const;
  56. int sgetc();
  57. int snextc();
  58. int sbumpc();
  59. void stossc();
  60. inline int sputbackc(char);
  61. inline int sputc(int);
  62. inline int sputn(const char *,int);
  63. inline int sgetn(char *,int);
  64. virtual int sync();
  65. virtual streambuf* setbuf(char *, int);
  66. virtual streampos seekoff(streamoff,ios::seek_dir,int =ios::in|ios::out);
  67. virtual streampos seekpos(streampos,int =ios::in|ios::out);
  68. virtual int xsputn(const char *,int);
  69. virtual int xsgetn(char *,int);
  70. virtual int overflow(int =EOF) = 0; // pure virtual function
  71. virtual int underflow() = 0; // pure virtual function
  72. virtual int pbackfail(int);
  73. void dbp();
  74. #ifdef _MT
  75. void setlock() { LockFlg--; } // <0 indicates lock required;
  76. void clrlock() { if (LockFlg <= 0) LockFlg++; }
  77. void lock() { if (LockFlg<0) _mtlock(lockptr()); };
  78. void unlock() { if (LockFlg<0) _mtunlock(lockptr()); }
  79. #else
  80. void lock() { }
  81. void unlock() { }
  82. #endif
  83. protected:
  84. streambuf();
  85. streambuf(char *,int);
  86. inline char * base() const;
  87. inline char * ebuf() const;
  88. inline char * pbase() const;
  89. inline char * pptr() const;
  90. inline char * epptr() const;
  91. inline char * eback() const;
  92. inline char * gptr() const;
  93. inline char * egptr() const;
  94. inline int blen() const;
  95. inline void setp(char *,char *);
  96. inline void setg(char *,char *,char *);
  97. inline void pbump(int);
  98. inline void gbump(int);
  99. void setb(char *,char *,int =0);
  100. inline int unbuffered() const;
  101. inline void unbuffered(int);
  102. int allocate();
  103. virtual int doallocate();
  104. #ifdef _MT
  105. _PCRT_CRITICAL_SECTION lockptr() { return & x_lock; }
  106. #endif
  107. private:
  108. int _fAlloc;
  109. int _fUnbuf;
  110. int x_lastc;
  111. char * _base;
  112. char * _ebuf;
  113. char * _pbase;
  114. char * _pptr;
  115. char * _epptr;
  116. char * _eback;
  117. char * _gptr;
  118. char * _egptr;
  119. #ifdef _MT
  120. int LockFlg; // <0 indicates locking required
  121. _CRT_CRITICAL_SECTION x_lock; // lock needed only for multi-thread operation
  122. #endif
  123. };
  124. inline int streambuf::in_avail() const { return (gptr()<_egptr) ? (int)(_egptr-gptr()) : 0; }
  125. inline int streambuf::out_waiting() const { return (_pptr>=_pbase) ? (int)(_pptr-_pbase) : 0; }
  126. inline int streambuf::sputbackc(char _c){ return (_eback<gptr()) ? *(--_gptr)=_c : pbackfail(_c); }
  127. inline int streambuf::sputc(int _i){ return (_pptr<_epptr) ? (unsigned char)(*(_pptr++)=(char)_i) : overflow(_i); }
  128. inline int streambuf::sputn(const char * _str,int _n) { return xsputn(_str, _n); }
  129. inline int streambuf::sgetn(char * _str,int _n) { return xsgetn(_str, _n); }
  130. inline char * streambuf::base() const { return _base; }
  131. inline char * streambuf::ebuf() const { return _ebuf; }
  132. inline int streambuf::blen() const {return ((_ebuf > _base) ? (int)(_ebuf-_base) : 0); }
  133. inline char * streambuf::pbase() const { return _pbase; }
  134. inline char * streambuf::pptr() const { return _pptr; }
  135. inline char * streambuf::epptr() const { return _epptr; }
  136. inline char * streambuf::eback() const { return _eback; }
  137. inline char * streambuf::gptr() const { return _gptr; }
  138. inline char * streambuf::egptr() const { return _egptr; }
  139. inline void streambuf::gbump(int _n) { if (_egptr) _gptr += _n; }
  140. inline void streambuf::pbump(int _n) { if (_epptr) _pptr += _n; }
  141. inline void streambuf::setg(char * _eb, char * _g, char * _eg) {_eback=_eb; _gptr=_g; _egptr=_eg; x_lastc=EOF; }
  142. inline void streambuf::setp(char * _p, char * _ep) {_pptr=_pbase=_p; _epptr=_ep; }
  143. inline int streambuf::unbuffered() const { return _fUnbuf; }
  144. inline void streambuf::unbuffered(int _f) { _fUnbuf = _f; }
  145. #ifdef _MSC_VER
  146. // Restore previous packing
  147. #pragma pack(pop)
  148. #endif // _MSC_VER
  149. #endif // _INC_STREAMB
  150. #endif /* __cplusplus */