|
arduino-audio-tools
|
Auto-expanding buffer composed of multiple buffer instances. More...
#include <DynamicMultiBuffer.h>
Public Member Functions | |
| DynamicMultiBuffer (size_t component_size, size_t initial_components=1, size_t max_components=0) | |
| Constructor with buffer configuration. | |
| virtual | ~DynamicMultiBuffer () |
| Destructor - releases all buffer components. | |
| T * | address () override |
| Get pointer to current read position. | |
| int | available () override |
| Get number of elements available to read. | |
| int | availableForWrite () override |
| Get space available for writing. | |
| bool | begin () |
| (Re)sets the read pos to the start | |
| bool | begin (int pos) |
| (Re)sets the read pos to the indicated position | |
| void | clear () |
| same as reset | |
| virtual int | clearArray (int len) |
| Removes the next len entries. | |
| size_t | getComponentCount () |
| Get the number of buffer components. | |
| size_t | getComponentSize () |
| Get the size of each component. | |
| bool | isEmpty () override |
| Check if the buffer is empty. | |
| bool | isFull () override |
| Check if the buffer is full. | |
| virtual float | levelPercent () |
| Returns the level of the buffer in %. | |
| bool | peek (T &result) override |
| Peek at the next value without removing it. | |
| bool | read (T &result) override |
| Read a single value from the buffer. | |
| int | readArray (T data[], int len) override |
| Optimized bulk read operation. | |
| void | reset () override |
| Reset the buffer to empty state. | |
| bool | resize (int new_size) override |
| Resize the buffer. | |
| size_t | size () override |
| Get total capacity of the buffer. | |
| bool | write (T data) override |
| Write a value to the buffer. | |
| int | writeArray (const T data[], int len) override |
| Optimized bulk write operation. | |
| virtual int | writeArrayOverwrite (const T data[], int len) |
| Fills the buffer data and overwrites the oldest data if the buffer is full. | |
Protected Member Functions | |
| bool | addBufferComponent () |
| Add a new buffer component. | |
| bool | isCurrentBufferFull () |
| Check if the current write buffer is full. | |
| size_t | totalCapacity () |
| Calculate total capacity of all buffer components. | |
Protected Attributes | |
| Vector< BufferType< T > * > | buffer_components |
| size_t | component_size_ = 0 |
| size_t | max_components_ = 0 |
| size_t | read_pos = 0 |
| size_t | write_pos = 0 |
Auto-expanding buffer composed of multiple buffer instances.
DynamicMultiBuffer manages a collection of buffer components, automatically adding new buffers when existing ones become full. This provides dynamically growing storage capacity while maintaining the performance characteristics of the underlying buffer implementation.
Ideal use cases:
| T | Data type to be stored in the buffer |
| BufferType | The buffer implementation to use for each component |
|
inline |
Constructor with buffer configuration.
| component_size | Size of each individual buffer component (elements) |
| initial_components | Number of buffer components to pre-allocate |
| max_components | Maximum number of components (0 for unlimited) |
|
inlinevirtual |
Destructor - releases all buffer components.
|
inlineprotected |
Add a new buffer component.
Creates and adds a new buffer component if allowed by max_components.
Get pointer to current read position.
Note: This method has limitations since data may span multiple buffer components. It returns the address from the current component.
Implements BaseBuffer< T >.
|
inlineoverridevirtual |
Get number of elements available to read.
Implements BaseBuffer< T >.
|
inlineoverridevirtual |
Get space available for writing.
Returns remaining space in existing components plus potential new components up to max_components limit.
Implements BaseBuffer< T >.
(Re)sets the read pos to the start
(Re)sets the read pos to the indicated position
|
inlineinherited |
same as reset
Removes the next len entries.
Reimplemented in SingleBuffer< T >.
Get the number of buffer components.
Get the size of each component.
|
inlineprotected |
Check if the current write buffer is full.
Check if the buffer is empty.
Check if the buffer is full.
Buffer is considered full only if we've reached max components and the last component is full.
Reimplemented from BaseBuffer< T >.
Peek at the next value without removing it.
Returns the next element that would be read without advancing the read position.
| result | Reference where the peeked value will be stored |
Implements BaseBuffer< T >.
Read a single value from the buffer.
Reads from the current read position, potentially spanning buffer components.
| result | Reference where the read value will be stored |
Implements BaseBuffer< T >.
Optimized bulk read operation.
Reads multiple elements, potentially spanning across buffer components.
| data | Buffer where read data will be stored |
| len | Number of elements to read |
Reimplemented from BaseBuffer< T >.
Reset the buffer to empty state.
Clears all buffer components but keeps them allocated.
Implements BaseBuffer< T >.
Resize the buffer.
Changes the number of buffer components to match the requested size.
| new_size | New size in number of elements |
Reimplemented from BaseBuffer< T >.
Get total capacity of the buffer.
Implements BaseBuffer< T >.
|
inlineprotected |
Calculate total capacity of all buffer components.
Write a value to the buffer.
Adds an element to the buffer at the current write position, automatically expanding capacity by adding a new buffer component if needed.
| data | Value to write |
Implements BaseBuffer< T >.
Optimized bulk write operation.
Writes multiple elements, automatically expanding capacity by adding new buffer components as needed.
| data | Array of elements to write |
| len | Number of elements to write |
Reimplemented from BaseBuffer< T >.
Fills the buffer data and overwrites the oldest data if the buffer is full.
|
protected |