home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c021 / 7.img / INCLUDE.ZIP / FSTREAM.H < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-04  |  4.6 KB  |  150 lines

  1. /* fstream.h -- class filebuf and fstream declarations
  2.  
  3.     Copyright (c) 1990 by Borland International    
  4.     All rights reserved
  5. */
  6.  
  7. #ifndef __FSTREAM_H
  8. #define __FSTREAM_H
  9.  
  10. #include <iostream.h>
  11.  
  12. #if __STDC__
  13. #define _Cdecl
  14. #else
  15. #define _Cdecl    cdecl
  16. #endif
  17.  
  18. class  filebuf : public streambuf {
  19. public:
  20. static const int openprot;    // default file protection
  21.  
  22.         // constructors, destructor
  23.         _Cdecl filebuf();    // make a closed filebuf
  24.         _Cdecl filebuf(int);    // make a filebuf attached to fd
  25.         _Cdecl filebuf(int _f, char*, int); // same, with specified buffer
  26.         _Cdecl ~filebuf();
  27.  
  28.     int    _Cdecl is_open();    // is the file open
  29.     int    _Cdecl fd();        // what is the file descriptor
  30.  
  31.     // open named file with mode and protection, attach to this filebuf
  32.     filebuf* _Cdecl open(const char*, int, int = filebuf::openprot);
  33.  
  34.     filebuf* _Cdecl close();    // flush and close file
  35.     filebuf* _Cdecl attach(int);    // attach this filebuf to opened file descriptor
  36.  
  37. /*
  38.  * These perform the streambuf functions on a filebuf
  39.  * Get and Put pointers are kept together
  40.  */
  41. virtual int    _Cdecl overflow(int = EOF);
  42. virtual int    _Cdecl underflow();
  43. virtual int    _Cdecl sync();
  44. virtual streampos  _Cdecl seekoff(streamoff, seek_dir, int);
  45. virtual streambuf* _Cdecl setbuf(char*, int);
  46.  
  47. protected:
  48.     int    xfd;        // the file descriptor, EOF if closed
  49.     int    mode;        // the opened mode
  50.     short    opened;    // non-zero if file is open
  51.  
  52.     streampos last_seek;    // unused            ***
  53.     char*   in_start;        // unused            ***
  54.  
  55.     int    _Cdecl last_op();    // unused            ***
  56.     char    lahead[2];        // current input char if unbuffered ***
  57. };
  58. /*
  59.  * The data members marked with *** above are not documented in the AT&T
  60.  * release of streams, so we cannot guarantee compatibility with any
  61.  * other streams release in the use or values of these data members.
  62.  * If you can document any expected behavior of these data members, we
  63.  * will try to adjust our implementation accordingly.
  64.  */
  65. inline int    _Cdecl filebuf::is_open()    { return opened; }
  66. inline int    _Cdecl filebuf::fd()        { return xfd; }
  67.  
  68.  
  69. class fstreambase : virtual public ios {
  70. public:
  71.         _Cdecl fstreambase();
  72.         _Cdecl fstreambase(const char*, int, int = filebuf::openprot);
  73.         _Cdecl fstreambase(int);
  74.         _Cdecl fstreambase(int _f, char*, int);
  75.         _Cdecl ~fstreambase();
  76.  
  77.     void    _Cdecl open(const char*, int, int = filebuf::openprot);
  78.     void    _Cdecl attach(int);
  79.     void    _Cdecl close();
  80.     void    _Cdecl setbuf(char*, int);
  81.     filebuf* _Cdecl rdbuf();
  82.  
  83. protected:
  84.     void    _Cdecl verify(int);    // unimplemented    ***
  85.  
  86. private:
  87.     filebuf    buf;
  88. };
  89. /*
  90.  * The function member marked with *** above is not documented in the AT&T
  91.  * release of streams, so we cannot guarantee compatibility with any
  92.  * other streams release in its use.
  93.  * If you can document any expected behavior of this function member, we
  94.  * will try to adjust our implementation accordingly.
  95.  */
  96. inline filebuf* _Cdecl fstreambase::rdbuf() { return &buf; }
  97.  
  98.  
  99. class ifstream : public fstreambase, public istream {
  100. public:
  101.         _Cdecl ifstream();
  102.         _Cdecl ifstream(const char*, int = ios::in, int = filebuf::openprot);
  103.         _Cdecl ifstream(int);
  104.         _Cdecl ifstream(int _f, char*, int);
  105.         _Cdecl ~ifstream();
  106.  
  107.     filebuf* _Cdecl rdbuf();
  108.     void    _Cdecl open(const char*, int = ios::in, int = filebuf::openprot);
  109. };
  110. inline filebuf* _Cdecl ifstream::rdbuf() { return fstreambase::rdbuf(); }
  111. inline void    _Cdecl ifstream::open(const char* name, int m, int prot) {
  112.                 fstreambase::open(name, m | ios::in, prot);
  113.                 }
  114.  
  115.  
  116. class ofstream : public fstreambase, public ostream {
  117. public:
  118.         _Cdecl ofstream();
  119.         _Cdecl ofstream(const char*, int = ios::out, int = filebuf::openprot);
  120.         _Cdecl ofstream(int);
  121.         _Cdecl ofstream(int _f, char*, int);
  122.         _Cdecl ~ofstream();
  123.  
  124.     filebuf* _Cdecl rdbuf();
  125.     void    _Cdecl open(const char*, int = ios::out, int = filebuf::openprot);
  126. };
  127. inline filebuf* _Cdecl ofstream::rdbuf() { return fstreambase::rdbuf(); }
  128. inline void    _Cdecl ofstream::open(const char* name, int m, int prot) {
  129.                 fstreambase::open(name, m | ios::out, prot);
  130.                 }
  131.  
  132.  
  133. class fstream : public fstreambase, public iostream {
  134. public:
  135.         _Cdecl fstream();
  136.         _Cdecl fstream(const char*, int, int = filebuf::openprot);
  137.         _Cdecl fstream(int);
  138.         _Cdecl fstream(int _f, char*, int);
  139.         _Cdecl ~fstream();
  140.  
  141.     filebuf* _Cdecl rdbuf();
  142.     void    _Cdecl open(const char *, int, int = filebuf::openprot);
  143. };
  144. inline filebuf* _Cdecl fstream::rdbuf() { return fstreambase::rdbuf(); }
  145. inline void    _Cdecl fstream::open(const char* name, int m, int prot) {
  146.                 fstreambase::open(name, m, prot);
  147.                 }
  148.  
  149. #endif
  150.