Public Member Functions | Private Attributes | List of all members
CircularBuffer Class Reference

Class for creating, writing to and reading from a circular buffer. More...

#include <circular_buffer.hpp>

Public Member Functions

std::size_t capacity () const
 Returns capacity_. More...
 
 CircularBuffer (std::size_t capacity)
 Constructor of CircularBuffer. More...
 
std::size_t read (uint8_t *data, std::size_t bytes)
 Returns number of bytes read. More...
 
std::size_t size () const
 Returns size_. More...
 
std::size_t write (const uint8_t *data, std::size_t bytes)
 Returns number of bytes written. More...
 
 ~CircularBuffer ()
 Destructor of CircularBuffer. More...
 

Private Attributes

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...
 
std::size_t head_
 Specifies where we start writing. More...
 
std::size_t size_
 Number of bytes that have been written but not yet read. More...
 
std::size_t tail_
 Specifies where we start reading. More...
 

Detailed Description

Class for creating, writing to and reading from a circular buffer.

Definition at line 51 of file circular_buffer.hpp.

Constructor & Destructor Documentation

◆ CircularBuffer()

CircularBuffer::CircularBuffer ( std::size_t  capacity)
explicit

Constructor of CircularBuffer.

Definition at line 39 of file circular_buffer.cpp.

◆ ~CircularBuffer()

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.

Member Function Documentation

◆ capacity()

std::size_t CircularBuffer::capacity ( ) const
inline

Returns capacity_.

Definition at line 61 of file circular_buffer.hpp.

◆ read()

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.

◆ size()

std::size_t CircularBuffer::size ( ) const
inline

Returns size_.

Definition at line 59 of file circular_buffer.hpp.

◆ write()

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.

Member Data Documentation

◆ capacity_

std::size_t CircularBuffer::capacity_
private

Capacity of the circular buffer.

Definition at line 75 of file circular_buffer.hpp.

◆ data_

uint8_t* CircularBuffer::data_
private

Pointer that always points to the same memory address, hence could be const pointer.

Definition at line 77 of file circular_buffer.hpp.

◆ head_

std::size_t CircularBuffer::head_
private

Specifies where we start writing.

Definition at line 69 of file circular_buffer.hpp.

◆ size_

std::size_t CircularBuffer::size_
private

Number of bytes that have been written but not yet read.

Definition at line 73 of file circular_buffer.hpp.

◆ tail_

std::size_t CircularBuffer::tail_
private

Specifies where we start reading.

Definition at line 71 of file circular_buffer.hpp.


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


rosaic
Author(s): Tibor Dome
autogenerated on Wed Oct 14 2020 03:43:50