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

Implements a circular data stream based on Util::circularbuf using samples of an arithmetic type SampleT. More...

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

Public Member Functions

 NumericSampleStream (size_t BufferSizeInSamples)
 Constructs a NumericSampleStream instance setting the limits on the sample values to the respective data type's (SampleT) full range. More...
 
 NumericSampleStream (size_t BufferSizeInSamples, SampleT MinValue, SampleT MaxValue)
 Constructs a NumericSampleStream instance setting the limits on the sample values to the the range [MinValue, MaxValue]. More...
 
virtual ~NumericSampleStream ()=default
 
bool IsBasicSampleConvertible () const noexcept override final
 Determines whether the data stream holds samples which are compatible to BasicSample. More...
 
void SetLimits (SampleT MinValue, SampleT MaxValue)
 Sets new sample value limits. More...
 
auto GetMinValue () const noexcept
 Getter for the minimal allowed sample value. More...
 
auto GetMaxValue () const noexcept
 Getter for the maximal allowed sample value. More...
 
- Public Member Functions inherited from DynExpInstr::CircularDataStream< SampleT, >
 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...
 
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...
 
- 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 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

virtual void WriteBasicSampleChild (const BasicSample &Sample) override
 Writes a single basic sample to the stream. More...
 
virtual BasicSample ReadBasicSampleChild () override
 Reads a single basic sample from the stream. More...
 
virtual void ValidateSample (const SampleT &Sample) const override
 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

SampleT MinValue
 Minimal allowed sample value. More...
 
SampleT MaxValue
 Maximal allowed sample value. More...
 

Additional Inherited Members

- Public Types inherited from DynExpInstr::CircularDataStream< SampleT, >
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...
 
- Protected Member Functions inherited from DynExpInstr::CircularDataStream< SampleT, >
virtual void ClearChild () override
 Removes all samples from the stream's buffer. More...
 
- Protected Member Functions inherited from DynExpInstr::CircularDataStreamBase
 CircularDataStreamBase ()=default
 
virtual ~CircularDataStreamBase ()=default
 

Detailed Description

template<typename SampleT, std::enable_if_t< std::is_arithmetic_v< SampleT >, int > = 0>
class DynExpInstr::NumericSampleStream< SampleT, >

Implements a circular data stream based on Util::circularbuf using samples of an arithmetic type SampleT.

Template Parameters
SampleTArithmetic type of the samples stored in the data stream

Definition at line 569 of file DataStreamInstrument.h.

Constructor & Destructor Documentation

◆ NumericSampleStream() [1/2]

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

Constructs a NumericSampleStream instance setting the limits on the sample values to the respective data type's (SampleT) full range.

Parameters
BufferSizeInSamplesInitial stream buffer size in samples

Definition at line 577 of file DataStreamInstrument.h.

◆ NumericSampleStream() [2/2]

template<typename SampleT , std::enable_if_t< std::is_arithmetic_v< SampleT >, int > = 0>
DynExpInstr::NumericSampleStream< SampleT, >::NumericSampleStream ( size_t  BufferSizeInSamples,
SampleT  MinValue,
SampleT  MaxValue 
)
inline

Constructs a NumericSampleStream instance setting the limits on the sample values to the the range [MinValue, MaxValue].

Parameters
BufferSizeInSamplesInitial stream buffer size in samples
MinValueMinimal allowed sample value
MaxValueMaximal allowed sample value

Definition at line 587 of file DataStreamInstrument.h.

◆ ~NumericSampleStream()

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

Member Function Documentation

◆ GetMaxValue()

template<typename SampleT , std::enable_if_t< std::is_arithmetic_v< SampleT >, int > = 0>
auto DynExpInstr::NumericSampleStream< SampleT, >::GetMaxValue ( ) const
inlinenoexcept

Getter for the maximal allowed sample value.

Returns
Returns MaxValue.

Definition at line 615 of file DataStreamInstrument.h.

◆ GetMinValue()

template<typename SampleT , std::enable_if_t< std::is_arithmetic_v< SampleT >, int > = 0>
auto DynExpInstr::NumericSampleStream< SampleT, >::GetMinValue ( ) const
inlinenoexcept

Getter for the minimal allowed sample value.

Returns
Returns MinValue.

Definition at line 609 of file DataStreamInstrument.h.

◆ IsBasicSampleConvertible()

template<typename SampleT , std::enable_if_t< std::is_arithmetic_v< SampleT >, int > = 0>
bool DynExpInstr::NumericSampleStream< SampleT, >::IsBasicSampleConvertible ( ) const
inlinefinaloverridevirtualnoexcept

Determines whether the data stream holds samples which are compatible to BasicSample.

Returns
Return true if the derived data stream's samples can be converted to BasicSample instances, false otherwise.

Reimplemented from DynExpInstr::DataStreamBase.

Definition at line 592 of file DataStreamInstrument.h.

◆ ReadBasicSampleChild()

template<typename SampleT , std::enable_if_t< std::is_arithmetic_v< SampleT >, int > = 0>
virtual BasicSample DynExpInstr::NumericSampleStream< SampleT, >::ReadBasicSampleChild ( )
inlineoverrideprivatevirtual

Reads a single basic sample from the stream.

Returns
Read sample

The time value of the returned sample is set to 0.

Reimplemented from DynExpInstr::DataStreamBase.

Definition at line 632 of file DataStreamInstrument.h.

◆ SetLimits()

template<typename SampleT , std::enable_if_t< std::is_arithmetic_v< SampleT >, int > = 0>
void DynExpInstr::NumericSampleStream< SampleT, >::SetLimits ( SampleT  MinValue,
SampleT  MaxValue 
)
inline

Sets new sample value limits.

Parameters
MinValueMinimal allowed sample value
MaxValueMaximal allowed sample value

Definition at line 599 of file DataStreamInstrument.h.

◆ ValidateSample()

template<typename SampleT , std::enable_if_t< std::is_arithmetic_v< SampleT >, int > = 0>
virtual void DynExpInstr::NumericSampleStream< SampleT, >::ValidateSample ( const SampleT &  Sample) const
inlineoverrideprivatevirtual

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 from DynExpInstr::CircularDataStream< SampleT, >.

Definition at line 646 of file DataStreamInstrument.h.

◆ WriteBasicSampleChild()

template<typename SampleT , std::enable_if_t< std::is_arithmetic_v< SampleT >, int > = 0>
virtual void DynExpInstr::NumericSampleStream< SampleT, >::WriteBasicSampleChild ( const BasicSample Sample)
inlineoverrideprivatevirtual

Writes a single basic sample to the stream.

Parameters
SampleSample to write

The time value of Sample is ignored.

Warning
Overflow might occur if BasicSample::DataType does not fit into SampleT!

Reimplemented from DynExpInstr::DataStreamBase.

Definition at line 623 of file DataStreamInstrument.h.

Member Data Documentation

◆ MaxValue

template<typename SampleT , std::enable_if_t< std::is_arithmetic_v< SampleT >, int > = 0>
SampleT DynExpInstr::NumericSampleStream< SampleT, >::MaxValue
private

Maximal allowed sample value.

Definition at line 655 of file DataStreamInstrument.h.

◆ MinValue

template<typename SampleT , std::enable_if_t< std::is_arithmetic_v< SampleT >, int > = 0>
SampleT DynExpInstr::NumericSampleStream< SampleT, >::MinValue
private

Minimal allowed sample value.

Definition at line 654 of file DataStreamInstrument.h.


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