DSOL::LiteVector< T > Class Template Reference

a 'lite' version of the std::Vector class. More...

#include <LiteVector.hpp>

List of all members.

Public Member Functions

void clear ()
 clears the LiteVector of its contents.
const T & get (const uint index) const
 returns a const reference of the item at the given index.
T & get (const uint index)
 gets the item at the given index.
const uint getBufferSize () const
 returns the size of the allocated memory.
const uint getSize () const
 returns the number of items in the array.
const bool insert (uint index, const T &item)
 inserts a given item into the LiteVector.
 LiteVector (const LiteVector &source)
 the Copy constructor, copies the data from 1 LiteVector to the other.
 LiteVector (const uint initSize=16, const uint incrementSize=8)
 the constructor that creates the array.
const bool operator!= (const LiteVector &source) const
 a comparison operator that returns the opposite of operator==.
const LiteVectoroperator= (const LiteVector &source)
 the asigment operator, copies the data from 1 LiteVector to the other.
const bool operator== (const LiteVector &source) const
 a comparison operator to compare 2 LiteVectors with each other.
const T & operator[] (const uint index) const
 allows to acces the items like a normal const array.
T & operator[] (const uint index)
 allows to acces the items like a normal array.
pop ()
 removes and returns the last item of the vector.
const bool push (const T &item)
 adds an item at the end of the vector.
remove (uint index)
 removes an item from the array.
const bool reserve (const uint emptySpaceSize)
 makes sure that the buffer has extra space for at least the number specified.
const bool resize (const uint newBufferSize)
 resizes the allocated memory buffer.
template<typename T2 >
const bool set (uint index, const T2 array, const uint length, const uint startPoint=0)
 sets multiple items into the LiteVector.
const bool set (uint index, const T &item)
 sets an given item at the given index.
 ~LiteVector ()
 the destructor that deallocates the memory


Detailed Description

template<typename T>
class DSOL::LiteVector< T >

a 'lite' version of the std::Vector class.

this class allows you to use an resizable dynamic array in an oo way without worrying about memory management. it doesn't contain exeptions and iterators and stuff like that, which makes it more suitable for devices with low memory.

it doesn't work with polymorphism (use pointers or references), because it only allocates enough memory for the base type.

the class uses the types copy constructor and = operator internally, so make sure to implement them correctly.


Constructor & Destructor Documentation

template<typename T >
DSOL::LiteVector< T >::LiteVector ( const uint  initSize = 16,
const uint  incrementSize = 8 
) [inline]

the constructor that creates the array.

Parameters:
initSize the initial size of the allocated memory, default is 16.
incrementSize the size that will be added to the memory buffer if it automaticly resizes, default is 8.

template<typename T >
DSOL::LiteVector< T >::LiteVector ( const LiteVector< T > &  source  )  [inline]

the Copy constructor, copies the data from 1 LiteVector to the other.

the 2 LiteVectors will have sepparate buffers in memory, so try not to copy LiteVectors to much.

Parameters:
source the source to copy from.

template<typename T >
DSOL::LiteVector< T >::~LiteVector (  )  [inline]

the destructor that deallocates the memory


Member Function Documentation

template<typename T >
void DSOL::LiteVector< T >::clear (  )  [inline]

clears the LiteVector of its contents.

template<typename T >
const T& DSOL::LiteVector< T >::get ( const uint  index  )  const [inline]

returns a const reference of the item at the given index.

this will return a const reference of the item stored at index if index < size, and a const reference of the item stored at 0 if index >= size. you can use this function with const LiteVector objects. you shouldn't be able to modefy the returned item.

Parameters:
index the index of the array of the item you want, must be between 0 and size-1.
Returns:
a const reference to the item at position given from index, or a const reference to the first item if index is out of bounds (will give an error in debug mode).

template<typename T >
T& DSOL::LiteVector< T >::get ( const uint  index  )  [inline]

gets the item at the given index.

this will return the item stored at index if index < size, and the item stored at 0 if index >= size. you can't use this to add items, use set() for that. Do NOT set a derived object in the vector this way. The vector only has enough memory for the base object (the one specified when creating the vector).

Parameters:
index the index of the array of the item you want, must be between 0 and size-1.
Returns:
a reference to the item at position given from index, or a reference to the first item if index is out of bounds (will give an error in debug mode).

template<typename T >
const uint DSOL::LiteVector< T >::getBufferSize (  )  const [inline]

returns the size of the allocated memory.

Returns:
the size of the allocated memory.

template<typename T >
const uint DSOL::LiteVector< T >::getSize (  )  const [inline]

returns the number of items in the array.

Returns:
the number of items in the array.

template<typename T >
const bool DSOL::LiteVector< T >::insert ( uint  index,
const T &  item 
) [inline]

inserts a given item into the LiteVector.

Parameters:
index the index at which the item should be inserted. the item at index and everything after it will be moved a spot.
item the item to insert into the LiteVector.
Returns:
true if it succeeded, false if something went wrong with resizing the LiteVector.

template<typename T >
const bool DSOL::LiteVector< T >::operator!= ( const LiteVector< T > &  source  )  const [inline]

a comparison operator that returns the opposite of operator==.

Parameters:
source the second LiteVector to compare with.
Returns:
false if both the size and the items of the 2 LiteVectors are equal, true otherwise.

template<typename T >
const LiteVector& DSOL::LiteVector< T >::operator= ( const LiteVector< T > &  source  )  [inline]

the asigment operator, copies the data from 1 LiteVector to the other.

the 2 LiteVectors will have sepparate buffers in memory, so try not to copy LiteVectors to much.

Parameters:
source the source to copy from.
Returns:
a reference to the object so you can chain multiple asignments together.

template<typename T >
const bool DSOL::LiteVector< T >::operator== ( const LiteVector< T > &  source  )  const [inline]

a comparison operator to compare 2 LiteVectors with each other.

2 LiteVectors will be considered equal to eachother if the size of the LiteVectors are equal, and every item in 1 LiteVector is equal to the items in the other LiteVector.

Parameters:
source the second LiteVector to compare with.
Returns:
true if both the size and the items of the 2 LiteVectors are equal, false otherwise.

template<typename T >
const T& DSOL::LiteVector< T >::operator[] ( const uint  index  )  const [inline]

allows to acces the items like a normal const array.

acts exactly the same as the const version of get(). you shouldn't be able to modefy the returned item.

Parameters:
index the item you want to get.
Returns:
a const reference to the item.

template<typename T >
T& DSOL::LiteVector< T >::operator[] ( const uint  index  )  [inline]

allows to acces the items like a normal array.

acts exactly the same as get(). you can't use this to add items, use set() for that. Do NOT set a derived object in the vector this way. the results are unpredictable. The vector only has enough memory for the base object (the one specified when creating the vector).

Parameters:
index the item you want to get.
Returns:
a reference to the item.

template<typename T >
T DSOL::LiteVector< T >::pop (  )  [inline]

removes and returns the last item of the vector.

Returns:
the last item of the vector.

template<typename T >
const bool DSOL::LiteVector< T >::push ( const T &  item  )  [inline]

adds an item at the end of the vector.

Parameters:
item a reference to the item that will be added to the end of the vector
Returns:
true if it succeeded, false if it tried to resize and failed

template<typename T >
T DSOL::LiteVector< T >::remove ( uint  index  )  [inline]

removes an item from the array.

removes the item at index from the array and returns the removed item. if the item wasn't the last item of the array, then the last item will be placed at that position (thus altering the order).

Parameters:
index the index of the item you want to remove. must be between 0 and size-1.
Returns:
the removed item

template<typename T >
const bool DSOL::LiteVector< T >::reserve ( const uint  emptySpaceSize  )  [inline]

makes sure that the buffer has extra space for at least the number specified.

with this function, you can make sure that the buffer has enough space to add items equal to the number specified without manually resizing the buffer. usefull if you are going to add alot of items soon. this will use incrementsize.

Parameters:
emptySpaceSize the number of empty spaces that should be reserved.
Returns:
true if there is enough space, false if the resizing failed.

template<typename T >
const bool DSOL::LiteVector< T >::resize ( const uint  newBufferSize  )  [inline]

resizes the allocated memory buffer.

with this, you can manualy resize the buffer. incrementsize will have no effect here.

Parameters:
newBufferSize the new size of the allocated memory buffer.
Returns:
true if the resizing worked, false if the resizing failed.

template<typename T >
template<typename T2 >
const bool DSOL::LiteVector< T >::set ( uint  index,
const T2  array,
const uint  length,
const uint  startPoint = 0 
) [inline]

sets multiple items into the LiteVector.

this allows you to set multiple items into the LiteVector object. the allocated memory will automaticly resize when needed. the items can be in any kind of collection that supports the [] operator to get acces to the items (standard arrays, LiteVectors, std::Vector, ect).

Parameters:
index the index of where you want to store the first item, must be 0-size
array the collection of items you want to store
length the number of items you want to store
startPoint the starting index of the collection of items, default is 0.
Returns:
true if it worked, false if something went wrong with resizing.

template<typename T >
const bool DSOL::LiteVector< T >::set ( uint  index,
const T &  item 
) [inline]

sets an given item at the given index.

this will overwrite the item at the index with the given item. if index is bigger than the size of the array, then the item will be added at the end of the array.

Parameters:
index the position of the array where you want to store the item
item a reference to the item you want to store in the array
Returns:
true if it succeeded, false if it tried to resize and failed


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

Generated on Thu Sep 10 19:09:47 2009 for DSOL by  doxygen 1.5.8