Ocean
Ocean::StaticVector< T, tCapacity > Class Template Reference

This class implements a static vector that has a fixed capacity. More...

Inheritance diagram for Ocean::StaticVector< T, tCapacity >:

Public Member Functions

 StaticVector ()=default
 Creates a new vector object. More...
 
 StaticVector (const T &value)
 Creates a new vector object. More...
 
 StaticVector (T &&value)
 Creates a new vector object. More...
 
 StaticVector (const size_t number, const T &value)
 Creates a new vector object. More...
 
 StaticVector (const T *values, const size_t size)
 Creates a new vector object. More...
 
 StaticVector (const std::vector< T > &values)
 Creates a new vector object. More...
 
 StaticVector (std::vector< T > &&values)
 Creates a new vector object. More...
 
size_t size () const
 Returns the size of this vector. More...
 
bool occupied () const
 Returns whether no free space is left. More...
 
void pushBack (const T &value)
 Adds a new element to this vector. More...
 
void pushBack (T &&value)
 Adds a new element to this vector. More...
 
bool securePushBack (const T &value)
 Adds a new element to this vector if this vector has free elements left, otherwise nothing happens. More...
 
bool securePushBack (T &&value)
 Adds a new element to this vector if this vector has free elements left, otherwise nothing happens. More...
 
template<size_t tCapacity2>
void pushBack (const StaticVector< T, tCapacity2 > &value)
 Adds a new elements to this vector. More...
 
void pushBack (const std::vector< T > &value)
 Adds a new elements to this vector. More...
 
void popBack ()
 Removes the last element from this vector. More...
 
void securePopBack ()
 Removes the last element from this vector. More...
 
void weakPopBack ()
 Removes the last element from this vector. More...
 
void secureWeakPopBack ()
 Removes the last element from this vector. More...
 
void erase (const size_t index)
 Erases one element of this vector. More...
 
void unstableErase (const size_t index)
 Erases one element from this vector. More...
 
void resize (const size_t size)
 Resizes this vector. More...
 
void weakResize (const size_t size)
 Resizes this vector. More...
 
void clear ()
 Clears all elements of this vector. More...
 
void weakClear ()
 Clears all elements of this vector by setting the internal index to zero (all stored elements are untouched). More...
 
const T & front () const
 Returns the first elements of this vector. More...
 
T & front ()
 Returns the first elements of this vector. More...
 
const T & back () const
 Returns the last elements of this vector. More...
 
T & back ()
 Returns the last elements of this vector. More...
 
bool empty () const
 Returns whether this vector hold no element. More...
 
const T & operator[] (const size_t index) const
 Returns one element of this vector. More...
 
T & operator[] (const size_t index)
 Returns one element of this vector. More...
 
bool operator== (const StaticVector< T, tCapacity > &second) const
 Returns whether two vectors are identical. More...
 
bool operator!= (const StaticVector< T, tCapacity > &second) const
 Returns whether two vectors are not identical. More...
 
 operator bool () const
 Returns whether this vector holds at least one element. More...
 
- Public Member Functions inherited from Ocean::StaticBuffer< T, tCapacity >
 StaticBuffer ()=default
 Creates a new buffer object. More...
 
 StaticBuffer (const T &value)
 Creates a new buffer object. More...
 
 StaticBuffer (T &&value)
 Creates a new buffer object. More...
 
 StaticBuffer (const T *buffer)
 Creates a new buffer object. More...
 
 StaticBuffer (const size_t number, const T &value)
 Creates a new buffer object. More...
 
 StaticBuffer (const std::vector< T > &values)
 Creates a new buffer object. More...
 
 StaticBuffer (std::vector< T > &&values)
 Creates a new buffer object. More...
 
void clear ()
 Clears all elements of this buffer. More...
 
const T & front () const
 Returns the first elements of this buffer. More...
 
T & front ()
 Returns the first elements of this buffer. More...
 
const T & back () const
 Returns the last elements of this buffer. More...
 
T & back ()
 Returns the last elements of this buffer. More...
 
const T * data () const
 Returns the buffer data pointer. More...
 
T * data ()
 Returns the buffer data pointer. More...
 
const T & operator[] (const size_t index) const
 Returns one element of this buffer. More...
 
T & operator[] (const size_t index)
 Returns one element of this buffer. More...
 
bool operator== (const StaticBuffer< T, tCapacity > &second) const
 Returns whether two buffers are identical. More...
 
bool operator!= (const StaticBuffer< T, tCapacity > &second) const
 Returns whether two buffers are not identical. More...
 

Protected Attributes

size_t size_ = 0
 The current number of stored elements, with range [0, tCapacity]. More...
 
- Protected Attributes inherited from Ocean::StaticBuffer< T, tCapacity >
elements_ [tCapacity > size_t(0) ? tCapacity :size_t(1)]
 Elements of this buffer (with at least one entry). More...
 

Additional Inherited Members

- Public Types inherited from Ocean::StaticBuffer< T, tCapacity >
typedef T Type
 Definition of the data type of each individual buffer element. More...
 
- Static Public Member Functions inherited from Ocean::StaticBuffer< T, tCapacity >
static constexpr size_t capacity ()
 Returns the capacity of this buffer. More...
 

Detailed Description

template<typename T, size_t tCapacity>
class Ocean::StaticVector< T, tCapacity >

This class implements a static vector that has a fixed capacity.

Template Parameters
TData type of the elements that will be stored
tCapacityNumber of elements that can be stored, with range [1, infinity)

Constructor & Destructor Documentation

◆ StaticVector() [1/7]

template<typename T , size_t tCapacity>
Ocean::StaticVector< T, tCapacity >::StaticVector ( )
default

Creates a new vector object.

◆ StaticVector() [2/7]

template<typename T , size_t tCapacity>
Ocean::StaticVector< T, tCapacity >::StaticVector ( const T &  value)
inlineexplicit

Creates a new vector object.

Parameters
valueThe value that will be set as first element

◆ StaticVector() [3/7]

template<typename T , size_t tCapacity>
Ocean::StaticVector< T, tCapacity >::StaticVector ( T &&  value)
inlineexplicit

Creates a new vector object.

Parameters
valueThe value that will be set as first element

◆ StaticVector() [4/7]

template<typename T , size_t tCapacity>
Ocean::StaticVector< T, tCapacity >::StaticVector ( const size_t  number,
const T &  value 
)
inline

Creates a new vector object.

Parameters
numberThe number of elements to be created
valueThe value that will be created in the first 'number' elements of this vector

◆ StaticVector() [5/7]

template<typename T , size_t tCapacity>
Ocean::StaticVector< T, tCapacity >::StaticVector ( const T *  values,
const size_t  size 
)
inline

Creates a new vector object.

Parameters
valuesThe values to be copied into this vector object, can be nullptr if 'size == 0'
sizeThe number of values to copy, with range [0, tCapacity]

◆ StaticVector() [6/7]

template<typename T , size_t tCapacity>
Ocean::StaticVector< T, tCapacity >::StaticVector ( const std::vector< T > &  values)
inlineexplicit

Creates a new vector object.

This constructor converts a stl vector object to a static vector object.
Only the first tCapacity elements of the given vector are copied.

Parameters
valuesThe values that will be used as first elements

◆ StaticVector() [7/7]

template<typename T , size_t tCapacity>
Ocean::StaticVector< T, tCapacity >::StaticVector ( std::vector< T > &&  values)
inlineexplicit

Creates a new vector object.

This constructor converts a stl vector object to a static vector object.
Only the first tCapacity elements of the given vector are copied.

Parameters
valuesThe values that will be used as first elements

Member Function Documentation

◆ back() [1/2]

template<typename T , size_t tCapacity>
T & Ocean::StaticVector< T, tCapacity >::back
inline

Returns the last elements of this vector.

Returns
Last element

◆ back() [2/2]

template<typename T , size_t tCapacity>
const T & Ocean::StaticVector< T, tCapacity >::back
inline

Returns the last elements of this vector.

Returns
Last element

◆ clear()

template<typename T , size_t tCapacity>
void Ocean::StaticVector< T, tCapacity >::clear
inline

Clears all elements of this vector.

See also
weakClear().

◆ empty()

template<typename T , size_t tCapacity>
bool Ocean::StaticVector< T, tCapacity >::empty
inline

Returns whether this vector hold no element.

Returns
True, if so

◆ erase()

template<typename T , size_t tCapacity>
void Ocean::StaticVector< T, tCapacity >::erase ( const size_t  index)
inline

Erases one element of this vector.

Parameters
indexThe index of the element that will be removed, with range [0, size())
See also
unstableErase().

◆ front() [1/2]

template<typename T , size_t tCapacity>
T & Ocean::StaticVector< T, tCapacity >::front
inline

Returns the first elements of this vector.

Returns
First element

◆ front() [2/2]

template<typename T , size_t tCapacity>
const T & Ocean::StaticVector< T, tCapacity >::front
inline

Returns the first elements of this vector.

Returns
First element

◆ occupied()

template<typename T , size_t tCapacity>
bool Ocean::StaticVector< T, tCapacity >::occupied
inline

Returns whether no free space is left.

Returns
True, if capacity() - size() == 0

◆ operator bool()

template<typename T , size_t tCapacity>
Ocean::StaticVector< T, tCapacity >::operator bool
inlineexplicit

Returns whether this vector holds at least one element.

Returns
True, if so

◆ operator!=()

template<typename T , size_t tCapacity>
bool Ocean::StaticVector< T, tCapacity >::operator!= ( const StaticVector< T, tCapacity > &  second) const
inline

Returns whether two vectors are not identical.

Parameters
secondThe second vector object
Returns
True, if so

◆ operator==()

template<typename T , size_t tCapacity>
bool Ocean::StaticVector< T, tCapacity >::operator== ( const StaticVector< T, tCapacity > &  second) const
inline

Returns whether two vectors are identical.

Parameters
secondThe second vector object
Returns
True, if so

◆ operator[]() [1/2]

template<typename T , size_t tCapacity>
T & Ocean::StaticVector< T, tCapacity >::operator[] ( const size_t  index)
inline

Returns one element of this vector.

Beware: No range check is done.

Parameters
indexThe index of the element that will be returned, with range [0, size())
Returns
Vector element

◆ operator[]() [2/2]

template<typename T , size_t tCapacity>
const T & Ocean::StaticVector< T, tCapacity >::operator[] ( const size_t  index) const
inline

Returns one element of this vector.

Beware: No range check is done.

Parameters
indexThe index of the element that will be returned, with range [0, size())
Returns
Vector element

◆ popBack()

template<typename T , size_t tCapacity>
void Ocean::StaticVector< T, tCapacity >::popBack
inline

Removes the last element from this vector.

Beware: No range check is applied. Thus: Check that this vector holds at least one element!

See also
weakPopBack(), pushBack().

◆ pushBack() [1/4]

template<typename T , size_t tCapacity>
template<size_t tCapacity2>
void Ocean::StaticVector< T, tCapacity >::pushBack ( const StaticVector< T, tCapacity2 > &  value)
inline

Adds a new elements to this vector.

This function avoids a memory overflow.

Parameters
valueValues to be added
Template Parameters
tCapacity2Capacity of the second vector

◆ pushBack() [2/4]

template<typename T , size_t tCapacity>
void Ocean::StaticVector< T, tCapacity >::pushBack ( const std::vector< T > &  value)
inline

Adds a new elements to this vector.

This function avoids a memory overflow.

Parameters
valueValues to be added

◆ pushBack() [3/4]

template<typename T , size_t tCapacity>
void Ocean::StaticVector< T, tCapacity >::pushBack ( const T &  value)
inline

Adds a new element to this vector.

Beware: No range check is applied.

Parameters
valueThe value to be added
See also
securePushBack().

◆ pushBack() [4/4]

template<typename T , size_t tCapacity>
void Ocean::StaticVector< T, tCapacity >::pushBack ( T &&  value)
inline

Adds a new element to this vector.

Beware: No range check is applied.

Parameters
valueThe value to be added
See also
securePushBack().

◆ resize()

template<typename T , size_t tCapacity>
void Ocean::StaticVector< T, tCapacity >::resize ( const size_t  size)
inline

Resizes this vector.

Parameters
sizeThe size to be applied, with range [0, tCapacity]
See also
weakResize().

◆ securePopBack()

template<typename T , size_t tCapacity>
void Ocean::StaticVector< T, tCapacity >::securePopBack
inline

Removes the last element from this vector.

If this vector holds no element, nothing is happen.

See also
weakPopBack(), pushBack().

◆ securePushBack() [1/2]

template<typename T , size_t tCapacity>
bool Ocean::StaticVector< T, tCapacity >::securePushBack ( const T &  value)
inline

Adds a new element to this vector if this vector has free elements left, otherwise nothing happens.

Parameters
valueThe value to be added
Returns
True, if succeeded
See also
pushBack().

◆ securePushBack() [2/2]

template<typename T , size_t tCapacity>
bool Ocean::StaticVector< T, tCapacity >::securePushBack ( T &&  value)
inline

Adds a new element to this vector if this vector has free elements left, otherwise nothing happens.

Parameters
valueThe value to be added
Returns
True, if succeeded
See also
pushBack().

◆ secureWeakPopBack()

template<typename T , size_t tCapacity>
void Ocean::StaticVector< T, tCapacity >::secureWeakPopBack
inline

Removes the last element from this vector.

This function simply decreases the element counter, the last element is untouched.
If this vector holds no element, nothing is happen.

See also
popBack().

◆ size()

template<typename T , size_t tCapacity>
size_t Ocean::StaticVector< T, tCapacity >::size
inline

Returns the size of this vector.

Returns
Vector size

◆ unstableErase()

template<typename T , size_t tCapacity>
void Ocean::StaticVector< T, tCapacity >::unstableErase ( const size_t  index)
inline

Erases one element from this vector.

The free element is replace by the last element in the vector, thus the previous order of the elements inside this vector is lost.
This erase function is faster than the standard erase function.

Parameters
indexThe index of the element that will be removed, with range [0, size())
See also
erase().

◆ weakClear()

template<typename T , size_t tCapacity>
void Ocean::StaticVector< T, tCapacity >::weakClear
inline

Clears all elements of this vector by setting the internal index to zero (all stored elements are untouched).

See also
clear().

◆ weakPopBack()

template<typename T , size_t tCapacity>
void Ocean::StaticVector< T, tCapacity >::weakPopBack
inline

Removes the last element from this vector.

This function simply decreases the element counter, the last element is untouched.
Beware: No range check is applied. Thus: Check that this vector holds at least one element!

See also
popBack().

◆ weakResize()

template<typename T , size_t tCapacity>
void Ocean::StaticVector< T, tCapacity >::weakResize ( const size_t  size)
inline

Resizes this vector.

This function simply sets the element counter.

Parameters
sizeThe size to be applied, with range [0, tCapacity]
See also
resize().

Field Documentation

◆ size_

template<typename T , size_t tCapacity>
size_t Ocean::StaticVector< T, tCapacity >::size_ = 0
protected

The current number of stored elements, with range [0, tCapacity].


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