DynExp
Highly flexible laboratory automation for dynamically changing experiments.
DynExpInstr::CircularDataStream< SampleT, > Class Template Reference

Implements a circular data stream based on Util::circularbuf. More...

+ Inheritance diagram for DynExpInstr::CircularDataStream< SampleT, >:

Public Types

using SampleType = SampleT
 Alias for SampleT. More...
 
- Public Types inherited from DynExpInstr::DataStreamBase
using BasicSampleListType = std::vector< BasicSample >
 Type of a list containing data stream samples of type BasicSample. More...
 

Public Member Functions

 CircularDataStream (size_t BufferSizeInSamples)
 Constructs a CircularDataStream instance. More...
 
virtual ~CircularDataStream ()=default
 
constexpr auto GetBytesPerSample () noexcept
 Determines the size of a single sample in bytes. More...
 
size_t GetNumAvailableSamplesToReadTillEnd () const noexcept override
 Determines the amount of samples which can be read from the stream's current get pointer position till the stream's end. More...
 
size_t GetNumFreeSamplesToWrite () const noexcept override
 Determines the amount of samples which can be written to the stream untill the stream's end is reached. More...
 
std::streampos GetReadPosition () const noexcept override
 Determines the current position of the stream's read (get) pointer in samples. More...
 
std::streampos GetWritePosition () const noexcept override
 Determines the current position of the stream's write (put) pointer in samples. More...
 
virtual bool SeekRel (signed long long OffsetInSamples, std::ios_base::seekdir SeekDir, std::ios_base::openmode Which=std::ios_base::in|std::ios_base::out) override
 Moves the stream's read/write pointer(s) to a position relative to SeekDir. More...
 
virtual bool SeekAbs (unsigned long long PositionInSamples, std::ios_base::openmode Which=std::ios_base::in|std::ios_base::out) override
 Moves the stream's read/write pointer(s) to an absolute position. More...
 
virtual void SeekBeg (std::ios_base::openmode Which=std::ios_base::in|std::ios_base::out) override
 Moves the read/write pointer to the first sample in the stream. More...
 
virtual void SeekEnd (std::ios_base::openmode Which=std::ios_base::in|std::ios_base::out) override
 Moves the read pointer to the last sample in the stream and/or moves the write pointer after the last written sample in the stream. More...
 
virtual bool SeekEqual (std::ios_base::openmode Which=std::ios_base::in|std::ios_base::out) override
 Moves the read/write pointer to the respective other one. More...
 
virtual size_t GetStreamSizeRead () const noexcept override
 Determines the stream's read buffer size in samples. More...
 
virtual size_t GetStreamSizeWrite () const noexcept override
 Determines the stream's write buffer size in samples. More...
 
virtual size_t GetNumSamplesWritten () const noexcept override
 Determines the number of samples which have been written to the stream in total. Before overflowing, this function should keep continuing to return the largest possible value. More...
 
virtual void SetStreamSize (size_t BufferSizeInSamples) override
 Sets the stream size in samples. More...
 
- Public Member Functions inherited from DynExpInstr::CircularDataStreamBase
size_t GetNumRecentBasicSamples (size_t Count) const
 Determines the amount of samples which have been written to the stream after the last Count samples. This is useful if the caller just wants to obtain recent samples but not the entire stream. Then, the caller should remember the amount of samples it knows already and call ReadRecentBasicSamples() next. More...
 
BasicSampleListType ReadRecentBasicSamples (size_t Count)
 Reads the most recent samples from the stream skipping Count samples. Also refer to GetNumRecentBasicSamples(). More...
 
- Public Member Functions inherited from DynExpInstr::DataStreamBase
virtual ~DataStreamBase ()=default
 
bool CanRead () const
 Determines whether the stream contains at least one sample which can be read (i.e. GetStreamSizeRead() returns a value greater than 0). More...
 
void Clear ()
 Removes all samples from the stream's buffer. More...
 
void WriteBasicSample (const BasicSample &Sample)
 Writes a single basic sample to the stream. More...
 
BasicSample ReadBasicSample ()
 Reads a single basic sample from the stream. More...
 
void WriteBasicSamples (const BasicSampleListType &Samples)
 Writes a list of basic sample to the stream. More...
 
BasicSampleListType ReadBasicSamples (size_t Count)
 Reads a list of basic sample from the stream. More...
 
virtual bool IsBasicSampleConvertible () const noexcept
 Determines whether the data stream holds samples which are compatible to BasicSample. More...
 
virtual bool IsBasicSampleTimeUsed () const noexcept
 Determines whether the data stream holds basic samples (IsBasicSampleConvertible() returns true) which contain information in their BasicSample::Time fields. More...
 

Private Member Functions

Override

Override by derived classes.

virtual void ValidateSample (const SampleT &Sample) const
 Checks whether a sample is considered valid. Derived classes can define rules to check the sample for validity. Does nothing if the sample is valid. More...
 

Private Attributes

Util::circularbuf StreamBuffer
 Circular stream buffer. More...
 
std::iostream Stream
 Stream to operate on StreamBuffer. More...
 
size_t NumSamplesWritten
 Amount of samples which have been written to Stream in total. More...
 

(De)serialization

Functions for (de)serialization of trivially-copyable types

void WriteSample (const SampleT &Sample)
 Writes a single sample to the stream's buffer StreamBuffer. More...
 
template<typename Rep , typename Period >
void WriteSample (const std::chrono::duration< Rep, Period > &Sample)
 Writes a single sample to the stream's buffer StreamBuffer by implicitly constructing the sample from a std::chrono::duration instance. More...
 
SampleT ReadSample ()
 Reads a single sample from the stream's buffer StreamBuffer. More...
 
template<typename T >
void WriteSamples (const std::vector< T > &Samples)
 Writes multiple samples to the stream's buffer StreamBuffer. More...
 
std::vector< SampleT > ReadSamples (size_t Count)
 Reads multiple samples from the stream's buffer StreamBuffer. More...
 
virtual void ClearChild () override
 Removes all samples from the stream's buffer. More...
 

Additional Inherited Members

- Protected Member Functions inherited from DynExpInstr::CircularDataStreamBase
 CircularDataStreamBase ()=default
 
virtual ~CircularDataStreamBase ()=default
 

Detailed Description

template<typename SampleT, std::enable_if_t< std::is_trivially_copyable_v< SampleT >, int > = 0>
class DynExpInstr::CircularDataStream< SampleT, >

Implements a circular data stream based on Util::circularbuf.

Template Parameters
SampleTType of the samples stored in the data stream

Definition at line 358 of file DataStreamInstrument.h.

Member Typedef Documentation

◆ SampleType

template<typename SampleT , std::enable_if_t< std::is_trivially_copyable_v< SampleT >, int > = 0>
using DynExpInstr::CircularDataStream< SampleT, >::SampleType = SampleT

Alias for SampleT.

Definition at line 361 of file DataStreamInstrument.h.

Constructor & Destructor Documentation

◆ CircularDataStream()

template<typename SampleT , std::enable_if_t< std::is_trivially_copyable_v< SampleT >, int > = 0>
DynExpInstr::CircularDataStream< SampleT, >::CircularDataStream ( size_t  BufferSizeInSamples)
inline

Constructs a CircularDataStream instance.

Parameters
BufferSizeInSamplesInitial stream buffer size in samples

Definition at line 367 of file DataStreamInstrument.h.

◆ ~CircularDataStream()

template<typename SampleT , std::enable_if_t< std::is_trivially_copyable_v< SampleT >, int > = 0>
virtual DynExpInstr::CircularDataStream< SampleT, >::~CircularDataStream ( )
virtualdefault

Member Function Documentation

◆ ClearChild()

template<typename SampleT , std::enable_if_t< std::is_trivially_copyable_v< SampleT >, int > = 0>
virtual void DynExpInstr::CircularDataStream< SampleT, >::ClearChild ( )
inlineoverrideprotectedvirtual

Removes all samples from the stream's buffer.

Implements DynExpInstr::DataStreamBase.

Definition at line 511 of file DataStreamInstrument.h.

◆ GetBytesPerSample()

template<typename SampleT , std::enable_if_t< std::is_trivially_copyable_v< SampleT >, int > = 0>
constexpr auto DynExpInstr::CircularDataStream< SampleT, >::GetBytesPerSample ( )
inlineconstexprnoexcept

Determines the size of a single sample in bytes.

Returns
Returns sizeof(SampleT).

Definition at line 379 of file DataStreamInstrument.h.

◆ GetNumAvailableSamplesToReadTillEnd()

template<typename SampleT , std::enable_if_t< std::is_trivially_copyable_v< SampleT >, int > = 0>
size_t DynExpInstr::CircularDataStream< SampleT, >::GetNumAvailableSamplesToReadTillEnd ( ) const
inlineoverridevirtualnoexcept

Determines the amount of samples which can be read from the stream's current get pointer position till the stream's end.

Returns
Returns the amount of available samples.

Implements DynExpInstr::CircularDataStreamBase.

Definition at line 381 of file DataStreamInstrument.h.

◆ GetNumFreeSamplesToWrite()

template<typename SampleT , std::enable_if_t< std::is_trivially_copyable_v< SampleT >, int > = 0>
size_t DynExpInstr::CircularDataStream< SampleT, >::GetNumFreeSamplesToWrite ( ) const
inlineoverridevirtualnoexcept

Determines the amount of samples which can be written to the stream untill the stream's end is reached.

Returns
Returns the amount of free samples.

Implements DynExpInstr::CircularDataStreamBase.

Definition at line 382 of file DataStreamInstrument.h.

◆ GetNumSamplesWritten()

template<typename SampleT , std::enable_if_t< std::is_trivially_copyable_v< SampleT >, int > = 0>
virtual size_t DynExpInstr::CircularDataStream< SampleT, >::GetNumSamplesWritten ( ) const
inlineoverridevirtualnoexcept

Determines the number of samples which have been written to the stream in total. Before overflowing, this function should keep continuing to return the largest possible value.

Returns
Total number of samples written to the stream

Implements DynExpInstr::DataStreamBase.

Definition at line 434 of file DataStreamInstrument.h.

◆ GetReadPosition()

template<typename SampleT , std::enable_if_t< std::is_trivially_copyable_v< SampleT >, int > = 0>
std::streampos DynExpInstr::CircularDataStream< SampleT, >::GetReadPosition ( ) const
inlineoverridevirtualnoexcept

Determines the current position of the stream's read (get) pointer in samples.

Returns
Returns the get pointer position in samples.

Implements DynExpInstr::CircularDataStreamBase.

Definition at line 383 of file DataStreamInstrument.h.

◆ GetStreamSizeRead()

template<typename SampleT , std::enable_if_t< std::is_trivially_copyable_v< SampleT >, int > = 0>
virtual size_t DynExpInstr::CircularDataStream< SampleT, >::GetStreamSizeRead ( ) const
inlineoverridevirtualnoexcept

Determines the stream's read buffer size in samples.

Returns
Read buffer size in samples

Implements DynExpInstr::DataStreamBase.

Definition at line 432 of file DataStreamInstrument.h.

◆ GetStreamSizeWrite()

template<typename SampleT , std::enable_if_t< std::is_trivially_copyable_v< SampleT >, int > = 0>
virtual size_t DynExpInstr::CircularDataStream< SampleT, >::GetStreamSizeWrite ( ) const
inlineoverridevirtualnoexcept

Determines the stream's write buffer size in samples.

Returns
Write buffer size in samples

Implements DynExpInstr::DataStreamBase.

Definition at line 433 of file DataStreamInstrument.h.

◆ GetWritePosition()

template<typename SampleT , std::enable_if_t< std::is_trivially_copyable_v< SampleT >, int > = 0>
std::streampos DynExpInstr::CircularDataStream< SampleT, >::GetWritePosition ( ) const
inlineoverridevirtualnoexcept

Determines the current position of the stream's write (put) pointer in samples.

Returns
Returns the put pointer position in samples.

Implements DynExpInstr::CircularDataStreamBase.

Definition at line 384 of file DataStreamInstrument.h.

◆ ReadSample()

template<typename SampleT , std::enable_if_t< std::is_trivially_copyable_v< SampleT >, int > = 0>
SampleT DynExpInstr::CircularDataStream< SampleT, >::ReadSample ( )
inline

Reads a single sample from the stream's buffer StreamBuffer.

Returns
Sample read

Definition at line 475 of file DataStreamInstrument.h.

◆ ReadSamples()

template<typename SampleT , std::enable_if_t< std::is_trivially_copyable_v< SampleT >, int > = 0>
std::vector<SampleT> DynExpInstr::CircularDataStream< SampleT, >::ReadSamples ( size_t  Count)
inline

Reads multiple samples from the stream's buffer StreamBuffer.

Parameters
CountAmount of samples to read
Returns
Samples read

Definition at line 500 of file DataStreamInstrument.h.

◆ SeekAbs()

template<typename SampleT , std::enable_if_t< std::is_trivially_copyable_v< SampleT >, int > = 0>
virtual bool DynExpInstr::CircularDataStream< SampleT, >::SeekAbs ( unsigned long long  PositionInSamples,
std::ios_base::openmode  Which = std::ios_base::in|std::ios_base::out 
)
inlineoverridevirtual

Moves the stream's read/write pointer(s) to an absolute position.

Parameters
PositionInSamplesDestiny position
WhichCombination of flags std::ios_base::in (read) and std::ios_base::out (write) specifying the pointers to move.
Returns
Returns true in case of success, false otherwise.

Implements DynExpInstr::CircularDataStreamBase.

Definition at line 393 of file DataStreamInstrument.h.

◆ SeekBeg()

template<typename SampleT , std::enable_if_t< std::is_trivially_copyable_v< SampleT >, int > = 0>
virtual void DynExpInstr::CircularDataStream< SampleT, >::SeekBeg ( std::ios_base::openmode  Which = std::ios_base::in|std::ios_base::out)
inlineoverridevirtual

Moves the read/write pointer to the first sample in the stream.

Parameters
WhichCombination of flags std::ios_base::in (read) and std::ios_base::out (write) specifying the pointers to move.

Implements DynExpInstr::DataStreamBase.

Definition at line 400 of file DataStreamInstrument.h.

◆ SeekEnd()

template<typename SampleT , std::enable_if_t< std::is_trivially_copyable_v< SampleT >, int > = 0>
virtual void DynExpInstr::CircularDataStream< SampleT, >::SeekEnd ( std::ios_base::openmode  Which = std::ios_base::in|std::ios_base::out)
inlineoverridevirtual

Moves the read pointer to the last sample in the stream and/or moves the write pointer after the last written sample in the stream.

Parameters
WhichCombination of flags std::ios_base::in (read) and std::ios_base::out (write) specifying the pointers to move.

Implements DynExpInstr::DataStreamBase.

Definition at line 405 of file DataStreamInstrument.h.

◆ SeekEqual()

template<typename SampleT , std::enable_if_t< std::is_trivially_copyable_v< SampleT >, int > = 0>
virtual bool DynExpInstr::CircularDataStream< SampleT, >::SeekEqual ( std::ios_base::openmode  Which = std::ios_base::in|std::ios_base::out)
inlineoverridevirtual

Moves the read/write pointer to the respective other one.

Parameters
WhichCombination of flags std::ios_base::in (read) and std::ios_base::out (write) specifying the pointers to move.
Returns
Return true in case of success, false otherwise.

Implements DynExpInstr::DataStreamBase.

Definition at line 413 of file DataStreamInstrument.h.

◆ SeekRel()

template<typename SampleT , std::enable_if_t< std::is_trivially_copyable_v< SampleT >, int > = 0>
virtual bool DynExpInstr::CircularDataStream< SampleT, >::SeekRel ( signed long long  OffsetInSamples,
std::ios_base::seekdir  SeekDir,
std::ios_base::openmode  Which = std::ios_base::in|std::ios_base::out 
)
inlineoverridevirtual

Moves the stream's read/write pointer(s) to a position relative to SeekDir.

Parameters
OffsetInSamplesDestiny position (relative to SeekDir)
SeekDirSet position relative to stream's beginning (std::ios_base::beg), its end (std::ios_base::end) or the current position (std::ios_base::cur).
WhichCombination of flags std::ios_base::in (read) and std::ios_base::out (write) specifying the pointers to move.
Returns
Returns true in case of success, false otherwise.

Implements DynExpInstr::CircularDataStreamBase.

Definition at line 386 of file DataStreamInstrument.h.

◆ SetStreamSize()

template<typename SampleT , std::enable_if_t< std::is_trivially_copyable_v< SampleT >, int > = 0>
virtual void DynExpInstr::CircularDataStream< SampleT, >::SetStreamSize ( size_t  BufferSizeInSamples)
inlineoverridevirtual

Sets the stream size in samples.

Parameters
BufferSizeInSamplesNew stream size in samples

Implements DynExpInstr::DataStreamBase.

Definition at line 435 of file DataStreamInstrument.h.

◆ ValidateSample()

template<typename SampleT , std::enable_if_t< std::is_trivially_copyable_v< SampleT >, int > = 0>
virtual void DynExpInstr::CircularDataStream< SampleT, >::ValidateSample ( const SampleT &  Sample) const
inlineprivatevirtual

Checks whether a sample is considered valid. Derived classes can define rules to check the sample for validity. Does nothing if the sample is valid.

Parameters
SampleSample to check
Exceptions
Util::InvalidDataExceptionis thrown if Sample is invalid.

Reimplemented in DynExpInstr::NumericSampleStream< SampleT, >.

Definition at line 529 of file DataStreamInstrument.h.

◆ WriteSample() [1/2]

template<typename SampleT , std::enable_if_t< std::is_trivially_copyable_v< SampleT >, int > = 0>
void DynExpInstr::CircularDataStream< SampleT, >::WriteSample ( const SampleT &  Sample)
inline

Writes a single sample to the stream's buffer StreamBuffer.

Parameters
SampleSample to write

Definition at line 445 of file DataStreamInstrument.h.

◆ WriteSample() [2/2]

template<typename SampleT , std::enable_if_t< std::is_trivially_copyable_v< SampleT >, int > = 0>
template<typename Rep , typename Period >
void DynExpInstr::CircularDataStream< SampleT, >::WriteSample ( const std::chrono::duration< Rep, Period > &  Sample)
inline

Writes a single sample to the stream's buffer StreamBuffer by implicitly constructing the sample from a std::chrono::duration instance.

Template Parameters
RepType of the number of ticks of a std::chrono::duration instance.
Periodstd::ratio representing the type of a fraction, which denotes the time in seconds in between subsequent ticks, of a std::chrono::duration instance.
Parameters
SampleTime sample to write

Definition at line 466 of file DataStreamInstrument.h.

◆ WriteSamples()

template<typename SampleT , std::enable_if_t< std::is_trivially_copyable_v< SampleT >, int > = 0>
template<typename T >
void DynExpInstr::CircularDataStream< SampleT, >::WriteSamples ( const std::vector< T > &  Samples)
inline

Writes multiple samples to the stream's buffer StreamBuffer.

Template Parameters
TType implicitly convertible to SampleT
Parameters
SamplesList of samples to write

Definition at line 489 of file DataStreamInstrument.h.

Member Data Documentation

◆ NumSamplesWritten

template<typename SampleT , std::enable_if_t< std::is_trivially_copyable_v< SampleT >, int > = 0>
size_t DynExpInstr::CircularDataStream< SampleT, >::NumSamplesWritten
private

Amount of samples which have been written to Stream in total.

Definition at line 534 of file DataStreamInstrument.h.

◆ Stream

template<typename SampleT , std::enable_if_t< std::is_trivially_copyable_v< SampleT >, int > = 0>
std::iostream DynExpInstr::CircularDataStream< SampleT, >::Stream
private

Stream to operate on StreamBuffer.

Definition at line 533 of file DataStreamInstrument.h.

◆ StreamBuffer

template<typename SampleT , std::enable_if_t< std::is_trivially_copyable_v< SampleT >, int > = 0>
Util::circularbuf DynExpInstr::CircularDataStream< SampleT, >::StreamBuffer
mutableprivate

Circular stream buffer.

Definition at line 532 of file DataStreamInstrument.h.


The documentation for this class was generated from the following file: