fstream.mh
来自「开放源码的编译器open watcom 1.6.0版的源代码」· MH 代码 · 共 223 行
MH
223 行
///////////////////////////////////////////////////////////////////////////
// FILE: fstream/fstream.h (fstream support)
//
:keep CPP_HDR
:include crwat.sp
//
// Description: This header is part of the C++ standard library. It
// defines the necessary classes for file stream support.
///////////////////////////////////////////////////////////////////////////
:segment !CNAME
#ifndef _FSTREAM_H_INCLUDED
#define _FSTREAM_H_INCLUDED
:include readonly.sp
#ifndef _FSTREAM_INCLUDED
#include <fstream>
#endif
using std::filebuf;
using std::fstreambase;
using std::ifstream;
using std::ofstream;
using std::fstream;
// All included names should also be in the global namespace.
#ifndef _IOSTREAM_H_INCLUDED
#include <iostream.h>
#endif
#endif
:elsesegment
#ifndef _FSTREAM_INCLUDED
#define _FSTREAM_INCLUDED
:include readonly.sp
#ifndef __cplusplus
#error The header fstream requires C++
#endif
#ifndef _COMDEF_H_INCLUDED
#include <_comdef.h>
#endif
#ifndef _IOSTREAM_INCLUDED
#include <iostream>
#endif
// POSIX file handle:
typedef int filedesc;
namespace std {
// **************************** FILEBUF ************************************
:include pshpackl.sp
class _WPRTLINK filebuf : public streambuf {
public:
static int const openprot; // default file protection
enum sh_mode { // sharing mode
sh_compat = 0x0000, // - compatibility mode
sh_read = 0x1000, // - allow others to read
sh_write = 0x2000, // - allow others to write
sh_none = 0x4000 // - do not allow others to read or write
};
typedef int shmode;
filebuf();
filebuf( filedesc __fd );
filebuf( filedesc __fd, char *__buf, int __len );
~filebuf();
int is_open() const;
filedesc fd() const;
filebuf *attach( filedesc __fd );
filebuf *open( char const *__name,
ios::openmode __mode,
int __prot = openprot );
filebuf *close();
virtual int pbackfail( int __c );
virtual int overflow( int = EOF );
virtual int underflow();
virtual streambuf *setbuf( char *__buf, int __len );
virtual streampos seekoff( streamoff __offset,
ios::seekdir __direction,
ios::openmode __ignored );
virtual int sync();
private:
filedesc __file_handle;
ios::openmode __file_mode;
char __unbuffered_get_area[ DEFAULT_PUTBACK_SIZE+1 ];
char __attached : 1;
int : 0;
};
:include poppack.sp
inline filedesc filebuf::fd() const {
return( __file_handle );
}
inline int filebuf::is_open() const {
return( __file_handle != EOF );
}
// **************************** FSTREAMBASE ********************************
:include pshpackl.sp
class _WPRTLINK fstreambase : virtual public ios {
public:
int is_open() const;
filedesc fd() const;
void attach( filedesc __fd );
void open( char const *__name,
ios::openmode __mode,
int __prot = filebuf::openprot );
void close();
filebuf *rdbuf() const;
void setbuf( char *__buf, int __len );
protected:
fstreambase();
fstreambase( char const *__name,
ios::openmode __mode,
int __prot = filebuf::openprot );
fstreambase( filedesc __fd );
fstreambase( filedesc __fd, char *__buf, int __len );
~fstreambase();
private:
filebuf __flbuf;
};
:include poppack.sp
inline filedesc fstreambase::fd() const {
__lock_it( __i_lock );
filebuf *__fb = rdbuf();
return( (__fb == NULL) ? EOF : __fb->fd() );
}
inline int fstreambase::is_open() const {
__lock_it( __i_lock );
filebuf *__fb = rdbuf();
return( (__fb == NULL) ? 0 : __fb->is_open() );
}
inline filebuf *fstreambase::rdbuf() const {
return( (filebuf *) ios::rdbuf() );
}
// **************************** IFSTREAM ***********************************
:include pshpackl.sp
class _WPRTLINK ifstream : public fstreambase, public istream {
public:
ifstream();
ifstream( char const *__name,
ios::openmode __mode = ios::in,
int __prot = filebuf::openprot );
ifstream( filedesc __fd );
ifstream( filedesc __fd, char *__buf, int __len );
~ifstream();
void open( char const *__name,
ios::openmode __mode = ios::in,
int __prot = filebuf::openprot );
};
:include poppack.sp
inline void ifstream::open( char const *__n, ios::openmode __m, int __p ) {
fstreambase::open( __n, __m, __p );
}
// **************************** OFSTREAM ***********************************
:include pshpackl.sp
class _WPRTLINK ofstream : public fstreambase, public ostream {
public:
ofstream();
ofstream( char const *__name,
ios::openmode __mode = ios::out,
int __prot = filebuf::openprot );
ofstream( filedesc __fd );
ofstream( filedesc __fd, char *__buf, int __len );
~ofstream();
void open( char const *__name,
ios::openmode __mode = ios::out,
int __prot = filebuf::openprot );
};
:include poppack.sp
inline void ofstream::open( char const *__n, ios::openmode __m, int __p ) {
fstreambase::open( __n, __m, __p );
}
// **************************** FSTREAM ************************************
:include pshpackl.sp
class _WPRTLINK fstream : public fstreambase, public iostream {
public:
fstream();
fstream( char const *__name,
ios::openmode __mode = ios::in|ios::out,
int __prot = filebuf::openprot );
fstream( filedesc __fd );
fstream( filedesc __fd, char *__buf, int __len );
~fstream();
void open( char const *__name,
ios::openmode __mode = ios::in|ios::out,
int __prot = filebuf::openprot );
};
:include poppack.sp
inline void fstream::open( char const *__n, ios::openmode __m, int __p ) {
fstreambase::open( __n, __m, __p );
}
}
#endif
:endsegment
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?