sdr::RingBuffer< Scalar > Class Template Reference

A simple typed ring-buffer. More...

`#include <buffer.hh>`

Inheritance diagram for sdr::RingBuffer< Scalar >:

## Public Member Functions

| RingBuffer ()
| Empty constructor. More...
| RingBuffer (size_t N)
| Constructs a ring buffer of size `N`. More...
| RingBuffer (const RingBuffer< Scalar > &other)
| Copy constructor, creates a reference to the `other` ring buffer. More...
virtual | ~RingBuffer ()
| Destructor. More...
const RingBuffer< Scalar > & | operator= (const RingBuffer< Scalar > &other)
| Assigment operator, turns this buffer into a reference to the `other` ring buffer. More...
Scalar & | operator[] (int idx)
| Element access. More...
size_t | stored () const
| Returns the number of stored elements. More...
size_t | free () const
| Returns the number of free elements. More...
size_t | size () const
| Returns the size of the ring buffer. More...
bool | put (const Buffer< Scalar > &data)
| Puts the given elements into the ring buffer. More...
bool | take (const Buffer< Scalar > &dest, size_t N)
| Takes `N` elements from the buffer and stores them into `dest`. More...
void | drop (size_t N)
| Drops `N` elements from the ring buffer. More...
void | resize (size_t N)
| Resizes the ring buffer to `N` elements. More...
Public Member Functions inherited from sdr::RawRingBuffer
| RawRingBuffer ()
| Empty constructor. More...
| RawRingBuffer (size_t size)
| Constructs a raw ring buffer with size `size`. More...
| RawRingBuffer (const RawRingBuffer &other)
| Copy constructor. More...
virtual | ~RawRingBuffer ()
| Destructor. More...
const RawRingBuffer & | operator= (const RawRingBuffer &other)
| Assignment operator, turns this ring buffer into a reference to the other one. More...
char & | operator[] (int idx)
| Element access. More...
size_t | bytesLen () const
| Returns the number of bytes available for reading. More...
size_t | bytesFree () const
| Returns the number of free bytes in the ring buffer. More...
bool | put (const RawBuffer &src)
| Puts the given data into the ring-buffer. More...
bool | take (const RawBuffer &dest, size_t N)
| Take `N` bytes from the ring buffer and store it into the given buffer `dest`. More...
void | drop (size_t N)
| Drops at most `N` bytes from the buffer. More...
void | clear ()
| Clear the ring-buffer. More...
void | resize (size_t N)
| Resizes the ring buffer. More...
Public Member Functions inherited from sdr::RawBuffer
| RawBuffer ()
| Constructs an empty buffer. More...
| RawBuffer (char *data, size_t offset, size_t len)
| Constructor from unowned data. More...
| RawBuffer (size_t N, BufferOwner *owner=0)
| Constructs a buffer and allocates N bytes. More...
| RawBuffer (const RawBuffer &other)
| Copy constructor. More...
| RawBuffer (const RawBuffer &other, size_t offset, size_t len)
| Creates a new view on the buffer. More...
virtual | ~RawBuffer ()
| Destructor. More...
const RawBuffer & | operator= (const RawBuffer &other)
| Assignment. More...
char * | ptr () const
| Returns the pointer to the data (w/o view). More...
char * | data () const
| Returns the pointer to the data of the buffer view. More...
size_t | bytesOffset () const
| Returns the offset of the data by the view. More...
size_t | bytesLen () const
| Returns the size of the buffer by the view. More...
size_t | storageSize () const
| Returns the raw buffer size in bytes. More...
bool | isEmpty () const
| Returns true if the buffer is invalid/empty. More...
void | ref () const
| Increment reference counter. More...
void | unref ()
| Dereferences the buffer. More...
int | refCount () const
| Returns the reference counter. More...
bool | isUnused () const
| We assume here that buffers are owned by one object: A buffer is therefore "unused" if the owner holds the only reference to the buffer. More...

## Protected Attributes

size_t | _size
| The size of the ring buffer. More...
size_t | _stored
| The number of stored elements. More...
Protected Attributes inherited from sdr::RawRingBuffer
size_t | _take_idx
| The current read pointer. More...
size_t | _b_stored
| Offset of the write pointer relative to the `_take_idx` ptr, such that the number of stored bytes is `_b_stored` and the write index is (_take_idx+_b_stored) % _storage_size. More...
Protected Attributes inherited from sdr::RawBuffer
char * | _ptr
| Holds the pointer to the data or 0, if buffer is empty. More...
size_t | _storage_size
| Holds the size of the buffer in bytes. More...
size_t | _b_offset
| Holds the offset of the buffer in bytes. More...
size_t | _b_length
| Holds the length of the buffer (view) in bytes. More...
int * | _refcount
| The reference counter. More...
BufferOwner * | _owner
| Holds a weak reference the buffer owner. More...

## Detailed Description

### template<class Scalar>
class sdr::RingBuffer< Scalar >

A simple typed ring-buffer.

## Constructor & Destructor Documentation

template<class Scalar>

sdr::RingBuffer< Scalar >::RingBuffer | ( |  | ) |

inline

Empty constructor.

template<class Scalar>

sdr::RingBuffer< Scalar >::RingBuffer | ( | size_t | N | ) |

inline

Constructs a ring buffer of size `N`.

template<class Scalar>

sdr::RingBuffer< Scalar >::RingBuffer | ( | const RingBuffer< Scalar > & | other | ) |

inline

Copy constructor, creates a reference to the `other` ring buffer.

template<class Scalar>

virtual sdr::RingBuffer< Scalar >::~RingBuffer | ( |  | ) |

inlinevirtual

Destructor.

## Member Function Documentation

template<class Scalar>

void sdr::RingBuffer< Scalar >::drop | ( | size_t | N | ) |

inline

Drops `N` elements from the ring buffer.

template<class Scalar>

size_t sdr::RingBuffer< Scalar >::free | ( |  | ) | const

inline

Returns the number of free elements.

template<class Scalar>

const RingBuffer<Scalar>& sdr::RingBuffer< Scalar >::operator= | ( | const RingBuffer< Scalar > & | other | ) |

inline

Assigment operator, turns this buffer into a reference to the `other` ring buffer.

template<class Scalar>

Scalar& sdr::RingBuffer< Scalar >::operator[] | ( | int | idx | ) |

inline

Element access.

template<class Scalar>

bool sdr::RingBuffer< Scalar >::put | ( | const Buffer< Scalar > & | data | ) |

inline

Puts the given elements into the ring buffer.

If the elements do not fit into the buffer, `false` is returned.

template<class Scalar>

void sdr::RingBuffer< Scalar >::resize | ( | size_t | N | ) |

inline

Resizes the ring buffer to `N` elements.

template<class Scalar>

size_t sdr::RingBuffer< Scalar >::size | ( |  | ) | const

inline

Returns the size of the ring buffer.

template<class Scalar>

size_t sdr::RingBuffer< Scalar >::stored | ( |  | ) | const

inline

Returns the number of stored elements.

template<class Scalar>

bool sdr::RingBuffer< Scalar >::take | ( | const Buffer< Scalar > & | dest,
|  | size_t | N
| ) |  |

inline

Takes `N` elements from the buffer and stores them into `dest`.

Returns `true` on success.

## Member Data Documentation

template<class Scalar>

size_t sdr::RingBuffer< Scalar >::_size

protected

The size of the ring buffer.

template<class Scalar>

size_t sdr::RingBuffer< Scalar >::_stored

protected

The number of stored elements.

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

- /Users/hannes/Uni/Elektronik/sdr/libsdr/src/buffer.hh