8 #ifndef META_OCEAN_BASE_STACK_HEAP_VECTOR_H
9 #define META_OCEAN_BASE_STACK_HEAP_VECTOR_H
25 template <
typename T,
size_t tStackCapacity>
28 static_assert(tStackCapacity >= 1,
"Invalid stack capacity!");
179 template <
typename... TArgs>
282 ConstIterator
end()
const;
310 template <
typename T,
size_t tStackCapacity>
318 template <
typename T,
size_t tStackCapacity>
326 template <
typename T,
size_t tStackCapacity>
336 template <
typename T,
size_t tStackCapacity>
339 return vector_[index_];
342 template <
typename T,
size_t tStackCapacity>
345 ocean_assert(&vector_ == &iterator.
vector_);
347 return &vector_ == &iterator.
vector_ && index_ == iterator.
index_;
350 template <
typename T,
size_t tStackCapacity>
353 return !(*
this == iterator);
356 template <
typename T,
size_t tStackCapacity>
364 template <
typename T,
size_t tStackCapacity>
372 template <
typename T,
size_t tStackCapacity>
382 template <
typename T,
size_t tStackCapacity>
385 return vector_[index_];
388 template <
typename T,
size_t tStackCapacity>
391 ocean_assert(&vector_ == &iterator.
vector_);
393 return &vector_ == &iterator.
vector_ && index_ == iterator.
index_;
396 template <
typename T,
size_t tStackCapacity>
399 return !(*
this == iterator);
402 template <
typename T,
size_t tStackCapacity>
408 template <
typename T,
size_t tStackCapacity>
413 for (
size_t n = 0; n <
size; ++n)
419 template <
typename T,
size_t tStackCapacity>
422 if (
size_ < tStackCapacity)
434 template <
typename T,
size_t tStackCapacity>
437 if (
size_ < tStackCapacity)
449 template <
typename T,
size_t tStackCapacity>
450 template <
typename... TArgs>
453 const size_t index =
size_;
457 if (index < tStackCapacity)
465 return heapElements_.emplace_back(std::forward<TArgs>(args)...);
469 template <
typename T,
size_t tStackCapacity>
472 ocean_assert(
size_ >= 1);
476 if (
size_ >= tStackCapacity)
486 template <
typename T,
size_t tStackCapacity>
498 for (
size_t n =
size; n < tStackCapacity; ++n)
503 if (
size_ > tStackCapacity)
505 if (
size < tStackCapacity)
519 if (
size > tStackCapacity)
528 template <
typename T,
size_t tStackCapacity>
531 for (
size_t n = 0; n < std::min(
size, tStackCapacity); ++n)
536 for (
size_t n =
size; n < std::min(tStackCapacity,
size_); ++n)
541 if (
size < tStackCapacity)
547 const size_t newHeapSize =
size - tStackCapacity;
555 template <
typename T,
size_t tStackCapacity>
563 template <
typename T,
size_t tStackCapacity>
569 template <
typename T,
size_t tStackCapacity>
575 template <
typename T,
size_t tStackCapacity>
578 for (
size_t nStack = 0; nStack < std::min(
size_, tStackCapacity); ++nStack)
588 template <
typename T,
size_t tStackCapacity>
600 template <
typename T,
size_t tStackCapacity>
608 template <
typename T,
size_t tStackCapacity>
616 template <
typename T,
size_t tStackCapacity>
621 if (
size_ <= tStackCapacity)
631 template <
typename T,
size_t tStackCapacity>
636 if (
size_ <= tStackCapacity)
646 template <
typename T,
size_t tStackCapacity>
652 template <
typename T,
size_t tStackCapacity>
658 template <
typename T,
size_t tStackCapacity>
664 template <
typename T,
size_t tStackCapacity>
670 template <
typename T,
size_t tStackCapacity>
673 ocean_assert(index <
size());
675 if (index < tStackCapacity)
683 template <
typename T,
size_t tStackCapacity>
686 ocean_assert(index <
size());
688 if (index < tStackCapacity)
Definition of an iterator allowing to iterate through the vector.
Definition: StackHeapVector.h:95
const StackHeapVector & vector_
The vector owning this iterator.
Definition: StackHeapVector.h:142
ConstIterator(const StackHeapVector &vector, const size_t index)
Creates a new iterator pointing to a specified elements in the vector.
Definition: StackHeapVector.h:357
bool operator==(const ConstIterator &iterator) const
Compares two iterators and returns whether both iterators point to the same vector element.
Definition: StackHeapVector.h:389
size_t index_
The index of the element within the vector to which the iterator points.
Definition: StackHeapVector.h:145
bool operator!=(const ConstIterator &iterator) const
Compares two iterators and returns whether both iterators do not point to the same vector element.
Definition: StackHeapVector.h:397
const T & operator*() const
De-references the iterator and provides access to the underlying element in the vector.
Definition: StackHeapVector.h:383
ConstIterator & operator++()
(Pre-) increments this iterator.
Definition: StackHeapVector.h:365
Definition of an iterator allowing to iterate through the vector.
Definition: StackHeapVector.h:37
size_t index_
The index of the element within the vector to which the iterator points.
Definition: StackHeapVector.h:87
bool operator==(const Iterator &iterator) const
Compares two iterators and returns whether both iterators point to the same vector element.
Definition: StackHeapVector.h:343
bool operator!=(const Iterator &iterator) const
Compares two iterators and returns whether both iterators do not point to the same vector element.
Definition: StackHeapVector.h:351
Iterator(StackHeapVector &vector, const size_t index)
Creates a new iterator pointing to a specified elements in the vector.
Definition: StackHeapVector.h:311
StackHeapVector & vector_
The vector owning this iterator.
Definition: StackHeapVector.h:84
T & operator*()
De-references the iterator and provides access to the underlying element in the vector.
Definition: StackHeapVector.h:337
Iterator & operator++()
(Pre-) increments this iterator.
Definition: StackHeapVector.h:319
Vector like data structure combining stack and heap memory.
Definition: StackHeapVector.h:27
size_t size_
The number of elements in this vector.
Definition: StackHeapVector.h:307
StackHeapVector(const size_t size, const T &element)
Creates a new vector object.
Definition: StackHeapVector.h:409
Iterator begin()
Returns an iterator to the first element in this vector.
Definition: StackHeapVector.h:647
void setCapacity(const size_t capacity)
Sets the capacity of this vector to a specified number of elements.
Definition: StackHeapVector.h:589
std::vector< T > heapElements_
The remaining elements located on the heap.
Definition: StackHeapVector.h:304
StackHeapVector()
Creates a new vector object.
Definition: StackHeapVector.h:403
const T & operator[](const size_t index) const
Elements access operator.
Definition: StackHeapVector.h:671
T stackElements_[tStackCapacity]
The elements located on the stack.
Definition: StackHeapVector.h:301
void assign(const size_t size, const T &element)
Replaces the content of the vector with 'size' copies of the provided element.
Definition: StackHeapVector.h:529
const T & back() const
Returns the last element of this vector.
Definition: StackHeapVector.h:617
T & emplaceBack(TArgs &&... args)
Emplaces a new element to the end of this vector.
Definition: StackHeapVector.h:451
Iterator end()
Returns an iterator to the element following the last element in this vector.
Definition: StackHeapVector.h:653
size_t capacity() const
Returns the overall capacity of this vector (including the capacity on the stack and on the heap).
Definition: StackHeapVector.h:564
const T & front() const
Returns the first element of this vector.
Definition: StackHeapVector.h:601
void pushBack(T &&element)
Pushes a new element to the end of this vector.
Definition: StackHeapVector.h:420
void resize(const size_t size)
Resizes the vector.
Definition: StackHeapVector.h:487
ConstIterator begin() const
Returns a const iterator to the first element in this vector.
Definition: StackHeapVector.h:659
T & operator[](const size_t index)
Elements access operator.
Definition: StackHeapVector.h:684
void clear()
Clears this vector.
Definition: StackHeapVector.h:576
T & back()
Returns the last element of this vector.
Definition: StackHeapVector.h:632
T & front()
Returns the first element of this vector.
Definition: StackHeapVector.h:609
ConstIterator end() const
Returns an iterator to the element following the last element in this vector.
Definition: StackHeapVector.h:665
void pushBack(const T &element)
Pushes a new element to the end of this vector.
Definition: StackHeapVector.h:435
bool isEmpty() const
Returns whether this vector is empty.
Definition: StackHeapVector.h:570
void popBack()
Removed the last elements from the vector.
Definition: StackHeapVector.h:470
size_t size() const
Returns the number of elements of this vector.
Definition: StackHeapVector.h:556
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15