home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 1.ddi / INCLUDE.ZIP / FSTREAM.H < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  7.3 KB  |  201 lines

  1. /*  fstream.h -- class filebuf and fstream declarations
  2.  
  3.     Copyright (c) 1990, 1992 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(___DEFS_H)
  15. #include <_defs.h>
  16. #endif
  17.  
  18. #if !defined(__IOSTREAM_H)
  19. #include <iostream.h>
  20. #endif
  21.  
  22. #pragma option -Vo-
  23. #if defined(__BCOPT__) && !defined(_RTL_ALLOW_po)
  24. #pragma option -po-
  25. #endif
  26.  
  27. _CLASSDEF(filebuf)
  28. _CLASSDEF(fstreambase)
  29. _CLASSDEF(ifstream)
  30. _CLASSDEF(ofstream)
  31. _CLASSDEF(fstream)
  32.  
  33. class  _CLASSTYPE filebuf : public streambuf {
  34. public:
  35. static const int openprot;  // default file protection
  36.  
  37.     // constructors, destructor
  38.     _Cdecl filebuf();   // make a closed filebuf
  39.     _Cdecl filebuf(int);    // make a filebuf attached to fd
  40.     _Cdecl filebuf(int __f, signed char _FAR *, int); // same, with specified buffer
  41.     _Cdecl filebuf(int __f, unsigned char _FAR *, int); // same, with specified buffer
  42.     _Cdecl ~filebuf();
  43.  
  44.     int _Cdecl is_open();   // is the file open
  45.     int _Cdecl fd();        // what is the file descriptor
  46.  
  47.     // open named file with mode and protection, attach to this filebuf
  48.     filebuf _FAR * _Cdecl open( const signed char _FAR *, int,
  49.                                 int = filebuf::openprot );
  50.     filebuf _FAR * _Cdecl open( const unsigned char _FAR *, int,
  51.                                 int = filebuf::openprot );
  52.  
  53.     filebuf _FAR * _Cdecl close();      // flush and close file
  54.     filebuf _FAR * _Cdecl attach(int);  // attach this filebuf to opened
  55.                                         // file descriptor
  56.  
  57. /*
  58.  * These perform the streambuf functions on a filebuf
  59.  * Get and Put pointers are kept together
  60.  */
  61. virtual int _Cdecl overflow(int = EOF);
  62. virtual int _Cdecl underflow();
  63. virtual int _Cdecl sync();
  64. virtual streampos  _Cdecl seekoff(streamoff, ios::seek_dir, int);
  65. virtual streambuf _FAR * _Cdecl setbuf(char _FAR *, int);
  66.  
  67. protected:
  68.     int xfd;        // the file descriptor, EOF if closed
  69.     int mode;       // the opened mode
  70.     short   opened; // non-zero if file is open
  71.  
  72.     streampos last_seek;    // unused           ***
  73.     char _FAR *   in_start; // unused           ***
  74.  
  75.     int _Cdecl last_op();   // unused           ***
  76.     char    lahead[2];      // current input char if unbuffered ***
  77. };
  78. /*
  79.  * The data members marked with *** above are not documented in the AT&T
  80.  * release of streams, so we cannot guarantee compatibility with any
  81.  * other streams release in the use or values of these data members.
  82.  * If you can document any expected behavior of these data members, we
  83.  * will try to adjust our implementation accordingly.
  84.  */
  85. inline int  _Cdecl filebuf::is_open()   { return opened; }
  86. inline int  _Cdecl filebuf::fd()        { return xfd; }
  87. inline filebuf _FAR * _Cdecl filebuf::open(const unsigned char _FAR * __name, int __m, int __prot) {
  88.     return filebuf::open((const signed char _FAR *) __name, __m, __prot);
  89.     }
  90.  
  91. class _CLASSTYPE fstreambase : virtual public ios {
  92. public:
  93.     _Cdecl fstreambase();
  94.     _Cdecl fstreambase(const signed char _FAR *, int, int = filebuf::openprot);
  95.     _Cdecl fstreambase(int);
  96.     _Cdecl fstreambase(int __f, signed char _FAR *, int);
  97.     _Cdecl ~fstreambase();
  98.  
  99.     void    _Cdecl open(const signed 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. class _CLASSTYPE ifstream : public fstreambase, public istream {
  121. public:
  122.     _Cdecl ifstream();
  123.     _Cdecl ifstream(const signed char _FAR *,int = ios::in,int = filebuf::openprot);
  124.     _Cdecl ifstream(const unsigned char _FAR *,int = ios::in,int = filebuf::openprot);
  125.     _Cdecl ifstream(int);
  126.     _Cdecl ifstream(int __f, signed char _FAR *, int);
  127.     _Cdecl ifstream(int __f, unsigned char _FAR *, int);
  128.     _Cdecl ~ifstream();
  129.  
  130.     filebuf _FAR * _Cdecl rdbuf();
  131.     void    _Cdecl open(const signed char _FAR *, int = ios::in,
  132.                         int = filebuf::openprot);
  133.     void    _Cdecl open(const unsigned char _FAR *, int = ios::in,
  134.                         int = filebuf::openprot);
  135. };
  136. inline filebuf _FAR * _Cdecl ifstream::rdbuf() { return fstreambase::rdbuf(); }
  137. inline void _Cdecl ifstream::open(const signed char _FAR * __name, int __m, int __prot) {
  138.     fstreambase::open(__name, __m | ios::in, __prot);
  139.     }
  140. inline void _Cdecl ifstream::open(const unsigned char _FAR * __name, int __m, int __prot) {
  141.     fstreambase::open((const signed char _FAR *)__name, __m | ios::in, __prot);
  142.     }
  143.  
  144.  
  145. class _CLASSTYPE ofstream : public fstreambase, public ostream {
  146. public:
  147.     _Cdecl ofstream();
  148.     _Cdecl ofstream(const signed char _FAR *, int = ios::out,
  149.                     int = filebuf::openprot);
  150.     _Cdecl ofstream(const unsigned char _FAR *, int = ios::out,
  151.                     int = filebuf::openprot);
  152.     _Cdecl ofstream(int);
  153.     _Cdecl ofstream(int __f, signed char _FAR *, int);
  154.     _Cdecl ofstream(int __f, unsigned char _FAR *, int);
  155.     _Cdecl ~ofstream();
  156.  
  157.     filebuf _FAR * _Cdecl rdbuf();
  158.     void    _Cdecl open(const signed char _FAR *, int = ios::out,
  159.                         int = filebuf::openprot);
  160.     void    _Cdecl open(const unsigned char _FAR *, int = ios::out,
  161.                         int = filebuf::openprot);
  162. };
  163. inline filebuf _FAR * _Cdecl ofstream::rdbuf() { return fstreambase::rdbuf(); }
  164. inline void _Cdecl ofstream::open(const signed char _FAR * __name, int __m, int __prot) {
  165.     fstreambase::open(__name, __m | ios::out, __prot);
  166.     }
  167. inline void _Cdecl ofstream::open(const unsigned char _FAR * __name, int __m, int __prot) {
  168.     fstreambase::open((const signed char _FAR *)__name, __m | ios::out, __prot);
  169.     }
  170.  
  171.  
  172. class _CLASSTYPE fstream : public fstreambase, public iostream {
  173. public:
  174.     _Cdecl fstream();
  175.     _Cdecl fstream(const signed char _FAR *, int, int = filebuf::openprot);
  176.     _Cdecl fstream(const unsigned char _FAR *, int, int = filebuf::openprot);
  177.     _Cdecl fstream(int);
  178.     _Cdecl fstream(int __f, signed char _FAR *, int);
  179.     _Cdecl fstream(int __f, unsigned char _FAR *, int);
  180.     _Cdecl ~fstream();
  181.  
  182.     filebuf _FAR * _Cdecl rdbuf();
  183.     void    _Cdecl open(const signed char _FAR *, int, int = filebuf::openprot);
  184.     void    _Cdecl open(const unsigned char _FAR *, int, int = filebuf::openprot);
  185. };
  186. inline filebuf _FAR * _Cdecl fstream::rdbuf() {return fstreambase::rdbuf();}
  187. inline void _Cdecl fstream::open(const signed char _FAR * __name, int __m, int __prot) {
  188.     fstreambase::open(__name, __m, __prot);
  189.     }
  190. inline void _Cdecl fstream::open(const unsigned char _FAR * __name, int __m, int __prot) {
  191.     fstreambase::open((const signed char _FAR *)__name, __m, __prot);
  192.     }
  193.  
  194.  
  195. #pragma option -Vo.
  196. #if defined(__BCOPT__)
  197. #pragma option -po.
  198. #endif
  199.  
  200. #endif
  201.