StreamReader is an non-essential Stream utility, adding simplicity of use for a common use case, and a significant performance boost. More...
#include <StreamReader.h>
Public Member Functions | |
StreamReader (const typename InputStream::Ptr< ElementType > &underlyingReadFromStreamAdopted) | |
nonvirtual optional< span< ElementType > > | Read (span< ElementType > intoBuffer, NoDataAvailableHandling blockFlag) |
Read into data referenced by span argument - and using argument blocking strategy (default blocking) | |
nonvirtual optional< ElementType > | ReadBlocking () |
ReadBlocking () reads either a single element, or fills in argument intoBuffer - but never blocks (nor throws EWouldBlock) | |
nonvirtual optional< span< ElementType > > | ReadNonBlocking (span< ElementType > intoBuffer) |
read into intoBuffer - returning nullopt if would block, and else returning subspan of input with read data present | |
nonvirtual span< ElementType > | ReadOrThrow (span< ElementType > intoBuffer, NoDataAvailableHandling blockFlag) |
Read (either one or into argument span) and taking NoDataAvailableHandling blockFlag), and throw if would block. | |
nonvirtual optional< ElementType > | Peek () |
Logically the same as InputStream::Ptr<ELEMENT_TYPE>::Peek () but reading cached data. | |
nonvirtual SeekOffsetType | GetOffset () const |
Logically the same as InputStream::Ptr<ELEMENT_TYPE>::GetOffset () - but without being 'synchronized' it maybe a different value than the underlying stream. | |
nonvirtual SeekOffsetType | Seek (SeekOffsetType offset) |
Logically the same as InputStream::Ptr<ELEMENT_TYPE>::Seek () - but without being 'synchronized' it maybe a different value than the underlying stream. | |
nonvirtual size_t | ReadAll (ElementType *intoStart, ElementType *intoEnd) |
Logically the same as InputStream::Ptr<ELEMENT_TYPE>::ReadAll () | |
nonvirtual optional< size_t > | AvailableToRead () const |
returns nullopt if nothing known available, zero if known EOF, and any other number of elements (typically 1) if that number know to be available to read | |
nonvirtual optional< SeekOffsetType > | RemainingLength () const |
returns nullopt if not known (typical, and the default) - but sometimes it is known, and quite helpful) | |
nonvirtual void | SynchronizeToUnderlyingStream () |
nonvirtual void | SynchronizeFromUnderlyingStream () |
StreamReader is an non-essential Stream utility, adding simplicity of use for a common use case, and a significant performance boost.
StreamReader is an unnecessary class for using the Streams library, but it is easy to use, similar to InputStream<T>::Ptr, and significantly more performant
TODO:
Definition at line 36 of file StreamReader.h.
Stroika::Foundation::Streams::StreamReader< ELEMENT_TYPE >::StreamReader | ( | const typename InputStream::Ptr< ElementType > & | underlyingReadFromStreamAdopted | ) |
Definition at line 110 of file StreamReader.inl.
optional< span< ELEMENT_TYPE > > Stroika::Foundation::Streams::StreamReader< ELEMENT_TYPE >::Read | ( | span< ElementType > | intoBuffer, |
NoDataAvailableHandling | blockFlag | ||
) |
Read into data referenced by span argument - and using argument blocking strategy (default blocking)
returns nullopt ONLY if blockFlag = eNonBlocking AND there is NO data available without blocking.
a return of NOT missing, but an empty span implies EOF.
BLOCKING until data is available, but can return with fewer elements than argument span-size without prejudice about how much more is available.
Definition at line 123 of file StreamReader.inl.
auto Stroika::Foundation::Streams::StreamReader< ELEMENT_TYPE >::ReadBlocking | ( | ) |
ReadBlocking () reads either a single element, or fills in argument intoBuffer - but never blocks (nor throws EWouldBlock)
ReadBlocking (): Reads a single element (blocking as long as needed) - or nullopt when at EOF.
ReadBlocking(span<ElementType> intoBuffer) fills in subspan with at least one element (or zero if at EOF)
Definition at line 138 of file StreamReader.inl.
auto Stroika::Foundation::Streams::StreamReader< ELEMENT_TYPE >::ReadNonBlocking | ( | span< ElementType > | intoBuffer | ) |
read into intoBuffer - returning nullopt if would block, and else returning subspan of input with read data present
same as Read (intoBuffer, NoDataAvailableHandling::eDontBlock)
Definition at line 162 of file StreamReader.inl.
auto Stroika::Foundation::Streams::StreamReader< ELEMENT_TYPE >::ReadOrThrow | ( | span< ElementType > | intoBuffer, |
NoDataAvailableHandling | blockFlag | ||
) |
Read (either one or into argument span) and taking NoDataAvailableHandling blockFlag), and throw if would block.
same as Read() APIs, but instead of returning optional, for cases where nullopt would be returned, throw EWouldBlock
when to use this variant? If implementing API where you are handed a blockFlag, but want to KISS, and just throw if EWouldBlock ..
Definition at line 170 of file StreamReader.inl.
size_t Stroika::Foundation::Streams::StreamReader< ELEMENT_TYPE >::ReadAll | ( | ElementType * | intoStart, |
ElementType * | intoEnd | ||
) |
Logically the same as InputStream::Ptr<ELEMENT_TYPE>::ReadAll ()
@todo add other overloads from InputStream::Ptr::ReadAll() - ...
Definition at line 226 of file StreamReader.inl.
optional< size_t > Stroika::Foundation::Streams::StreamReader< ELEMENT_TYPE >::AvailableToRead | ( | ) | const |
returns nullopt if nothing known available, zero if known EOF, and any other number of elements (typically 1) if that number know to be available to read
Definition at line 242 of file StreamReader.inl.
optional< SeekOffsetType > Stroika::Foundation::Streams::StreamReader< ELEMENT_TYPE >::RemainingLength | ( | ) | const |
returns nullopt if not known (typical, and the default) - but sometimes it is known, and quite helpful)
But for a disk file, you MIGHT (not always - like unix special files) know the length of the file. This is for that case.
Definition at line 250 of file StreamReader.inl.
void Stroika::Foundation::Streams::StreamReader< ELEMENT_TYPE >::SynchronizeToUnderlyingStream | ( | ) |
If you must use the underlying stream along-side StreamReader, you can use SynchronizeToUnderlyingStream and SynchronizeFromUnderlyingStream to allow each class to update each other.
Definition at line 259 of file StreamReader.inl.
void Stroika::Foundation::Streams::StreamReader< ELEMENT_TYPE >::SynchronizeFromUnderlyingStream | ( | ) |
If you must use the underlying stream along-side StreamReader, you can use SynchronizeToUnderlyingStream and SynchronizeFromUnderlyingStream to allow each class to update each other.
Definition at line 264 of file StreamReader.inl.