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.

190 lines
5.0 KiB

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