Loading...
Searching...
No Matches
Public Member Functions | List of all members
BObjectList< T > Class Template Reference

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
BObjectListoperator= (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.
 

Detailed Description

template<class T>
class BObjectList< T >

BObjectList is a wrapper around BList that adds type safety, optional object ownership, search, and insert operations.

Since
Haiku R1

Constructor & Destructor Documentation

◆ BObjectList() [1/2]

template<class T >
BObjectList< T >::BObjectList ( int32  itemsPerBlock = 20,
bool  owning = false 
)

Creates a new BObjectList.

Parameters
itemsPerBlockThe number of items per block to allocate.
owningWhether or not the BObjectList deletes its items when it is emptied or deleted.
Since
Haiku R1

◆ BObjectList() [2/2]

template<class T >
BObjectList< T >::BObjectList ( const BObjectList< T > &  list)

Creates a new BObjectList as a copy of another list.

Parameters
listThe list to copy from.
Since
Haiku R1

References BObjectList< T >::CountItems(), and BObjectList< T >::ItemAt().

◆ ~BObjectList()

template<class T >
BObjectList< T >::~BObjectList
virtual

Deletes the list.

If the list owns its items they are deleted too.

Since
Haiku R1

Member Function Documentation

◆ AddItem() [1/2]

template<class T >
bool BObjectList< T >::AddItem ( T *  item)

Append the item to the end of the list.

Parameters
itemThe item to append.
Returns
Whether or not the item was appended.
Return values
trueThe item was appended.
falseitem was not appended, since resizing the BObjectList failed.
Since
Haiku R1

References BList::AddItem().

◆ AddItem() [2/2]

template<class T >
bool BObjectList< T >::AddItem ( T *  item,
int32  index 
)

Add item at the specified index.

Parameters
itemThe item to add.
indexThe place in the list to add the item.
Returns
Whether or not the item was added.
Return values
trueThe item was added.
falseItem was not added. Either the index is negative or invalid, or resizing the BObjectList failed.
Since
Haiku R1

References BList::AddItem().

◆ AddList() [1/2]

template<class T >
bool BObjectList< T >::AddList ( BObjectList< T > *  list)

Append a list of items to this list.

The original list is not altered.

Parameters
listThe list to be added.
Returns
Whether or not the list was added.
Return values
trueThe list was added.
falseFailed to append the list, resizing failed.
Since
Haiku R1

References BList::AddList().

◆ AddList() [2/2]

template<class T >
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.

Parameters
listThe list to be added.
indexThe position in the current list where the new item(s) are added.
Returns
Whether or not the list was added.
Return values
trueThe list was added.
falseFailed to insert the list resizing failed.
Since
Haiku R1

References BList::AddList().

◆ BinarySearch() [1/2]

template<class T >
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.

Parameters
keyThe key to search for.
funcThe comparison function to use.
Returns
A pointer to T.
Since
Haiku R1

◆ BinarySearch() [2/2]

template<class T >
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.

Parameters
keyThe key to search for.
funcThe comparison function to use.
stateAdditional information used to search for the item.
Returns
A pointer to T.
Since
Haiku R1

◆ CountItems()

template<class T >
int32 BObjectList< T >::CountItems

Returns the number of items in the list.

Returns
The number of items in the list as an int32.
Since
Haiku R1

References BList::CountItems().

Referenced by BObjectList< T >::BObjectList(), and BObjectList< T >::operator=().

◆ EachElement() [1/2]

template<class T >
const T * BObjectList< T >::EachElement ( ConstEachFunction  func,
void *  params 
) const

Perform an action on each item in the list.

Parameters
funcA function that takes a void* argument and returns a boolean.
paramsparameters for func.
Returns
A pointer to the item.
Since
Haiku R1

◆ EachElement() [2/2]

template<class T >
T * BObjectList< T >::EachElement ( EachFunction  func,
void *  params 
)

Perform an action on each item in the list.

Parameters
funcA function that takes a void* argument and returns a boolean.
paramsparameters for func.
Returns
A pointer to the item.
Since
Haiku R1

◆ FindIf() [1/2]

template<class T >
T * BObjectList< T >::FindIf ( const UnaryPredicate< T > &  predicate)

Find items that match predicate.

Returns
A pointer to T.
Since
Haiku R1

◆ FindIf() [2/2]

template<class T >
const T * BObjectList< T >::FindIf ( const UnaryPredicate< T > &  predicate) const

Find items that match predicate.

Returns
A const pointer to T.
Since
Haiku R1

◆ FirstItem()

template<class T >
T * BObjectList< T >::FirstItem

Return a pointer to the first item in the list.

Returns
A pointer to the first item or NULL if the list is empty.
See also
BObjectList<T>::LastItem() const
Since
Haiku R1

References BList::FirstItem().

◆ HasItem()

template<class T >
bool BObjectList< T >::HasItem ( const T *  item) const

Return whether or not item is in the list.

Returns
true if the item was in the list, false otherwise.
Since
Haiku R1

References BList::HasItem().

◆ HSortItems()

template<class T >
void BObjectList< T >::HSortItems ( CompareFunction  function)

Sort the items with the use of a supplied comparison function.

Parameters
functionThe function used to sort the items.
Since
Haiku R1

◆ IndexOf()

template<class T >
int32 BObjectList< T >::IndexOf ( const T *  item) const

Return the index of item.

Returns
The index of the item, or -1 when the item is not in the list.
Since
Haiku R1

References BList::IndexOf().

◆ IsEmpty()

template<class T >
bool BObjectList< T >::IsEmpty

Return whether or not there are items in the list.

Returns
true if the list was empty, false otherwise.
Since
Haiku R1

References BList::IsEmpty().

◆ ItemAt()

template<class T >
T * BObjectList< T >::ItemAt ( int32  index) const
inline

Return a pointer to the item at the given index.

Parameters
indexThe item to retrieve.
Returns
A pointer to the item in that position, or NULL if the index is out of bounds.
Since
Haiku R1

References BList::ItemAt().

Referenced by BObjectList< T >::BObjectList(), and BObjectList< T >::operator=().

◆ LastItem()

template<class T >
T * BObjectList< T >::LastItem

Return a pointer to the last item in the list.

Returns
A pointer to the last item or NULL if the list is empty.
See also
BObjectList<T>::FirstItem() const
Since
Haiku R1

References BList::LastItem().

◆ MakeEmpty()

template<class T >
void BObjectList< T >::MakeEmpty ( bool  deleteIfOwning = true)

Clear all the items from the list.

Parameters
deleteIfOwningAlso deletes items if owned.
Since
Haiku R1

References BList::MakeEmpty().

◆ MoveItem()

template<class T >
bool BObjectList< T >::MoveItem ( int32  from,
int32  to 
)

Move the item at from to the position of to.

Parameters
fromThe index to move the item from.
toThe index to move the item to.
Returns
Whether or not the items were moved.
Return values
trueThe items were moved.
falseThe from or to index was invalid.
See also
BList::MoveItem()
Since
Haiku R1

◆ operator=()

template<class T >
BObjectList< T > & BObjectList< T >::operator= ( const BObjectList< T > &  list)

Creates a new BObjectList as a copy of another list by overloading the = operator.

Parameters
listThe list to copy from.
Since
Haiku R1

References BObjectList< T >::CountItems(), and BObjectList< T >::ItemAt().

◆ RemoveItem()

template<class T >
bool BObjectList< T >::RemoveItem ( T *  item,
bool  deleteIfOwning = true 
)

Remove item from the list.

Parameters
itemThe item to be removed.
deleteIfOwningAlso delete the item if owned.
Returns
Whether or not the item was removed.
Return values
trueThe item was found and removed.
falseThe item was not in this list and thus not removed.
Since
Haiku R1

References BList::RemoveItem().

◆ RemoveItemAt()

template<class T >
T * BObjectList< T >::RemoveItemAt ( int32  index)

Remove the item at index from the list.

Parameters
indexThe index of the item to be removed.
Returns
The pointer to the item that was removed, or NULL if the index was invalid.
Since
Haiku R1

References BList::RemoveItem().

◆ ReplaceItem()

template<class T >
bool BObjectList< T >::ReplaceItem ( int32  index,
T *  item 
)

Replace an item with another one.

Parameters
indexThe offset in the list where to put the item.
itemThe new item to put in the list.
Returns
Whether or not the item was replaced.
Return values
trueThe item was replaced.
falseThe index was invalid.
Since
Haiku R1

◆ SortItems() [1/2]

template<class T >
void BObjectList< T >::SortItems ( CompareFunction  function)

Sort the items with the use of a supplied comparison function.

Parameters
functionThe function used to sort the items.
Since
Haiku R1

References BList::SortItems().

◆ SortItems() [2/2]

template<class T >
void BObjectList< T >::SortItems ( CompareFunctionWithState  function,
void *  state 
)

Sort the items with the use of a supplied comparison function and addtional state.

Parameters
functionThe function used to sort the items.
stateAdditional information used to sort the items.
Since
Haiku R1

References BList::SortItems().

◆ SwapWithItem()

template<class T >
T * BObjectList< T >::SwapWithItem ( int32  index,
T *  item 
)

Swap the item with the item at index.

Parameters
indexThe offset in the list where to put the item.
itemThe new item to put in the list.
Returns
A pointer to the item in that position, or NULL if the index is out of bounds.
Since
Haiku R1