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.

184 lines
5.0 KiB

  1. /***
  2. *streamb.h - definitions/declarations for the streambuf class
  3. *
  4. * Copyright (c) 1990-1994, 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. ****/
  12. #ifndef _INC_STREAMB
  13. #define _INC_STREAMB
  14. /* Define _CRTIMP */
  15. #ifndef _CRTIMP
  16. #ifdef _NTSDK
  17. /* definition compatible with NT SDK */
  18. #define _CRTIMP
  19. #else /* ndef _NTSDK */
  20. /* current definition */
  21. #ifdef _DLL
  22. #define _CRTIMP __declspec(dllimport)
  23. #else /* ndef _DLL */
  24. #define _CRTIMP
  25. #endif /* _DLL */
  26. #endif /* _NTSDK */
  27. #endif /* _CRTIMP */
  28. #include <ios.h> // need ios::seek_dir definition
  29. #ifdef _MT // defined in ios.h
  30. extern "C" {
  31. _CRTIMP void __cdecl _mtlock(PRTL_CRITICAL_SECTION);
  32. _CRTIMP void __cdecl _mtunlock(PRTL_CRITICAL_SECTION);
  33. }
  34. #endif
  35. #ifndef NULL
  36. #define NULL 0
  37. #endif
  38. #ifndef EOF
  39. #define EOF (-1)
  40. #endif
  41. #ifdef _MSC_VER
  42. // C4505: "unreferenced local function has been removed"
  43. #pragma warning(disable:4505) // disable C4505 warning
  44. // #pragma warning(default:4505) // use this to reenable, if desired
  45. // Force word packing to avoid possible -Zp override
  46. #pragma pack(push,4)
  47. #endif // _MSC_VER
  48. typedef long streampos, streamoff;
  49. class _CRTIMP ios;
  50. class _CRTIMP streambuf {
  51. public:
  52. virtual ~streambuf();
  53. inline int in_avail() const;
  54. inline int out_waiting() const;
  55. int sgetc();
  56. int snextc();
  57. int sbumpc();
  58. void stossc();
  59. inline int sputbackc(char);
  60. inline int sputc(int);
  61. inline int sputn(const char *,int);
  62. inline int sgetn(char *,int);
  63. virtual int sync();
  64. // enum seek_dir { beg=0, cur=1, end=2 }; // CONSIDER: needed ???
  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. PRTL_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. RTL_CRITICAL_SECTION x_lock; // lock needed only for multi-thread operation
  122. #endif
  123. };
  124. inline int streambuf::in_avail() const { return (gptr()<_egptr) ? (_egptr-gptr()) : 0; }
  125. inline int streambuf::out_waiting() const { return (_pptr>=_pbase) ? (_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) ? (_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 */