Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* |
michael@0 | 7 | * Robin J. Maxwell 11-22-96 |
michael@0 | 8 | * Fredrik Roubert <roubert@google.com> 2010-07-23 |
michael@0 | 9 | * Matt Austern <austern@google.com> 2010-07-23 |
michael@0 | 10 | */ |
michael@0 | 11 | |
michael@0 | 12 | #ifndef _PRSTRMS_H |
michael@0 | 13 | #define _PRSTRMS_H |
michael@0 | 14 | |
michael@0 | 15 | #include <cstddef> |
michael@0 | 16 | #include <istream> |
michael@0 | 17 | #include <ostream> |
michael@0 | 18 | #include <streambuf> |
michael@0 | 19 | |
michael@0 | 20 | #include "prio.h" |
michael@0 | 21 | |
michael@0 | 22 | #ifdef _MSC_VER |
michael@0 | 23 | // http://support.microsoft.com/kb/q168958/ |
michael@0 | 24 | class PR_IMPLEMENT(std::_Mutex); |
michael@0 | 25 | class PR_IMPLEMENT(std::ios_base); |
michael@0 | 26 | #endif |
michael@0 | 27 | |
michael@0 | 28 | |
michael@0 | 29 | class PR_IMPLEMENT(PRfilebuf): public std::streambuf |
michael@0 | 30 | { |
michael@0 | 31 | public: |
michael@0 | 32 | PRfilebuf(); |
michael@0 | 33 | PRfilebuf(PRFileDesc *fd); |
michael@0 | 34 | PRfilebuf(PRFileDesc *fd, char_type *ptr, std::streamsize len); |
michael@0 | 35 | virtual ~PRfilebuf(); |
michael@0 | 36 | |
michael@0 | 37 | bool is_open() const { return _fd != NULL; } |
michael@0 | 38 | |
michael@0 | 39 | PRfilebuf *open( |
michael@0 | 40 | const char *name, |
michael@0 | 41 | std::ios_base::openmode flags, |
michael@0 | 42 | PRIntn mode); |
michael@0 | 43 | PRfilebuf *attach(PRFileDesc *fd); |
michael@0 | 44 | PRfilebuf *close(); |
michael@0 | 45 | |
michael@0 | 46 | protected: |
michael@0 | 47 | virtual std::streambuf *setbuf(char_type *ptr, std::streamsize len); |
michael@0 | 48 | virtual pos_type seekoff( |
michael@0 | 49 | off_type offset, |
michael@0 | 50 | std::ios_base::seekdir dir, |
michael@0 | 51 | std::ios_base::openmode flags); |
michael@0 | 52 | virtual pos_type seekpos( |
michael@0 | 53 | pos_type pos, |
michael@0 | 54 | std::ios_base::openmode flags) { |
michael@0 | 55 | return seekoff(pos, std::ios_base::beg, flags); |
michael@0 | 56 | } |
michael@0 | 57 | virtual int sync(); |
michael@0 | 58 | virtual int_type underflow(); |
michael@0 | 59 | virtual int_type overflow(int_type c = traits_type::eof()); |
michael@0 | 60 | |
michael@0 | 61 | // TODO: Override pbackfail(), showmanyc(), uflow(), xsgetn(), and xsputn(). |
michael@0 | 62 | |
michael@0 | 63 | private: |
michael@0 | 64 | bool allocate(); |
michael@0 | 65 | void setb(char_type *buf_base, char_type *buf_end, bool user_buf); |
michael@0 | 66 | |
michael@0 | 67 | PRFileDesc *_fd; |
michael@0 | 68 | bool _opened; |
michael@0 | 69 | bool _allocated; |
michael@0 | 70 | bool _unbuffered; |
michael@0 | 71 | bool _user_buf; |
michael@0 | 72 | char_type *_buf_base; |
michael@0 | 73 | char_type *_buf_end; |
michael@0 | 74 | }; |
michael@0 | 75 | |
michael@0 | 76 | |
michael@0 | 77 | class PR_IMPLEMENT(PRifstream): public std::istream |
michael@0 | 78 | { |
michael@0 | 79 | public: |
michael@0 | 80 | PRifstream(); |
michael@0 | 81 | PRifstream(PRFileDesc *fd); |
michael@0 | 82 | PRifstream(PRFileDesc *fd, char_type *ptr, std::streamsize len); |
michael@0 | 83 | PRifstream(const char *name, openmode flags = in, PRIntn mode = 0); |
michael@0 | 84 | virtual ~PRifstream(); |
michael@0 | 85 | |
michael@0 | 86 | PRfilebuf *rdbuf() const { return &_filebuf; } |
michael@0 | 87 | bool is_open() const { return _filebuf.is_open(); } |
michael@0 | 88 | |
michael@0 | 89 | void open(const char *name, openmode flags = in, PRIntn mode = 0); |
michael@0 | 90 | void attach(PRFileDesc *fd); |
michael@0 | 91 | void close(); |
michael@0 | 92 | |
michael@0 | 93 | private: |
michael@0 | 94 | mutable PRfilebuf _filebuf; |
michael@0 | 95 | }; |
michael@0 | 96 | |
michael@0 | 97 | |
michael@0 | 98 | class PR_IMPLEMENT(PRofstream): public std::ostream |
michael@0 | 99 | { |
michael@0 | 100 | public: |
michael@0 | 101 | PRofstream(); |
michael@0 | 102 | PRofstream(PRFileDesc *fd); |
michael@0 | 103 | PRofstream(PRFileDesc *fd, char_type *ptr, std::streamsize len); |
michael@0 | 104 | PRofstream(const char *name, openmode flags = out, PRIntn mode = 0); |
michael@0 | 105 | virtual ~PRofstream(); |
michael@0 | 106 | |
michael@0 | 107 | PRfilebuf *rdbuf() const { return &_filebuf; } |
michael@0 | 108 | bool is_open() const { return _filebuf.is_open(); } |
michael@0 | 109 | |
michael@0 | 110 | void open(const char *name, openmode flags = out, PRIntn mode = 0); |
michael@0 | 111 | void attach(PRFileDesc *fd); |
michael@0 | 112 | void close(); |
michael@0 | 113 | |
michael@0 | 114 | private: |
michael@0 | 115 | mutable PRfilebuf _filebuf; |
michael@0 | 116 | }; |
michael@0 | 117 | |
michael@0 | 118 | |
michael@0 | 119 | class PR_IMPLEMENT(PRfstream): public std::iostream |
michael@0 | 120 | { |
michael@0 | 121 | public: |
michael@0 | 122 | PRfstream(); |
michael@0 | 123 | PRfstream(PRFileDesc *fd); |
michael@0 | 124 | PRfstream(PRFileDesc *fd, char_type *ptr, std::streamsize len); |
michael@0 | 125 | PRfstream(const char *name, openmode flags = in | out, PRIntn mode = 0); |
michael@0 | 126 | virtual ~PRfstream(); |
michael@0 | 127 | |
michael@0 | 128 | PRfilebuf *rdbuf() const { return &_filebuf; } |
michael@0 | 129 | bool is_open() const { return _filebuf.is_open(); } |
michael@0 | 130 | |
michael@0 | 131 | void open(const char *name, openmode flags = in | out, PRIntn mode = 0); |
michael@0 | 132 | void attach(PRFileDesc *fd); |
michael@0 | 133 | void close(); |
michael@0 | 134 | |
michael@0 | 135 | private: |
michael@0 | 136 | mutable PRfilebuf _filebuf; |
michael@0 | 137 | }; |
michael@0 | 138 | |
michael@0 | 139 | |
michael@0 | 140 | #endif /* _PRSTRMS_H */ |