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.

142 lines
4.4 KiB

  1. /***
  2. *streamb.h - definitions/declarations for the streambuf class
  3. *
  4. * Copyright (c) 1990-1992, 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. #ifdef M_I86HM
  15. #define _HFAR_ __far
  16. #else
  17. #define _HFAR_
  18. #endif
  19. #ifndef NULL
  20. #define NULL 0
  21. #endif
  22. #ifndef EOF
  23. #define EOF (-1)
  24. #endif
  25. // Force word packing to avoid possible -Zp override
  26. #pragma pack(2)
  27. #pragma warning(disable:4505) // disable unwanted /W4 warning
  28. // #pragma warning(default:4505) // use this to reenable, if necessary
  29. typedef long streampos, streamoff;
  30. class streambuf {
  31. public:
  32. virtual ~streambuf();
  33. inline int in_avail() const;
  34. inline int out_waiting() const;
  35. int sgetc();
  36. int snextc();
  37. int sbumpc();
  38. void stossc();
  39. inline int sputbackc(char);
  40. inline int sputc(int);
  41. inline int sputn(const char _HFAR_ *,int);
  42. inline int sgetn(char _HFAR_ *,int);
  43. virtual int sync();
  44. // enum seek_dir { beg=0, cur=1, end=2 }; // CONSIDER: needed ???
  45. virtual streambuf* setbuf(char _HFAR_ *, int);
  46. virtual streampos seekoff(streamoff,ios::seek_dir,int =ios::in|ios::out);
  47. virtual streampos seekpos(streampos,int =ios::in|ios::out);
  48. virtual int xsputn(const char _HFAR_ *,int);
  49. virtual int xsgetn(char _HFAR_ *,int);
  50. virtual int overflow(int =EOF) = 0; // pure virtual function
  51. virtual int underflow() = 0; // pure virtual function
  52. virtual int pbackfail(int);
  53. void dbp();
  54. protected:
  55. streambuf();
  56. streambuf(char _HFAR_ *,int);
  57. inline char _HFAR_ * base() const;
  58. inline char _HFAR_ * ebuf() const;
  59. inline char _HFAR_ * pbase() const;
  60. inline char _HFAR_ * pptr() const;
  61. inline char _HFAR_ * epptr() const;
  62. inline char _HFAR_ * eback() const;
  63. inline char _HFAR_ * gptr() const;
  64. inline char _HFAR_ * egptr() const;
  65. inline int blen() const;
  66. inline void setp(char _HFAR_ *,char _HFAR_ *);
  67. inline void setg(char _HFAR_ *,char _HFAR_ *,char _HFAR_ *);
  68. inline void pbump(int);
  69. inline void gbump(int);
  70. void setb(char _HFAR_ *,char _HFAR_ *,int =0);
  71. inline int unbuffered() const;
  72. inline void unbuffered(int);
  73. int allocate();
  74. virtual int doallocate();
  75. private:
  76. int _fAlloc;
  77. int _fUnbuf;
  78. int x_lastc;
  79. char _HFAR_ * _base;
  80. char _HFAR_ * _ebuf;
  81. char _HFAR_ * _pbase;
  82. char _HFAR_ * _pptr;
  83. char _HFAR_ * _epptr;
  84. char _HFAR_ * _eback;
  85. char _HFAR_ * _gptr;
  86. char _HFAR_ * _egptr;
  87. };
  88. inline int streambuf::in_avail() const { return (gptr()<_egptr) ? (_egptr-gptr()) : 0; }
  89. inline int streambuf::out_waiting() const { return (_pptr>=_pbase) ? (_pptr-_pbase) : 0; }
  90. inline int streambuf::sputbackc(char _c){ return (_eback<gptr()) ? *(--_gptr)=_c : pbackfail(_c); }
  91. inline int streambuf::sputc(int _i){ return (_pptr<_epptr) ? (unsigned char)(*(_pptr++)=(char)_i) : overflow(_i); }
  92. inline int streambuf::sputn(const char _HFAR_ * _str,int _n) { return xsputn(_str, _n); }
  93. inline int streambuf::sgetn(char _HFAR_ * _str,int _n) { return xsgetn(_str, _n); }
  94. inline char _HFAR_ * streambuf::base() const { return _base; }
  95. inline char _HFAR_ * streambuf::ebuf() const { return _ebuf; }
  96. inline int streambuf::blen() const {return ((_ebuf > _base) ? (_ebuf-_base) : 0); }
  97. inline char _HFAR_ * streambuf::pbase() const { return _pbase; }
  98. inline char _HFAR_ * streambuf::pptr() const { return _pptr; }
  99. inline char _HFAR_ * streambuf::epptr() const { return _epptr; }
  100. inline char _HFAR_ * streambuf::eback() const { return _eback; }
  101. inline char _HFAR_ * streambuf::gptr() const { return _gptr; }
  102. inline char _HFAR_ * streambuf::egptr() const { return _egptr; }
  103. inline void streambuf::gbump(int n) { if (_egptr) _gptr += n; }
  104. inline void streambuf::pbump(int n) { if (_epptr) _pptr += n; }
  105. inline void streambuf::setg(char _HFAR_ * eb, char _HFAR_ * g, char _HFAR_ * eg) {_eback=eb; _gptr=g; _egptr=eg; x_lastc=EOF; }
  106. inline void streambuf::setp(char _HFAR_ * p, char _HFAR_ * ep) {_pptr=_pbase=p; _epptr=ep; }
  107. inline int streambuf::unbuffered() const { return _fUnbuf; }
  108. inline void streambuf::unbuffered(int fUnbuf) { _fUnbuf = fUnbuf; }
  109. // Restore default packing
  110. #pragma pack()
  111. #endif