VECTOR< TYPE > Class Template Reference

#include <vector.hpp>

Public Member Functions

 VECTOR ()
 Default Constructor. More...
 
 VECTOR (int initialCapacity)
 Constructor with initial capacity as Vector size. More...
 
 VECTOR (const VECTOR &copy)
 Copy Constructor. More...
 
VECTORoperator= (const VECTOR &copy)
 =Operator to copy the vector. More...
 
 ~VECTOR ()
 Destructor of the vector. More...
 
const TYPE & front ()
 
const TYPE & back ()
 
const TYPE & pop_front ()
 Pops & returns the first(oldest) element of the vector (index 0). (SLOW) More...
 
const TYPE & pop_back ()
 Pops & returns the last element from the vector. (FAST) More...
 
void push_back (const TYPE &element)
 Pushes the element to the end of the vector. (FAST) More...
 
void push_front (const TYPE &element)
 Pushes the element at the 1st location (index 0). (SLOW) More...
 
void reverse ()
 Reverses the order of the vector contents. More...
 
const TYPE & rotateRight ()
 Rotates the vector right by 1 and. More...
 
const TYPE & rotateLeft ()
 Rotates the vector left by 1 and. More...
 
const TYPE & eraseAt (unsigned int pos)
 Erases the element at pos and returns it. All elements are shifted left from this pos. More...
 
int getFirstIndexOf (const TYPE &find)
 
bool remove (const TYPE &element)
 Removes the first Vector Element match from this vector,. More...
 
int removeAll (const TYPE &element)
 Removes all Vector Elements that match the given element,. More...
 
bool replace (const TYPE &find, const TYPE &replace)
 Replaces the first element "find" and replaces it with "replace". More...
 
int replaceAll (const TYPE &find, const TYPE &replace)
 Replaces all instances of "find" and replaces it with "replace". More...
 
void fill (const TYPE &fillElement)
 Fills the entire vector capacity with the given fillElement. More...
 
void fillUnused (const TYPE &fillElement)
 Fills the unused capacity of the vector with the given fillElement. More...
 
unsigned int size () const
 
unsigned int capacity () const
 
void reserve (unsigned int size)
 Reserves the memory for the vector up front. More...
 
void setGrowthFactor (int factor)
 Changes the size the vector grows by. More...
 
void clear ()
 Clears the entire vector. More...
 
bool isEmpty ()
 
TYPE & at (const unsigned int i)
 Access element at given index. More...
 
TYPE & operator[] (const unsigned int i)
 [] Operator for Left-hand-side. More...
 
const TYPE & operator[] (const unsigned int i) const
 [] Operator of Right-hand-side. More...
 
void operator+= (const TYPE &item)
 += Operator which is same as push_back() of an item More...
 

Detailed Description

template<typename TYPE>
class VECTOR< TYPE >

Vector class

This vector class can by used as a dynamic array. This can provide fast-index based retrieval of stored elements and also provides fast methods to erase or rotate the elements. The underlining storage uses pointer-based storage and entire objects are not created or deleted when the vector contents change.

Usage:

VECTOR<int> intVec;
intVec += 1;
intVec += 2;
intVec += 3;
intVec.remove(2); // Vector now: 1 3
intVec.rotateLeft(); // 1 3 --> 3 1
printf("%i %i", intVec[0], intVec[1]); // Prints: 3 1

Constructor & Destructor Documentation

template<typename TYPE >
VECTOR< TYPE >::VECTOR ( )

Default Constructor.

template<typename TYPE >
VECTOR< TYPE >::VECTOR ( int  initialCapacity)

Constructor with initial capacity as Vector size.

template<typename TYPE >
VECTOR< TYPE >::VECTOR ( const VECTOR< TYPE > &  copy)

Copy Constructor.

template<typename TYPE >
VECTOR< TYPE >::~VECTOR ( )

Destructor of the vector.

Member Function Documentation

template<typename TYPE >
TYPE & VECTOR< TYPE >::at ( const unsigned int  i)

Access element at given index.

template<typename TYPE >
const TYPE & VECTOR< TYPE >::back ( )
Returns
the last added element of the vector.
template<typename TYPE >
unsigned int VECTOR< TYPE >::capacity ( void  ) const
Returns
The capacity of the vector (allocated memory)
template<typename TYPE >
void VECTOR< TYPE >::clear ( void  )

Clears the entire vector.

template<typename TYPE >
const TYPE & VECTOR< TYPE >::eraseAt ( unsigned int  pos)

Erases the element at pos and returns it. All elements are shifted left from this pos.

template<typename TYPE>
void VECTOR< TYPE >::fill ( const TYPE &  fillElement)

Fills the entire vector capacity with the given fillElement.

template<typename TYPE>
void VECTOR< TYPE >::fillUnused ( const TYPE &  fillElement)

Fills the unused capacity of the vector with the given fillElement.

template<typename TYPE >
const TYPE & VECTOR< TYPE >::front ( )
Returns
the first(oldest) element of the vector (index 0).
template<typename TYPE>
int VECTOR< TYPE >::getFirstIndexOf ( const TYPE &  find)
Returns
the first index at which the element find is located at
template<typename TYPE >
bool VECTOR< TYPE >::isEmpty ( )
Returns
True if the vector is empty
template<typename TYPE>
void VECTOR< TYPE >::operator+= ( const TYPE &  item)
inline

+= Operator which is same as push_back() of an item

template<typename TYPE >
VECTOR< TYPE > & VECTOR< TYPE >::operator= ( const VECTOR< TYPE > &  copy)

=Operator to copy the vector.

template<typename TYPE >
TYPE & VECTOR< TYPE >::operator[] ( const unsigned int  i)

[] Operator for Left-hand-side.

template<typename TYPE >
const TYPE & VECTOR< TYPE >::operator[] ( const unsigned int  i) const

[] Operator of Right-hand-side.

template<typename TYPE >
const TYPE & VECTOR< TYPE >::pop_back ( )

Pops & returns the last element from the vector. (FAST)

template<typename TYPE >
const TYPE & VECTOR< TYPE >::pop_front ( void  )

Pops & returns the first(oldest) element of the vector (index 0). (SLOW)

template<typename TYPE>
void VECTOR< TYPE >::push_back ( const TYPE &  element)

Pushes the element to the end of the vector. (FAST)

template<typename TYPE>
void VECTOR< TYPE >::push_front ( const TYPE &  element)

Pushes the element at the 1st location (index 0). (SLOW)

template<typename TYPE>
bool VECTOR< TYPE >::remove ( const TYPE &  element)

Removes the first Vector Element match from this vector,.

Returns
true if successful
template<typename TYPE>
int VECTOR< TYPE >::removeAll ( const TYPE &  element)

Removes all Vector Elements that match the given element,.

Returns
number of elements removed
template<typename TYPE>
bool VECTOR< TYPE >::replace ( const TYPE &  find,
const TYPE &  replace 
)

Replaces the first element "find" and replaces it with "replace".

template<typename TYPE>
int VECTOR< TYPE >::replaceAll ( const TYPE &  find,
const TYPE &  replace 
)

Replaces all instances of "find" and replaces it with "replace".

template<typename TYPE >
void VECTOR< TYPE >::reserve ( unsigned int  size)

Reserves the memory for the vector up front.

template<typename TYPE >
void VECTOR< TYPE >::reverse ( )

Reverses the order of the vector contents.

template<typename TYPE >
const TYPE & VECTOR< TYPE >::rotateLeft ( )

Rotates the vector left by 1 and.

Returns
front() value
template<typename TYPE >
const TYPE & VECTOR< TYPE >::rotateRight ( )

Rotates the vector right by 1 and.

Returns
front() value
template<typename TYPE >
void VECTOR< TYPE >::setGrowthFactor ( int  factor)

Changes the size the vector grows by.

template<typename TYPE >
unsigned int VECTOR< TYPE >::size ( void  ) const
Returns
The size of the vector (actual usage)

The documentation for this class was generated from the following file:
  • /var/www/html/SJSU-DEV-Linux/firmware/default/lib/L3_Utils/vector.hpp