home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c083 / 14.ddi / GENINC.PAK / FSTREAM.H < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-02  |  10.9 KB  |  334 lines

  1. /*  
  2.    fstream.h -- class filebuf and fstream declarations
  3.  
  4. */
  5.  
  6. /*
  7.  *      C/C++ Run Time Library - Version 6.0
  8.  *
  9.  *      Copyright (c) 1987, 1993 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. #pragma option -a-
  30. #pragma option -Vo-
  31. #pragma option  -RT
  32.  
  33.  
  34. #if !defined(__FLAT__)
  35.  
  36. #if defined(__BCOPT__) && !defined(_RTL_ALLOW_po) && !defined(__FLAT__)
  37. #pragma option -po-
  38. #endif
  39.  
  40. _CLASSDEF(filebuf)
  41. _CLASSDEF(fstreambase)
  42. _CLASSDEF(ifstream)
  43. _CLASSDEF(ofstream)
  44. _CLASSDEF(fstream)
  45.  
  46. class  _CLASSTYPE filebuf : public streambuf {
  47. public:
  48. static const int openprot;  // default file protection
  49.  
  50.     // constructors, destructor
  51.     _Cdecl filebuf();   // make a closed filebuf
  52.     _Cdecl filebuf(int);    // make a filebuf attached to fd
  53.     _Cdecl filebuf(int __f, char _FAR *, int); // same, with specified buffer
  54.     _Cdecl ~filebuf();
  55.  
  56.     int _Cdecl is_open();   // is the file open
  57.     int _Cdecl fd();        // what is the file descriptor
  58.  
  59.     // open named file with mode and protection, attach to this filebuf
  60.     filebuf _FAR * _Cdecl open(const char _FAR *, int, int = filebuf::openprot);
  61.  
  62.     filebuf _FAR * _Cdecl close();      // flush and close file
  63.     filebuf _FAR * _Cdecl attach(int);  // attach this filebuf to opened
  64.                                         // file descriptor
  65.  
  66. /*
  67.  * These perform the streambuf functions on a filebuf
  68.  * Get and Put pointers are kept together
  69.  */
  70. virtual int _Cdecl overflow(int = EOF);
  71. virtual int _Cdecl underflow();
  72. virtual int _Cdecl sync();
  73. virtual streampos  _Cdecl seekoff(streamoff, ios::seek_dir, int);
  74. virtual streambuf _FAR * _Cdecl setbuf(char _FAR *, int);
  75.  
  76. protected:
  77.     int xfd;        // the file descriptor, EOF if closed
  78.     int mode;       // the opened mode
  79.     short   opened; // non-zero if file is open
  80.  
  81.     streampos last_seek;    // unused           ***
  82.     char _FAR *   in_start; // unused           ***
  83.  
  84.     int _Cdecl last_op();   // unused           ***
  85.     char    lahead[2];      // current input char if unbuffered ***
  86. };
  87. /*
  88.  * The data members marked with *** above are not documented in the AT&T
  89.  * release of streams, so we cannot guarantee compatibility with any
  90.  * other streams release in the use or values of these data members.
  91.  * If you can document any expected behavior of these data members, we
  92.  * will try to adjust our implementation accordingly.
  93.  */
  94. inline int  _Cdecl filebuf::is_open()   { return opened; }
  95. inline int  _Cdecl filebuf::fd()        { return xfd; }
  96.  
  97. class _CLASSTYPE fstreambase : virtual public ios {
  98. public:
  99.     _Cdecl fstreambase();
  100.     _Cdecl fstreambase(const char _FAR *, int, int = filebuf::openprot);
  101.     _Cdecl fstreambase(int);
  102.     _Cdecl fstreambase(int __f, char _FAR *, int);
  103.     _Cdecl ~fstreambase();
  104.  
  105.     void    _Cdecl open(const char _FAR *, int, int = filebuf::openprot);
  106.     void    _Cdecl attach(int);
  107.     void    _Cdecl close();
  108.     void    _Cdecl setbuf(char _FAR *, int);
  109.     filebuf _FAR * _Cdecl rdbuf();
  110.  
  111. protected:
  112.     void    _Cdecl verify(int); // unimplemented    ***
  113.  
  114. private:
  115.     filebuf buf;
  116. };
  117. /*
  118.  * The function member marked with *** above is not documented in the AT&T
  119.  * release of streams, so we cannot guarantee compatibility with any
  120.  * other streams release in its use.
  121.  * If you can document any expected behavior of this function member, we
  122.  * will try to adjust our implementation accordingly.
  123.  */
  124. inline filebuf _FAR * _Cdecl fstreambase::rdbuf() { return &buf; }
  125.  
  126. class _CLASSTYPE ifstream : public fstreambase, public istream {
  127. public:
  128.     _Cdecl ifstream();
  129.     _Cdecl ifstream(const char _FAR *,int = ios::in,int = filebuf::openprot);
  130.     _Cdecl ifstream(int);
  131.     _Cdecl ifstream(int __f, char _FAR *, int);
  132.     _Cdecl ~ifstream();
  133.  
  134.     filebuf _FAR * _Cdecl rdbuf();
  135.     void    _Cdecl open(const char _FAR *, int = ios::in,
  136.                         int = filebuf::openprot);
  137. };
  138. inline filebuf _FAR * _Cdecl ifstream::rdbuf() { return fstreambase::rdbuf(); }
  139. inline void _Cdecl ifstream::open(const char _FAR * __name, int __m, int __prot) {
  140.     fstreambase::open(__name, __m | ios::in, __prot);
  141.     }
  142.  
  143.  
  144. class _CLASSTYPE ofstream : public fstreambase, public ostream {
  145. public:
  146.     _Cdecl ofstream();
  147.     _Cdecl ofstream(const char _FAR *, int = ios::out, int = filebuf::openprot);
  148.     _Cdecl ofstream(int);
  149.     _Cdecl ofstream(int __f, char _FAR *, int);
  150.     _Cdecl ~ofstream();
  151.  
  152.     filebuf _FAR * _Cdecl rdbuf();
  153.     void    _Cdecl open(const char _FAR *, int = ios::out,
  154.                         int = filebuf::openprot);
  155. };
  156. inline filebuf _FAR * _Cdecl ofstream::rdbuf() { return fstreambase::rdbuf(); }
  157. inline void _Cdecl ofstream::open(const char _FAR * __name, int __m, int __prot) {
  158.     fstreambase::open(__name, __m | ios::out, __prot);
  159.     }
  160.  
  161.  
  162. class _CLASSTYPE fstream : public fstreambase, public iostream {
  163. public:
  164.     _Cdecl fstream();
  165.     _Cdecl fstream(const char _FAR *, int, int = filebuf::openprot);
  166.     _Cdecl fstream(int);
  167.     _Cdecl fstream(int __f, char _FAR *, int);
  168.     _Cdecl ~fstream();
  169.  
  170.     filebuf _FAR * _Cdecl rdbuf();
  171.     void    _Cdecl open(const char _FAR *, int, int = filebuf::openprot);
  172. };
  173. inline filebuf _FAR * _Cdecl fstream::rdbuf() {return fstreambase::rdbuf();}
  174. inline void _Cdecl fstream::open(const char _FAR * __name, int __m, int __prot) {
  175.     fstreambase::open(__name, __m, __prot);
  176.     }
  177.  
  178. #if defined(__BCOPT__) && !defined(_RTL_ALLOW_po) && !defined(__FLAT__) 
  179. #pragma option -po.
  180. #endif
  181.  
  182. #else  /* defined __FLAT__ */
  183.  
  184. _CLASSDEF(filebuf)
  185. _CLASSDEF(fstreambase)
  186. _CLASSDEF(ifstream)
  187. _CLASSDEF(ofstream)
  188. _CLASSDEF(fstream)
  189.  
  190. class  _EXPCLASS filebuf : public streambuf {
  191. public:
  192. static const int openprot;  // default file protection
  193.  
  194.     // constructors, destructor
  195.     _RTLENTRY filebuf();   // make a closed filebuf
  196.     _RTLENTRY filebuf(int);    // make a filebuf attached to fd
  197.     _RTLENTRY filebuf(int _f, char *, int); // same, with specified buffer
  198.     _RTLENTRY ~filebuf();
  199.  
  200.     int _RTLENTRY is_open();   // is the file open
  201.     int _RTLENTRY fd();        // what is the file descriptor
  202.  
  203.     // open named file with mode and protection, attach to this filebuf
  204.     filebuf* _RTLENTRY open( const char *, int,
  205.                                 int = filebuf::openprot );
  206.  
  207.     filebuf* _RTLENTRY close();      // flush and close file
  208.     filebuf* _RTLENTRY attach(int);  // attach this filebuf to opened
  209.                                         // file descriptor
  210.  
  211. /*
  212.  * These perform the streambuf functions on a filebuf
  213.  * Get and Put pointers are kept together
  214.  */
  215. virtual int _RTLENTRY overflow(int = EOF);
  216. virtual int _RTLENTRY underflow();
  217. virtual int _RTLENTRY sync();
  218. virtual streampos  _RTLENTRY seekoff(streamoff, ios::seek_dir, int);
  219. virtual streambuf* _RTLENTRY setbuf(char *, int);
  220. virtual void _RTLENTRY lock();
  221. virtual void _RTLENTRY unlock();
  222.  
  223. protected:
  224.     int xfd;        // the file descriptor, EOF if closed
  225.     int mode;       // the opened mode
  226.     short   opened; // non-zero if file is open
  227.  
  228.     streampos last_seek;    // unused           ***
  229.     char *   in_start; // unused           ***
  230.  
  231.     int _RTLENTRY last_op();   // unused           ***
  232.     char    lahead[2];      // current input char if unbuffered ***
  233. };
  234. /*
  235.  * The data members marked with *** above are not documented in the AT&T
  236.  * release of streams, so we cannot guarantee compatibility with any
  237.  * other streams release in the use or values of these data members.
  238.  * If you can document any expected behavior of these data members, we
  239.  * will try to adjust our implementation accordingly.
  240.  */
  241. inline int  _RTLENTRY filebuf::is_open()   { return opened; }
  242. inline int  _RTLENTRY filebuf::fd()        { return xfd; }
  243.  
  244. class _EXPCLASS fstreambase : virtual public ios {
  245. public:
  246.     _RTLENTRY fstreambase();
  247.     _RTLENTRY fstreambase(const char *, int, int = filebuf::openprot);
  248.     _RTLENTRY fstreambase(int);
  249.     _RTLENTRY fstreambase(int _f, char *, int);
  250.     _RTLENTRY ~fstreambase();
  251.  
  252.     void    _RTLENTRY open(const char *, int, int = filebuf::openprot);
  253.     void    _RTLENTRY attach(int);
  254.     void    _RTLENTRY close();
  255.     void    _RTLENTRY setbuf(char *, int);
  256.     filebuf* _RTLENTRY rdbuf();
  257.  
  258. protected:
  259.     void    _RTLENTRY verify(int); // unimplemented    ***
  260.  
  261. private:
  262.     filebuf buf;
  263. };
  264. /*
  265.  * The function member marked with *** above is not documented in the AT&T
  266.  * release of streams, so we cannot guarantee compatibility with any
  267.  * other streams release in its use.
  268.  * If you can document any expected behavior of this function member, we
  269.  * will try to adjust our implementation accordingly.
  270.  */
  271. inline filebuf* _RTLENTRY fstreambase::rdbuf() { return &buf; }
  272.  
  273.  
  274. class _EXPCLASS ifstream : public fstreambase, public istream {
  275. public:
  276.     _RTLENTRY ifstream();
  277.     _RTLENTRY ifstream(const char *,int = ios::in,int = filebuf::openprot);
  278.     _RTLENTRY ifstream(int);
  279.     _RTLENTRY ifstream(int _f, char *, int);
  280.     _RTLENTRY ~ifstream();
  281.  
  282.     filebuf* _RTLENTRY rdbuf();
  283.     void    _RTLENTRY open(const char *, int = ios::in,
  284.                         int = filebuf::openprot);
  285. };
  286. inline filebuf* _RTLENTRY ifstream::rdbuf() { return fstreambase::rdbuf(); }
  287. inline void _RTLENTRY ifstream::open(const char * name, int m, int prot) {
  288.                 fstreambase::open(name, m | ios::in, prot);
  289.                 }
  290.  
  291.  
  292. class _EXPCLASS ofstream : public fstreambase, public ostream {
  293. public:
  294.     _RTLENTRY ofstream();
  295.     _RTLENTRY ofstream(const char *, int = ios::out,
  296.                     int = filebuf::openprot);
  297.     _RTLENTRY ofstream(int);
  298.     _RTLENTRY ofstream(int _f, char *, int);
  299.     _RTLENTRY ~ofstream();
  300.  
  301.     filebuf* _RTLENTRY rdbuf();
  302.     void    _RTLENTRY open(const char *, int = ios::out,
  303.                         int = filebuf::openprot);
  304. };
  305. inline filebuf* _RTLENTRY ofstream::rdbuf() { return fstreambase::rdbuf(); }
  306. inline void _RTLENTRY ofstream::open(const char * name, int m, int prot) {
  307.                 fstreambase::open(name, m | ios::out, prot);
  308.                 }
  309.  
  310.  
  311. class _EXPCLASS fstream : public fstreambase, public iostream {
  312. public:
  313.     _RTLENTRY fstream();
  314.     _RTLENTRY fstream(const char *, int, int = filebuf::openprot);
  315.     _RTLENTRY fstream(int);
  316.     _RTLENTRY fstream(int _f, char *, int);
  317.     _RTLENTRY ~fstream();
  318.  
  319.     filebuf* _RTLENTRY rdbuf();
  320.     void    _RTLENTRY open(const char *, int, int = filebuf::openprot);
  321. };
  322. inline filebuf* _RTLENTRY fstream::rdbuf() {return fstreambase::rdbuf();}
  323. inline void _RTLENTRY fstream::open(const char * name, int m, int prot) {
  324.                 fstreambase::open(name, m, prot);
  325.                 }
  326.  
  327. #endif  /* __FLAT__ */
  328.  
  329. #pragma option -RT.
  330. #pragma option -Vo.
  331. #pragma option -a. /* restore default packing */
  332.  
  333. #endif  /* __FSTREAM_H */
  334.