MIRA
|
Generic buffer class that can be used as a replacement for std::vector whenever copying and reallocation of internal array buffer needs to be avoided. More...
#include <utils/Buffer.h>
Public Types | |
typedef T | value_type |
typedef Alloc::pointer | pointer |
typedef Alloc::const_pointer | const_pointer |
typedef Alloc::reference | reference |
typedef Alloc::const_reference | const_reference |
typedef T * | iterator |
typedef const T * | const_iterator |
typedef std::size_t | size_type |
typedef ptrdiff_t | difference_type |
typedef Alloc | allocator_type |
Public Member Functions | |
Buffer () | |
Default constructor constructing an empty buffer. More... | |
Buffer (size_type size) | |
Buffer (T *carray, size_type size) | |
Use already allocated memory in carray with size size. More... | |
Buffer (std::vector< T > &&other) | |
Constructs a buffer that TAKES OVER all data from the specified vector. More... | |
~Buffer () | |
Destructor. More... | |
Buffer (const Buffer &other) | |
Copy constructor. More... | |
Buffer & | operator= (const Buffer &other) |
Assignment. More... | |
void | copy (const Buffer &other) |
Copies a buffer into this. More... | |
Buffer (Buffer &&other) noexcept | |
Move constructor. More... | |
Buffer & | operator= (Buffer &&other) noexcept |
Move assignment. More... | |
void | swap (Buffer &other) |
Swaps the content of this buffer with the other buffer. More... | |
bool | operator== (const Buffer &other) const |
Checks for equality with other buffer. More... | |
bool | operator!= (const Buffer &other) const |
Checks for inequality with other buffer. More... | |
iterator | begin () |
Returns an iterator referring to the first element in the vector container. More... | |
const_iterator | begin () const |
Returns an iterator referring to the first element in the vector container. More... | |
iterator | end () |
Returns an iterator referring to the past-the-end element in the vector container. More... | |
const_iterator | end () const |
Returns an iterator referring to the past-the-end element in the vector container. More... | |
size_type | max_size () const |
Returns the maximum size of the buffer. More... | |
size_type | size () const |
Returns the used size of the buffer set by resize() More... | |
size_type | sizeInBytes () const |
Returns the used size in bytes. More... | |
bool | empty () const |
Checks if the buffer is empty (used size == 0). More... | |
size_type | capacity () const |
Returns the reserved size/capacity of the buffer (Its real size) set by reserve() More... | |
allocator_type | get_allocator () const |
Returns the allocator. More... | |
void | reserve (size_type reserve) |
Allocates new memory if reserved size < new reserved size. More... | |
void | resize (size_type size) |
Resizes the buffer. More... | |
void | push_back (const T &x) |
Adds a new element at the end of the vector, after its current last element. More... | |
void | push_back (T *data, size_type size) |
Adds new elements to the end of the vector, after its current last element. More... | |
void | push_back (const Buffer< T > &data) |
Adds new elements to the end of the vector, after its current last element. More... | |
void | pop_back () |
Removes the last element in the vector, effectively reducing the vector size by one. More... | |
void | pop_back (size_type elements) |
Removes the last elements in the vector, effectively reducing the vector size by elements. More... | |
void | pop_front () |
Removes the first element in the vector by copying all remaining data to the front invalidating all iterators and references to the buffer. More... | |
void | pop_front (size_type elements) |
Removes the first elements in the vector by copying all remaining data to the front invalidating all iterators and references to the buffer. More... | |
void | clear () |
All the elements of the vector are dropped. More... | |
reference | operator[] (size_type n) |
Returns a reference to the element at position n in the vector container. More... | |
const_reference | operator[] (size_type n) const |
Returns a reference to the element at position n in the vector container. More... | |
reference | at (size_type n) |
The difference between this member function and member operator function operator[] is that vector::at signals if the requested position is out of range by throwing an out_of_range exception. More... | |
const_reference | at (size_type n) const |
The difference between this member function and member operator function operator[] is that vector::at signals if the requested position is out of range by throwing an out_of_range exception. More... | |
reference | front () |
Returns a reference to the first element in the vector container. More... | |
const_reference | front () const |
Returns a reference to the first element in the vector container. More... | |
reference | back () |
Returns a reference to the last element in the vector container. More... | |
const_reference | back () const |
Returns a reference to the last element in the vector container. More... | |
pointer | data () |
Returns a pointer to the underlying data. More... | |
const_pointer | data () const |
Returns a const pointer to the underlying data. More... | |
Protected Attributes | |
T * | mBuffer |
Pointer to the data buffer. More... | |
size_type | mSize |
The used elements of the buffer. More... | |
size_type | mReserved |
The real size of the buffer. More... | |
bool | mBufferCreated |
Was the buffer created (is it owned) by us. More... | |
Alloc | mAllocator |
The allocator used to allocate new memory. More... | |
std::vector< T > * | mTakenVector |
Used to take over the data from a vector without copying. More... | |
Generic buffer class that can be used as a replacement for std::vector whenever copying and reallocation of internal array buffer needs to be avoided.
The Buffer has the following advantages over the std::vector:
typedef T value_type |
typedef Alloc::pointer pointer |
typedef Alloc::const_pointer const_pointer |
typedef Alloc::reference reference |
typedef Alloc::const_reference const_reference |
typedef T* iterator |
typedef const T* const_iterator |
typedef std::size_t size_type |
typedef ptrdiff_t difference_type |
typedef Alloc allocator_type |
|
inline |
Default constructor constructing an empty buffer.
Use already allocated memory in carray with size size.
Buffer does not take ownership of carray. No data is copied unless calling reserve or resize with size > size of carray.
|
inline |
Constructs a buffer that TAKES OVER all data from the specified vector.
The content of the vector will be destroyed and will be completely moved to the created buffer without any necessary copying. Please note, that the vector is passed as rvalue reference. In order to move the content of a vector into the newly created buffer, you can construct the buffer as follows:
|
inline |
Destructor.
|
inline |
Copies a buffer into this.
|
inline |
Swaps the content of this buffer with the other buffer.
|
inline |
Checks for equality with other buffer.
|
inline |
Checks for inequality with other buffer.
|
inline |
Returns an iterator referring to the first element in the vector container.
|
inline |
Returns an iterator referring to the first element in the vector container.
|
inline |
Returns an iterator referring to the past-the-end element in the vector container.
|
inline |
Returns an iterator referring to the past-the-end element in the vector container.
|
inline |
Returns the maximum size of the buffer.
|
inline |
Returns the used size in bytes.
|
inline |
Checks if the buffer is empty (used size == 0).
|
inline |
Returns the reserved size/capacity of the buffer (Its real size) set by reserve()
|
inline |
Returns the allocator.
|
inline |
Allocates new memory if reserved size < new reserved size.
Otherwise allocated memory stays the same. Reserved memory is the smallest power of two >= new reserved size.
|
inline |
Resizes the buffer.
Sets only size to given size if buffer reserved size is >= new size. Allocates more memory and copies existing data if reserved size < new size If size is increased, new fields are uninitialized and need to be filled e.g. by copying elements into them.
|
inline |
Adds a new element at the end of the vector, after its current last element.
The content of this new element is initialized to a copy of x.
|
inline |
Adds new elements to the end of the vector, after its current last element.
The content of these new elements is initialized to a copy of data.
|
inline |
Adds new elements to the end of the vector, after its current last element.
The content of these new elements is initialized to a copy of data.
|
inline |
Removes the last element in the vector, effectively reducing the vector size by one.
Does not free any memory but an iterator to the removed element will become invalid.
|
inline |
Removes the last elements in the vector, effectively reducing the vector size by elements.
Does not free any memory but iterators to removed elements will become invalid.
|
inline |
Removes the first element in the vector by copying all remaining data to the front invalidating all iterators and references to the buffer.
|
inline |
Removes the first elements in the vector by copying all remaining data to the front invalidating all iterators and references to the buffer.
|
inline |
All the elements of the vector are dropped.
Returns a reference to the element at position n in the vector container.
|
inline |
Returns a reference to the element at position n in the vector container.
The difference between this member function and member operator function operator[] is that vector::at signals if the requested position is out of range by throwing an out_of_range exception.
|
inline |
The difference between this member function and member operator function operator[] is that vector::at signals if the requested position is out of range by throwing an out_of_range exception.
|
inline |
Returns a reference to the first element in the vector container.
|
inline |
Returns a reference to the first element in the vector container.
|
inline |
Returns a reference to the last element in the vector container.
|
inline |
Returns a reference to the last element in the vector container.
|
inline |
Returns a pointer to the underlying data.
|
inline |
Returns a const pointer to the underlying data.
|
protected |
Pointer to the data buffer.
|
protected |
The used elements of the buffer.
|
protected |
The real size of the buffer.
|
protected |
Was the buffer created (is it owned) by us.
|
protected |
The allocator used to allocate new memory.
|
protected |
Used to take over the data from a vector without copying.