sdr::RawRingBuffer Class Reference

A simple ring buffer. More...

`#include <buffer.hh>`

Inheritance diagram for sdr::RawRingBuffer:

## Public Member Functions

| 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 | _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

A simple ring buffer.

## Constructor & Destructor Documentation

RawRingBuffer::RawRingBuffer | ( |  | ) |

Empty constructor.

RawRingBuffer::RawRingBuffer | ( | size_t | size | ) |

Constructs a raw ring buffer with size `size`.

RawRingBuffer::RawRingBuffer | ( | const RawRingBuffer & | other | ) |

Copy constructor.

RawRingBuffer::~RawRingBuffer | ( |  | ) |

virtual

Destructor.

## Member Function Documentation

size_t sdr::RawRingBuffer::bytesFree | ( |  | ) | const

inline

Returns the number of free bytes in the ring buffer.

size_t sdr::RawRingBuffer::bytesLen | ( |  | ) | const

inline

Returns the number of bytes available for reading.

void sdr::RawRingBuffer::clear | ( |  | ) |

inline

Clear the ring-buffer.

void sdr::RawRingBuffer::drop | ( | size_t | N | ) |

inline

Drops at most `N` bytes from the buffer.

const RawRingBuffer& sdr::RawRingBuffer::operator= | ( | const RawRingBuffer & | other | ) |

inline

Assignment operator, turns this ring buffer into a reference to the other one.

char& sdr::RawRingBuffer::operator[] | ( | int | idx | ) |

inline

Element access.

bool sdr::RawRingBuffer::put | ( | const RawBuffer & | src | ) |

inline

Puts the given data into the ring-buffer.

The size of `src` must be smaller or equal to the number of free bytes. Returns `true` if the data was written successfully to the buffer.

Todo:
  Allow overwrite

void sdr::RawRingBuffer::resize | ( | size_t | N | ) |

inline

Resizes the ring buffer.

Also clears it.

bool sdr::RawRingBuffer::take | ( | const RawBuffer & | dest,
|  | size_t | N
| ) |  |

inline

Take `N` bytes from the ring buffer and store it into the given buffer `dest`.

Returns `true` if the data was taken successfully from the ring buffer.

## Member Data Documentation

size_t sdr::RawRingBuffer::_b_stored

protected

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.

size_t sdr::RawRingBuffer::_take_idx

protected

The current read pointer.

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

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