8 #ifndef META_OCEAN_BASE_STATIC_VECTOR_H
9 #define META_OCEAN_BASE_STATIC_VECTOR_H
23 template <
typename T,
size_t tCapacity>
79 inline size_t size()
const;
125 template <
size_t tCapacity2>
172 inline void erase(
const size_t index);
274 explicit inline operator bool()
const;
282 template <
typename T,
size_t tCapacity>
287 static_assert(tCapacity > 0,
"Invalid vector capacity!");
290 template <
typename T,
size_t tCapacity>
295 static_assert(tCapacity > 0,
"Invalid vector capacity!");
298 template <
typename T,
size_t tCapacity>
303 static_assert(tCapacity > 0,
"Invalid vector capacity!");
305 ocean_assert(number <= tCapacity);
308 template <
typename T,
size_t tCapacity>
311 static_assert(tCapacity > 0,
"Invalid vector capacity!");
313 ocean_assert(size <= tCapacity);
315 for (
size_t n = 0; n < std::min(size, tCapacity); ++n)
317 this->elements_[n] = values[n];
323 template <
typename T,
size_t tCapacity>
326 size_(min(tCapacity, values.size()))
328 static_assert(tCapacity > 0,
"Invalid vector capacity!");
331 template <
typename T,
size_t tCapacity>
334 size_(min(tCapacity, values.size()))
336 static_assert(tCapacity > 0,
"Invalid vector capacity!");
339 template <
typename T,
size_t tCapacity>
345 template <
typename T,
size_t tCapacity>
348 return size_ == tCapacity;
351 template <
typename T,
size_t tCapacity>
354 ocean_assert(size_ < tCapacity);
356 this->elements_[size_++] = value;
359 template <
typename T,
size_t tCapacity>
362 ocean_assert(size_ < tCapacity);
364 this->elements_[size_++] = std::move(value);
367 template <
typename T,
size_t tCapacity>
370 if (size_ >= tCapacity)
375 this->elements_[size_++] = value;
380 template <
typename T,
size_t tCapacity>
383 if (size_ >= tCapacity)
388 this->elements_[size_++] = std::move(value);
393 template <
typename T,
size_t tCapacity>
394 template <
size_t tCapacity2>
397 size_t elements = min(value.
size(), tCapacity - size_);
399 for (
size_t n = 0; n < elements; ++n)
401 this->elements_[n + size_] = value.
elements_[n];
407 template <
typename T,
size_t tCapacity>
410 size_t elements = min(value.size(), tCapacity - size_);
412 for (
size_t n = 0; n < elements; ++n)
414 this->elements_[n + size_] = value.elements_[n];
420 template <
typename T,
size_t tCapacity>
423 ocean_assert(size_ > 0);
425 this->elements_[--size_] = T();
428 template <
typename T,
size_t tCapacity>
433 this->elements_[--size_] = T();
437 template <
typename T,
size_t tCapacity>
440 ocean_assert(size_ > 0);
445 template <
typename T,
size_t tCapacity>
454 template <
typename T,
size_t tCapacity>
457 ocean_assert(!empty());
459 return this->elements_[0];
462 template <
typename T,
size_t tCapacity>
465 ocean_assert(!empty());
467 return this->elements_[0];
470 template <
typename T,
size_t tCapacity>
473 ocean_assert(!empty());
475 return this->elements_[size_ - 1];
478 template <
typename T,
size_t tCapacity>
481 ocean_assert(!empty());
483 return this->elements_[size_ - 1];
486 template <
typename T,
size_t tCapacity>
492 template <
typename T,
size_t tCapacity>
495 ocean_assert(index < size_);
497 for (
size_t n = index + 1; n < size_; ++n)
499 this->elements_[n - 1] = std::move(this->elements_[n]);
502 this->elements_[--size_] = T();
505 template <
typename T,
size_t tCapacity>
508 ocean_assert(index < size_);
514 this->elements_[index] = std::move(this->elements_[size_]);
517 this->elements_[size_] = T();
520 template <
typename T,
size_t tCapacity>
523 ocean_assert(size <= tCapacity);
525 for (
size_t n = size; n < size_; ++n)
527 this->elements_[n] = T();
533 template <
typename T,
size_t tCapacity>
536 ocean_assert(size <= tCapacity);
541 template <
typename T,
size_t tCapacity>
544 for (
size_t n = 0; n < size_; ++n)
546 this->elements_[n] = T();
552 template <
typename T,
size_t tCapacity>
558 template <
typename T,
size_t tCapacity>
561 ocean_assert(index < size_);
563 return this->elements_[index];
566 template <
typename T,
size_t tCapacity>
569 ocean_assert(index < size_);
571 return this->elements_[index];
574 template <
typename T,
size_t tCapacity>
577 if (size_ != second.
size_)
582 for (
size_t n = 0; n < size_; ++n)
584 if (this->elements_[n] != second.
elements_[n])
593 template <
typename T,
size_t tCapacity>
596 return !(*
this == second);
599 template <
typename T,
size_t tCapacity>
This class implements a static buffer that has a fixed capacity.
Definition: StaticBuffer.h:24
T elements_[tCapacity > size_t(0) ? tCapacity :size_t(1)]
Elements of this buffer (with at least one entry).
Definition: StaticBuffer.h:160
This class implements a static vector that has a fixed capacity.
Definition: StaticVector.h:25
size_t size_
The current number of stored elements, with range [0, tCapacity].
Definition: StaticVector.h:279
bool securePushBack(T &&value)
Adds a new element to this vector if this vector has free elements left, otherwise nothing happens.
Definition: StaticVector.h:381
StaticVector(const T *values, const size_t size)
Creates a new vector object.
Definition: StaticVector.h:309
StaticVector(const size_t number, const T &value)
Creates a new vector object.
Definition: StaticVector.h:299
const T & front() const
Returns the first elements of this vector.
Definition: StaticVector.h:455
void pushBack(const std::vector< T > &value)
Adds a new elements to this vector.
Definition: StaticVector.h:408
void secureWeakPopBack()
Removes the last element from this vector.
Definition: StaticVector.h:446
size_t size() const
Returns the size of this vector.
Definition: StaticVector.h:340
bool occupied() const
Returns whether no free space is left.
Definition: StaticVector.h:346
T & back()
Returns the last elements of this vector.
Definition: StaticVector.h:479
void popBack()
Removes the last element from this vector.
Definition: StaticVector.h:421
void erase(const size_t index)
Erases one element of this vector.
Definition: StaticVector.h:493
T & operator[](const size_t index)
Returns one element of this vector.
Definition: StaticVector.h:567
void clear()
Clears all elements of this vector.
Definition: StaticVector.h:542
void pushBack(T &&value)
Adds a new element to this vector.
Definition: StaticVector.h:360
void securePopBack()
Removes the last element from this vector.
Definition: StaticVector.h:429
StaticVector()=default
Creates a new vector object.
StaticVector(std::vector< T > &&values)
Creates a new vector object.
Definition: StaticVector.h:332
void weakClear()
Clears all elements of this vector by setting the internal index to zero (all stored elements are unt...
Definition: StaticVector.h:553
StaticVector(const T &value)
Creates a new vector object.
Definition: StaticVector.h:283
void resize(const size_t size)
Resizes this vector.
Definition: StaticVector.h:521
void unstableErase(const size_t index)
Erases one element from this vector.
Definition: StaticVector.h:506
StaticVector(T &&value)
Creates a new vector object.
Definition: StaticVector.h:291
void pushBack(const StaticVector< T, tCapacity2 > &value)
Adds a new elements to this vector.
Definition: StaticVector.h:395
bool operator!=(const StaticVector< T, tCapacity > &second) const
Returns whether two vectors are not identical.
Definition: StaticVector.h:594
StaticVector(const std::vector< T > &values)
Creates a new vector object.
Definition: StaticVector.h:324
void weakResize(const size_t size)
Resizes this vector.
Definition: StaticVector.h:534
void weakPopBack()
Removes the last element from this vector.
Definition: StaticVector.h:438
T & front()
Returns the first elements of this vector.
Definition: StaticVector.h:463
bool empty() const
Returns whether this vector hold no element.
Definition: StaticVector.h:487
void pushBack(const T &value)
Adds a new element to this vector.
Definition: StaticVector.h:352
bool securePushBack(const T &value)
Adds a new element to this vector if this vector has free elements left, otherwise nothing happens.
Definition: StaticVector.h:368
const T & operator[](const size_t index) const
Returns one element of this vector.
Definition: StaticVector.h:559
const T & back() const
Returns the last elements of this vector.
Definition: StaticVector.h:471
bool operator==(const StaticVector< T, tCapacity > &second) const
Returns whether two vectors are identical.
Definition: StaticVector.h:575
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15