home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / progs / CB / DATA.Z / FSTREAM.H < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-18  |  6.3 KB  |  217 lines

  1. /*
  2.    fstream.h -- class filebuf and fstream declarations
  3.  
  4. */
  5.  
  6. /* $Copyright: 1987$ */
  7. /* $Revision:   8.1  $ */
  8.  
  9. #ifndef __cplusplus
  10. #error Must use C++ for the type fstream.
  11. #endif
  12.  
  13. #ifndef __FSTREAM_H
  14. #define __FSTREAM_H
  15.  
  16. #if !defined(___DEFS_H)
  17. #include <_defs.h>
  18. #endif
  19.  
  20. #if !defined(__IOSTREAM_H)
  21. #include <iostream.h>
  22. #endif
  23.  
  24.  
  25. #if !defined(RC_INVOKED)
  26.  
  27. #pragma pack(push, 1)
  28.  
  29. #if defined(__BCOPT__)
  30. #if !defined(_RTL_ALLOW_po) && !defined(__FLAT__)
  31. #pragma option -po-     // disable Object data calling convention
  32. #endif
  33. #endif
  34.  
  35. #if !defined(__TINY__)
  36. #pragma option -RT
  37. #endif
  38.  
  39. #pragma option -Vo-
  40.  
  41. #if defined(__STDC__)
  42. #pragma warn -nak
  43. #endif
  44.  
  45. #endif  /* !RC_INVOKED */
  46.  
  47.  
  48. _CLASSDEF(filebuf)
  49. _CLASSDEF(fstreambase)
  50. _CLASSDEF(ifstream)
  51. _CLASSDEF(ofstream)
  52. _CLASSDEF(fstream)
  53.  
  54. class  _EXPCLASS filebuf : public streambuf {
  55. public:
  56. static const int openprot;  // default file protection
  57.  
  58.     // constructors, destructor
  59.     _RTLENTRY filebuf();   // make a closed filebuf
  60.     _RTLENTRY filebuf(int);    // make a filebuf attached to fd
  61.     _RTLENTRY filebuf(int __f, char _FAR *, int); // same, with specified buffer
  62.     _RTLENTRY ~filebuf();
  63.  
  64.     int _RTLENTRY is_open();   // is the file open
  65.     int _RTLENTRY fd();        // what is the file descriptor
  66.  
  67.     // open named file with mode and protection, attach to this filebuf
  68.     filebuf _FAR * _RTLENTRY open(const char _FAR *, int, int = filebuf::openprot);
  69.  
  70.     filebuf _FAR * _RTLENTRY close();      // flush and close file
  71.     filebuf _FAR * _RTLENTRY attach(int);  // attach this filebuf to opened
  72.                                         // file descriptor
  73.  
  74. /*
  75.  * These perform the streambuf functions on a filebuf
  76.  * Get and Put pointers are kept together
  77.  */
  78. virtual int _RTLENTRY overflow(int = EOF);
  79. virtual int _RTLENTRY underflow();
  80. virtual int _RTLENTRY sync();
  81. virtual streampos  _RTLENTRY seekoff(streamoff, ios::seek_dir, int);
  82. virtual streambuf _FAR * _RTLENTRY setbuf(char _FAR *, int);
  83.  
  84. #if defined(__FLAT__)
  85. virtual void _RTLENTRY lock();
  86. virtual void _RTLENTRY unlock();
  87. #endif
  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. #if !defined(_RTL_ALLOW_po) && !defined(__FLAT__)
  206. #pragma option -po.     // restore Object data calling convention
  207. #endif
  208. #endif
  209.  
  210. /* restore default packing */
  211. #pragma pack(pop)
  212.  
  213. #endif  /* !RC_INVOKED */
  214.  
  215.  
  216. #endif  /* __FSTREAM_H */
  217.