36 Buffer(
const vector<U>& list) {
reset(list.data(), list.size()); }
38 template<
class U, szt N>
40 template<
class U, szt N>
41 Buffer(
const array<U,N>& list) {
reset(list.data(), list.size()); }
49 T&
at(
szt pos)
const {
if (pos >= _size)
throw std::out_of_range(
"invalid buffer index");
return _data[pos]; }
53 T&
front()
const {
return _data[0]; }
55 T&
back()
const {
return _data[_size - 1]; }
57 T*
data()
const {
return _data; }
65 T*
begin()
const {
return _data; }
67 T*
end()
const {
return _data + _size; }
74 bool empty()
const {
return !_data || !_size; }
76 explicit operator bool()
const {
return !
empty(); }
81 bool operator==(
const Buffer& rhs)
const {
return _data == rhs._data && _size == rhs._size; }
85 void reset() { _data =
nullptr; _size = 0; }
A contiguous region of referenced (not owned by object) memory.
Definition: Buffer.h:17
std::reverse_iterator< iterator > reverse_iterator
Definition: Buffer.h:26
Buffer & operator=(Buffer &&rhs)
Definition: Buffer.h:46
sdt difference_type
Definition: Buffer.h:22
static optnull_t optnull
Null optional, use to reset an optional to an uninitialized state or test for initialization.
Definition: Optional.h:12
bool operator!=(const Buffer &rhs) const
Definition: Buffer.h:82
void reset()
Set data to null with zero size.
Definition: Buffer.h:85
T * pointer
Definition: Buffer.h:24
ptrdiff_t sdt
Size difference type, shorthand for ptrdiff_t.
Definition: Core.h:92
szt size_type
Definition: Buffer.h:21
bool empty() const
Checks whether the buffer does not have any elements.
Definition: Buffer.h:74
Buffer & operator=(const Buffer &rhs)
Definition: Buffer.h:45
Buffer slice(szt pos, optional< szt > size=optnull) const
Get a view of this memory region in range [pos, pos+size)
Definition: Buffer.h:62
Buffer(const Buffer &rhs)
Definition: Buffer.h:42
T & reference
Definition: Buffer.h:23
T value_type
Definition: Buffer.h:20
static std::common_type< Num, Num2, Num3 >::type clamp(Num val, Num2 min, Num3 max)
Ensure that a number is within a range.
Definition: Alge.h:99
T * end() const
Returns an iterator to the end.
Definition: Buffer.h:67
Buffer(vector< U > &list)
Construct from vector with compatible memory reference type.
Definition: Buffer.h:34
Buffer(Buffer &&rhs)
Definition: Buffer.h:43
Buffer(const vector< U > &list)
Definition: Buffer.h:36
szt size() const
Returns the number of elements.
Definition: Buffer.h:78
bool operator==(const Buffer &rhs) const
Check if buffers reference same memory region.
Definition: Buffer.h:81
size_t szt
Size type, shorthand for size_t.
Definition: Core.h:90
Enables any type to be optional so it can exist in an uninitialized null state.
Definition: Optional.h:52
T & operator[](szt pos) const
Access element without bounds checking.
Definition: Buffer.h:51
reverse_iterator rbegin() const
Returns a reverse iterator to the beginning.
Definition: Buffer.h:69
Buffer(T *data, szt size)
Construct from memory reference and number of contiguous elements in region.
Definition: Buffer.h:31
Buffer()
Construct empty buffer with null data and zero size.
Definition: Buffer.h:29
reverse_iterator rend() const
Returns a reverse iterator to the end.
Definition: Buffer.h:71
Buffer(const array< U, N > &list)
Definition: Buffer.h:41
T * iterator
Definition: Buffer.h:25
T * begin() const
Returns an iterator to the beginning.
Definition: Buffer.h:65
T & at(szt pos) const
Access element with bounds checking, throws std::out_of_range.
Definition: Buffer.h:49
T & front() const
Returns the first element without bounds checking.
Definition: Buffer.h:53
T & back() const
Returns the last element without bounds checking.
Definition: Buffer.h:55
Buffer(array< U, N > &list)
Construct from array with compatible memory reference type.
Definition: Buffer.h:39
Global Honeycomb namespace.
void reset(T *data, szt size)
Set new data and size.
Definition: Buffer.h:87
T * data() const
Get the referenced memory.
Definition: Buffer.h:57