BArray is a base class and maintains a contiguous chunk of memory as an dynamic array. It can also work with fixed memory. It allows finding items and inserting them in order using binary search. Unless there is a special need, use ObjArray class instead of using this directly.
#include <arr.h>
Inheritance diagram for jvar::BArray:
Collaboration diagram for jvar::BArray:Public Types | |
| enum | { FLAG_FIXEDBUF = 0x1 } |
| typedef int(* | Compare )(const void *, const void *) |
Public Member Functions | |
| BArray (size_t elemsize, Compare comp) | |
| BArray (const BArray &src) | |
| BArray (BArray &src) | |
| BArray & | operator= (const BArray &src) |
| BArray & | operator= (const BArray *src) |
| 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 (int pos) |
| bool | remove (const void *elem) |
| void * | find (const void *elem) |
| void * | get (int pos) |
| 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 |
| jvar::BArray::BArray | ( | size_t | elemsize, |
| Compare | comp | ||
| ) | [inline] |
Constructor
| elemsize | Size of the array element |
| comp | Compare function |
| jvar::BArray::BArray | ( | const BArray & | src | ) | [inline] |
Constructor
| src | Another array |
| jvar::BArray::BArray | ( | BArray & | src | ) | [inline] |
Constructor
| src | Another array |
| void* jvar::BArray::add | ( | const void * | elem | ) | [inline] |
Adds an element in order using the compare function
| elem | Pointer to the element which will be copied |
References addOrModify().
| void * jvar::BArray::addOrModify | ( | const void * | elem, |
| bool | modifyfound = true |
||
| ) |
| void* jvar::BArray::append | ( | const void * | elem | ) | [inline] |
Appends or adds an element at the end of the array
| elem | Pointer to the element which will be copied |
References insert(), and length().
Referenced by jvar::ObjArray< int >::append().
| void jvar::BArray::clear | ( | ) |
Deletes all elements
References FLAG_FIXEDBUF, jvar::Buffer::free(), and mFlags.
Referenced by jvar::PropArray< Variant >::clear().
| void * jvar::BArray::find | ( | const void * | elem | ) |
Finds an element in array that matches the provided element
| elem | Pointer to an element to search |
| bool jvar::BArray::findPos | ( | const void * | findelem, |
| int & | pos | ||
| ) | [inline] |
Finds the position of an element
| findelem | Pointer to an element to search |
| pos | Returns the position of the found element |
| bool jvar::BArray::full | ( | ) | [inline] |
Determines if the array is at capacity.
Referenced by insert().
| void* jvar::BArray::get | ( | int | pos | ) | [inline] |
Retrieves an element from the array. Note: This function does not do any bounds checking.
| pos | Position to retrieve the element |
Reimplemented in jvar::ObjArray< T >, jvar::ObjArray< DataElem >, jvar::ObjArray< Variant >, jvar::ObjArray< std::string >, and jvar::ObjArray< int >.
| void * jvar::BArray::insert | ( | int | pos, |
| const void * | elem | ||
| ) |
Insert an element into the array
| pos | Position to insert at |
| elem | Pointer to element which will be copied |
References FLAG_FIXEDBUF, full(), length(), and mFlags.
Referenced by addOrModify(), jvar::ObjArray< int >::addOrModify(), append(), and jvar::ObjArray< int >::insert().
| int jvar::BArray::length | ( | ) | [inline] |
Returns the number of elements in the array
Referenced by jvar::PropArray< Variant >::addOrModify(), append(), jvar::ObjArray< int >::forEach(), jvar::PropArray< Variant >::forEach(), jvar::ObjArray< int >::forEachReverse(), jvar::PropArray< Variant >::forEachSort(), jvar::ObjArray< int >::get(), insert(), jvar::PropArray< Variant >::length(), and remove().
| bool jvar::BArray::remove | ( | int | pos | ) |
Removes an element from the array
| pos | Position of the item to remove |
Reimplemented in jvar::ObjArray< T >, jvar::ObjArray< DataElem >, jvar::ObjArray< Variant >, jvar::ObjArray< std::string >, and jvar::ObjArray< int >.
References FLAG_FIXEDBUF, length(), and mFlags.
| bool jvar::BArray::remove | ( | const void * | elem | ) |
Removes an element from array that matches the provided element
| elem | Pointer to an element to search |
| void jvar::BArray::reserve | ( | int | elemcount | ) | [inline] |
Ensures that the array has at least the specified allocation
| elemcount | Number of element to reserve |
| void jvar::BArray::sort | ( | Compare | comp = NULL | ) | [inline] |
Sorts the array
| comp | Compare function (if NULL, the one from constructor is used) |
| void jvar::BArray::useFixedMem | ( | void * | memptr, |
| int * | countptr, | ||
| int | maxlen | ||
| ) |
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 FLAG_FIXEDBUF, jvar::Buffer::free(), and mFlags.
| uint jvar::BArray::mFlags |
Flags for this array
Referenced by clear(), insert(), remove(), and useFixedMem().