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. | |
| Buffer (const std::size_t capacity) | |
| Create a buffer with a specific capacity. | |
| virtual | ~Buffer () |
| void | setCapacity (const std::size_t capacity) |
| Resize the capacity. | |
| std::size_t | capacity () const |
| Get the capacity. | |
| void | setSize (const std::size_t size) |
| Set the size. | |
| std::size_t | size () const |
| Get the size. | |
| bool | empty () const |
| Whether or not the buffer is empty. | |
| void | push_back (const T &value) |
| Add a new entry on the end. | |
| void | move (T &value) |
| Moves the object into the buffer (calls std::move()) | |
| void | append (const_iterator in_begin, const_iterator in_end) |
| Add new entries to the end. | |
| void | append (const std::vector< T > &vals) |
| Add new entries to the end. | |
| void | clear () |
| Remove all entries (does not change the capacity) Note: this does NOT at all free any entries. | |
| virtual void | erase (const std::size_t num)=0 |
| Remove the first num elements. | |
| virtual void | eraseChunk (const std::size_t chunk_size)=0 |
| iterator | begin () |
| Iterator for the first entry in the buffer. | |
| const_iterator | begin () const |
| Const iterator for the first entry in the buffer. | |
| iterator | end () |
| Iterator for the last entry in the buffer. | |
| const_iterator | end () const |
| Const iterator for the last entry in the buffer. | |
| 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. | |
| 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. | |
| 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. | |
| 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. | |
| T & | operator[] (const std::size_t index) |
| Access an entry at index. | |
| const T & | operator[] (const std::size_t index) const |
| Const access an entry at an index. | |
| void | swap (std::vector< T > &in_data) |
| Use in_data as our data vector. | |
| const std::vector< T > & | data () |
| Access the raw underlying storage. | |
| std::size_t | dataBeginPos () const |
| The current beginning position of the buffer in data(). | |
| std::size_t | dataEndPos () const |
| The current end position of the buffer in data(). | |
Protected Member Functions | |
| virtual std::size_t | newEnd (const std::size_t new_end)=0 |
| Find out where the new end will be. | |
Protected Attributes | |
| std::vector< T > | _data |
| The raw data. | |
| std::size_t | _begin_pos |
| The beginning position. | |
| std::size_t | _end_pos |
| The ending position. | |
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 | ( | ) |
| MooseUtils::Buffer< T >::Buffer | ( | const std::size_t | capacity | ) |
|
inlinevirtual |
| void MooseUtils::Buffer< T >::append | ( | const std::vector< T > & | vals | ) |
Add new entries to the end.
Definition at line 253 of file Buffer.h.
| 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.
|
inline |
|
inline |
|
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 >.
|
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 >.
|
inline |
| void MooseUtils::Buffer< T >::clear | ( | ) |
Remove all entries (does not change the capacity) Note: this does NOT at all free any entries.
|
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 |
|
inline |
|
inline |
|
inline |
|
inline |
|
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 |
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 | ) |
| const T & MooseUtils::Buffer< T >::operator[] | ( | const std::size_t | index | ) | const |
| void MooseUtils::Buffer< T >::push_back | ( | const T & | value | ) |
|
inline |
|
inline |
|
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 | ) |
|
protected |
The beginning position.
Definition at line 208 of file Buffer.h.
Referenced by MooseUtils::Buffer< T >::begin(), 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 >::begin(), MooseUtils::Buffer< T >::capacity(), MooseUtils::Buffer< T >::data(), MooseUtils::Buffer< T >::end(), 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 >::end(), MooseUtils::Buffer< T >::setSize(), and MooseUtils::Buffer< T >::size().