|
|
1.1 root 1: /***
2: *fstream.h - definitions/declarations for filebuf and fstream classes
3: *
1.1.1.2 ! root 4: * Copyright (c) 1991-1993, Microsoft Corporation. All rights reserved.
1.1 root 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:
1.1.1.2 ! root 18: // C4505: "unreferenced local function has been removed"
! 19: #pragma warning(disable:4505) // disable C4505 warning
! 20: // #pragma warning(default:4505) // use this to reenable, if desired
! 21:
! 22: // C4103 : "used #pragma pack to change alignment"
! 23: #pragma warning(disable:4103) // disable C4103 warning
! 24: // #pragma warning(default:4103) // use this to reenable, if desired
! 25:
1.1 root 26: // Force word packing to avoid possible -Zp override
27: #pragma pack(4)
28:
29: typedef int filedesc;
30:
31: class filebuf : public streambuf {
32: public:
33: static const int openprot; // default share/prot mode for open
34:
35: // optional share values for 3rd argument (prot) of open or constructor
36: static const int sh_none; // exclusive mode no sharing
37: static const int sh_read; // allow read sharing
38: static const int sh_write; // allow write sharing
39: // use (sh_read | sh_write) to allow both read and write sharing
40:
41: // options for setmode member function
42: static const int binary;
43: static const int text;
44:
45: filebuf();
46: filebuf(filedesc);
47: filebuf(filedesc, char *, int);
48: ~filebuf();
49:
50: filebuf* attach(filedesc);
51: filedesc fd() const { return (x_fd==-1) ? EOF : x_fd; }
52: int is_open() const { return (x_fd!=-1); }
53: filebuf* open(const char *, int, int = filebuf::openprot);
54: filebuf* close();
55: int setmode(int = filebuf::text);
56:
57: virtual int overflow(int=EOF);
58: virtual int underflow();
59:
60: virtual streambuf* setbuf(char *, int);
61: virtual streampos seekoff(streamoff, ios::seek_dir, int);
62: // virtual streampos seekpos(streampos, int);
63: virtual int sync();
64:
65: private:
66: filedesc x_fd;
67: int x_fOpened;
68: };
69:
70: class ifstream : public istream {
71: public:
72: ifstream();
73: ifstream(const char *, int =ios::in, int = filebuf::openprot);
74: ifstream(filedesc);
75: ifstream(filedesc, char *, int);
76: ~ifstream();
77:
78: streambuf * setbuf(char *, int);
79: filebuf* rdbuf() const { return (filebuf*) ios::rdbuf(); }
80:
81: void attach(filedesc);
82: filedesc fd() const { return rdbuf()->fd(); }
83:
84: int is_open() const { return rdbuf()->is_open(); }
85: void open(const char *, int =ios::in, int = filebuf::openprot);
86: void close();
87: int setmode(int mode = filebuf::text) { return rdbuf()->setmode(mode); }
88: };
89:
90: class ofstream : public ostream {
91: public:
92: ofstream();
93: ofstream(const char *, int =ios::out, int = filebuf::openprot);
94: ofstream(filedesc);
95: ofstream(filedesc, char *, int);
96: ~ofstream();
97:
98: streambuf * setbuf(char *, int);
99: filebuf* rdbuf() const { return (filebuf*) ios::rdbuf(); }
100:
101: void attach(filedesc);
102: filedesc fd() const { return rdbuf()->fd(); }
103:
104: int is_open() const { return rdbuf()->is_open(); }
105: void open(const char *, int =ios::out, int = filebuf::openprot);
106: void close();
107: int setmode(int mode = filebuf::text) { return rdbuf()->setmode(mode); }
108: };
109:
110: class fstream : public iostream {
111: public:
112: fstream();
113: fstream(const char *, int, int = filebuf::openprot);
114: fstream(filedesc);
115: fstream(filedesc, char *, int);
116: ~fstream();
117:
118: streambuf * setbuf(char *, int);
119: filebuf* rdbuf() const { return (filebuf*) ostream::rdbuf(); }
120:
121: void attach(filedesc);
122: filedesc fd() const { return rdbuf()->fd(); }
123:
124: int is_open() const { return rdbuf()->is_open(); }
125: void open(const char *, int, int = filebuf::openprot);
126: void close();
127: int setmode(int mode = filebuf::text) { return rdbuf()->setmode(mode); }
128: };
129:
130: // manipulators to dynamically change file access mode (filebufs only)
131: inline ios& binary(ios& _fstrm) \
132: { ((filebuf*)_fstrm.rdbuf())->setmode(filebuf::binary); return _fstrm; }
133: inline ios& text(ios& _fstrm) \
134: { ((filebuf*)_fstrm.rdbuf())->setmode(filebuf::text); return _fstrm; }
135:
136: // Restore default packing
137: #pragma pack()
138:
139: #endif // !_INC_FSTREAM
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.