home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / LinAlg 3.1 / ANSI #includes addenda / streambuf < prev   
Encoding:
Text File  |  1995-05-30  |  4.3 KB  |  157 lines  |  [TEXT/MMCC]

  1. // streambuf standard header
  2. #ifndef _STREAMBUF_
  3. #define _STREAMBUF_
  4. #include <ios>
  5.  
  6. #if __MWERKS__
  7. #pragma options align=mac68k
  8. #endif
  9.  
  10.         // macros
  11. #define EOF    (-1)
  12.         // type streamoff
  13. typedef long streamoff;
  14. const streamoff _BADOFF = -1;
  15.         // class streampos
  16. class streampos {
  17. public:
  18.     streampos(streamoff = 0, const _Fpost * = 0);
  19.     streamoff offset() const;
  20.     operator streamoff (void) const { return offset(); }
  21.     streamoff operator-(const streampos&) const;
  22.     streampos& operator+=(streamoff _O)
  23.         {_Pos += _O; return (*this); }
  24.     streampos& operator-=(streamoff _O)
  25.         {_Pos -= _O; return (*this); }
  26.     streampos operator+(streamoff _O) const
  27.         {streampos s = *this; s += _O; return s; }
  28.     streampos operator-(streamoff _O) const
  29.         {streampos s = *this; s -= _O; return s; }
  30.     _Bool operator==(const streampos&) const;
  31.     _Bool operator!=(const streampos& _R) const
  32.         {return (!(*this == _R)); }
  33.     _Fpost *_Fpos()
  34.         {return (&_Fp); }
  35. private:
  36.     streamoff _Pos;
  37.     _Fpost _Fp;
  38.     };
  39.         // class streambuf
  40. class streambuf {
  41. public:
  42.     virtual ~streambuf();
  43.     virtual int showmany();
  44.     streampos pubseekoff(streamoff _O, ios::seekdir _W,
  45.         ios::openmode _M = ios::in | ios::out)
  46.         {return (seekoff(_O, _W, _M)); }
  47.     streampos pubseekoff(streamoff _O, ios::seek_dir _W,
  48.         ios::open_mode _M)
  49.         {return (pubseekoff(_O, (ios::seekdir)_W, (ios::openmode)_M)); }
  50.     streampos pubseekpos(streampos _P,
  51.         ios::openmode _M = ios::in | ios::out)
  52.         {return (seekpos(_P, _M)); }
  53.     streampos pubseekpos(streampos _P, ios::open_mode _M)
  54.         {return (seekpos(_P, (ios::openmode)_M)); }
  55.     streambuf *pubsetbuf(char *_S, int _N)
  56.         {return (setbuf(_S, _N)); }
  57.     int pubsync()
  58.         {return (sync()); }
  59.     int sbumpc()
  60.         {return (gptr() != 0 && gptr() < egptr()
  61.             ? *_Gn()++ : uflow()); }
  62.     int sgetc()
  63.         {return (gptr() != 0 && gptr() < egptr()
  64.             ? *_Gn() : underflow()); }
  65.     int sgetn(char *_S, int _N)
  66.         {return (xsgetn(_S, _N)); }
  67.     int snextc()
  68.         {return (sbumpc() == EOF ? EOF : sgetc()); }
  69.     int sputbackc(char _C)
  70.         {return (gptr() != 0 && eback() < gptr()
  71.             && _C == gptr()[-1]
  72.             ? *--_Gn() : pbackfail((unsigned char)_C)); }
  73.     int sungetc()
  74.         {return (gptr() != 0 && eback() < gptr()
  75.             ? *--_Gn() : pbackfail()); }
  76.     int sputc(int _C)
  77.         {return (pptr() != 0 && pptr() < epptr()
  78.             ? (*_Pn()++ = _C) : overflow(_C)); }
  79.     int sputn(const char *_S, int _N)
  80.         {return (xsputn(_S, _N)); }
  81.     int in_avail()
  82.         {return (gptr() != 0 && gptr() < egptr()
  83.             ? egptr() - gptr() : showmany()); }
  84. protected:
  85.     streambuf()
  86.         {_Init(); }
  87.     streambuf(ios::_Uninitialized)
  88.         {}
  89.     char *eback() const
  90.         {return (*_IGbeg); }
  91.     char *gptr() const
  92.         {return (*_IGnext); }
  93.     char *egptr() const
  94.         {return (*_IGend); }
  95.     void gbump(int _N)
  96.         {*_IGnext += _N; }
  97.     void setg(char *_B, char *_N, char *_E)
  98.         {*_IGbeg = _B, *_IGnext = _N, *_IGend = _E; }
  99.     char *pbase() const
  100.         {return (*_IPbeg); }
  101.     char *pptr() const
  102.         {return (*_IPnext); }
  103.     char *epptr() const
  104.         {return (*_IPend); }
  105.     void pbump(int _N)
  106.         {*_IPnext += _N; }
  107.     void setp(char *_B, char *_E)
  108.         {*_IPbeg = _B, *_IPnext = _B, *_IPend = _E; }
  109.     void setp(char *_B, char *_N, char *_E)
  110.         {*_IPbeg = _B, *_IPnext = _N, *_IPend = _E; }
  111.     unsigned char *&_Gn()
  112.         {return ((unsigned char *&)*_IGnext); }
  113.     unsigned char *&_Pn()
  114.         {return ((unsigned char *&)*_IPnext); }
  115.     virtual int overflow(int = EOF);
  116.     virtual int pbackfail(int = EOF);
  117.     virtual int underflow();
  118.     virtual int uflow();
  119.     virtual int xsgetn(char *, int);
  120.     virtual int xsputn(const char *, int);
  121.     virtual streampos seekoff(streamoff, ios::seekdir,
  122.         ios::openmode = ios::in | ios::out);
  123.     virtual streampos seekpos(streampos,
  124.         ios::openmode = ios::in | ios::out);
  125.     virtual streambuf *setbuf(char *, int);
  126.     virtual int sync();
  127.     void _Init();
  128.     void _Init(char **, char **, char **, char **, char **,
  129.         char **);
  130. private:
  131.     streambuf(const streambuf&); // undefined
  132.     streambuf& operator=(const streambuf&); // undefined
  133.     char *_Gbeg, *_Gnext, *_Gend;
  134.     char *_Pbeg, *_Pnext, *_Pend;
  135.     char **_IGbeg, **_IGnext, **_IGend;
  136.     char **_IPbeg, **_IPnext, **_IPend;
  137.     };
  138.  
  139. #if __MWERKS__
  140. #pragma options align=reset
  141. #endif
  142.  
  143. #endif
  144.  
  145. /*
  146.  * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  147.  * Consult your license regarding permissions and restrictions.
  148.  */
  149.  
  150. /* Change log:
  151.  *94June04 PlumHall baseline
  152.  *94Sept30 Applied diffs for Fri Aug 26 00:51:20 1994
  153.  *94Sept30 Applied diffs for Tue Aug 30 07:28:05 1994
  154.  *94Oct07 Inserted MW changes
  155.  *94Dec27mm Added in_avail following pjp.
  156.  */
  157.