Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
InputStreamDelegationHelper.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_InputStreamDelegationHelper_h_
5#define _Stroika_Foundation_Streams_InputStreamDelegationHelper_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
10
11/**
12 * \file
13 *
14 * \note Code-Status: <a href="Code-Status.md#Alpha">Alpha</a>
15 */
16
17namespace Stroika::Foundation::Streams {
18
19 /**
20 * This does nothing useful, in and of itself: it just takes an input stream and wraps it into another input stream.
21 * But it provides a useful helper to reduce typing when you want to 'wrap'/'hook' an existing input stream and just react
22 * to a few things (like progress/reads).
23 */
24 template <typename ELEMENT_TYPE>
25 struct InputStreamDelegationHelper : public InputStream::IRep<ELEMENT_TYPE> {
27 : fRealIn{realIn}
28 {
29 RequireNotNull (realIn); // no point in a wrapping a null pointer!
30 }
31 // Stream::IRep
32 virtual bool IsSeekable () const override
33 {
34 return fRealIn.IsSeekable ();
35 }
36 // InputStream::IRep
37 virtual void CloseRead () override
38 {
39 fRealIn.Close ();
40 }
41 virtual bool IsOpenRead () const override
42 {
43 return fRealIn.IsOpen ();
44 }
45 virtual SeekOffsetType GetReadOffset () const override
46 {
47 return fRealIn.GetOffset ();
48 }
49 virtual SeekOffsetType SeekRead (Whence whence, SignedSeekOffsetType offset) override
50 {
51 return fRealIn.Seek (whence, offset);
52 }
53 virtual optional<size_t> AvailableToRead () override
54 {
55 return fRealIn.AvailableToRead ();
56 }
57 virtual optional<SeekOffsetType> RemainingLength () override
58 {
59 return fRealIn.RemainingLength ();
60 }
61 virtual optional<span<ELEMENT_TYPE>> Read (span<ELEMENT_TYPE> intoBuffer, NoDataAvailableHandling blockFlag) override
62 {
63 return fRealIn.Read (intoBuffer, blockFlag);
64 }
65 typename InputStream::Ptr<ELEMENT_TYPE> fRealIn;
66 };
67
68}
69
70/*
71 ********************************************************************************
72 ***************************** Implementation Details ***************************
73 ********************************************************************************
74 */
75#include "InputStreamDelegationHelper.inl"
76
77#endif /*_Stroika_Foundation_Streams_InputStreamDelegationHelper_h_*/
#define RequireNotNull(p)
Definition Assertions.h:347
NoDataAvailableHandling
If eDontBlock passed to most Stream APIs, then when the code would do a blocking read,...
Definition Stream.h:90
InputStream<>::Ptr is Smart pointer (with abstract Rep) class defining the interface to reading from ...
virtual optional< size_t > AvailableToRead() override
returns nullopt if nothing known available, zero if known EOF, and any other number of elements (typi...
virtual optional< SeekOffsetType > RemainingLength() override
returns nullopt if not known (typical, and the default) - but sometimes it is known,...
virtual optional< span< ELEMENT_TYPE > > Read(span< ELEMENT_TYPE > intoBuffer, NoDataAvailableHandling blockFlag) override