A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
Kinoko::fixed_vector< T > Class Template Reference

#include <Types.hh>

Description

template<typename T>
class Kinoko::fixed_vector< T >

Dynamically sized array that only allocates once.

It's possible that only an upper bound is known for a given vector. However, in the event that there are more objects than expected, we want to error. Effectively, this behaves identically to std::vector<T, EGG::Allocator<T>> except that it cannot be later resized.

Template Parameters
TThe type of objects in the array.

Definition at line 177 of file Types.hh.

Public Member Functions

 fixed_vector ()
 Non-initializing constructor.
 fixed_vector (size_t capacity)
 Initializing constructor.
 fixed_vector (const fixed_vector &rhs)
 Copy constructor.
 fixed_vector (fixed_vector &&rhs)
 Move constructor.
fixed_vectoroperator= (const fixed_vector &rhs)
 Copy assignment operator.
fixed_vectoroperator= (fixed_vector &&rhs)
 Move assignment operator.
 ~fixed_vector ()
 Destructor.
T & push_back (const T &obj)
 Copies a new element into the array.
T & push_back (T &&obj)
 Moves a new element into the array.
template<typename... Args>
T & emplace_back (Args &&...args)
 Creates a new element in-place in the array.
void pop_back ()
 Deletes the last existing element from the array.
void reserve (size_t capacity)
 Initializes the vector with the provided capacity.
bool empty () const
 Checks if there are no existing elements in the array.
bool full () const
 Checks if all elements exist in the array.
bool initialized () const
 Checks if the array exists and if the capacity is non-zero.
size_t size () const
 Gets the number of existing elements in the array.
size_t capacity () const
 Gets the maximum number of elements that can exist in the array.
T & front ()
 Gets the first element in the array.
const T & front () const
 Gets the first element in the array.
T & back ()
 Gets the last existing element in the array.
const T & back () const
 Gets the last existing element in the array.
T & operator[] (size_t idx)
 Indexes the array. Validates that the object exists.
const T & operator[] (size_t idx) const
 Indexes the array. Validates that the object exists.
T * begin () noexcept
 Iterator for the beginning of the existing array.
const T * begin () const noexcept
 Iterator for the beginning of the existing array.
T * end () noexcept
 Iterator for the end of the existing array.
const T * end () const noexcept
 Iterator for the end of the existing array.

Private Member Functions

void destroy ()
 Destroys existing elements and frees the buffer, resetting to an uninitialized state.
void allocate (size_t capacity)
 Allocates the array.

Private Attributes

T * m_data
size_t m_size
size_t m_capacity

Constructor & Destructor Documentation

◆ fixed_vector() [1/4]

template<typename T>
Kinoko::fixed_vector< T >::fixed_vector ( )
inline

Non-initializing constructor.

Definition at line 180 of file Types.hh.

◆ fixed_vector() [2/4]

template<typename T>
Kinoko::fixed_vector< T >::fixed_vector ( size_t capacity)
inline

Initializing constructor.

Parameters
capacityThe number of elements to initialize the vector with.

Definition at line 184 of file Types.hh.

◆ fixed_vector() [3/4]

template<typename T>
Kinoko::fixed_vector< T >::fixed_vector ( const fixed_vector< T > & rhs)
inline

Copy constructor.

Allocates a buffer of the same capacity and deep copies existing elements

Definition at line 190 of file Types.hh.

◆ fixed_vector() [4/4]

template<typename T>
Kinoko::fixed_vector< T >::fixed_vector ( fixed_vector< T > && rhs)
inline

Move constructor.

Transfers ownership of the buffer and leaves rhs in an invalid state

Definition at line 201 of file Types.hh.

◆ ~fixed_vector()

template<typename T>
Kinoko::fixed_vector< T >::~fixed_vector ( )
inline

Destructor.

Destroys all existing elements in the array in-place from the end to the start.

Definition at line 244 of file Types.hh.

Member Function Documentation

◆ allocate()

template<typename T>
void Kinoko::fixed_vector< T >::allocate ( size_t capacity)
inlineprivate

Allocates the array.

Parameters
capacityThe number of elements to initialize the vector with.

Definition at line 406 of file Types.hh.

◆ back() [1/2]

template<typename T>
T & Kinoko::fixed_vector< T >::back ( )
inline

Gets the last existing element in the array.

Returns
A reference to the last existing element in the array.

Definition at line 336 of file Types.hh.

◆ back() [2/2]

template<typename T>
const T & Kinoko::fixed_vector< T >::back ( ) const
inline

Gets the last existing element in the array.

Returns
A const reference to the last existing element in the array.

Definition at line 343 of file Types.hh.

◆ begin() [1/2]

template<typename T>
const T * Kinoko::fixed_vector< T >::begin ( ) const
inlinenoexcept

Iterator for the beginning of the existing array.

Returns
Const iterator.

Definition at line 373 of file Types.hh.

◆ begin() [2/2]

template<typename T>
T * Kinoko::fixed_vector< T >::begin ( )
inlinenoexcept

Iterator for the beginning of the existing array.

Returns
Iterator.

Definition at line 366 of file Types.hh.

◆ capacity()

template<typename T>
size_t Kinoko::fixed_vector< T >::capacity ( ) const
inlinenodiscard

Gets the maximum number of elements that can exist in the array.

Returns
The maximum number of elements that can exist in the array.

Definition at line 316 of file Types.hh.

◆ destroy()

template<typename T>
void Kinoko::fixed_vector< T >::destroy ( )
inlineprivate

Destroys existing elements and frees the buffer, resetting to an uninitialized state.

Definition at line 394 of file Types.hh.

◆ emplace_back()

template<typename T>
template<typename... Args>
T & Kinoko::fixed_vector< T >::emplace_back ( Args &&... args)
inline

Creates a new element in-place in the array.

Template Parameters
...ArgsVariadic template for packing.
Parameters
...argsArguments to the constructor.
Returns
A reference to the object.

Definition at line 271 of file Types.hh.

◆ empty()

template<typename T>
bool Kinoko::fixed_vector< T >::empty ( ) const
inlinenodiscard

Checks if there are no existing elements in the array.

Returns
True if the array is empty, otherwise false.

Definition at line 292 of file Types.hh.

◆ end() [1/2]

template<typename T>
const T * Kinoko::fixed_vector< T >::end ( ) const
inlinenoexcept

Iterator for the end of the existing array.

Returns
Const iterator.

Definition at line 387 of file Types.hh.

◆ end() [2/2]

template<typename T>
T * Kinoko::fixed_vector< T >::end ( )
inlinenoexcept

Iterator for the end of the existing array.

Returns
Iterator.

Definition at line 380 of file Types.hh.

◆ front() [1/2]

template<typename T>
T & Kinoko::fixed_vector< T >::front ( )
inline

Gets the first element in the array.

Returns
A reference to the first element in the array.

Definition at line 322 of file Types.hh.

◆ front() [2/2]

template<typename T>
const T & Kinoko::fixed_vector< T >::front ( ) const
inline

Gets the first element in the array.

Returns
A const reference to the first element in the array.

Definition at line 329 of file Types.hh.

◆ full()

template<typename T>
bool Kinoko::fixed_vector< T >::full ( ) const
inlinenodiscard

Checks if all elements exist in the array.

Returns
True if the array is full, otherwise false.

Definition at line 298 of file Types.hh.

◆ initialized()

template<typename T>
bool Kinoko::fixed_vector< T >::initialized ( ) const
inlinenodiscard

Checks if the array exists and if the capacity is non-zero.

Returns
True if the array is initialized, otherwise false.

Definition at line 304 of file Types.hh.

◆ operator=() [1/2]

template<typename T>
fixed_vector & Kinoko::fixed_vector< T >::operator= ( const fixed_vector< T > & rhs)
inline

Copy assignment operator.

Destroys the existing buffer, then allocates a new one and deep copies

Definition at line 210 of file Types.hh.

◆ operator=() [2/2]

template<typename T>
fixed_vector & Kinoko::fixed_vector< T >::operator= ( fixed_vector< T > && rhs)
inline

Move assignment operator.

Destroys the existing buffer, then transfers ownership from rhs

Definition at line 226 of file Types.hh.

◆ operator[]() [1/2]

template<typename T>
T & Kinoko::fixed_vector< T >::operator[] ( size_t idx)
inline

Indexes the array. Validates that the object exists.

Parameters
idxThe index to the array.
Returns
A reference to the object at the corresponding index.

Definition at line 351 of file Types.hh.

◆ operator[]() [2/2]

template<typename T>
const T & Kinoko::fixed_vector< T >::operator[] ( size_t idx) const
inline

Indexes the array. Validates that the object exists.

Parameters
idxThe index to the array.
Returns
A const reference to the object at the corresponding index.

Definition at line 359 of file Types.hh.

◆ pop_back()

template<typename T>
void Kinoko::fixed_vector< T >::pop_back ( )
inline

Deletes the last existing element from the array.

Definition at line 278 of file Types.hh.

◆ push_back() [1/2]

template<typename T>
T & Kinoko::fixed_vector< T >::push_back ( const T & obj)
inline

Copies a new element into the array.

Parameters
objThe object to copy.
Returns
A reference to the object.

Definition at line 251 of file Types.hh.

◆ push_back() [2/2]

template<typename T>
T & Kinoko::fixed_vector< T >::push_back ( T && obj)
inline

Moves a new element into the array.

Parameters
objThe object to move.
Returns
A reference to the object.

Definition at line 260 of file Types.hh.

◆ reserve()

template<typename T>
void Kinoko::fixed_vector< T >::reserve ( size_t capacity)
inline

Initializes the vector with the provided capacity.

Parameters
capacityThe number of elements to initialize the vector with.

Definition at line 285 of file Types.hh.

◆ size()

template<typename T>
size_t Kinoko::fixed_vector< T >::size ( ) const
inlinenodiscard

Gets the number of existing elements in the array.

Returns
The number of existing elements in the array.

Definition at line 310 of file Types.hh.

Member Data Documentation

◆ m_capacity

template<typename T>
size_t Kinoko::fixed_vector< T >::m_capacity
private

Definition at line 415 of file Types.hh.

◆ m_data

template<typename T>
T* Kinoko::fixed_vector< T >::m_data
private

Definition at line 413 of file Types.hh.

◆ m_size

template<typename T>
size_t Kinoko::fixed_vector< T >::m_size
private

Definition at line 414 of file Types.hh.