commonlib
VectorWithIds< T > Class Template Reference

Public Types

using iterator = VectorWithIdsIterators::VectorWithIdsIterator< T, VectorWithIdsIterators::ConstTypeSwitch::isNonConst >
 
using const_iterator = VectorWithIdsIterators::VectorWithIdsIterator< T, VectorWithIdsIterators::ConstTypeSwitch::isConst >
 

Public Member Functions

 VectorWithIds (std::size_t idMinGenerated=0, std::size_t idStepSizeGenerated=1)
 Constructor with optional minimum automatic id and step between generated ids. More...
 
 VectorWithIds (const VectorWithIds &other)
 Copy constructor.
 
VectorWithIds< T > & operator= (const VectorWithIds &other)
 Copy assignment.
 
 VectorWithIds (VectorWithIds< T > &&other)
 Move constructor.
 
VectorWithIds< T > & operator= (VectorWithIds< T > &&other)
 Move assignment.
 
T & operator[] (std::size_t pos)
 Mutable access element at position. More...
 
const T & operator[] (std::size_t pos) const
 Read only access to element at position. More...
 
T & back ()
 Mutable access to the last element in the container. More...
 
const T & back () const
 Read only access to the last element in the container. More...
 
void clear ()
 Deletes all objects in the container and sets the size to zero.
 
std::size_t size () const
 
bool empty () const
 
void emplaceBack ()
 Constructs an additional element at the at the back of the container by calling a default constructor. More...
 
bool emplaceBackWithId (int32_t id)
 Constructs an additional element at the at the back of the container by calling a default constructor if the id passed isn't yet taken. More...
 
iterator erase (iterator position)
 Erases an element at an iterator position. More...
 
iterator erase (std::size_t pos)
 Erases an element at an iterator position. More...
 
void swap (int32_t posA, int32_t posB)
 Swaps elements in container at indexed positions passed. More...
 
int32_t getId (int32_t pos) const
 Swaps elements in container at indexed positions passed. More...
 
iterator findById (int32_t id)
 Searches for an element with an id passed. More...
 
const_iterator findById (int32_t id) const
 Searches for an element with an id passed. More...
 
void cloneStructure (const VectorWithIds< T > &other)
 Clones the structure of the container to the one of the passed object. More...
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 

Constructor & Destructor Documentation

◆ VectorWithIds()

template<class T >
VectorWithIds< T >::VectorWithIds ( std::size_t  idMinGenerated = 0,
std::size_t  idStepSizeGenerated = 1 
)

Constructor with optional minimum automatic id and step between generated ids.

The automatic ids will newer be lower than the minimum specified. Automatic id number will always lie on a multiple of step size with an offset of minimum id: (ID - idMinGenerated) % idStepSizeGenerated = 0. Assert is triggered if step size is equal to 0.

Parameters
idMinGeneratedminimum id that can be automatically generated
idStepSizeGeneratedminimum step

Member Function Documentation

◆ back() [1/2]

template<typename T >
T & VectorWithIds< T >::back ( )

Mutable access to the last element in the container.

Returns
reference to the last element in container

◆ back() [2/2]

template<typename T >
const T & VectorWithIds< T >::back ( ) const

Read only access to the last element in the container.

Returns
constant reference to the last element in container

◆ begin() [1/2]

template<typename T>
iterator VectorWithIds< T >::begin ( )
inline
Returns
an iterator pointing to the first element of the container

◆ begin() [2/2]

template<typename T>
const_iterator VectorWithIds< T >::begin ( ) const
inline
Returns
a constant iterator pointing to the first element of the container

◆ cbegin()

template<typename T>
const_iterator VectorWithIds< T >::cbegin ( ) const
inline
Returns
a constant iterator pointing to the first element of the container

◆ cend()

template<typename T>
const_iterator VectorWithIds< T >::cend ( ) const
inline
Returns
a constant iterator pointing to position past the last element of the container

◆ cloneStructure()

template<typename T >
void VectorWithIds< T >::cloneStructure ( const VectorWithIds< T > &  other)

Clones the structure of the container to the one of the passed object.

Order based on id number order of the passed container, existing objects are put in the same order as in the passed container. Missing objects are constructed with a default constructor. Elements that had an id number which is not present in the passed container are deleted. Objects from the passed container aren't copied or transferred to the existing container.

Parameters
othercontainer from which the structure is cloned

◆ emplaceBack()

template<typename T >
void VectorWithIds< T >::emplaceBack ( )

Constructs an additional element at the at the back of the container by calling a default constructor.

Automatic id is automatically assigned to the new element according to minimum generated id and minimum step between generated id numbers. The id is always the minimum id that isn't yet taken by another element.

◆ emplaceBackWithId()

template<typename T >
bool VectorWithIds< T >::emplaceBackWithId ( int32_t  id)

Constructs an additional element at the at the back of the container by calling a default constructor if the id passed isn't yet taken.

True is returned only when an element has been added.

Parameters
idnumber of the newly constructed element at the back of container
Returns
true if element with passed id was added to the container

◆ empty()

template<typename T >
bool VectorWithIds< T >::empty ( ) const
Returns
true if the container is empty otherwise false

◆ end() [1/2]

template<typename T>
iterator VectorWithIds< T >::end ( )
inline
Returns
an iterator pointing to position past the last element of the container

◆ end() [2/2]

template<typename T>
const_iterator VectorWithIds< T >::end ( ) const
inline
Returns
a constant iterator pointing to position past the last element of the container

◆ erase() [1/2]

template<typename T >
VectorWithIds< T >::iterator VectorWithIds< T >::erase ( iterator  position)

Erases an element at an iterator position.

Parameters
positionand iterator pointing to the single element to be removed from the container
Returns
an iterator pointing to the new location of the element that followed the element erased by the function call

◆ erase() [2/2]

template<typename T >
VectorWithIds< T >::iterator VectorWithIds< T >::erase ( std::size_t  pos)

Erases an element at an iterator position.

Parameters
indexof a single element to be removed from the container
Returns
an iterator pointing to the new location of the element that followed the element erased by the function call

◆ findById() [1/2]

template<typename T >
VectorWithIds< T >::iterator VectorWithIds< T >::findById ( int32_t  id)

Searches for an element with an id passed.

Returns an iterator pointing to the element with a passed id. If element with that id doesn't exist an iterator pointing container end is returned.

Parameters
idof an element being searched
Returns
an iterator pointing to the element found or to container end if element wasn't found

◆ findById() [2/2]

template<typename T >
VectorWithIds< T >::const_iterator VectorWithIds< T >::findById ( int32_t  id) const

Searches for an element with an id passed.

Returns a constant iterator pointing to the element with a passed id. If element with that id doesn't exist an iterator pointing container end is returned.

Parameters
idvalue of an element being searched
Returns
a constant iterator pointing to the element found or to container end if element wasn't found

◆ getId()

template<typename T >
int32_t VectorWithIds< T >::getId ( int32_t  pos) const

Swaps elements in container at indexed positions passed.

Parameters
posindex position of an element
Returns
id number at the position passed

◆ operator[]() [1/2]

template<typename T >
T & VectorWithIds< T >::operator[] ( std::size_t  pos)

Mutable access element at position.

Parameters
posindex position of an element
Returns
reference of an object at the position

◆ operator[]() [2/2]

template<typename T >
const T & VectorWithIds< T >::operator[] ( std::size_t  pos) const

Read only access to element at position.

Parameters
posindex position of an element
Returns
constant reference of an object at the position

◆ size()

template<typename T >
std::size_t VectorWithIds< T >::size ( ) const
Returns
number of elements in the container

◆ swap()

template<typename T >
void VectorWithIds< T >::swap ( int32_t  posA,
int32_t  posB 
)

Swaps elements in container at indexed positions passed.

Parameters
posAindex of the to be swapped element
posBindex of the to be swapped element

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