Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
InputOutputStream.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Streams_InputOutputStream_h_
5#define _Stroika_Foundation_Streams_InputOutputStream_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include "InputStream.h"
10#include "OutputStream.h"
11
12/**
13 * \file
14 *
15 * \note Code-Status: <a href="Code-Status.md#Beta">Beta</a>
16 *
17 */
18
19namespace Stroika::Foundation::Streams::InputOutputStream {
20
21 template <typename ELEMENT_TYPE>
22 class Ptr;
23
24 template <typename ELEMENT_TYPE>
25 class IRep;
26
27 /**
28 * \note Design Note:
29 * There are two principle cases of combining input and output streams into an InputOutputStream:
30 * 1> where there the sequences of data are unrelated
31 * 2> where writes to the input side of the stream 'appears' in the 'output' side of the stream.
32 *
33 * Stroika used to have two kinds of input output streams - BinaryTiedStream, and BinaryInputOutputStream.
34 * However, that distinction was abandoned in v2.0a97, since there appeared to be no reason to capture this distinction
35 * (we may want to revisit, but that's the plan for now - LGP 2017-01-28)
36 *
37 * An InputOutputStream<> could be either one of these two cases - where writes to one side appear on reads
38 * of the other side (such as @see MemoryStream), or where they are unrelated, such as with
39 * @see SocketStream.
40 */
41
42 /**
43 * \brief InputOutputStream is single stream object that acts much as a InputStream::Ptr and an OutputStream::Ptr.
44 *
45 * @see @InputOutputStream<ELEMENT_TYPE>
46 *
47 * \note Design Note:
48 * InputOutputStream::Ptr<ELEMENT_TYPE> inherits from InputStream::Ptr<ELEMENT_TYPE> and OutputStream::Ptr<ELEMENT_TYPE>,
49 * so it has two copies of the shared_ptr, even though there is only one underlying 'rep' object.
50 *
51 * It is required/guaranteed by the implementation that the 'input' and 'output' sides refer to the same underlying
52 * 'rep'.
53 *
54 * \note Design Note:
55 * InputOutputStream::Ptr<ELEMENT_TYPE> need not have the same value for IsSeekable () -
56 * but if you call InputOutputStream<ELEMENT_TYPE>::IsSeekable () - that method requires they both be the same.
57 *
58 * \note \em Thread-Safety <a href="Thread-Safety.md#C++-Standard-Thread-Safety-For-Envelope-But-Ambiguous-Thread-Safety-For-Letter">C++-Standard-Thread-Safety-For-Envelope-But-Ambiguous-Thread-Safety-For-Letter/a>
59 *
60 * \note <a href="Design-Overview.md#Comparisons">Comparisons</a>:
61 * o only operator== (nullptr_t) is supported
62 */
63 template <typename ELEMENT_TYPE>
64 class Ptr : public InputStream::Ptr<ELEMENT_TYPE>, public OutputStream::Ptr<ELEMENT_TYPE> {
65 public:
66 /**
67 *
68 * Overloads:
69 * Ptr/nullptr
70 * defaults to null (aka empty ())
71 * shared_ptr<IRep<ELEMENT_TYPE>>
72 * rep is the underlying shared output Stream object.
73 * \pre rep != nullptr (use nullptr_t constructor)
74 */
75 Ptr () = default;
76 Ptr (nullptr_t);
77 Ptr (const Ptr&) = default;
78 Ptr (Ptr&&) = default;
79 Ptr (const shared_ptr<IRep<ELEMENT_TYPE>>& rep);
80
81 public:
82 /**
83 */
84 nonvirtual Ptr& operator= (const Ptr&) = default;
85 nonvirtual Ptr& operator= (Ptr&&) = default;
86
87 public:
88 /**
89 * \pre InputStream::Ptr<ELEMENT_TYPE>::IsSeekable () == OutputStream<ELEMENT_TYPE>::IsSeekable ()
90 */
91 nonvirtual bool IsSeekable () const;
92
93 public:
94 /**
95 * Close BOTH the InputStream and OutputStream side of this InputOutputStream.
96 *
97 * \brief Alias for CloseRead (); CloseWrite ();
98 */
99 nonvirtual void Close () const;
100 nonvirtual void Close (bool reset);
101
102 public:
103 /**
104 * \brief Alias for InputStream<>::Ptr::Close ();
105 */
106 nonvirtual void CloseRead () const;
107 nonvirtual void CloseRead (bool reset);
108
109 public:
110 /**
111 * @aliases OutputStream<>::Ptr::Close ();
112 */
113 nonvirtual void CloseWrite () const;
114 nonvirtual void CloseWrite (bool reset);
115
116 public:
117 /**
118 * Return true, unless a call to CloseRead () has been done on the underlying stream (not just Ptr).
119 * @see CloseRead ()
120 */
121 nonvirtual bool IsOpenRead () const;
122
123 public:
124 /**
125 * Return true, unless a call to CloseWrite () has been done on the underlying stream (not just Ptr).
126 * @see CloseWrite ()
127 */
128 nonvirtual bool IsOpenWrite () const;
129
130 public:
131 /**
132 *
133 */
134 nonvirtual SeekOffsetType GetReadOffset () const;
135
136 public:
137 /**
138 *
139 */
140 nonvirtual SeekOffsetType GetWriteOffset () const;
141
142 public:
143 /**
144 *
145 */
146 nonvirtual SeekOffsetType SeekWrite (SignedSeekOffsetType offset) const;
147 nonvirtual SeekOffsetType SeekWrite (Whence whence, SignedSeekOffsetType offset) const;
148
149 public:
150 /**
151 *
152 */
153 nonvirtual SeekOffsetType SeekRead (SignedSeekOffsetType offset) const;
154 nonvirtual SeekOffsetType SeekRead (Whence whence, SignedSeekOffsetType offset) const;
155
156 public:
157 /**
158 * \brief return true iff stream ptr is nullptr
159 *
160 * @see reset()
161 */
162 nonvirtual bool operator== (nullptr_t) const;
163
164 public:
165 /**
166 * \brief access to underlying stream smart pointer
167 */
168 nonvirtual shared_ptr<IRep<ELEMENT_TYPE>> GetSharedRep () const;
169
170 public:
171 /**
172 * \pre *this != nullptr
173 */
174 nonvirtual const IRep<ELEMENT_TYPE>& GetRepConstRef () const;
175
176 public:
177 /**
178 * \pre *this != nullptr
179 */
180 nonvirtual IRep<ELEMENT_TYPE>& GetRepRWRef () const;
181 };
182
183 /**
184 *
185 */
186 template <typename ELEMENT_TYPE>
187 class IRep : public InputStream::IRep<ELEMENT_TYPE>, public OutputStream::IRep<ELEMENT_TYPE> {
188 public:
189 using ElementType = ELEMENT_TYPE;
190
191 public:
192 IRep () = default;
193 IRep (const IRep&) = delete;
194
195 public:
196 nonvirtual IRep& operator= (const IRep&) = delete;
197 };
198
199}
200
201/*
202 ********************************************************************************
203 ***************************** Implementation Details ***************************
204 ********************************************************************************
205 */
206#include "InputOutputStream.inl"
207
208#endif /*_Stroika_Foundation_Streams_InputOutputStream_h_*/
InputOutputStream is single stream object that acts much as a InputStream::Ptr and an OutputStream::P...
nonvirtual void Close() const
Alias for CloseRead (); CloseWrite ();.
nonvirtual const IRep< ELEMENT_TYPE > & GetRepConstRef() const
nonvirtual shared_ptr< IRep< ELEMENT_TYPE > > GetSharedRep() const
access to underlying stream smart pointer
nonvirtual IRep< ELEMENT_TYPE > & GetRepRWRef() const
nonvirtual bool operator==(nullptr_t) const
return true iff stream ptr is nullptr
nonvirtual void CloseRead() const
Alias for InputStream<>::Ptr::Close ();.
InputStream<>::Ptr is Smart pointer (with abstract Rep) class defining the interface to reading from ...
Abstract interface for output stream object. Don't call directly (use Ptr usually) - but use directly...
OutputStream<>::Ptr is Smart pointer to a stream-based sink of data.
nonvirtual void reset() noexcept
Definition Stream.inl:50