home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c031 / 4.ddi / INCLUDE / FSTREAM.H$ / FSTREAM
Encoding:
Text File  |  1992-01-15  |  4.0 KB  |  142 lines

  1. /***
  2. *fstream.h - definitions/declarations for filebuf and fstream classes
  3. *
  4. *    Copyright (c) 1991-1992, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *    This file defines the classes, values, macros, and functions
  8. *    used by the filebuf and fstream classes.
  9. *    [AT&T C++]
  10. *
  11. ****/
  12.  
  13. #ifndef _INC_FSTREAM
  14. #define _INC_FSTREAM
  15.  
  16. #include <iostream.h>
  17.  
  18. // Force word packing to avoid possible -Zp override
  19. #pragma pack(2)
  20.  
  21. #pragma warning(disable:4505)        // disable unwanted /W4 warning
  22. // #pragma warning(default:4505)    // use this to reenable, if necessary
  23.  
  24. #ifdef M_I86HM        // fold huge member pointers into far
  25. #define _HFAR_ __far
  26. #else
  27. #define _HFAR_
  28. #endif
  29.  
  30. typedef int filedesc;
  31.  
  32. class filebuf : public streambuf {
  33. public:
  34. static    const int    openprot;    // default share/prot mode for open
  35.  
  36. // optional share values for 3rd argument (prot) of open or constructor
  37. static    const int    sh_compat;    // compatibility share mode
  38. static    const int    sh_none;    // exclusive mode no sharing
  39. static    const int    sh_read;    // allow read sharing
  40. static    const int    sh_write;    // allow write sharing
  41. // use (sh_read | sh_write) to allow both read and write sharing
  42.  
  43. // options for setmode member function
  44. static    const int    binary;
  45. static    const int    text;
  46.  
  47.             filebuf();
  48.             filebuf(filedesc);
  49.             filebuf(filedesc, char _HFAR_ *, int);
  50.             ~filebuf();
  51.  
  52.     filebuf*    attach(filedesc);
  53.     filedesc    fd() const { return (x_fd==-1) ? EOF : x_fd; }
  54.     int        is_open() const { return (x_fd!=-1); }
  55.     filebuf*    open(const char _HFAR_ *, int, int = filebuf::openprot);
  56.     filebuf*    close();
  57.     int        setmode(int = filebuf::text);
  58.  
  59. virtual    int        overflow(int=EOF);
  60. virtual    int        underflow();
  61.  
  62. virtual    streambuf*    setbuf(char _HFAR_ *, int);
  63. virtual    streampos    seekoff(streamoff, ios::seek_dir, int);
  64. // virtual    streampos    seekpos(streampos, int);
  65. virtual    int        sync();
  66.  
  67. private:
  68.     filedesc    x_fd;
  69.     int        x_fOpened;
  70. };
  71.  
  72. class ifstream : public istream {
  73. public:
  74.     ifstream();
  75.     ifstream(const char _HFAR_ *, int =ios::in, int = filebuf::openprot);
  76.     ifstream(filedesc);
  77.     ifstream(filedesc, char _HFAR_ *, int);
  78.     ~ifstream();
  79.  
  80.     streambuf * setbuf(char _HFAR_ *, int);
  81.     filebuf* rdbuf() const { return (filebuf*) ios::rdbuf(); }
  82.  
  83.     void attach(filedesc);
  84.     filedesc fd() const { return rdbuf()->fd(); }
  85.  
  86.     int is_open() const { return rdbuf()->is_open(); }
  87.     void open(const char _HFAR_ *, int =ios::in, int = filebuf::openprot);
  88.     void close();
  89.     int setmode(int mode = filebuf::text) { return rdbuf()->setmode(mode); }
  90. };
  91.  
  92. class ofstream : public ostream {
  93. public:
  94.     ofstream();
  95.     ofstream(const char _HFAR_ *, int =ios::out, int = filebuf::openprot);
  96.     ofstream(filedesc);
  97.     ofstream(filedesc, char _HFAR_ *, int);
  98.     ~ofstream();
  99.  
  100.     streambuf * setbuf(char _HFAR_ *, int);
  101.     filebuf* rdbuf() const { return (filebuf*) ios::rdbuf(); }
  102.  
  103.     void attach(filedesc);
  104.     filedesc fd() const { return rdbuf()->fd(); }
  105.  
  106.     int is_open() const { return rdbuf()->is_open(); }
  107.     void open(const char _HFAR_ *, int =ios::out, int = filebuf::openprot);
  108.     void close();
  109.     int setmode(int mode = filebuf::text) { return rdbuf()->setmode(mode); }
  110. };
  111.     
  112. class fstream : public iostream {
  113. public:
  114.     fstream();
  115.     fstream(const char _HFAR_ *, int, int = filebuf::openprot);
  116.     fstream(filedesc);
  117.     fstream(filedesc, char _HFAR_ *, int);
  118.     ~fstream();
  119.  
  120.     streambuf * setbuf(char _HFAR_ *, int);
  121.     filebuf* rdbuf() const { return (filebuf*) ostream::rdbuf(); }
  122.  
  123.     void attach(filedesc);
  124.     filedesc fd() const { return rdbuf()->fd(); }
  125.  
  126.     int is_open() const { return rdbuf()->is_open(); }
  127.     void open(const char _HFAR_ *, int, int = filebuf::openprot);
  128.     void close();
  129.     int setmode(int mode = filebuf::text) { return rdbuf()->setmode(mode); }
  130. };
  131.     
  132. // manipulators to dynamically change file access mode (filebufs only)
  133. inline    ios& binary(ios& _fstrm) \
  134.    { ((filebuf*)_fstrm.rdbuf())->setmode(filebuf::binary); return _fstrm; }
  135. inline    ios& text(ios& _fstrm) \
  136.    { ((filebuf*)_fstrm.rdbuf())->setmode(filebuf::text); return _fstrm; }
  137.  
  138. // Restore default packing
  139. #pragma pack()
  140.  
  141. #endif        // !_INC_FSTREAM
  142.