libsdr
0.1.0
A simple SDR library
|
A simple ring buffer. More...
#include <buffer.hh>
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... | |
A simple ring buffer.
RawRingBuffer::RawRingBuffer | ( | ) |
Empty constructor.
RawRingBuffer::RawRingBuffer | ( | size_t | size | ) |
Constructs a raw ring buffer with size size
.
RawRingBuffer::RawRingBuffer | ( | const RawRingBuffer & | other | ) |
Copy constructor.
|
virtual |
Destructor.
|
inline |
Returns the number of free bytes in the ring buffer.
|
inline |
Returns the number of bytes available for reading.
|
inline |
Clear the ring-buffer.
|
inline |
Drops at most N
bytes from the buffer.
|
inline |
Assignment operator, turns this ring buffer into a reference to the other one.
|
inline |
Element access.
|
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.
|
inline |
Resizes the ring buffer.
Also clears it.
|
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.
|
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.
|
protected |
The current read pointer.