Annotation of mstools/h/fstream.h, revision 1.1.1.1

1.1       root        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(4)
                     20: 
                     21: #pragma warning(disable:4505)          // disable unwanted /W4 warning
                     22: // #pragma warning(default:4505)       // use this to reenable, if necessary
                     23: 
                     24: typedef int filedesc;
                     25: 
                     26: class filebuf : public streambuf {
                     27: public:
                     28: static const int       openprot;       // default share/prot mode for open
                     29: 
                     30: // optional share values for 3rd argument (prot) of open or constructor
                     31: static const int       sh_none;        // exclusive mode no sharing
                     32: static const int       sh_read;        // allow read sharing
                     33: static const int       sh_write;       // allow write sharing
                     34: // use (sh_read | sh_write) to allow both read and write sharing
                     35: 
                     36: // options for setmode member function
                     37: static const int       binary;
                     38: static const int       text;
                     39: 
                     40:                        filebuf();
                     41:                        filebuf(filedesc);
                     42:                        filebuf(filedesc, char *, int);
                     43:                        ~filebuf();
                     44: 
                     45:        filebuf*        attach(filedesc);
                     46:        filedesc        fd() const { return (x_fd==-1) ? EOF : x_fd; }
                     47:        int             is_open() const { return (x_fd!=-1); }
                     48:        filebuf*        open(const char *, int, int = filebuf::openprot);
                     49:        filebuf*        close();
                     50:        int             setmode(int = filebuf::text);
                     51: 
                     52: virtual        int             overflow(int=EOF);
                     53: virtual        int             underflow();
                     54: 
                     55: virtual        streambuf*      setbuf(char *, int);
                     56: virtual        streampos       seekoff(streamoff, ios::seek_dir, int);
                     57: // virtual     streampos       seekpos(streampos, int);
                     58: virtual        int             sync();
                     59: 
                     60: private:
                     61:        filedesc        x_fd;
                     62:        int             x_fOpened;
                     63: };
                     64: 
                     65: class ifstream : public istream {
                     66: public:
                     67:        ifstream();
                     68:        ifstream(const char *, int =ios::in, int = filebuf::openprot);
                     69:        ifstream(filedesc);
                     70:        ifstream(filedesc, char *, int);
                     71:        ~ifstream();
                     72: 
                     73:        streambuf * setbuf(char *, int);
                     74:        filebuf* rdbuf() const { return (filebuf*) ios::rdbuf(); }
                     75: 
                     76:        void attach(filedesc);
                     77:        filedesc fd() const { return rdbuf()->fd(); }
                     78: 
                     79:        int is_open() const { return rdbuf()->is_open(); }
                     80:        void open(const char *, int =ios::in, int = filebuf::openprot);
                     81:        void close();
                     82:        int setmode(int mode = filebuf::text) { return rdbuf()->setmode(mode); }
                     83: };
                     84: 
                     85: class ofstream : public ostream {
                     86: public:
                     87:        ofstream();
                     88:        ofstream(const char *, int =ios::out, int = filebuf::openprot);
                     89:        ofstream(filedesc);
                     90:        ofstream(filedesc, char *, int);
                     91:        ~ofstream();
                     92: 
                     93:        streambuf * setbuf(char *, int);
                     94:        filebuf* rdbuf() const { return (filebuf*) ios::rdbuf(); }
                     95: 
                     96:        void attach(filedesc);
                     97:        filedesc fd() const { return rdbuf()->fd(); }
                     98: 
                     99:        int is_open() const { return rdbuf()->is_open(); }
                    100:        void open(const char *, int =ios::out, int = filebuf::openprot);
                    101:        void close();
                    102:        int setmode(int mode = filebuf::text) { return rdbuf()->setmode(mode); }
                    103: };
                    104:        
                    105: class fstream : public iostream {
                    106: public:
                    107:        fstream();
                    108:        fstream(const char *, int, int = filebuf::openprot);
                    109:        fstream(filedesc);
                    110:        fstream(filedesc, char *, int);
                    111:        ~fstream();
                    112: 
                    113:        streambuf * setbuf(char *, int);
                    114:        filebuf* rdbuf() const { return (filebuf*) ostream::rdbuf(); }
                    115: 
                    116:        void attach(filedesc);
                    117:        filedesc fd() const { return rdbuf()->fd(); }
                    118: 
                    119:        int is_open() const { return rdbuf()->is_open(); }
                    120:        void open(const char *, int, int = filebuf::openprot);
                    121:        void close();
                    122:        int setmode(int mode = filebuf::text) { return rdbuf()->setmode(mode); }
                    123: };
                    124:        
                    125: // manipulators to dynamically change file access mode (filebufs only)
                    126: inline ios& binary(ios& _fstrm) \
                    127:    { ((filebuf*)_fstrm.rdbuf())->setmode(filebuf::binary); return _fstrm; }
                    128: inline ios& text(ios& _fstrm) \
                    129:    { ((filebuf*)_fstrm.rdbuf())->setmode(filebuf::text); return _fstrm; }
                    130: 
                    131: // Restore default packing
                    132: #pragma pack()
                    133: 
                    134: #endif         // !_INC_FSTREAM

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.