nsprpub/lib/prstreams/prstrms.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/lib/prstreams/prstrms.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,140 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 + * Robin J. Maxwell 11-22-96
    1.11 + * Fredrik Roubert <roubert@google.com> 2010-07-23
    1.12 + * Matt Austern <austern@google.com> 2010-07-23
    1.13 + */
    1.14 +
    1.15 +#ifndef _PRSTRMS_H
    1.16 +#define _PRSTRMS_H
    1.17 +
    1.18 +#include <cstddef>
    1.19 +#include <istream>
    1.20 +#include <ostream>
    1.21 +#include <streambuf>
    1.22 +
    1.23 +#include "prio.h"
    1.24 +
    1.25 +#ifdef _MSC_VER
    1.26 +// http://support.microsoft.com/kb/q168958/
    1.27 +class PR_IMPLEMENT(std::_Mutex);
    1.28 +class PR_IMPLEMENT(std::ios_base);
    1.29 +#endif
    1.30 +
    1.31 +
    1.32 +class PR_IMPLEMENT(PRfilebuf): public std::streambuf
    1.33 +{
    1.34 +public:
    1.35 +    PRfilebuf();
    1.36 +    PRfilebuf(PRFileDesc *fd);
    1.37 +    PRfilebuf(PRFileDesc *fd, char_type *ptr, std::streamsize len);
    1.38 +    virtual ~PRfilebuf();
    1.39 +
    1.40 +    bool is_open() const { return _fd != NULL; }
    1.41 +
    1.42 +    PRfilebuf *open(
    1.43 +                  const char *name,
    1.44 +                  std::ios_base::openmode flags,
    1.45 +                  PRIntn mode);
    1.46 +    PRfilebuf *attach(PRFileDesc *fd);
    1.47 +    PRfilebuf *close();
    1.48 +
    1.49 +protected:
    1.50 +    virtual std::streambuf *setbuf(char_type *ptr, std::streamsize len);
    1.51 +    virtual pos_type seekoff(
    1.52 +                         off_type offset,
    1.53 +                         std::ios_base::seekdir dir,
    1.54 +                         std::ios_base::openmode flags);
    1.55 +    virtual pos_type seekpos(
    1.56 +                         pos_type pos,
    1.57 +                         std::ios_base::openmode flags) {
    1.58 +        return seekoff(pos, std::ios_base::beg, flags);
    1.59 +    }
    1.60 +    virtual int sync();
    1.61 +    virtual int_type underflow();
    1.62 +    virtual int_type overflow(int_type c = traits_type::eof());
    1.63 +
    1.64 +    // TODO: Override pbackfail(), showmanyc(), uflow(), xsgetn(), and xsputn().
    1.65 +
    1.66 +private:
    1.67 +    bool allocate();
    1.68 +    void setb(char_type *buf_base, char_type *buf_end, bool user_buf);
    1.69 +
    1.70 +    PRFileDesc *_fd;
    1.71 +    bool _opened;
    1.72 +    bool _allocated;
    1.73 +    bool _unbuffered;
    1.74 +    bool _user_buf;
    1.75 +    char_type *_buf_base;
    1.76 +    char_type *_buf_end;
    1.77 +};
    1.78 +
    1.79 +
    1.80 +class PR_IMPLEMENT(PRifstream): public std::istream
    1.81 +{
    1.82 +public:
    1.83 +    PRifstream();
    1.84 +    PRifstream(PRFileDesc *fd);
    1.85 +    PRifstream(PRFileDesc *fd, char_type *ptr, std::streamsize len);
    1.86 +    PRifstream(const char *name, openmode flags = in, PRIntn mode = 0);
    1.87 +    virtual ~PRifstream();
    1.88 +
    1.89 +    PRfilebuf *rdbuf() const { return &_filebuf; }
    1.90 +    bool is_open() const { return _filebuf.is_open(); }
    1.91 +
    1.92 +    void open(const char *name, openmode flags = in, PRIntn mode = 0);
    1.93 +    void attach(PRFileDesc *fd);
    1.94 +    void close();
    1.95 +
    1.96 +private:
    1.97 +    mutable PRfilebuf _filebuf;
    1.98 +};
    1.99 +
   1.100 +
   1.101 +class PR_IMPLEMENT(PRofstream): public std::ostream
   1.102 +{
   1.103 +public:
   1.104 +    PRofstream();
   1.105 +    PRofstream(PRFileDesc *fd);
   1.106 +    PRofstream(PRFileDesc *fd, char_type *ptr, std::streamsize len);
   1.107 +    PRofstream(const char *name, openmode flags = out, PRIntn mode = 0);
   1.108 +    virtual ~PRofstream();
   1.109 +
   1.110 +    PRfilebuf *rdbuf() const { return &_filebuf; }
   1.111 +    bool is_open() const { return _filebuf.is_open(); }
   1.112 +
   1.113 +    void open(const char *name, openmode flags = out, PRIntn mode = 0);
   1.114 +    void attach(PRFileDesc *fd);
   1.115 +    void close();
   1.116 +
   1.117 +private:
   1.118 +    mutable PRfilebuf _filebuf;
   1.119 +};
   1.120 +
   1.121 +
   1.122 +class PR_IMPLEMENT(PRfstream): public std::iostream
   1.123 +{
   1.124 +public:
   1.125 +    PRfstream();
   1.126 +    PRfstream(PRFileDesc *fd);
   1.127 +    PRfstream(PRFileDesc *fd, char_type *ptr, std::streamsize len);
   1.128 +    PRfstream(const char *name, openmode flags = in | out, PRIntn mode = 0);
   1.129 +    virtual ~PRfstream();
   1.130 +
   1.131 +    PRfilebuf *rdbuf() const { return &_filebuf; }
   1.132 +    bool is_open() const { return _filebuf.is_open(); }
   1.133 +
   1.134 +    void open(const char *name, openmode flags = in | out, PRIntn mode = 0);
   1.135 +    void attach(PRFileDesc *fd);
   1.136 +    void close();
   1.137 +
   1.138 +private:
   1.139 +    mutable PRfilebuf _filebuf;
   1.140 +};
   1.141 +
   1.142 +
   1.143 +#endif /* _PRSTRMS_H */

mercurial