home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c081_11 / 2.ddi / INCLUDE.ZIP / FSTREAM.H < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-13  |  5.6 KB  |  175 lines

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