Hopsan
HVector< T > Class Template Reference

Public Member Functions

 HVector (const HVector< T > &rOther)
 copy constructor
 
 HVector (const std::vector< T > &rOther)
 
void clear ()
 Clear the array.
 
void reserve (size_t s)
 Reserve capacity for the array.
 
void resize (size_t s)
 Resize the array, keeping old data if any.
 
void resize (size_t s, const T &defaultValue)
 Resize the array, initializing all values to defaultValue.
 
void append (const T &data)
 Append data.
 
void assign_from (const T *pData, size_t count)
 Assign from C-array param [in] pData A pointer to the array param [in] count The number of elements to copy from the array.
 
const T & operator[] (size_t i) const
 
T & operator[] (size_t i)
 
const T & last () const
 
T & last ()
 
const T & first () const
 
T & first ()
 
size_t size () const
 Returns the number of elements in the array.
 
size_t capacity () const
 Returns the reserved number of element slots in the array.
 
bool empty () const
 Check if the array is empty.
 
bool contains (const T &data) const
 
HVector< T > & operator= (const HVector< T > &rhs)
 
T * data ()
 

Member Function Documentation

◆ append()

template<typename T >
void append ( const T & data)
inline

Append data.

Note
This function is slow, it will reallocate all array memory every time
Parameters
[in]dataData to append

◆ capacity()

template<typename T >
size_t capacity ( ) const
inline

Returns the reserved number of element slots in the array.

Returns
Number of reserved elements in the array

◆ empty()

template<typename T >
bool empty ( ) const
inline

Check if the array is empty.

Returns
true if the array is empty

◆ reserve()

template<typename T >
void reserve ( size_t s)
inline

Reserve capacity for the array.

If new size is smaller than old nothing is changed If new size is larger than old, the additional elements will be uninitialized

Parameters
[in]sNew size

◆ resize() [1/2]

template<typename T >
void resize ( size_t s)
inline

Resize the array, keeping old data if any.

If new size is smaller than old, old data will intact up to the new size If new size is larger than old, the additional elements will be uninitialized

Parameters
[in]sNew size

◆ resize() [2/2]

template<typename T >
void resize ( size_t s,
const T & defaultValue )
inline

Resize the array, initializing all values to defaultValue.

Parameters
[in]sNew size
[in]defaultValueinitialize value for all elements

◆ size()

template<typename T >
size_t size ( ) const
inline

Returns the number of elements in the array.

Returns
Number of elements in the array