Base class for a buffer. More...
#include <Buffer.h>
Public Types | |
typedef std::vector< T >::iterator | iterator |
typedef std::vector< T >::const_iterator | const_iterator |
Public Member Functions | |
Buffer () | |
Create an empty buffer. More... | |
Buffer (const std::size_t capacity) | |
Create a buffer with a specific capacity. More... | |
virtual | ~Buffer () |
void | setCapacity (const std::size_t capacity) |
Resize the capacity. More... | |
std::size_t | capacity () const |
Get the capacity. More... | |
void | setSize (const std::size_t size) |
Set the size. More... | |
std::size_t | size () const |
Get the size. More... | |
bool | empty () const |
Whether or not the buffer is empty. More... | |
void | push_back (const T &value) |
Add a new entry on the end. More... | |
void | move (T &value) |
Moves the object into the buffer (calls std::move()) More... | |
void | append (const_iterator in_begin, const_iterator in_end) |
Add new entries to the end. More... | |
void | append (const std::vector< T > &vals) |
Add new entries to the end. More... | |
void | clear () |
Remove all entries (does not change the capacity) Note: this does NOT at all free any entries. More... | |
virtual void | erase (const std::size_t num)=0 |
Remove the first num elements. More... | |
virtual void | eraseChunk (const std::size_t chunk_size)=0 |
iterator | begin () |
Iterator for the first entry in the buffer. More... | |
const_iterator | begin () const |
Const iterator for the first entry in the buffer. More... | |
iterator | end () |
Iterator for the last entry in the buffer. More... | |
const_iterator | end () const |
Const iterator for the last entry in the buffer. More... | |
virtual iterator | beginChunk (const std::size_t chunk_size)=0 |
Iterator for the first entry with a given chunk size in the buffer If chunk_size is greater than the size of the buffer, the full range will be given. More... | |
virtual const_iterator | beginChunk (const std::size_t chunk_size) const =0 |
Const iterator for the first entry with a given chunk size in the buffer If chunk_size is greater than the size of the buffer, the full range will be given. More... | |
virtual iterator | endChunk (const std::size_t chunk_size)=0 |
Iterator for the last entry of a chunk size in the buffer If chunk_size is greater than the size of the buffer, the full range will be given. More... | |
virtual const_iterator | endChunk (const std::size_t chunk_size) const =0 |
Const iterator for the last entry of a chunk size in the buffer If chunk_size is greater than the size of the buffer, the full range will be given. More... | |
T & | operator[] (const std::size_t index) |
Access an entry at index. More... | |
const T & | operator[] (const std::size_t index) const |
Const access an entry at an index. More... | |
void | swap (std::vector< T > &in_data) |
Use in_data as our data vector. More... | |
const std::vector< T > & | data () |
Access the raw underlying storage. More... | |
std::size_t | dataBeginPos () const |
The current beginning position of the buffer in data(). More... | |
std::size_t | dataEndPos () const |
The current end position of the buffer in data(). More... | |
Protected Member Functions | |
virtual std::size_t | newEnd (const std::size_t new_end)=0 |
Find out where the new end will be. More... | |
Protected Attributes | |
std::vector< T > | _data |
The raw data. More... | |
std::size_t | _begin_pos |
The beginning position. More... | |
std::size_t | _end_pos |
The ending position. More... | |
Base class for a buffer.
Enables the controlled access of an underlying raw vector for storage, which can be used to limit memory allocation and copies for various buffer types while providing a useful public API.
typedef std::vector<T>::const_iterator MooseUtils::Buffer< T >::const_iterator |
typedef std::vector<T>::iterator MooseUtils::Buffer< T >::iterator |
MooseUtils::Buffer< T >::Buffer | ( | ) |
Create an empty buffer.
Definition at line 214 of file Buffer.h.
MooseUtils::Buffer< T >::Buffer | ( | const std::size_t | capacity | ) |
Create a buffer with a specific capacity.
Definition at line 219 of file Buffer.h.
|
inlinevirtual |
void MooseUtils::Buffer< T >::append | ( | const_iterator | in_begin, |
const_iterator | in_end | ||
) |
Add new entries to the end.
Everything in [in_begin, in_end) is appended
Definition at line 241 of file Buffer.h.
void MooseUtils::Buffer< T >::append | ( | const std::vector< T > & | vals | ) |
Add new entries to the end.
Definition at line 253 of file Buffer.h.
|
inline |
Iterator for the first entry in the buffer.
Definition at line 113 of file Buffer.h.
|
inline |
Const iterator for the first entry in the buffer.
Definition at line 117 of file Buffer.h.
|
pure virtual |
Iterator for the first entry with a given chunk size in the buffer If chunk_size is greater than the size of the buffer, the full range will be given.
Implemented in MooseUtils::CircularBuffer< T >, and MooseUtils::LIFOBuffer< T >.
|
pure virtual |
Const iterator for the first entry with a given chunk size in the buffer If chunk_size is greater than the size of the buffer, the full range will be given.
Implemented in MooseUtils::CircularBuffer< T >, and MooseUtils::LIFOBuffer< T >.
|
inline |
void MooseUtils::Buffer< T >::clear | ( | ) |
Remove all entries (does not change the capacity) Note: this does NOT at all free any entries.
Definition at line 260 of file Buffer.h.
|
inline |
Access the raw underlying storage.
This is considered an advanced interface. Typically, you should use the begin(), beginChunk(), end(), and endChunk() methods for accessing the data. This should really only be used in unit tests for verifying the underlying storage.
Definition at line 172 of file Buffer.h.
|
inline |
The current beginning position of the buffer in data().
This is considered an advanced interface because data() is the internal storage for the buffer. It should really only be used in unit tests for verifying the underlying storage.
Definition at line 182 of file Buffer.h.
|
inline |
|
inline |
|
inline |
|
inline |
|
pure virtual |
Iterator for the last entry of a chunk size in the buffer If chunk_size is greater than the size of the buffer, the full range will be given.
Implemented in MooseUtils::CircularBuffer< T >, and MooseUtils::LIFOBuffer< T >.
|
pure virtual |
Const iterator for the last entry of a chunk size in the buffer If chunk_size is greater than the size of the buffer, the full range will be given.
Implemented in MooseUtils::CircularBuffer< T >, and MooseUtils::LIFOBuffer< T >.
|
pure virtual |
Remove the first num elements.
Note that erased items are not guaranteed to be freed immediately
Implemented in MooseUtils::CircularBuffer< T >, and MooseUtils::LIFOBuffer< T >.
|
pure virtual |
Implemented in MooseUtils::CircularBuffer< T >, and MooseUtils::LIFOBuffer< T >.
void MooseUtils::Buffer< T >::move | ( | T & | value | ) |
|
protectedpure virtual |
Find out where the new end will be.
This will resize/copy data as necessary
new_end | the proposed new_end position |
Implemented in MooseUtils::CircularBuffer< T >, and MooseUtils::LIFOBuffer< T >.
Referenced by MooseUtils::Buffer< T >::setSize().
T & MooseUtils::Buffer< T >::operator[] | ( | const std::size_t | index | ) |
Access an entry at index.
Definition at line 268 of file Buffer.h.
const T & MooseUtils::Buffer< T >::operator[] | ( | const std::size_t | index | ) | const |
Const access an entry at an index.
Definition at line 276 of file Buffer.h.
void MooseUtils::Buffer< T >::push_back | ( | const T & | value | ) |
|
inline |
|
inline |
Set the size.
Definition at line 58 of file Buffer.h.
|
inline |
Get the size.
Definition at line 62 of file Buffer.h.
Referenced by MooseUtils::Buffer< T >::empty().
void MooseUtils::Buffer< T >::swap | ( | std::vector< T > & | in_data | ) |
Use in_data as our data vector.
Definition at line 284 of file Buffer.h.
|
protected |
The beginning position.
Definition at line 208 of file Buffer.h.
Referenced by MooseUtils::Buffer< T >::begin(), MooseUtils::Buffer< T >::dataBeginPos(), MooseUtils::Buffer< T >::setSize(), and MooseUtils::Buffer< T >::size().
|
protected |
The raw data.
Definition at line 205 of file Buffer.h.
Referenced by MooseUtils::Buffer< T >::begin(), MooseUtils::Buffer< T >::capacity(), MooseUtils::Buffer< T >::data(), MooseUtils::Buffer< T >::end(), and MooseUtils::Buffer< T >::setCapacity().
|
protected |
The ending position.
Definition at line 210 of file Buffer.h.
Referenced by MooseUtils::Buffer< T >::dataEndPos(), MooseUtils::Buffer< T >::end(), MooseUtils::Buffer< T >::setSize(), and MooseUtils::Buffer< T >::size().