8#ifndef META_OCEAN_BASE_SHIFT_VECTOR_H
9#define META_OCEAN_BASE_SHIFT_VECTOR_H
43 typedef typename std::deque<T>::iterator
Iterator;
238 inline void insert(
const Index index,
const T& element,
const T& intermediateElement);
259 inline void insert(
const Index index, T&& element,
const T& intermediateElement);
341 explicit inline operator bool()
const;
369 firstIndex_(object.firstIndex_),
370 elements_(object.elements_)
378 *
this = std::move(
object);
383 firstIndex_(firstIndex)
390 firstIndex_(firstIndex),
398 firstIndex_(firstIndex),
399 elements_(size, element)
406 firstIndex_(firstIndex),
409 for (
size_t n = 0; n <
size; ++n)
424 ocean_assert(!elements_.empty());
426 if (elements_.empty())
428 return firstIndex_ - 1;
431 return firstIndex_ +
Index(elements_.size()) - 1;
437 ocean_assert(!elements_.empty());
439 if (elements_.empty())
444 return firstIndex_ +
Index(elements_.size());
456 ocean_assert(!elements_.empty());
457 ocean_assert((*
this)[firstIndex()] == elements_.front());
459 return elements_.front();
465 ocean_assert(!elements_.empty());
466 ocean_assert((*
this)[firstIndex()] == elements_.front());
468 return elements_.front();
474 ocean_assert(!elements_.empty());
475 ocean_assert((*
this)[lastIndex()] == elements_.back());
477 return elements_.back();
483 ocean_assert(!elements_.empty());
484 ocean_assert((*
this)[lastIndex()] == elements_.back());
486 return elements_.back();
492 return elements_.size();
498 elements_.resize(size);
504 elements_.resize(size, element);
510 elements_.push_back(element);
516 elements_.push_back(element);
522 elements_.push_front(element);
529 elements_.push_front(element);
536 ocean_assert(!elements_.empty());
537 elements_.pop_back();
543 ocean_assert(!elements_.empty());
544 elements_.pop_front();
551 if (index < firstIndex_)
554 while (index + 1 < firstIndex_)
563 if (index >= (
Index)(firstIndex_ + elements_.size()))
565 elements_.resize(index - firstIndex_ + 1);
568 elements_[index - firstIndex_] = element;
575 if (index < firstIndex_)
578 while (index + 1 < firstIndex_)
580 pushFront(intermediateElement);
587 if (index >= (
Index)(firstIndex_ + elements_.size()))
589 elements_.resize(index - firstIndex_ + 1, intermediateElement);
592 elements_[index - firstIndex_] = element;
600 if (index < firstIndex_)
603 while (index + 1 < firstIndex_)
612 if (index >= (
Index)(firstIndex_ + elements_.size()))
614 elements_.resize(index - firstIndex_ + 1);
617 elements_[index - firstIndex_] = std::move(element);
624 if (index < firstIndex_)
627 while (index + 1 < firstIndex_)
629 pushFront(intermediateElement);
636 if (index >= (
Index)(firstIndex_ + elements_.size()))
638 elements_.resize(index - firstIndex_ + 1, intermediateElement);
641 elements_[index - firstIndex_] = element;
648 return index >= firstIndex_ && index <
Index(firstIndex_ + elements_.size());
654 return elements_.empty();
666 return std::vector<T>(elements_.begin(), elements_.end());
672 return elements_.begin();
678 return elements_.begin();
684 return elements_.end();
690 return elements_.end();
697 elements_ =
object.elements_;
708 object.firstIndex_ = 0;
710 elements_ = std::move(
object.elements_);
719 ocean_assert(!isEmpty());
720 ocean_assert(isValidIndex(index));
721 ocean_assert(index >= firstIndex() && index <= lastIndex());
723 return elements_[index - firstIndex_];
729 ocean_assert(!isEmpty());
730 ocean_assert(isValidIndex(index));
731 ocean_assert(index >= firstIndex() && index <= lastIndex());
733 return elements_[index - firstIndex_];
739 return !elements_.empty();
745 return firstIndex_ ==
object.
firstIndex_ && elements_ ==
object.elements_;
751 return !(*
this == object);
This class implements a vector with shifted elements.
Definition ShiftVector.h:27
T Type
Definition of the data type of each element of this object.
Definition ShiftVector.h:33
ShiftVector(const Index firstIndex)
Creates a new shift vector object.
Definition ShiftVector.h:382
void resize(const size_t size, const T &element)
Changes the number of elements of this vector.
Definition ShiftVector.h:502
bool isValidIndex(const Index index) const
Returns whether a specific index is valid for this vector and matches to the current offset layout.
Definition ShiftVector.h:646
const T & operator[](const Index index) const
Returns one element of this object.
Definition ShiftVector.h:717
ShiftVector< T > & operator=(ShiftVector< T > &&object) noexcept
Move operator.
Definition ShiftVector.h:703
ShiftVector(ShiftVector< T > &&object) noexcept
Move constructor.
Definition ShiftVector.h:376
T & operator[](const Index index)
Returns one element of this object.
Definition ShiftVector.h:727
void insert(const Index index, T &&element, const T &intermediateElement)
Inserts (or overwrites) an element at a specific position of this vector.
Definition ShiftVector.h:622
const T & back() const
Returns the element located at the last (including) index.
Definition ShiftVector.h:472
bool operator==(const ShiftVector< T > &object) const
Compares two shift vector objects whether they are equal.
Definition ShiftVector.h:743
size_t size() const
Returns the number of elements that are stored by this object.
Definition ShiftVector.h:490
ShiftVector(const Index firstIndex, const T *elements, const size_t size)
Creates a new shift vector object and copies a specified number of elements.
Definition ShiftVector.h:405
Index endIndex() const
Returns the index of the element behind the last (excluding) element of this object.
Definition ShiftVector.h:435
void resize(const size_t size)
Changes the number of elements of this vector.
Definition ShiftVector.h:496
void insert(const Index index, T &&element)
Inserts (or overwrites) an element at a specific position of this vector.
Definition ShiftVector.h:598
ShiftVector(const ShiftVector< T > &object)
Copy constructor.
Definition ShiftVector.h:368
ShiftVector(const Index firstIndex, const size_t size, const T &element)
Creates a new shift vector object.
Definition ShiftVector.h:397
void pushBack(const T &element)
Adds a new element to the end of this vector.
Definition ShiftVector.h:508
std::deque< T > elements_
Elements of this object.
Definition ShiftVector.h:364
ConstIterator begin() const
Returns the iterator for the first data element.
Definition ShiftVector.h:676
T & front()
Returns the element located at the first index.
Definition ShiftVector.h:463
void pushFront(T &&element)
Adds a new element to the front of this vector.
Definition ShiftVector.h:527
void popFront()
Removes an element form the front of this vector.
Definition ShiftVector.h:541
bool operator!=(const ShiftVector< T > &object) const
Compares two shift vector object whether they are not equal.
Definition ShiftVector.h:749
void pushFront(const T &element)
Adds a new element to the front of this vector.
Definition ShiftVector.h:520
ShiftVector()=default
Creates a new shift vector object.
void clear()
Clears this object, the specified index shift will be untouched.
Definition ShiftVector.h:658
Index firstIndex_
The index of the first element.
Definition ShiftVector.h:361
bool isEmpty() const
Returns whether this object holds no element.
Definition ShiftVector.h:652
ConstIterator end() const
Returns the end iterator.
Definition ShiftVector.h:688
std::ptrdiff_t Index
Definition of an element index.
Definition ShiftVector.h:38
std::deque< T >::const_iterator ConstIterator
Definition of a const data iterator.
Definition ShiftVector.h:48
void setFirstIndex(const Index index)
Sets the index of the first element of this vector.
Definition ShiftVector.h:448
Iterator begin()
Returns the iterator for the first data element.
Definition ShiftVector.h:670
std::deque< T >::iterator Iterator
Definition of a data iterator.
Definition ShiftVector.h:43
void popBack()
Removes an element from the end of this vector.
Definition ShiftVector.h:534
Index lastIndex() const
Returns the index of the last (including) element of this object.
Definition ShiftVector.h:422
ShiftVector< T > & operator=(const ShiftVector< T > &object)
Assign operator.
Definition ShiftVector.h:694
Iterator end()
Returns the end iterator.
Definition ShiftVector.h:682
T & back()
Returns the element located at the last (including) index.
Definition ShiftVector.h:481
void insert(const Index index, const T &element)
Inserts (or overwrites) an element at a specific position of this vector.
Definition ShiftVector.h:549
ShiftVector(const Index firstIndex, const size_t size)
Creates a new shift vector object.
Definition ShiftVector.h:389
std::vector< T > data() const
Returns a vector storing the elements.
Definition ShiftVector.h:664
void insert(const Index index, const T &element, const T &intermediateElement)
Inserts (or overwrites) an element at a specific position of this vector.
Definition ShiftVector.h:573
void pushBack(T &&element)
Adds a new element to the end of this vector.
Definition ShiftVector.h:514
const T & front() const
Returns the element located at the first index.
Definition ShiftVector.h:454
Index firstIndex() const
Returns the index of the first element of this object.
Definition ShiftVector.h:416
The namespace covering the entire Ocean framework.
Definition Accessor.h:15