ObjArray is similar to stl::vector. It maintains a contiguous chunk of memory as an dynamic array of objects. It takes care of calling constructors and desctructors. It allows finding elements and inserting them in order using binary search. It allows creating objects directly on the array as well.
#include <arr.h>
Inheritance diagram for jvar::ObjArray< T >:
Collaboration diagram for jvar::ObjArray< T >:Public Types | |
| enum | { FLAG_FIXEDBUF = 0x1 } |
| typedef int(* | Compare )(const void *, const void *) |
Public Member Functions | |
| ObjArray (Compare comp) | |
| ObjArray (const ObjArray &src) | |
| ObjArray (ObjArray &src) | |
| ObjArray & | operator= (const ObjArray &src) |
| ObjArray & | operator= (const ObjArray *src) |
| T * | insert (int pos) |
| T * | insertCustom (int pos) |
| T * | append () |
| T * | addOrModify (const T *keyelem, bool modifyfound=true) |
| T * | add (const T *keyelem) |
| bool | remove (const T *keyelem) |
| bool | remove (int pos) |
| T * | find (const T *elem) |
| T * | get (int pos) |
| bool | forEach (Iter< T > &iter) |
| bool | forEachReverse (Iter< T > &iter) |
| void | useFixedMem (void *memptr, int *countptr, int maxlen) |
| void | clear () |
| void * | insert (int pos, const void *elem) |
| void * | append (const void *elem) |
| void * | add (const void *elem) |
| void * | addOrModify (const void *elem, bool modifyfound=true) |
| bool | remove (const void *elem) |
| void * | find (const void *elem) |
| int | length () |
| bool | full () |
| void | sort (Compare comp=NULL) |
| bool | findPos (const void *findelem, int &pos) |
| void | reserve (int elemcount) |
Public Attributes | |
| uint | mFlags |
Protected Member Functions | |
| void | copyFrom (BArray &src, bool alloconly, bool move) |
| bool | binSearch (const void *findelem, int &pos) |
| void | ensureAlloc (int desiredlen) |
anonymous enum [inherited] |
| void* jvar::BArray::add | ( | const void * | elem | ) | [inline, inherited] |
Adds an element in order using the compare function
| elem | Pointer to the element which will be copied |
References jvar::BArray::addOrModify().
| T* jvar::ObjArray< T >::add | ( | const T * | keyelem | ) | [inline] |
Adds an item based to the array keeping it sorted
| keyelem | Element to add |
| void * jvar::BArray::addOrModify | ( | const void * | elem, |
| bool | modifyfound = true |
||
| ) | [inherited] |
Adds an element or modifies it if it already exists
| elem | Pointer to element which will be copied |
| modifyfound | Should it be modified (true=allow, false=don't allow) |
References jvar::BArray::insert().
Referenced by jvar::BArray::add().
| T* jvar::ObjArray< T >::addOrModify | ( | const T * | keyelem, |
| bool | modifyfound = true |
||
| ) | [inline] |
Adds a new element or modifies it if exists.
| keyelem | Element to search and add if doesn't exist or modify |
| modifyfound | Allow modifying the lement |
Referenced by jvar::ObjArray< int >::add().
| void* jvar::BArray::append | ( | const void * | elem | ) | [inline, inherited] |
Appends or adds an element at the end of the array
| elem | Pointer to the element which will be copied |
References jvar::BArray::insert(), and jvar::BArray::length().
Referenced by jvar::ObjArray< int >::append().
| T* jvar::ObjArray< T >::append | ( | ) | [inline] |
Appends a new element at the end of the array
| void jvar::BArray::clear | ( | ) | [inherited] |
Deletes all elements
References jvar::BArray::FLAG_FIXEDBUF, jvar::Buffer::free(), and jvar::BArray::mFlags.
Referenced by jvar::PropArray< Variant >::clear().
| void * jvar::BArray::find | ( | const void * | elem | ) | [inherited] |
Finds an element in array that matches the provided element
| elem | Pointer to an element to search |
| T* jvar::ObjArray< T >::find | ( | const T * | elem | ) | [inline] |
Finds the item
| elem | Element to find (only the key is used) |
Referenced by jvar::ObjArray< int >::find().
| bool jvar::BArray::findPos | ( | const void * | findelem, |
| int & | pos | ||
| ) | [inline, inherited] |
Finds the position of an element
| findelem | Pointer to an element to search |
| pos | Returns the position of the found element |
| bool jvar::ObjArray< T >::forEach | ( | Iter< T > & | iter | ) | [inline] |
Returns an iterator to go over elements of the array in order
| iter | Iterator |
| bool jvar::ObjArray< T >::forEachReverse | ( | Iter< T > & | iter | ) | [inline] |
Returns an iterator go over elements in reverse order
| iter | Iterator |
| bool jvar::BArray::full | ( | ) | [inline, inherited] |
Determines if the array is at capacity.
Referenced by jvar::BArray::insert().
| T* jvar::ObjArray< T >::get | ( | int | pos | ) | [inline] |
Returns an element from the array
| pos | Position of retrieve the element |
Reimplemented from jvar::BArray.
Referenced by jvar::PropArray< Variant >::forEach(), jvar::ObjArray< int >::get(), jvar::PropArray< Variant >::get(), jvar::PropArray< Variant >::getKey(), and jvar::PropArray< Variant >::remove().
| void * jvar::BArray::insert | ( | int | pos, |
| const void * | elem | ||
| ) | [inherited] |
Insert an element into the array
| pos | Position to insert at |
| elem | Pointer to element which will be copied |
References jvar::BArray::FLAG_FIXEDBUF, jvar::BArray::full(), jvar::BArray::length(), and jvar::BArray::mFlags.
Referenced by jvar::BArray::addOrModify(), jvar::ObjArray< int >::addOrModify(), jvar::BArray::append(), and jvar::ObjArray< int >::insert().
| T* jvar::ObjArray< T >::insert | ( | int | pos | ) | [inline] |
Inserts a new element at the provided position in the array
| pos | Position to insert |
Referenced by jvar::PropArray< Variant >::addOrModify(), and jvar::ObjArray< int >::insertCustom().
| T* jvar::ObjArray< T >::insertCustom | ( | int | pos | ) | [inline] |
Inserts an element at the provided position in the array. The new element is not constructed by ths call. The caller uses "inplace new" to call a non-default constructor.
| pos | Position to insert |
| int jvar::BArray::length | ( | ) | [inline, inherited] |
Returns the number of elements in the array
Referenced by jvar::PropArray< Variant >::addOrModify(), jvar::BArray::append(), jvar::ObjArray< int >::forEach(), jvar::PropArray< Variant >::forEach(), jvar::ObjArray< int >::forEachReverse(), jvar::PropArray< Variant >::forEachSort(), jvar::ObjArray< int >::get(), jvar::BArray::insert(), jvar::PropArray< Variant >::length(), and jvar::BArray::remove().
| bool jvar::BArray::remove | ( | const void * | elem | ) | [inherited] |
Removes an element from array that matches the provided element
| elem | Pointer to an element to search |
| bool jvar::ObjArray< T >::remove | ( | const T * | keyelem | ) | [inline] |
Removes an item using a key
| keyelem | Element to remove (only key is used) |
Referenced by jvar::ObjArray< int >::remove(), and jvar::PropArray< Variant >::remove().
| bool jvar::ObjArray< T >::remove | ( | int | pos | ) | [inline] |
Removes an element from the provided position
| pos | Position to remove the item |
Reimplemented from jvar::BArray.
| void jvar::BArray::reserve | ( | int | elemcount | ) | [inline, inherited] |
Ensures that the array has at least the specified allocation
| elemcount | Number of element to reserve |
| void jvar::BArray::sort | ( | Compare | comp = NULL | ) | [inline, inherited] |
Sorts the array
| comp | Compare function (if NULL, the one from constructor is used) |
| void jvar::BArray::useFixedMem | ( | void * | memptr, |
| int * | countptr, | ||
| int | maxlen | ||
| ) | [inherited] |
Enters fixed memory mode using the provided memory
| memptr | Pointer to allocated fixed memory |
| countptr | Pointer to a variable where current count is held |
| maxlen | Maximum number of elements (size specified in constructor) |
References jvar::BArray::FLAG_FIXEDBUF, jvar::Buffer::free(), and jvar::BArray::mFlags.
uint jvar::BArray::mFlags [inherited] |
Flags for this array
Referenced by jvar::BArray::clear(), jvar::BArray::insert(), jvar::BArray::remove(), and jvar::BArray::useFixedMem().