#include <LiteVector.hpp>
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 LiteVector & | operator= (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. | |
T | 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. | |
T | 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 |
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.
DSOL::LiteVector< T >::LiteVector | ( | const uint | initSize = 16 , |
|
const uint | incrementSize = 8 | |||
) | [inline] |
the constructor that creates the array.
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. |
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.
source | the source to copy from. |
DSOL::LiteVector< T >::~LiteVector | ( | ) | [inline] |
the destructor that deallocates the memory
void DSOL::LiteVector< T >::clear | ( | ) | [inline] |
clears the LiteVector of its contents.
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.
index | the index of the array of the item you want, must be between 0 and size-1. |
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).
index | the index of the array of the item you want, must be between 0 and size-1. |
const uint DSOL::LiteVector< T >::getBufferSize | ( | ) | const [inline] |
returns the size of the allocated memory.
const uint DSOL::LiteVector< T >::getSize | ( | ) | const [inline] |
returns the number of items in the array.
const bool DSOL::LiteVector< T >::insert | ( | uint | index, | |
const T & | item | |||
) | [inline] |
inserts a given item into the LiteVector.
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. |
const bool DSOL::LiteVector< T >::operator!= | ( | const LiteVector< T > & | source | ) | const [inline] |
a comparison operator that returns the opposite of operator==.
source | the second LiteVector to compare with. |
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.
source | the source to copy from. |
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.
source | the second LiteVector to compare with. |
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.
index | the item you want to get. |
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).
index | the item you want to get. |
T DSOL::LiteVector< T >::pop | ( | ) | [inline] |
removes and returns the last item of the vector.
const bool DSOL::LiteVector< T >::push | ( | const T & | item | ) | [inline] |
adds an item at the end of the vector.
item | a reference to the item that will be added to the end of the vector |
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).
index | the index of the item you want to remove. must be between 0 and size-1. |
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.
emptySpaceSize | the number of empty spaces that should be reserved. |
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.
newBufferSize | the new size of the allocated memory buffer. |
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).
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. |
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.
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 |