Skip to main content
Version: 4.16

Vector

A very simple container class using pre-allocated memory.

Template Parameters:

  • T The type of objects this container works on.
  • capacity The maximum number of objects this container can store.

Public Functions#

voidadd(T e)
Adds an element to the Vector if the Vector is not full.
voidclear()
Clears the contents of the container.
boolcontains(T elem)
Checks if the Vector contains an element.
boolisEmpty() const
Query if this object is empty.
uint16_tmaxCapacity() const
Query the maximum capacity of the vector.
T &operator[](uint16_t idx)
Index operator.
const T &operator[](uint16_t idx) const
Const version of the index operator.
voidquickRemoveAt(uint16_t index)
Removes an element at the specified index of the Vector.
voidremove(T e)
Removes an element from the Vector if found in the Vector.
TremoveAt(uint16_t index)
Removes an element at the specified index of the Vector.
voidreverse()
Reverses the ordering of the elements in the Vector.
uint16_tsize() const
Gets the current size of the Vector which is the number of elements contained in the Vector.
Vector()
Default constructor.

Public Functions Documentation#

add#

void add(Te)

Adds an element to the Vector if the Vector is not full.

Adds an element to the Vector if the Vector is not full. Does nothing if the Vector is full.

Parameters:
eThe element to add to the Vector.

clear#

void clear()

Clears the contents of the container.

It does not destruct any of the elements in the Vector.

contains#

bool contains(Telem)

Checks if the Vector contains an element.

The == operator of the element is used when comparing it with the elements in the Vector.

Parameters:
elemThe element.
Returns:

true if the Vector contains the element, false otherwise.

isEmpty#

bool isEmpty()const

Query if this object is empty.

Returns:

true if the Vector contains no elements.

maxCapacity#

uint16_t maxCapacity()const

Query the maximum capacity of the vector.

Returns:

The capacity the Vector was initialized with.

operator[]#

T & operator[](uint16_tidx)

Index operator.

Parameters:
idxThe index of the element to obtain.
Returns:

A reference to the element placed at index idx.

operator[]#

const T & operator[](uint16_tidx)

Const version of the index operator.

Parameters:
idxThe index of the element to obtain.
Returns:

A const reference to the element placed at index idx.

quickRemoveAt#

void quickRemoveAt(uint16_tindex)

Removes an element at the specified index of the Vector.

The last element in the list is moved to the position where the element is removed.

Parameters:
indexThe index to remove.

remove#

void remove(Te)

Removes an element from the Vector if found in the Vector.

Does nothing if the element is not found in the Vector. The == operator of the element is used when comparing it with the elements in the Vector.

Parameters:
eThe element to remove from the Vector.

removeAt#

removeAt(uint16_tindex)

Removes an element at the specified index of the Vector.

Will "bubble-down" any remaining elements after the specified index.

Parameters:
indexThe index to remove.
Returns:

The value of the removed element.

reverse#

void reverse()

Reverses the ordering of the elements in the Vector.

size#

uint16_t size()const

Gets the current size of the Vector which is the number of elements contained in the Vector.

Gets the current size of the Vector which is the number of elements contained in the Vector.

Returns:

The size of the Vector.

Vector#

Default constructor.

Constructs an empty vector.