nsprpub/lib/prstreams/prstrms.h

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

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

mercurial