home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c221 / 7.ddi / MWHC.007 / H < prev    next >
Encoding:
Text File  |  1992-08-26  |  4.1 KB  |  189 lines

  1. /*
  2.  *   fstream.h
  3.  *
  4.  *   C++ IOStreams specialized for use with files.
  5.  *
  6.  *           Copyright (c) 1991-1992, MetaWare Incorporated
  7.  */
  8.  
  9. /*   $Id: fstream.h,v 1.11 1992/02/18 01:39:00 tom Exp $ */
  10.  
  11.  
  12. #ifndef __FSTREAM_H
  13. #define __FSTREAM_H
  14. #pragma push_align_members(64);
  15.  
  16. #c_include <iostream.h>
  17.  
  18.  
  19. #pragma on(nodebug)
  20. /*
  21.  *   Class filebuf:
  22.  *
  23.  *      streambuf specialized for use with files.
  24.  *      Supports associated file descriptor, seek, read and write
  25.  *      to external file.
  26.  *
  27.  */
  28.  
  29. class  filebuf : public streambuf {
  30.  
  31. private:
  32.     void        fb_checkstate();
  33.  
  34. protected:
  35.     int        xfd;        // File descriptor for this filebuf.
  36.     int        mode;        // Open mode of file descriptor.
  37.     char        opened;        // TRUE == xfd is open.
  38.     streampos    last_seek;    // Position after last seek.
  39.     char*         in_start;
  40.     int        last_op();    // ???  Not implemented.
  41.     char        lahead[2];    // Input buffer for unbuffered filebufs.
  42.  
  43. public:
  44.     static const int openprot;    // Default permissions = 0644(rw,r,r)
  45.  
  46.     void        fb_dbp(int __level);
  47.  
  48.             filebuf();    // Buffered, no handle, not open.
  49.  
  50.                     // Buffered, __handle already open.
  51.             filebuf(int __handle);
  52.  
  53.                     // Buffered, __handle already open.
  54.             filebuf(int __handle, char* __buf, int __len);
  55.  
  56.     int        is_open() { return opened; }
  57.     int        fd() { return xfd; }
  58.  
  59.                     // Open file.
  60.     filebuf*    open(const char *__pathname, long __mode,
  61.                 long __prot=filebuf::openprot);
  62.  
  63.                     // Use __handle, fail if already open.
  64.     filebuf*    attach(int __handle);
  65.  
  66.                     // Sync and close file.
  67.     filebuf*     close();
  68.  
  69.                     // Sync and close file.
  70.             ~filebuf();
  71.  
  72. // virtuals
  73.     virtual int    overflow(int=EOF);
  74.     virtual int    underflow();
  75.     virtual int    sync();
  76.     virtual streampos
  77.             seekoff(streamoff __offset, ios::seek_dir __dir,
  78.                 long __mode);
  79.     virtual streambuf*
  80.             setbuf(char* __buf, int __len);
  81.     };
  82.  
  83.  
  84.  
  85. /*
  86.  *   Class fstreambase:
  87.  *
  88.  *      Base class for input/output functions on filebufs.
  89.  *
  90.  */
  91.  
  92. class fstreambase : virtual public ios { 
  93.  
  94. private:
  95.     void        check_stat();
  96.     filebuf        buf;
  97.  
  98. protected:
  99.     void        verify(int);
  100.  
  101. public:
  102.             fstreambase();
  103.     
  104.             fstreambase(const char* __name, long __mode,
  105.                     long __prot=filebuf::openprot);
  106.             fstreambase(int __handle);
  107.             fstreambase(int __handle, char* __buf, int __len);
  108.             ~fstreambase();
  109.     void        open(const char* __name, long __mode, 
  110.                     long __prot=filebuf::openprot);
  111.     void        attach(int __handle);
  112.     void        close();
  113.     filebuf*    setbuf(char* __buf, int __len);
  114.     filebuf*    rdbuf() { return &buf; }
  115.     };
  116.  
  117.  
  118. /*
  119.  *   Class ifstream:
  120.  *
  121.  *      istream specialized for files.
  122.  *
  123.  */
  124.  
  125. class ifstream : public fstreambase, public istream {
  126. public:
  127.             ifstream();
  128.             ifstream(const char* __name, long __mode=ios::in,
  129.                     long __prot=filebuf::openprot);
  130.             ifstream(int __handle);
  131.             ifstream(int __handle, char* __buf, int __len);
  132.             ~ifstream();
  133.  
  134.     filebuf*    rdbuf() { return fstreambase::rdbuf(); }
  135.     void        open(const char* __fname, long __mode=ios::in, 
  136.                     long __prot=filebuf::openprot);
  137.     };
  138.  
  139.  
  140. /*
  141.  *   Class ofstream:
  142.  *
  143.  *      ostream specialized for files.
  144.  *
  145.  */
  146.  
  147. class ofstream : public fstreambase, public ostream {
  148. public:
  149.             ofstream();
  150.             ofstream(const char* __name, long __mode=ios::out,
  151.                     long __prot=filebuf::openprot);
  152.             ofstream(int __handle);
  153.             ofstream(int __handle, char* __buf, int __len);
  154.             ~ofstream();
  155.  
  156.     filebuf*    rdbuf() { return fstreambase::rdbuf(); }
  157.     void        open(const char* __name, long __mode=ios::out, 
  158.                     long __prot=filebuf::openprot);
  159.     };
  160.  
  161.  
  162. /*
  163.  *   Class fstream:
  164.  *
  165.  *      iostream specialized for files.
  166.  *
  167.  */
  168.  
  169. class fstream : public fstreambase, public iostream {
  170. public:
  171.             fstream();
  172.     
  173.             fstream(const char* __name, long __mode,
  174.                     long __prot=filebuf::openprot);
  175.             fstream(int __handle);
  176.             fstream(int __handle, char* __buf, int __len);
  177.             ~fstream();
  178.     filebuf*    rdbuf() { return fstreambase::rdbuf(); }
  179.     void        open(const char* __name, long __mode, 
  180.                 long __prot=filebuf::openprot);
  181.     };
  182. #pragma pop(nodebug)
  183.  
  184. #pragma pop_align_members();
  185. #endif // __FSTREAM_H
  186.  
  187.  
  188. /**          Copyright (c) 1991-1992, MetaWare Incorporated             **/
  189.