michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * Robin J. Maxwell 11-22-96 michael@0: * Fredrik Roubert 2010-07-23 michael@0: * Matt Austern 2010-07-23 michael@0: */ michael@0: michael@0: #ifndef _PRSTRMS_H michael@0: #define _PRSTRMS_H michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include "prio.h" michael@0: michael@0: #ifdef _MSC_VER michael@0: // http://support.microsoft.com/kb/q168958/ michael@0: class PR_IMPLEMENT(std::_Mutex); michael@0: class PR_IMPLEMENT(std::ios_base); michael@0: #endif michael@0: michael@0: michael@0: class PR_IMPLEMENT(PRfilebuf): public std::streambuf michael@0: { michael@0: public: michael@0: PRfilebuf(); michael@0: PRfilebuf(PRFileDesc *fd); michael@0: PRfilebuf(PRFileDesc *fd, char_type *ptr, std::streamsize len); michael@0: virtual ~PRfilebuf(); michael@0: michael@0: bool is_open() const { return _fd != NULL; } michael@0: michael@0: PRfilebuf *open( michael@0: const char *name, michael@0: std::ios_base::openmode flags, michael@0: PRIntn mode); michael@0: PRfilebuf *attach(PRFileDesc *fd); michael@0: PRfilebuf *close(); michael@0: michael@0: protected: michael@0: virtual std::streambuf *setbuf(char_type *ptr, std::streamsize len); michael@0: virtual pos_type seekoff( michael@0: off_type offset, michael@0: std::ios_base::seekdir dir, michael@0: std::ios_base::openmode flags); michael@0: virtual pos_type seekpos( michael@0: pos_type pos, michael@0: std::ios_base::openmode flags) { michael@0: return seekoff(pos, std::ios_base::beg, flags); michael@0: } michael@0: virtual int sync(); michael@0: virtual int_type underflow(); michael@0: virtual int_type overflow(int_type c = traits_type::eof()); michael@0: michael@0: // TODO: Override pbackfail(), showmanyc(), uflow(), xsgetn(), and xsputn(). michael@0: michael@0: private: michael@0: bool allocate(); michael@0: void setb(char_type *buf_base, char_type *buf_end, bool user_buf); michael@0: michael@0: PRFileDesc *_fd; michael@0: bool _opened; michael@0: bool _allocated; michael@0: bool _unbuffered; michael@0: bool _user_buf; michael@0: char_type *_buf_base; michael@0: char_type *_buf_end; michael@0: }; michael@0: michael@0: michael@0: class PR_IMPLEMENT(PRifstream): public std::istream michael@0: { michael@0: public: michael@0: PRifstream(); michael@0: PRifstream(PRFileDesc *fd); michael@0: PRifstream(PRFileDesc *fd, char_type *ptr, std::streamsize len); michael@0: PRifstream(const char *name, openmode flags = in, PRIntn mode = 0); michael@0: virtual ~PRifstream(); michael@0: michael@0: PRfilebuf *rdbuf() const { return &_filebuf; } michael@0: bool is_open() const { return _filebuf.is_open(); } michael@0: michael@0: void open(const char *name, openmode flags = in, PRIntn mode = 0); michael@0: void attach(PRFileDesc *fd); michael@0: void close(); michael@0: michael@0: private: michael@0: mutable PRfilebuf _filebuf; michael@0: }; michael@0: michael@0: michael@0: class PR_IMPLEMENT(PRofstream): public std::ostream michael@0: { michael@0: public: michael@0: PRofstream(); michael@0: PRofstream(PRFileDesc *fd); michael@0: PRofstream(PRFileDesc *fd, char_type *ptr, std::streamsize len); michael@0: PRofstream(const char *name, openmode flags = out, PRIntn mode = 0); michael@0: virtual ~PRofstream(); michael@0: michael@0: PRfilebuf *rdbuf() const { return &_filebuf; } michael@0: bool is_open() const { return _filebuf.is_open(); } michael@0: michael@0: void open(const char *name, openmode flags = out, PRIntn mode = 0); michael@0: void attach(PRFileDesc *fd); michael@0: void close(); michael@0: michael@0: private: michael@0: mutable PRfilebuf _filebuf; michael@0: }; michael@0: michael@0: michael@0: class PR_IMPLEMENT(PRfstream): public std::iostream michael@0: { michael@0: public: michael@0: PRfstream(); michael@0: PRfstream(PRFileDesc *fd); michael@0: PRfstream(PRFileDesc *fd, char_type *ptr, std::streamsize len); michael@0: PRfstream(const char *name, openmode flags = in | out, PRIntn mode = 0); michael@0: virtual ~PRfstream(); michael@0: michael@0: PRfilebuf *rdbuf() const { return &_filebuf; } michael@0: bool is_open() const { return _filebuf.is_open(); } michael@0: michael@0: void open(const char *name, openmode flags = in | out, PRIntn mode = 0); michael@0: void attach(PRFileDesc *fd); michael@0: void close(); michael@0: michael@0: private: michael@0: mutable PRfilebuf _filebuf; michael@0: }; michael@0: michael@0: michael@0: #endif /* _PRSTRMS_H */