home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / C++-7 / DISK4 / INCLUDE / STREAMB.H$ / STREAMB
Encoding:
Text File  |  1992-01-15  |  4.4 KB  |  139 lines

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