Melon
A C++ library designed for RadishOS.
Loading...
Searching...
No Matches
Melon::Vector::Vector< T > Class Template Reference

A linear dynamic generic container. TODO: if possible, support objects with no default constructor. More...

#include <Vector.hpp>

Public Member Functions

 Vector ()
 Default constructor.
template<Typing::USize N>
 Vector (const T(&objects)[N])
 Constructs the vector from existing objects.
 Vector (const Vector< T > &other)
 Copy constructor.
 Vector (Vector< T > &&other)
 Move constructor.
const T * begin (this const Vector< T > &self)
 Gets a pointer to the base of the data.
const T * end (this const Vector< T > &self)
 Gets a pointer to the end of the data.
void pushBack (this Vector< T > &self, const T &object)
 Add an object to the end of the vector.
template<typename... ARGS>
void emplaceBack (this Vector< T > &self, ARGS &&...args)
 Constructs an object and add it at the end of the vector.
T & popBack (this Vector< T > &self)
 Removes the last object from the vector.
void erase (this Vector< T > &self, Typing::USize index)
 Erases object at a given position in the vector.
void clear (this Vector< T > &self)
 Clears the vector.
const T * data (this const Vector< T > &self)
 Gets a pointer to the internal buffer storage.
Memory::Buffer< T > toBuffer (this const Vector< T > &self)
 Gets a copy of the internal buffer.
Typing::USize length (this const Vector< T > &self)
 Gets the length of the vector.
Typing::USize capacity (this const Vector< T > &self)
 Gets the capacity of the vector.
bool isEmpty (this const Vector< T > &self)
 Checks if the vector is empty.
bool operator== (this const Vector< T > &self, const Vector< T > &other)
 Checks if both buffers are the same.
T & operator[] (this Vector< T > &self, Typing::USize index)
 Gets an object from the vector.
const T & operator[] (this const Vector< T > &self, Typing::USize index)
 Gets an object from the vector.
Vector< T > & operator= (this Vector< T > &self, const Vector< T > &other)
 Copy assignment operator.
Vector< T > & operator= (this Vector< T > &self, Vector< T > &&other)
 Move assignment operator.

Detailed Description

template<typename T>
class Melon::Vector::Vector< T >

A linear dynamic generic container. TODO: if possible, support objects with no default constructor.

Constructor & Destructor Documentation

◆ Vector() [1/4]

template<typename T>
Melon::Vector::Vector< T >::Vector ( )
inline

Default constructor.

Allocates minimal space to store the buffer.

◆ Vector() [2/4]

template<typename T>
template<Typing::USize N>
Melon::Vector::Vector< T >::Vector ( const T(&) objects[N])
inline

Constructs the vector from existing objects.

Parameters
objectsarray of objects

◆ Vector() [3/4]

template<typename T>
Melon::Vector::Vector< T >::Vector ( const Vector< T > & other)
inline

Copy constructor.

Parameters
othervector to copy

◆ Vector() [4/4]

template<typename T>
Melon::Vector::Vector< T >::Vector ( Vector< T > && other)
inline

Move constructor.

Parameters
othervector to move

Member Function Documentation

◆ begin()

template<typename T>
const T * Melon::Vector::Vector< T >::begin ( this const Vector< T > & self)
inline

Gets a pointer to the base of the data.

Returns
constant pointer to base of data

◆ capacity()

template<typename T>
Typing::USize Melon::Vector::Vector< T >::capacity ( this const Vector< T > & self)
inline

Gets the capacity of the vector.

Returns
capacity

◆ data()

template<typename T>
const T * Melon::Vector::Vector< T >::data ( this const Vector< T > & self)
inline

Gets a pointer to the internal buffer storage.

Returns
constant pointer to the internal buffer storage

◆ emplaceBack()

template<typename T>
template<typename... ARGS>
void Melon::Vector::Vector< T >::emplaceBack ( this Vector< T > & self,
ARGS &&... args )
inline

Constructs an object and add it at the end of the vector.

If the number of objects in the vector exceeds the vector's capacity, the buffer is extended to two times the current capacity.

Parameters
argsconstructor arguments

◆ end()

template<typename T>
const T * Melon::Vector::Vector< T >::end ( this const Vector< T > & self)
inline

Gets a pointer to the end of the data.

Returns
constant pointer to end of data

◆ erase()

template<typename T>
void Melon::Vector::Vector< T >::erase ( this Vector< T > & self,
Typing::USize index )
inline

Erases object at a given position in the vector.

Parameters
indexobject position

◆ isEmpty()

template<typename T>
bool Melon::Vector::Vector< T >::isEmpty ( this const Vector< T > & self)
inline

Checks if the vector is empty.

Returns
boolean

◆ length()

template<typename T>
Typing::USize Melon::Vector::Vector< T >::length ( this const Vector< T > & self)
inline

Gets the length of the vector.

Returns
object count

◆ operator=() [1/2]

template<typename T>
Vector< T > & Melon::Vector::Vector< T >::operator= ( this Vector< T > & self,
const Vector< T > & other )
inline

Copy assignment operator.

Parameters
othervector to copy
Returns
self

◆ operator=() [2/2]

template<typename T>
Vector< T > & Melon::Vector::Vector< T >::operator= ( this Vector< T > & self,
Vector< T > && other )
inline

Move assignment operator.

Parameters
othervector to copy
Returns
self

◆ operator==()

template<typename T>
bool Melon::Vector::Vector< T >::operator== ( this const Vector< T > & self,
const Vector< T > & other )
inline

Checks if both buffers are the same.

This checks for the buffer only, not for the object count and capacity.

Returns
boolean

◆ operator[]() [1/2]

template<typename T>
const T & Melon::Vector::Vector< T >::operator[] ( this const Vector< T > & self,
Typing::USize index )
inline

Gets an object from the vector.

Parameters
indexobject position

◆ operator[]() [2/2]

template<typename T>
T & Melon::Vector::Vector< T >::operator[] ( this Vector< T > & self,
Typing::USize index )
inline

Gets an object from the vector.

Parameters
indexobject position

◆ popBack()

template<typename T>
T & Melon::Vector::Vector< T >::popBack ( this Vector< T > & self)
inline

Removes the last object from the vector.

Actually, the object is not removed. The object count is basically decremented, making the last object unaccessible.

Returns
last object

◆ pushBack()

template<typename T>
void Melon::Vector::Vector< T >::pushBack ( this Vector< T > & self,
const T & object )
inline

Add an object to the end of the vector.

If the number of objects in the vector exceeds the vector's capacity, the buffer is extended to two times the current capacity.

Parameters
objectobject to add

◆ toBuffer()

template<typename T>
Memory::Buffer< T > Melon::Vector::Vector< T >::toBuffer ( this const Vector< T > & self)
inline

Gets a copy of the internal buffer.

Returns
copy of the internal buffer

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