The Open Master Hearing Aid (openMHA)  openMHA
Open community platform for hearing aid algorithm research
mha_fifo_t< T > Class Template Reference

A FIFO class. More...

Inheritance diagram for mha_fifo_t< T >:
Inheritance graph

Public Types

typedef std::vector< T >::value_type value_type
 The data type exchanged by this fifo. More...
 

Public Member Functions

virtual void write (const T *data, unsigned count)
 write specified ammount of data to the fifo. More...
 
virtual void read (T *outbuf, unsigned count)
 read data from fifo More...
 
virtual unsigned get_fill_count () const
 Read-only access to fill_count. More...
 
virtual unsigned get_available_space () const
 Read-only access to available_space. More...
 
virtual unsigned get_max_fill_count () const
 The capacity of this fifo. More...
 
 mha_fifo_t (unsigned max_fill_count, const T &t=T())
 Create FIFO with fixed buffer size, where all (initially unused) instances of T are initialized as copies of t. More...
 
virtual ~mha_fifo_t ()=default
 Make destructor virtual. More...
 
 mha_fifo_t (const mha_fifo_t &)=delete
 Copy constructor. More...
 
 mha_fifo_t (mha_fifo_t &&)=delete
 Move constructor. More...
 
mha_fifo_t< T > & operator= (const mha_fifo_t< T > &)=delete
 Assignment operator. More...
 
mha_fifo_t< T > & operator= (mha_fifo_t< T > &&)=delete
 Move assignment operator. More...
 

Protected Member Functions

void clear ()
 Empty the fifo at once. More...
 
const T * get_write_ptr () const
 read-only access to the write pointer for derived classes More...
 
const T * get_read_ptr () const
 read-only access to read pointer for derived classes More...
 
unsigned get_fill_count (const T *wp, const T *rp) const
 Compute fill count from given write pointer and read pointer. More...
 

Private Attributes

std::vector< T > buf
 The memory allocated to store the data in the fifo. More...
 
T * write_ptr
 points to location where to write next More...
 
const T * read_ptr
 points to location where to read next More...
 

Detailed Description

template<class T>
class mha_fifo_t< T >

A FIFO class.

Synchronization: None. Use external synchronisation or synchronization in inheriting class. Assignment, copy and move constructors are disabled.

Member Typedef Documentation

◆ value_type

template<class T >
typedef std::vector<T>::value_type mha_fifo_t< T >::value_type

The data type exchanged by this fifo.

Constructor & Destructor Documentation

◆ mha_fifo_t() [1/3]

template<class T >
mha_fifo_t< T >::mha_fifo_t ( unsigned  max_fill_count,
const T &  t = T() 
)
explicit

Create FIFO with fixed buffer size, where all (initially unused) instances of T are initialized as copies of t.

Parameters
max_fill_countThe maximum number of instances of T that can be held at the same time inside the fifo.
Thefifo allocates a vector of max_fill_count+1 instances of T for storage, one of which is always unused.

◆ ~mha_fifo_t()

template<class T >
virtual mha_fifo_t< T >::~mha_fifo_t ( )
virtualdefault

Make destructor virtual.

◆ mha_fifo_t() [2/3]

template<class T >
mha_fifo_t< T >::mha_fifo_t ( const mha_fifo_t< T > &  )
delete

Copy constructor.

◆ mha_fifo_t() [3/3]

template<class T >
mha_fifo_t< T >::mha_fifo_t ( mha_fifo_t< T > &&  )
delete

Move constructor.

Member Function Documentation

◆ write()

template<class T >
void mha_fifo_t< T >::write ( const T *  data,
unsigned  count 
)
virtual

write specified ammount of data to the fifo.

Parameters
dataPointer to source data.
countNumber of instances to copy
Exceptions
MHA_Errorwhen there is not enough space available.

Reimplemented in mha_fifo_lf_t< T >, mha_fifo_lw_t< T >, and mha_drifter_fifo_t< T >.

◆ read()

template<class T >
void mha_fifo_t< T >::read ( T *  outbuf,
unsigned  count 
)
virtual

read data from fifo

Parameters
outbufPointer to the target buffer.
countNumber of instances to copy.
Exceptions
MHA_Errorwhen there is not enough data available.

Reimplemented in mha_fifo_lf_t< T >, mha_fifo_lw_t< T >, and mha_drifter_fifo_t< T >.

◆ get_fill_count() [1/2]

template<class T >
virtual unsigned mha_fifo_t< T >::get_fill_count ( ) const
inlinevirtual

◆ get_available_space()

template<class T >
unsigned mha_fifo_t< T >::get_available_space
virtual

◆ get_max_fill_count()

template<class T >
virtual unsigned mha_fifo_t< T >::get_max_fill_count ( ) const
inlinevirtual

The capacity of this fifo.

◆ operator=() [1/2]

template<class T >
mha_fifo_t<T>& mha_fifo_t< T >::operator= ( const mha_fifo_t< T > &  )
delete

Assignment operator.

◆ operator=() [2/2]

template<class T >
mha_fifo_t<T>& mha_fifo_t< T >::operator= ( mha_fifo_t< T > &&  )
delete

Move assignment operator.

◆ clear()

template<class T >
void mha_fifo_t< T >::clear ( )
inlineprotected

Empty the fifo at once.

Should be called by the reader, or when the reader is inactive.

◆ get_write_ptr()

template<class T >
const T* mha_fifo_t< T >::get_write_ptr ( ) const
inlineprotected

read-only access to the write pointer for derived classes

◆ get_read_ptr()

template<class T >
const T* mha_fifo_t< T >::get_read_ptr ( ) const
inlineprotected

read-only access to read pointer for derived classes

◆ get_fill_count() [2/2]

template<class T >
unsigned mha_fifo_t< T >::get_fill_count ( const T *  wp,
const T *  rp 
) const
inlineprotected

Compute fill count from given write pointer and read pointer.

Parameters
wpWrite pointer.
rpRead pointer.
Precondition
wp and rp must point to an instance of T inside buf.
Returns
Number of elements that can be read from the fifo when wp and rp have the given values.

Member Data Documentation

◆ buf

template<class T >
std::vector<T> mha_fifo_t< T >::buf
private

The memory allocated to store the data in the fifo.

At least one location in buf is always unused, because we have max_fill_count + 1 possible fillcounts [0:max_fill_count] that we need to distinguish.

◆ write_ptr

template<class T >
T* mha_fifo_t< T >::write_ptr
private

points to location where to write next

◆ read_ptr

template<class T >
const T* mha_fifo_t< T >::read_ptr
private

points to location where to read next


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