8 #ifndef META_OCEAN_BASE_STATIC_BUFFER_H
9 #define META_OCEAN_BASE_STATIC_BUFFER_H
22 template <
typename T,
size_t tCapacity>
160 T
elements_[tCapacity > size_t(0) ? tCapacity : size_t(1)];
163 template <
typename T,
size_t tCapacity>
166 static_assert(tCapacity > 0,
"Invalid buffer capacity!");
168 elements_[0] = value;
171 template <
typename T,
size_t tCapacity>
174 static_assert(tCapacity > 0,
"Invalid buffer capacity!");
176 elements_[0] = std::move(value);
179 template <
typename T,
size_t tCapacity>
182 static_assert(tCapacity > 0,
"Invalid buffer capacity!");
184 ocean_assert(buffer !=
nullptr);
186 for (
size_t n = 0u; n < tCapacity; ++n)
188 elements_[n] = buffer[n];
192 template <
typename T,
size_t tCapacity>
195 static_assert(tCapacity > 0,
"Invalid buffer capacity!");
197 ocean_assert(number <= tCapacity);
199 for (
size_t n = 0; n < number; ++n)
201 elements_[n] = value;
205 template <
typename T,
size_t tCapacity>
208 static_assert(tCapacity > 0,
"Invalid buffer capacity!");
210 const size_t size = min(tCapacity, values.size());
212 for (
size_t n = 0; n < size; ++n)
214 elements_[n] = values[n];
218 template <
typename T,
size_t tCapacity>
221 static_assert(tCapacity > 0,
"Invalid buffer capacity!");
223 const size_t size = min(tCapacity, values.size());
225 for (
size_t n = 0; n < size; ++n)
227 elements_[n] = std::move(values[n]);
231 template <
typename T,
size_t tCapacity>
234 static_assert(tCapacity > 0,
"Invalid buffer capacity!");
239 template <
typename T,
size_t tCapacity>
245 template <
typename T,
size_t tCapacity>
251 template <
typename T,
size_t tCapacity>
254 for (
size_t n = 0; n < tCapacity; ++n)
260 template <
typename T,
size_t tCapacity>
263 static_assert(tCapacity > 0,
"Invalid buffer capacity!");
268 template <
typename T,
size_t tCapacity>
271 static_assert(tCapacity > 0,
"Invalid buffer capacity!");
276 template <
typename T,
size_t tCapacity>
279 static_assert(tCapacity > 0,
"Invalid buffer capacity!");
281 return elements_[tCapacity - 1];
284 template <
typename T,
size_t tCapacity>
287 static_assert(tCapacity > 0,
"Invalid buffer capacity!");
289 return elements_[tCapacity - 1];
292 template <
typename T,
size_t tCapacity>
295 static_assert(tCapacity > 0,
"Invalid buffer capacity!");
297 ocean_assert(index < tCapacity);
299 return elements_[index];
302 template <
typename T,
size_t tCapacity>
305 static_assert(tCapacity > 0,
"Invalid buffer capacity!");
307 ocean_assert(index < tCapacity);
309 return elements_[index];
312 template <
typename T,
size_t tCapacity>
315 for (
size_t n = 0; n < tCapacity; ++n)
326 template <
typename T,
size_t tCapacity>
329 return !(*
this == second);
This class implements a static buffer that has a fixed capacity.
Definition: StaticBuffer.h:24
const T * data() const
Returns the buffer data pointer.
Definition: StaticBuffer.h:240
T elements_[tCapacity > size_t(0) ? tCapacity :size_t(1)]
Elements of this buffer (with at least one entry).
Definition: StaticBuffer.h:160
StaticBuffer(std::vector< T > &&values)
Creates a new buffer object.
Definition: StaticBuffer.h:219
static constexpr size_t capacity()
Returns the capacity of this buffer.
Definition: StaticBuffer.h:232
T Type
Definition of the data type of each individual buffer element.
Definition: StaticBuffer.h:30
T * data()
Returns the buffer data pointer.
Definition: StaticBuffer.h:246
StaticBuffer(T &&value)
Creates a new buffer object.
Definition: StaticBuffer.h:172
const T & back() const
Returns the last elements of this buffer.
Definition: StaticBuffer.h:277
bool operator!=(const StaticBuffer< T, tCapacity > &second) const
Returns whether two buffers are not identical.
Definition: StaticBuffer.h:327
T & back()
Returns the last elements of this buffer.
Definition: StaticBuffer.h:285
StaticBuffer(const size_t number, const T &value)
Creates a new buffer object.
Definition: StaticBuffer.h:193
T & front()
Returns the first elements of this buffer.
Definition: StaticBuffer.h:269
const T & front() const
Returns the first elements of this buffer.
Definition: StaticBuffer.h:261
StaticBuffer(const T &value)
Creates a new buffer object.
Definition: StaticBuffer.h:164
StaticBuffer()=default
Creates a new buffer object.
const T & operator[](const size_t index) const
Returns one element of this buffer.
Definition: StaticBuffer.h:293
bool operator==(const StaticBuffer< T, tCapacity > &second) const
Returns whether two buffers are identical.
Definition: StaticBuffer.h:313
T & operator[](const size_t index)
Returns one element of this buffer.
Definition: StaticBuffer.h:303
StaticBuffer(const std::vector< T > &values)
Creates a new buffer object.
Definition: StaticBuffer.h:206
StaticBuffer(const T *buffer)
Creates a new buffer object.
Definition: StaticBuffer.h:180
void clear()
Clears all elements of this buffer.
Definition: StaticBuffer.h:252
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15