scclib
Stable Cloud Computing C++ Library
iostream.h
Go to the documentation of this file.
1 /*
2 BSD 3-Clause License
3 
4 Copyright (c) 2022, Stable Cloud Computing, Inc.
5 
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8 
9 1. Redistributions of source code must retain the above copyright notice, this
10  list of conditions and the following disclaimer.
11 
12 2. Redistributions in binary form must reproduce the above copyright notice,
13  this list of conditions and the following disclaimer in the documentation
14  and/or other materials provided with the distribution.
15 
16 3. Neither the name of the copyright holder nor the names of its
17  contributors may be used to endorse or promote products derived from
18  this software without specific prior written permission.
19 
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31 #ifndef _SCC_UTIL_IOSTREAM_H
32 #define _SCC_UTIL_IOSTREAM_H
33 
34 #include <istream>
35 #include <string>
36 #include <memory>
37 #include <util/iobase.h>
38 
39 namespace scc::util
40 {
41 
58 class InStream : public std::istream
59 {
60 public:
66  InStream(Reader&, size_t = 1024);
71  InStream(const std::shared_ptr<Reader>&, size_t = 1024);
73  InStream() = delete;
75  InStream(const InStream&) = delete;
77  InStream& operator=(const InStream&) = delete;
79  InStream(InStream&&);
82  virtual ~InStream();
83 
84  void read_reset(const std::shared_ptr<Reader>&);
85  std::shared_ptr<Reader> read_shared() const;
86 
88  virtual size_t recvbuf_size() const;
90  virtual void recvbuf_size(size_t);
98  virtual std::string recv_fail() const;
99 
100  void clear(std::ios::iostate = std::ios::goodbit);
101 };
102 
107 class OutStream : public std::ostream
108 {
109 public:
115  OutStream(Writer&, size_t = 1024);
120  OutStream(const std::shared_ptr<Writer>&, size_t = 1024);
122  OutStream() = delete;
124  OutStream(const OutStream&) = delete;
126  OutStream& operator=(const OutStream&) = delete;
128  OutStream(OutStream&&);
131  virtual ~OutStream();
132 
133  void write_reset(const std::shared_ptr<Writer>&);
134  std::shared_ptr<Writer> write_shared() const;
135 
137  size_t sendbuf_size() const;
139  void sendbuf_size(size_t);
147  virtual std::string send_fail() const;
148 
149  void clear(std::ios::iostate = std::ios::goodbit);
150 };
151 
156 class IoStream : public std::iostream
157 {
158 public:
166  IoStream(Reader&, Writer&, size_t = 1024, size_t = 1024);
173  IoStream(const std::shared_ptr<Reader>&, const std::shared_ptr<Writer>&, size_t = 1024, size_t = 1024);
175  IoStream() = delete;
177  IoStream(const IoStream&) = delete;
179  IoStream& operator=(const IoStream&) = delete;
181  IoStream(IoStream&&);
184  virtual ~IoStream();
185 
186  void read_reset(const std::shared_ptr<Reader>&);
187  void write_reset(const std::shared_ptr<Writer>&);
188  std::shared_ptr<Reader> read_shared() const;
189  std::shared_ptr<Writer> write_shared() const;
190 
192  size_t recvbuf_size() const;
194  void recvbuf_size(size_t);
196  size_t sendbuf_size() const;
198  void sendbuf_size(size_t);
200  virtual std::string recv_fail() const;
202  virtual std::string send_fail() const;
203 
204  void clear(std::ios::iostate = std::ios::goodbit);
205 };
206 
209 }
210 
211 #endif
Input stream wrapper for reader.
Definition: iostream.h:59
virtual size_t recvbuf_size() const
Size of receive buffer.
Definition: iostream.cc:397
InStream & operator=(const InStream &)=delete
Copy assign not allowed.
InStream(const InStream &)=delete
Copy construct not allowed.
InStream()=delete
No default construct.
virtual std::string recv_fail() const
Failure message from the input stream.
Definition: iostream.cc:419
Input/output stream wrapper for reader/writer.
Definition: iostream.h:157
virtual std::string send_fail() const
Failure message from outstream.
Definition: iostream.cc:671
size_t recvbuf_size() const
Size of receive buffer.
Definition: iostream.cc:621
IoStream(const IoStream &)=delete
Copy construct not allowed.
IoStream()=delete
No default construct.
virtual std::string recv_fail() const
Failure message from instream.
Definition: iostream.cc:661
IoStream & operator=(const IoStream &)=delete
Copy assign not allowed.
size_t sendbuf_size() const
Size of send buffer.
Definition: iostream.cc:631
Output stream wrapper for writer.
Definition: iostream.h:108
size_t sendbuf_size() const
Size of send buffer.
Definition: iostream.cc:499
OutStream(const OutStream &)=delete
Copy construct not allowed.
OutStream()=delete
No default construct.
OutStream & operator=(const OutStream &)=delete
Copy assign not allowed.
virtual std::string send_fail() const
Failure message from outstream.
Definition: iostream.cc:519
Input/output stream base reader/writer interface classes.
Interface class for objects which can be read.
Definition: iobase.h:67
Interface class for objects which can be written.
Definition: iobase.h:86