home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / INC.PAK / FSTREAM.H < prev    next >
C/C++ Source or Header  |  1995-08-29  |  7KB  |  221 lines

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