home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / SASC6571.LZX / cxxinclude / stdiostream.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-24  |  1.6 KB  |  76 lines

  1. /* Copyright (c) 1993             by SAS Institute Inc., Cary NC     */
  2.  
  3. #ifndef __STDIOSTREAM_H
  4. #define __STDIOSTREAM_H
  5.  
  6. #ifndef _STDDEFH
  7. #include <stddef.h>
  8. #endif
  9.  
  10. #ifndef __IOSTREAM_H
  11. #include <iostream.h>
  12. #endif
  13.  
  14. /********
  15.  
  16. class stdiobuf
  17.     stdiobufs are a simple interface to FILE*.
  18.     stdiobufs will probably not be part of ANSI C++.
  19.  
  20.     Calls to a stdiobuf are mapped directly to calls to 
  21.     ANSI C stdio functions.
  22.  
  23. ********/
  24.  
  25. class stdiobuf : public streambuf {
  26.     public:
  27.  
  28.            // Attach to a FILE*.
  29.       stdiobuf( FILE* _file ) : x_file( _file ) {}
  30.  
  31.            // disconnect
  32.       virtual ~stdiobuf() {}
  33.  
  34.           // Return the attached FILE*.
  35.       FILE* stdiofile() _INLINE_FUNC({ return x_file; })
  36.  
  37.            // Override or replace from streambuf.
  38.       virtual int        overflow(int=EOF);
  39.       virtual int        underflow();
  40.       virtual int        sync();
  41.       virtual int xsputn(const char* s,int n);
  42.       virtual int xsgetn(char*  s,int n);
  43.       virtual streampos seekoff(streamoff offset, ios::seek_dir dir,
  44.                         int mode);
  45.       virtual streampos seekpos(streampos, int =ios::in|ios::out);
  46.       virtual int pbackfail(int c);
  47.       virtual streambuf* setbuf(char* p, size_t len);
  48.  
  49.     private:
  50.         FILE* x_file;
  51.         char  _buf[2];      // buffer for i/o
  52.     };
  53.  
  54.  
  55.  
  56. class stdiostream : public iostream {
  57.  
  58.     public:
  59.  
  60.            // Attach to a FILE*.
  61.       stdiostream( FILE* _file ) 
  62.           : ios( &buffer ), buffer( _file )
  63.           {}
  64.  
  65.       stdiobuf* rdbuf() _INLINE_FUNC({ return &buffer; })
  66.  
  67.     private:
  68.       stdiobuf buffer;
  69.     };
  70.  
  71.  
  72. #endif  /* __STDIOSTREAM_H */
  73.  
  74.  
  75.  
  76.