BObjectList is a wrapper around BList that adds type safety, optional object ownership, search, and insert operations. More...
Inherits _PointerList_.
Public Member Functions | |
BObjectList (const BObjectList &list) | |
Creates a new BObjectList as a copy of another list. | |
BObjectList (int32 itemsPerBlock=20, bool owning=false) | |
Creates a new BObjectList. | |
virtual | ~BObjectList () |
Deletes the list. | |
Operators | |
BObjectList & | operator= (const BObjectList &list) |
Creates a new BObjectList as a copy of another list by overloading the = operator. | |
Adding and Removing Items | |
bool | AddItem (T *) |
Append the item to the end of the list. | |
bool | AddItem (T *, int32) |
Add item at the specified index. | |
bool | AddList (BObjectList *) |
Append a list of items to this list. | |
bool | AddList (BObjectList *, int32) |
Add a list of items to this list at the specified index. | |
bool | RemoveItem (T *, bool deleteIfOwning=true) |
Remove item from the list. | |
T * | RemoveItemAt (int32) |
Remove the item at index from the list. | |
void | MakeEmpty (bool deleteIfOwning=true) |
Clear all the items from the list. | |
T * | ItemAt (int32) const |
Return a pointer to the item at the given index. | |
bool | ReplaceItem (int32 index, T *) |
Replace an item with another one. | |
Reordering Items | |
T * | SwapWithItem (int32 index, T *newItem) |
Swap the item with the item at index. | |
bool | MoveItem (int32 from, int32 to) |
Move the item at from to the position of to. | |
void | SortItems (CompareFunction) |
Sort the items with the use of a supplied comparison function. | |
void | SortItems (CompareFunctionWithState, void *state) |
Sort the items with the use of a supplied comparison function and addtional state. | |
void | HSortItems (CompareFunction) |
Sort the items with the use of a supplied comparison function. | |
Querying Items | |
T * | FirstItem () const |
Return a pointer to the first item in the list. | |
T * | LastItem () const |
Return a pointer to the last item in the list. | |
int32 | IndexOf (const T *) const |
Return the index of item. | |
bool | HasItem (const T *) const |
Return whether or not item is in the list. | |
bool | IsEmpty () const |
Return whether or not there are items in the list. | |
int32 | CountItems () const |
Returns the number of items in the list. | |
Iterating Over Items | |
T * | EachElement (EachFunction, void *) |
Perform an action on each item in the list. | |
const T * | EachElement (ConstEachFunction, void *) const |
Perform an action on each item in the list. | |
Finding Items | |
const T * | FindIf (const UnaryPredicate< T > &) const |
Find items that match predicate. | |
T * | FindIf (const UnaryPredicate< T > &) |
Find items that match predicate. | |
T * | BinarySearch (const T &, CompareFunction) const |
Search for key in the list of items using the supplied comparison function via a binary search algorithm. | |
T * | BinarySearch (const T &, CompareFunctionWithState, void *state) const |
Search for key in the list of items using the supplied comparison function via a binary search algorithm. | |
BObjectList is a wrapper around BList that adds type safety, optional object ownership, search, and insert operations.
BObjectList< T >::BObjectList | ( | int32 | itemsPerBlock = 20 , |
bool | owning = false |
||
) |
Creates a new BObjectList.
itemsPerBlock | The number of items per block to allocate. |
owning | Whether or not the BObjectList deletes its items when it is emptied or deleted. |
BObjectList< T >::BObjectList | ( | const BObjectList< T > & | list | ) |
Creates a new BObjectList as a copy of another list.
list | The list to copy from. |
References BObjectList< T >::CountItems(), and BObjectList< T >::ItemAt().
|
virtual |
Deletes the list.
If the list owns its items they are deleted too.
bool BObjectList< T >::AddItem | ( | T * | item | ) |
Append the item to the end of the list.
item | The item to append. |
true | The item was appended. |
false | item was not appended, since resizing the BObjectList failed. |
References BList::AddItem().
bool BObjectList< T >::AddItem | ( | T * | item, |
int32 | index | ||
) |
Add item at the specified index.
item | The item to add. |
index | The place in the list to add the item. |
true | The item was added. |
false | Item was not added. Either the index is negative or invalid, or resizing the BObjectList failed. |
References BList::AddItem().
bool BObjectList< T >::AddList | ( | BObjectList< T > * | list | ) |
Append a list of items to this list.
The original list is not altered.
list | The list to be added. |
true | The list was added. |
false | Failed to append the list, resizing failed. |
References BList::AddList().
bool BObjectList< T >::AddList | ( | BObjectList< T > * | list, |
int32 | index | ||
) |
Add a list of items to this list at the specified index.
The original list is not altered.
list | The list to be added. |
index | The position in the current list where the new item(s) are added. |
true | The list was added. |
false | Failed to insert the list resizing failed. |
References BList::AddList().
T * BObjectList< T >::BinarySearch | ( | const T & | key, |
CompareFunction | func | ||
) | const |
Search for key in the list of items using the supplied comparison function via a binary search algorithm.
key | The key to search for. |
func | The comparison function to use. |
T * BObjectList< T >::BinarySearch | ( | const T & | key, |
CompareFunctionWithState | func, | ||
void * | state | ||
) | const |
Search for key in the list of items using the supplied comparison function via a binary search algorithm.
key | The key to search for. |
func | The comparison function to use. |
state | Additional information used to search for the item. |
int32 BObjectList< T >::CountItems |
Returns the number of items in the list.
References BList::CountItems().
Referenced by BObjectList< T >::BObjectList(), and BObjectList< T >::operator=().
const T * BObjectList< T >::EachElement | ( | ConstEachFunction | func, |
void * | params | ||
) | const |
Perform an action on each item in the list.
func | A function that takes a void* argument and returns a boolean. |
params | parameters for func. |
T * BObjectList< T >::EachElement | ( | EachFunction | func, |
void * | params | ||
) |
Perform an action on each item in the list.
func | A function that takes a void* argument and returns a boolean. |
params | parameters for func. |
T * BObjectList< T >::FindIf | ( | const UnaryPredicate< T > & | predicate | ) |
Find items that match predicate.
const T * BObjectList< T >::FindIf | ( | const UnaryPredicate< T > & | predicate | ) | const |
Find items that match predicate.
T * BObjectList< T >::FirstItem |
Return a pointer to the first item in the list.
NULL
if the list is empty.References BList::FirstItem().
bool BObjectList< T >::HasItem | ( | const T * | item | ) | const |
Return whether or not item is in the list.
true
if the item was in the list, false
otherwise.References BList::HasItem().
void BObjectList< T >::HSortItems | ( | CompareFunction | function | ) |
Sort the items with the use of a supplied comparison function.
function | The function used to sort the items. |
int32 BObjectList< T >::IndexOf | ( | const T * | item | ) | const |
Return the index of item.
References BList::IndexOf().
bool BObjectList< T >::IsEmpty |
Return whether or not there are items in the list.
true
if the list was empty, false
otherwise.References BList::IsEmpty().
|
inline |
Return a pointer to the item at the given index.
index | The item to retrieve. |
NULL
if the index is out of bounds.References BList::ItemAt().
Referenced by BObjectList< T >::BObjectList(), and BObjectList< T >::operator=().
T * BObjectList< T >::LastItem |
Return a pointer to the last item in the list.
NULL
if the list is empty.References BList::LastItem().
void BObjectList< T >::MakeEmpty | ( | bool | deleteIfOwning = true | ) |
Clear all the items from the list.
deleteIfOwning | Also deletes items if owned. |
References BList::MakeEmpty().
bool BObjectList< T >::MoveItem | ( | int32 | from, |
int32 | to | ||
) |
Move the item at from to the position of to.
from | The index to move the item from. |
to | The index to move the item to. |
true | The items were moved. |
false | The from or to index was invalid. |
BObjectList< T > & BObjectList< T >::operator= | ( | const BObjectList< T > & | list | ) |
Creates a new BObjectList as a copy of another list by overloading the = operator.
list | The list to copy from. |
References BObjectList< T >::CountItems(), and BObjectList< T >::ItemAt().
bool BObjectList< T >::RemoveItem | ( | T * | item, |
bool | deleteIfOwning = true |
||
) |
Remove item from the list.
item | The item to be removed. |
deleteIfOwning | Also delete the item if owned. |
true | The item was found and removed. |
false | The item was not in this list and thus not removed. |
References BList::RemoveItem().
T * BObjectList< T >::RemoveItemAt | ( | int32 | index | ) |
Remove the item at index from the list.
index | The index of the item to be removed. |
NULL
if the index was invalid.References BList::RemoveItem().
bool BObjectList< T >::ReplaceItem | ( | int32 | index, |
T * | item | ||
) |
Replace an item with another one.
index | The offset in the list where to put the item. |
item | The new item to put in the list. |
true | The item was replaced. |
false | The index was invalid. |
void BObjectList< T >::SortItems | ( | CompareFunction | function | ) |
Sort the items with the use of a supplied comparison function.
function | The function used to sort the items. |
References BList::SortItems().
void BObjectList< T >::SortItems | ( | CompareFunctionWithState | function, |
void * | state | ||
) |
Sort the items with the use of a supplied comparison function and addtional state.
function | The function used to sort the items. |
state | Additional information used to sort the items. |
References BList::SortItems().
T * BObjectList< T >::SwapWithItem | ( | int32 | index, |
T * | item | ||
) |
Swap the item with the item at index.
index | The offset in the list where to put the item. |
item | The new item to put in the list. |
NULL
if the index is out of bounds.