Ocean
Ocean::ShiftVector< T > Class Template Reference

This class implements a vector with shifted elements. More...

Inheritance diagram for Ocean::ShiftVector< T >:

Public Types

typedef T Type
 Definition of the data type of each element of this object. More...
 
typedef std::ptrdiff_t Index
 Definition of an element index. More...
 
typedef std::deque< T >::iterator Iterator
 Definition of a data iterator. More...
 
typedef std::deque< T >::const_iterator ConstIterator
 Definition of a const data iterator. More...
 

Public Member Functions

 ShiftVector ()=default
 Creates a new shift vector object. More...
 
 ShiftVector (const ShiftVector< T > &object)
 Copy constructor. More...
 
 ShiftVector (ShiftVector< T > &&object) noexcept
 Move constructor. More...
 
 ShiftVector (const Index firstIndex)
 Creates a new shift vector object. More...
 
 ShiftVector (const Index firstIndex, const size_t size)
 Creates a new shift vector object. More...
 
 ShiftVector (const Index firstIndex, const size_t size, const T &element)
 Creates a new shift vector object. More...
 
 ShiftVector (const Index firstIndex, const T *elements, const size_t size)
 Creates a new shift vector object and copies a specified number of elements. More...
 
Index firstIndex () const
 Returns the index of the first element of this object. More...
 
Index lastIndex () const
 Returns the index of the last (including) element of this object. More...
 
Index endIndex () const
 Returns the index of the element behind the last (excluding) element of this object. More...
 
void setFirstIndex (const Index index)
 Sets the index of the first element of this vector. More...
 
const T & front () const
 Returns the element located at the first index. More...
 
T & front ()
 Returns the element located at the first index. More...
 
const T & back () const
 Returns the element located at the last (including) index. More...
 
T & back ()
 Returns the element located at the last (including) index. More...
 
size_t size () const
 Returns the number of elements that are stored by this object. More...
 
void resize (const size_t size)
 Changes the number of elements of this vector. More...
 
void resize (const size_t size, const T &element)
 Changes the number of elements of this vector. More...
 
void pushBack (const T &element)
 Adds a new element to the end of this vector. More...
 
void pushBack (T &&element)
 Adds a new element to the end of this vector. More...
 
void pushFront (const T &element)
 Adds a new element to the front of this vector. More...
 
void pushFront (T &&element)
 Adds a new element to the front of this vector. More...
 
void popBack ()
 Removes an element from the end of this vector. More...
 
void popFront ()
 Removes an element form the front of this vector. More...
 
void insert (const Index index, const T &element)
 Inserts (or overwrites) an element at a specific position of this vector. More...
 
void insert (const Index index, const T &element, const T &intermediateElement)
 Inserts (or overwrites) an element at a specific position of this vector. More...
 
void insert (const Index index, T &&element)
 Inserts (or overwrites) an element at a specific position of this vector. More...
 
void insert (const Index index, T &&element, const T &intermediateElement)
 Inserts (or overwrites) an element at a specific position of this vector. More...
 
bool isValidIndex (const Index index) const
 Returns whether a specific index is valid for this vector and matches to the current offset layout. More...
 
bool isEmpty () const
 Returns whether this object holds no element. More...
 
void clear ()
 Clears this object, the specified index shift will be untouched. More...
 
std::vector< T > data () const
 Returns a vector storing the elements. More...
 
Iterator begin ()
 Returns the iterator for the first data element. More...
 
ConstIterator begin () const
 Returns the iterator for the first data element. More...
 
Iterator end ()
 Returns the end iterator. More...
 
ConstIterator end () const
 Returns the end iterator. More...
 
ShiftVector< T > & operator= (const ShiftVector< T > &object)
 Assign operator. More...
 
ShiftVector< T > & operator= (ShiftVector< T > &&object) noexcept
 Move operator. More...
 
const T & operator[] (const Index index) const
 Returns one element of this object. More...
 
T & operator[] (const Index index)
 Returns one element of this object. More...
 
 operator bool () const
 Returns whether this object holds at least one element. More...
 
bool operator== (const ShiftVector< T > &object) const
 Compares two shift vector objects whether they are equal. More...
 
bool operator!= (const ShiftVector< T > &object) const
 Compares two shift vector object whether they are not equal. More...
 

Protected Attributes

Index firstIndex_ = Index(0)
 The index of the first element. More...
 
std::deque< T > elements_
 Elements of this object. More...
 

Detailed Description

template<typename T>
class Ocean::ShiftVector< T >

This class implements a vector with shifted elements.

The elements are shifted by a shift offset index so that the elements can be accessed by adding this shift offset to the normal element index.
The shift offset can either be positive or negative.

Template Parameters
TData type of the elements that are stored

Member Typedef Documentation

◆ ConstIterator

template<typename T >
typedef std::deque<T>::const_iterator Ocean::ShiftVector< T >::ConstIterator

Definition of a const data iterator.

◆ Index

template<typename T >
typedef std::ptrdiff_t Ocean::ShiftVector< T >::Index

Definition of an element index.

◆ Iterator

template<typename T >
typedef std::deque<T>::iterator Ocean::ShiftVector< T >::Iterator

Definition of a data iterator.

◆ Type

template<typename T >
typedef T Ocean::ShiftVector< T >::Type

Definition of the data type of each element of this object.

Constructor & Destructor Documentation

◆ ShiftVector() [1/7]

template<typename T >
Ocean::ShiftVector< T >::ShiftVector ( )
default

Creates a new shift vector object.

◆ ShiftVector() [2/7]

template<typename T >
Ocean::ShiftVector< T >::ShiftVector ( const ShiftVector< T > &  object)

Copy constructor.

Parameters
objectVector object to be copied

◆ ShiftVector() [3/7]

template<typename T >
Ocean::ShiftVector< T >::ShiftVector ( ShiftVector< T > &&  object)
noexcept

Move constructor.

Parameters
objectVector object to be moved

◆ ShiftVector() [4/7]

template<typename T >
Ocean::ShiftVector< T >::ShiftVector ( const Index  firstIndex)
explicit

Creates a new shift vector object.

Parameters
firstIndexThe index of the first element of this vector

◆ ShiftVector() [5/7]

template<typename T >
Ocean::ShiftVector< T >::ShiftVector ( const Index  firstIndex,
const size_t  size 
)

Creates a new shift vector object.

Parameters
firstIndexThe index of the first element of this vector
sizeNumber of elements to be created

◆ ShiftVector() [6/7]

template<typename T >
Ocean::ShiftVector< T >::ShiftVector ( const Index  firstIndex,
const size_t  size,
const T &  element 
)

Creates a new shift vector object.

Parameters
firstIndexThe index of the first element of this vector
sizeNumber of elements to be created
elementPattern element that will be copied as often as requested

◆ ShiftVector() [7/7]

template<typename T >
Ocean::ShiftVector< T >::ShiftVector ( const Index  firstIndex,
const T *  elements,
const size_t  size 
)

Creates a new shift vector object and copies a specified number of elements.

Parameters
firstIndexThe index of the first element of this vector
elementsThe elements to be copied
sizeNumber of elements to be copied

Member Function Documentation

◆ back() [1/2]

template<typename T >
T & Ocean::ShiftVector< T >::back
inline

Returns the element located at the last (including) index.

Beware: Ensure that this object holds at least one element before accessing the element.

Returns
The first element
See also
lastIndex().

◆ back() [2/2]

template<typename T >
const T & Ocean::ShiftVector< T >::back
inline

Returns the element located at the last (including) index.

Beware: Ensure that this object holds at least one element before accessing the element.

Returns
The last element
See also
lastIndex().

◆ begin() [1/2]

template<typename T >
ShiftVector< T >::Iterator Ocean::ShiftVector< T >::begin
inline

Returns the iterator for the first data element.

Returns
Iterator for the first data element

◆ begin() [2/2]

template<typename T >
ShiftVector< T >::ConstIterator Ocean::ShiftVector< T >::begin
inline

Returns the iterator for the first data element.

Returns
Iterator for the first data element

◆ clear()

template<typename T >
void Ocean::ShiftVector< T >::clear
inline

Clears this object, the specified index shift will be untouched.

◆ data()

template<typename T >
std::vector< T > Ocean::ShiftVector< T >::data

Returns a vector storing the elements.

Returns
Vector holding the elements

◆ end() [1/2]

template<typename T >
ShiftVector< T >::Iterator Ocean::ShiftVector< T >::end
inline

Returns the end iterator.

Returns
Iterator for the end

◆ end() [2/2]

template<typename T >
ShiftVector< T >::ConstIterator Ocean::ShiftVector< T >::end
inline

Returns the end iterator.

Returns
Iterator for the end

◆ endIndex()

template<typename T >
ShiftVector< T >::Index Ocean::ShiftVector< T >::endIndex
inline

Returns the index of the element behind the last (excluding) element of this object.

Thus, there does not exist an element with the returning index.

Returns
Index of ending element
See also
lastIndex()

◆ firstIndex()

template<typename T >
ShiftVector< T >::Index Ocean::ShiftVector< T >::firstIndex
inline

Returns the index of the first element of this object.

Returns
Index of first element

◆ front() [1/2]

template<typename T >
T & Ocean::ShiftVector< T >::front
inline

Returns the element located at the first index.

Beware: Ensure that this object holds at least one element before accessing the element.

Returns
The first element
See also
firstIndex().

◆ front() [2/2]

template<typename T >
const T & Ocean::ShiftVector< T >::front
inline

Returns the element located at the first index.

Beware: Ensure that this object holds at least one element before accessing the element.

Returns
The first element
See also
firstIndex().

◆ insert() [1/4]

template<typename T >
void Ocean::ShiftVector< T >::insert ( const Index  index,
const T &  element 
)
inline

Inserts (or overwrites) an element at a specific position of this vector.

If the position is outside the current range of the vector (in negative or positive direction) than this vector will be extended accordingly.
Whenever the vector will be extended, all intermediate elements (elements at new indices not equal to the given index) are initialized with the default constructor of the data type of this vector.
Beware: If elements have to be added at the front, than the index of the first element will also be adjusted.

Parameters
indexThe index of the element
elementThe element to be inserted at the given index

◆ insert() [2/4]

template<typename T >
void Ocean::ShiftVector< T >::insert ( const Index  index,
const T &  element,
const T &  intermediateElement 
)
inline

Inserts (or overwrites) an element at a specific position of this vector.

If the position is outside the current range of the vector (in negative or positive direction) than this vector will be extended accordingly.
Whenever the vector will be extended, all intermediate elements (elements at new indices not equal to the given index) are initialized with the given intermediate element instance.
Beware: If elements have to be added at the front, than the index of the first element will also be adjusted.

Parameters
indexThe index of the element
elementThe element to be inserted at the given index
intermediateElementThe element that is copied to all intermediate elements (elements at new indices not equal to the given index)

◆ insert() [3/4]

template<typename T >
void Ocean::ShiftVector< T >::insert ( const Index  index,
T &&  element 
)
inline

Inserts (or overwrites) an element at a specific position of this vector.

If the position is outside the current range of the vector (in negative or positive direction) than this vector will be extended accordingly.
Whenever the vector will be extended, all intermediate elements (elements at new indices not equal to the given index) are initialized with the default constructor of the data type of this vector.
Beware: If elements have to be added at the front, than the index of the first element will also be adjusted.

Parameters
indexThe index of the element
elementThe element to be inserted at the given index

◆ insert() [4/4]

template<typename T >
void Ocean::ShiftVector< T >::insert ( const Index  index,
T &&  element,
const T &  intermediateElement 
)
inline

Inserts (or overwrites) an element at a specific position of this vector.

If the position is outside the current range of the vector (in negative or positive direction) than this vector will be extended accordingly.
Whenever the vector will be extended, all intermediate elements (elements at new indices not equal to the given index) are initialized with the given intermediate element instance.
Beware: If elements have to be added at the front, than the index of the first element will also be adjusted.

Parameters
indexThe index of the element
elementThe element to be inserted at the given index
intermediateElementThe element that is copied to all intermediate elements (elements at new indices not equal to the given index)

◆ isEmpty()

template<typename T >
bool Ocean::ShiftVector< T >::isEmpty
inline

Returns whether this object holds no element.

Returns
True, if so

◆ isValidIndex()

template<typename T >
bool Ocean::ShiftVector< T >::isValidIndex ( const Index  index) const
inline

Returns whether a specific index is valid for this vector and matches to the current offset layout.

Parameters
indexThe index to be checked
Returns
True, if succeeded

◆ lastIndex()

template<typename T >
ShiftVector< T >::Index Ocean::ShiftVector< T >::lastIndex
inline

Returns the index of the last (including) element of this object.

Returns
Index of last element
See also
endIndex().

◆ operator bool()

template<typename T >
Ocean::ShiftVector< T >::operator bool
inlineexplicit

Returns whether this object holds at least one element.

Returns
True, if so

◆ operator!=()

template<typename T >
bool Ocean::ShiftVector< T >::operator!= ( const ShiftVector< T > &  object) const
inline

Compares two shift vector object whether they are not equal.

Parameters
objectSecond shift vector object to be compared
Returns
True, if so

◆ operator=() [1/2]

template<typename T >
ShiftVector< T > & Ocean::ShiftVector< T >::operator= ( const ShiftVector< T > &  object)

Assign operator.

Parameters
objectVector object to be copied
Returns
Reference to this object

◆ operator=() [2/2]

template<typename T >
ShiftVector< T > & Ocean::ShiftVector< T >::operator= ( ShiftVector< T > &&  object)
noexcept

Move operator.

Parameters
objectVector object to be moved
Returns
Reference to this object

◆ operator==()

template<typename T >
bool Ocean::ShiftVector< T >::operator== ( const ShiftVector< T > &  object) const

Compares two shift vector objects whether they are equal.

Two shift vector object are equal if they have the same firstIndex() parameter, if they have the same size and if all elements are equal.

Parameters
objectSecond shift vector object to be compared
Returns
True, if so

◆ operator[]() [1/2]

template<typename T >
T & Ocean::ShiftVector< T >::operator[] ( const Index  index)
inline

Returns one element of this object.

Parameters
indexThe index of the element to be returned, with range [firstIndex(), lastIndex()]
Returns
Requested element

◆ operator[]() [2/2]

template<typename T >
const T & Ocean::ShiftVector< T >::operator[] ( const Index  index) const
inline

Returns one element of this object.

Parameters
indexThe index of the element to be returned, with range [firstIndex(), lastIndex()]
Returns
Requested element

◆ popBack()

template<typename T >
void Ocean::ShiftVector< T >::popBack
inline

Removes an element from the end of this vector.

The internal shift offset is untouched.

◆ popFront()

template<typename T >
void Ocean::ShiftVector< T >::popFront
inline

Removes an element form the front of this vector.

The internal shift offset will be incremented by 1 so that the indices of the remaining elements remain unchanged.

◆ pushBack() [1/2]

template<typename T >
void Ocean::ShiftVector< T >::pushBack ( const T &  element)
inline

Adds a new element to the end of this vector.

The internal shift offset is untouched.

Parameters
elementNew element to be added

◆ pushBack() [2/2]

template<typename T >
void Ocean::ShiftVector< T >::pushBack ( T &&  element)
inline

Adds a new element to the end of this vector.

The internal shift offset is untouched.

Parameters
elementNew element to be added

◆ pushFront() [1/2]

template<typename T >
void Ocean::ShiftVector< T >::pushFront ( const T &  element)
inline

Adds a new element to the front of this vector.

The internal shift offset will be decremented by 1 so that the indices of the existing elements remain unchanged.

Parameters
elementNew element to be added

◆ pushFront() [2/2]

template<typename T >
void Ocean::ShiftVector< T >::pushFront ( T &&  element)
inline

Adds a new element to the front of this vector.

The internal shift offset will be decremented by 1 so that the indices of the existing elements remain unchanged.

Parameters
elementNew element to be added

◆ resize() [1/2]

template<typename T >
void Ocean::ShiftVector< T >::resize ( const size_t  size)
inline

Changes the number of elements of this vector.

If the new size is greater than the current size, than new elements are inserted with default initialization of the data type handled by this vector.

Parameters
sizeNew element number

◆ resize() [2/2]

template<typename T >
void Ocean::ShiftVector< T >::resize ( const size_t  size,
const T &  element 
)
inline

Changes the number of elements of this vector.

If the new size is greater than the current size, than new elements are inserted and initialized as copies of the given pattern element.

Parameters
sizeNew element number
elementThe pattern element that is copied to each new internal element if necessary

◆ setFirstIndex()

template<typename T >
void Ocean::ShiftVector< T >::setFirstIndex ( const Index  index)
inline

Sets the index of the first element of this vector.

The elements of this vector will be untouched, however the individual elements receive a new index due to the new shift offset.

Parameters
indexThe index of the first element

◆ size()

template<typename T >
size_t Ocean::ShiftVector< T >::size
inline

Returns the number of elements that are stored by this object.

Returns
Number of elements

Field Documentation

◆ elements_

template<typename T >
std::deque<T> Ocean::ShiftVector< T >::elements_
protected

Elements of this object.

◆ firstIndex_

template<typename T >
Index Ocean::ShiftVector< T >::firstIndex_ = Index(0)
protected

The index of the first element.


The documentation for this class was generated from the following file: