home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / borhead.zip / FSTREAM.H < prev    next >
C/C++ Source or Header  |  1994-11-09  |  6KB  |  213 lines

  1. /*
  2.    fstream.h -- class filebuf and fstream declarations
  3.  
  4. */
  5.  
  6. /*
  7.  *      C/C++ Run Time Library - Version 1.5
  8.  *
  9.  *      Copyright (c) 1987, 1994 by Borland International
  10.  *      All Rights Reserved.
  11.  *
  12.  */
  13.  
  14. #ifndef __cplusplus
  15. #error Must use C++ for the type fstream.
  16. #endif
  17.  
  18. #ifndef __FSTREAM_H
  19. #define __FSTREAM_H
  20.  
  21. #if !defined(___DEFS_H)
  22. #include <_defs.h>
  23. #endif
  24.  
  25. #if !defined(__IOSTREAM_H)
  26. #include <iostream.h>
  27. #endif
  28.  
  29.  
  30. #if !defined(RC_INVOKED)
  31.  
  32. #pragma option -a-
  33.  
  34. #if defined(__BCOPT__)
  35. #endif
  36.  
  37. #if !defined(__TINY__)
  38. #pragma option -RT
  39. #endif
  40.  
  41. #pragma option -Vo-
  42.  
  43. #if defined(__STDC__)
  44. #pragma warn -nak
  45. #endif
  46.  
  47. #endif  /* !RC_INVOKED */
  48.  
  49.  
  50. _CLASSDEF(filebuf)
  51. _CLASSDEF(fstreambase)
  52. _CLASSDEF(ifstream)
  53. _CLASSDEF(ofstream)
  54. _CLASSDEF(fstream)
  55.  
  56. class  _EXPCLASS filebuf : public streambuf {
  57. public:
  58. static const int openprot;  // default file protection
  59.  
  60.     // constructors, destructor
  61.     _RTLENTRY filebuf();   // make a closed filebuf
  62.     _RTLENTRY filebuf(int);    // make a filebuf attached to fd
  63.     _RTLENTRY filebuf(int __f, char _FAR *, int); // same, with specified buffer
  64.     _RTLENTRY ~filebuf();
  65.  
  66.     int _RTLENTRY is_open();   // is the file open
  67.     int _RTLENTRY fd();        // what is the file descriptor
  68.  
  69.     // open named file with mode and protection, attach to this filebuf
  70.     filebuf _FAR * _RTLENTRY open(const char _FAR *, int, int = filebuf::openprot);
  71.  
  72.     filebuf _FAR * _RTLENTRY close();      // flush and close file
  73.     filebuf _FAR * _RTLENTRY attach(int);  // attach this filebuf to opened
  74.                                         // file descriptor
  75.  
  76. /*
  77.  * These perform the streambuf functions on a filebuf
  78.  * Get and Put pointers are kept together
  79.  */
  80. virtual int _RTLENTRY overflow(int = EOF);
  81. virtual int _RTLENTRY underflow();
  82. virtual int _RTLENTRY sync();
  83. virtual streampos  _RTLENTRY seekoff(streamoff, ios::seek_dir, int);
  84. virtual streambuf _FAR * _RTLENTRY setbuf(char _FAR *, int);
  85.  
  86. virtual void _RTLENTRY lock();
  87. virtual void _RTLENTRY unlock();
  88.  
  89. protected:
  90.     int xfd;        // the file descriptor, EOF if closed
  91.     int mode;       // the opened mode
  92.     short   opened; // non-zero if file is open
  93.  
  94.     streampos last_seek;    // unused           ***
  95.     char _FAR *   in_start; // unused           ***
  96.  
  97.     int _RTLENTRY last_op();   // unused           ***
  98.     char    lahead[2];      // current input char if unbuffered ***
  99. };
  100. /*
  101.  * The data members marked with *** above are not documented in the AT&T
  102.  * release of streams, so we cannot guarantee compatibility with any
  103.  * other streams release in the use or values of these data members.
  104.  * If you can document any expected behavior of these data members, we
  105.  * will try to adjust our implementation accordingly.
  106.  */
  107. inline int  _RTLENTRY filebuf::is_open()   { return opened; }
  108. inline int  _RTLENTRY filebuf::fd()        { return xfd; }
  109.  
  110. class _EXPCLASS fstreambase : virtual public ios {
  111. public:
  112.     _RTLENTRY fstreambase();
  113.     _RTLENTRY fstreambase(const char _FAR *, int, int = filebuf::openprot);
  114.     _RTLENTRY fstreambase(int);
  115.     _RTLENTRY fstreambase(int __f, char _FAR *, int);
  116.     _RTLENTRY ~fstreambase();
  117.  
  118.     void    _RTLENTRY open(const char _FAR *, int, int = filebuf::openprot);
  119.     void    _RTLENTRY attach(int);
  120.     void    _RTLENTRY close();
  121.     void    _RTLENTRY setbuf(char _FAR *, int);
  122.     filebuf _FAR * _RTLENTRY rdbuf();
  123.  
  124. protected:
  125.     void    _RTLENTRY verify(int); // unimplemented    ***
  126.  
  127. private:
  128.     filebuf buf;
  129. };
  130. /*
  131.  * The function member marked with *** above is not documented in the AT&T
  132.  * release of streams, so we cannot guarantee compatibility with any
  133.  * other streams release in its use.
  134.  * If you can document any expected behavior of this function member, we
  135.  * will try to adjust our implementation accordingly.
  136.  */
  137. inline filebuf _FAR * _RTLENTRY fstreambase::rdbuf() { return &buf; }
  138.  
  139. class _EXPCLASS ifstream : public fstreambase, public istream {
  140. public:
  141.     _RTLENTRY ifstream();
  142.     _RTLENTRY ifstream(const char _FAR *,int = ios::in,int = filebuf::openprot);
  143.     _RTLENTRY ifstream(int);
  144.     _RTLENTRY ifstream(int __f, char _FAR *, int);
  145.     _RTLENTRY ~ifstream();
  146.  
  147.     filebuf _FAR * _RTLENTRY rdbuf();
  148.     void    _RTLENTRY open(const char _FAR *, int = ios::in,
  149.                         int = filebuf::openprot);
  150. };
  151. inline filebuf _FAR * _RTLENTRY ifstream::rdbuf() { return fstreambase::rdbuf(); }
  152. inline void _RTLENTRY ifstream::open(const char _FAR * __name, int __m, int __prot) {
  153.     fstreambase::open(__name, __m | ios::in, __prot);
  154.     }
  155.  
  156.  
  157. class _EXPCLASS ofstream : public fstreambase, public ostream {
  158. public:
  159.     _RTLENTRY ofstream();
  160.     _RTLENTRY ofstream(const char _FAR *, int = ios::out, int = filebuf::openprot);
  161.     _RTLENTRY ofstream(int);
  162.     _RTLENTRY ofstream(int __f, char _FAR *, int);
  163.     _RTLENTRY ~ofstream();
  164.  
  165.     filebuf _FAR * _RTLENTRY rdbuf();
  166.     void    _RTLENTRY open(const char _FAR *, int = ios::out,
  167.                         int = filebuf::openprot);
  168. };
  169. inline filebuf _FAR * _RTLENTRY ofstream::rdbuf() { return fstreambase::rdbuf(); }
  170. inline void _RTLENTRY ofstream::open(const char _FAR * __name, int __m, int __prot) {
  171.     fstreambase::open(__name, __m | ios::out, __prot);
  172.     }
  173.  
  174.  
  175. class _EXPCLASS fstream : public fstreambase, public iostream {
  176. public:
  177.     _RTLENTRY fstream();
  178.     _RTLENTRY fstream(const char _FAR *, int, int = filebuf::openprot);
  179.     _RTLENTRY fstream(int);
  180.     _RTLENTRY fstream(int __f, char _FAR *, int);
  181.     _RTLENTRY ~fstream();
  182.  
  183.     filebuf _FAR * _RTLENTRY rdbuf();
  184.     void    _RTLENTRY open(const char _FAR *, int, int = filebuf::openprot);
  185. };
  186. inline filebuf _FAR * _RTLENTRY fstream::rdbuf() {return fstreambase::rdbuf();}
  187. inline void _RTLENTRY fstream::open(const char _FAR * __name, int __m, int __prot) {
  188.     fstreambase::open(__name, __m, __prot);
  189.     }
  190.  
  191.  
  192. #if !defined(RC_INVOKED)
  193.  
  194. #if defined(__STDC__)
  195. #pragma warn .nak
  196. #endif
  197.  
  198. #pragma option -Vo.
  199.  
  200. #if !defined(__TINY__)
  201. #pragma option -RT.
  202. #endif
  203.  
  204. #if defined(__BCOPT__)
  205. #endif
  206.  
  207. #pragma option -a. /* restore default packing */
  208.  
  209. #endif  /* !RC_INVOKED */
  210.  
  211.  
  212. #endif  /* __FSTREAM_H */
  213.