ROSaic
|
Class for creating, writing to and reading from a circular buffer. More...
#include <circular_buffer.hpp>
Public Member Functions | |
CircularBuffer (std::size_t capacity) | |
Constructor of CircularBuffer. More... | |
~CircularBuffer () | |
Destructor of CircularBuffer. More... | |
std::size_t | size () const |
Returns size_. More... | |
std::size_t | capacity () const |
Returns capacity_. More... | |
std::size_t | write (const uint8_t *data, std::size_t bytes) |
Returns number of bytes written. More... | |
std::size_t | read (uint8_t *data, std::size_t bytes) |
Returns number of bytes read. More... | |
Private Attributes | |
std::size_t | head_ |
Specifies where we start writing. More... | |
std::size_t | tail_ |
Specifies where we start reading. More... | |
std::size_t | size_ |
Number of bytes that have been written but not yet read. More... | |
std::size_t | capacity_ |
Capacity of the circular buffer. More... | |
uint8_t * | data_ |
Pointer that always points to the same memory address, hence could be const pointer. More... | |
Class for creating, writing to and reading from a circular buffer.
Definition at line 51 of file circular_buffer.hpp.
|
explicit |
Constructor of CircularBuffer.
Definition at line 39 of file circular_buffer.cpp.
References capacity(), and data_.
CircularBuffer::~CircularBuffer | ( | ) |
Destructor of CircularBuffer.
The destructor frees memory (first line) and points the dangling pointer to NULL (second line).
Definition at line 45 of file circular_buffer.cpp.
References data_.
|
inline |
Returns capacity_.
Definition at line 61 of file circular_buffer.hpp.
References capacity_, read(), and write().
Referenced by CircularBuffer(), read(), and write().
std::size_t CircularBuffer::read | ( | uint8_t * | data, |
std::size_t | bytes | ||
) |
Returns number of bytes read.
Definition at line 86 of file circular_buffer.cpp.
References capacity(), capacity_, data_, size_, and tail_.
Referenced by capacity().
|
inline |
Returns size_.
Definition at line 59 of file circular_buffer.hpp.
References size_.
std::size_t CircularBuffer::write | ( | const uint8_t * | data, |
std::size_t | bytes | ||
) |
Returns number of bytes written.
Definition at line 51 of file circular_buffer.cpp.
References capacity(), capacity_, data_, head_, and size_.
Referenced by io_comm_rx::AsyncManager< StreamT >::asyncReadSomeHandler(), and capacity().
|
private |
Capacity of the circular buffer.
Definition at line 75 of file circular_buffer.hpp.
Referenced by capacity(), read(), and write().
|
private |
Pointer that always points to the same memory address, hence could be const pointer.
Definition at line 77 of file circular_buffer.hpp.
Referenced by CircularBuffer(), read(), write(), and ~CircularBuffer().
|
private |
Specifies where we start writing.
Definition at line 69 of file circular_buffer.hpp.
Referenced by write().
|
private |
Number of bytes that have been written but not yet read.
Definition at line 73 of file circular_buffer.hpp.
|
private |
Specifies where we start reading.
Definition at line 71 of file circular_buffer.hpp.
Referenced by read().