Stroika Library 3.0d20
 
Loading...
Searching...
No Matches
Stream.h File Reference
#include "Stroika/Foundation/StroikaPreComp.h"
#include <memory>
#include "Stroika/Foundation/Common/Common.h"
#include "Stroika/Foundation/Common/Enumeration.h"
#include "Stroika/Foundation/Debug/AssertExternallySynchronizedMutex.h"
#include "Stroika/Foundation/Memory/Common.h"
#include "Stream.inl"

Go to the source code of this file.

Classes

class  Stroika::Foundation::Streams::Ptr< ELEMENT_TYPE >
 A Streams::Ptr<ELEMENT_TYPE> is a smart-pointer to a stream of elements of type T. More...
 
class  Stroika::Foundation::Streams::IRep< ELEMENT_TYPE >
 

Namespaces

namespace  Stroika::Foundation
 

Typedefs

using Stroika::Foundation::Streams::SeekOffsetType = uint64_t
 
using Stroika::Foundation::Streams::SignedSeekOffsetType = int64_t
 

Enumerations

enum class  Stroika::Foundation::Streams::Whence : uint8_t
 
enum class  Stroika::Foundation::Streams::SeekableFlag
 
enum class  Stroika::Foundation::Streams::NoDataAvailableHandling { eDontBlock , eBlockIfNoDataAvailable , eDEFAULT = eBlockIfNoDataAvailable }
 If eDontBlock passed to most Stream APIs, then when the code would do a blocking read, instead it will return nullopt or throw EWouldBlock. More...
 

Detailed Description

Note
Code-Status: Beta

Definition in file Stream.h.

Typedef Documentation

◆ SeekOffsetType

SeekOffsetType is unsigned, normally, because for most purposes its zero based.

See also
SignedSeekOffsetType.
Note
We use a 64-bit integer here, because streaming >4GB files is common, even in devices so tiny as a cellphone. and no larger because its inconceivable to store that much data anytime soon.

Definition at line 47 of file Stream.h.

◆ SignedSeekOffsetType

SignedSeekOffsetType is signed variant of SeekOffsetType - used to specify a seek offset which can sometimes negative (backwards).

See also
SignedSeekOffsetType.

Definition at line 55 of file Stream.h.

Enumeration Type Documentation

◆ Whence

enum class Stroika::Foundation::Streams::Whence : uint8_t
strong

When seeking, you can seek (offset) from the start (typical/start) or from the end of the stream, or from the current position)

Definition at line 28 of file Stream.h.

◆ SeekableFlag

Used in some subclasses as a flag to indicate stream seekability.

Note
Common::DefaultNames<> supported

Definition at line 62 of file Stream.h.

◆ NoDataAvailableHandling

If eDontBlock passed to most Stream APIs, then when the code would do a blocking read, instead it will return nullopt or throw EWouldBlock.

Note
the idea of 'blocking' is somewhat vague. In the context of streams, it simply refers to behavior of reading at least one element (or writing all requested elements).

For reading, the low level Read () API (that everything is built off of) - will take a span<Element> and not return until it has at least one read. Failure to read more is nearly meaningless, and is fine. If it is KNOWN you are at EOF - end of stream - then and only then can the Read return 0 elements read.

But if you cannot read at least one (say reading from a socket and no data is available), then Read () can return the special value nullopt.

For Writing - the Stream Write API (for simplicity sake) doesn't allow for incomplete writes. It blocks until all elements are written.

Note
- currently OutputStream classes don't use NoDataAvailableHandling (as of Stroika v3.0d15). Future versions may allow for non-blocking writes, but pretty unclear how to handle that (ie do we allow partial writes and if so, how to track - PITA). For now - simpler to just always block on writes. – LGP 2025-01-29
Enumerator
eDontBlock 

Don't block EITHER translates into a THROW of EWouldBlock or returning of nullopt, depending on the API where this flag is used.

eBlockIfNoDataAvailable 

Note - even when blocking, Stroika APIs respect thread cancelation

eDEFAULT 

By far safest, simplest approach, but sometimes unacceptable for various reasons, typically involving multiprocessing, and I/O.

Definition at line 90 of file Stream.h.