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 (int32 itemsPerBlock=20, bool owning=false)
 Creates a new BObjectList. More...
 
 BObjectList (const BObjectList &list)
 Creates a new BObjectList as a copy of another list. More...
 
virtual ~BObjectList ()
 Deletes the list. More...
 
Operators
BObjectListoperator= (const BObjectList &list)
 Creates a new BObjectList as a copy of another list by overloading the = operator. More...
 
Adding and Removing Items
bool AddItem (T *)
 Append the item to the end of the list. More...
 
bool AddItem (T *, int32)
 Add item at the specified index. More...
 
bool AddList (BObjectList *)
 Append a list of items to this list. More...
 
bool AddList (BObjectList *, int32)
 Add a list of items to this list at the specified index. More...
 
bool RemoveItem (T *, bool deleteIfOwning=true)
 Remove item from the list. More...
 
T * RemoveItemAt (int32)
 Remove the item at index from the list. More...
 
void MakeEmpty (bool deleteIfOwning=true)
 Clear all the items from the list. More...
 
T * ItemAt (int32) const
 Return a pointer to the item at the given index. More...
 
bool ReplaceItem (int32 index, T *)
 Replace an item with another one. More...
 
Reordering Items
T * SwapWithItem (int32 index, T *newItem)
 Swap the item with the item at index. More...
 
bool MoveItem (int32 from, int32 to)
 Move the item at from to the position of to. More...
 
void SortItems (CompareFunction)
 Sort the items with the use of a supplied comparison function. More...
 
void SortItems (CompareFunctionWithState, void *state)
 Sort the items with the use of a supplied comparison function and addtional state. More...
 
void HSortItems (CompareFunction)
 Sort the items with the use of a supplied comparison function. More...
 
Querying Items
T * FirstItem () const
 Return a pointer to the first item in the list. More...
 
T * LastItem () const
 Return a pointer to the last item in the list. More...
 
int32 IndexOf (const T *) const
 Return the index of item. More...
 
bool HasItem (const T *) const
 Return whether or not item is in the list. More...
 
bool IsEmpty () const
 Return whether or not there are items in the list. More...
 
int32 CountItems () const
 Returns the number of items in the list. More...
 
Iterating Over Items
T * EachElement (EachFunction, void *)
 Perform an action on each item in the list. More...
 
const T * EachElement (ConstEachFunction, void *) const
 Perform an action on each item in the list. More...
 
Finding Items
const T * FindIf (const UnaryPredicate< T > &) const
 Find items that match predicate. More...
 
T * FindIf (const UnaryPredicate< T > &)
 Find items that match predicate. More...
 
T * BinarySearch (const T &, CompareFunction) const
 Search for key in the list of items using the supplied comparison function via a binary search algorithm. More...
 
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. More...
 

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

◆ ~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

Referenced by BObjectList< BBitmap >::BinarySearch().

◆ 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

◆ 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

◆ 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

◆ 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 ( ) const

Returns the number of items in the list.

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

Referenced by BObjectList< BBitmap >::BObjectList(), BObjectList< BBitmap >::FindIf(), BObjectList< BBitmap >::MakeEmpty(), and BObjectList< BBitmap >::operator=().

◆ EachElement() [1/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

◆ EachElement() [2/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

◆ FindIf() [1/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

◆ FindIf() [2/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

◆ FirstItem()

template<class T >
T * BObjectList< T >::FirstItem ( ) const

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

◆ 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

◆ 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

Referenced by BObjectList< BBitmap >::HSortItems().

◆ 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

◆ IsEmpty()

template<class T >
bool BObjectList< T >::IsEmpty ( ) const

Return whether or not there are items in the list.

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

◆ 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

Referenced by BObjectList< BBitmap >::BinarySearch(), BObjectList< BBitmap >::BObjectList(), BObjectList< BBitmap >::FindIf(), BObjectList< BBitmap >::MakeEmpty(), BObjectList< BBitmap >::operator=(), BObjectList< BBitmap >::ReplaceItem(), and BObjectList< BBitmap >::SwapWithItem().

◆ LastItem()

template<class T >
T * BObjectList< T >::LastItem ( ) const

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

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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