|
|
@@ -31,45 +31,24 @@ of Be Incorporated in the United States and other countries. Other brand product
|
|
|
|
names are registered trademarks or trademarks of their respective holders.
|
|
|
|
names are registered trademarks or trademarks of their respective holders.
|
|
|
|
All rights reserved.
|
|
|
|
All rights reserved.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _OBJECT_LIST_H
|
|
|
|
|
|
|
|
#define _OBJECT_LIST_H
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <new>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <List.h>
|
|
|
|
|
|
|
|
#include <SupportDefs.h>
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
|
|
|
** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING **
|
|
|
|
|
|
|
|
** **
|
|
|
|
|
|
|
|
** DANGER, WILL ROBINSON! **
|
|
|
|
|
|
|
|
** **
|
|
|
|
|
|
|
|
** The interfaces contained here are part of BeOS's **
|
|
|
|
|
|
|
|
** **
|
|
|
|
|
|
|
|
** >> PRIVATE NOT FOR PUBLIC USE << **
|
|
|
|
|
|
|
|
** **
|
|
|
|
|
|
|
|
** implementation. **
|
|
|
|
|
|
|
|
** **
|
|
|
|
|
|
|
|
** These interfaces WILL CHANGE in future releases. **
|
|
|
|
|
|
|
|
** If you use them, your app WILL BREAK at some future time. **
|
|
|
|
|
|
|
|
** **
|
|
|
|
|
|
|
|
** (And yes, this does mean that binaries built from OpenTracker will not **
|
|
|
|
|
|
|
|
** be compatible with some future releases of the OS. When that happens, **
|
|
|
|
|
|
|
|
** we will provide an updated version of this file to keep compatibility.) **
|
|
|
|
|
|
|
|
** **
|
|
|
|
|
|
|
|
** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING **
|
|
|
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// ObjectList is a wrapper around BList that adds type safety,
|
|
|
|
// ObjectList is a wrapper around BList that adds type safety,
|
|
|
|
// optional object ownership, search, insert operations, etc.
|
|
|
|
// optional object ownership, search, insert operations, etc.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __OBJECT_LIST__
|
|
|
|
|
|
|
|
#define __OBJECT_LIST__
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _BE_H
|
|
|
|
|
|
|
|
#include <List.h>
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <SupportDefs.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T> class BObjectList;
|
|
|
|
template<class T> class BObjectList;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
struct UnaryPredicate {
|
|
|
|
struct UnaryPredicate {
|
|
|
|
|
|
|
|
|
|
|
@@ -84,6 +63,7 @@ private:
|
|
|
|
friend class BObjectList<T>;
|
|
|
|
friend class BObjectList<T>;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
int
|
|
|
|
int
|
|
|
|
UnaryPredicate<T>::_unary_predicate_glue(const void *item, void *context)
|
|
|
|
UnaryPredicate<T>::_unary_predicate_glue(const void *item, void *context)
|
|
|
@@ -111,10 +91,12 @@ public:
|
|
|
|
void HSortItems(GenericCompareFunctionWithState, void *state);
|
|
|
|
void HSortItems(GenericCompareFunctionWithState, void *state);
|
|
|
|
|
|
|
|
|
|
|
|
void *BinarySearch(const void *, GenericCompareFunction) const;
|
|
|
|
void *BinarySearch(const void *, GenericCompareFunction) const;
|
|
|
|
void *BinarySearch(const void *, GenericCompareFunctionWithState, void *state) const;
|
|
|
|
void *BinarySearch(const void *, GenericCompareFunctionWithState,
|
|
|
|
|
|
|
|
void *state) const;
|
|
|
|
|
|
|
|
|
|
|
|
int32 BinarySearchIndex(const void *, GenericCompareFunction) const;
|
|
|
|
int32 BinarySearchIndex(const void *, GenericCompareFunction) const;
|
|
|
|
int32 BinarySearchIndex(const void *, GenericCompareFunctionWithState, void *state) const;
|
|
|
|
int32 BinarySearchIndex(const void *, GenericCompareFunctionWithState,
|
|
|
|
|
|
|
|
void *state) const;
|
|
|
|
int32 BinarySearchIndexByPredicate(const void *, UnaryPredicateGlue) const;
|
|
|
|
int32 BinarySearchIndexByPredicate(const void *, UnaryPredicateGlue) const;
|
|
|
|
|
|
|
|
|
|
|
|
bool Owning() const;
|
|
|
|
bool Owning() const;
|
|
|
@@ -125,6 +107,7 @@ protected:
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
class BObjectList : private _PointerList_ {
|
|
|
|
class BObjectList : private _PointerList_ {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
@@ -133,22 +116,22 @@ public:
|
|
|
|
typedef T* (*EachFunction)(T*, void*);
|
|
|
|
typedef T* (*EachFunction)(T*, void*);
|
|
|
|
typedef const T* (*ConstEachFunction)(const T*, void*);
|
|
|
|
typedef const T* (*ConstEachFunction)(const T*, void*);
|
|
|
|
typedef int (*CompareFunction)(const T*, const T*);
|
|
|
|
typedef int (*CompareFunction)(const T*, const T*);
|
|
|
|
typedef int (* CompareFunctionWithState)(const T *, const T *, void *state);
|
|
|
|
typedef int (*CompareFunctionWithState)(const T*, const T*,
|
|
|
|
|
|
|
|
void* state);
|
|
|
|
|
|
|
|
|
|
|
|
BObjectList(int32 itemsPerBlock = 20, bool owning = false);
|
|
|
|
BObjectList(int32 itemsPerBlock = 20,
|
|
|
|
|
|
|
|
bool owning = false);
|
|
|
|
BObjectList(const BObjectList& list);
|
|
|
|
BObjectList(const BObjectList& list);
|
|
|
|
// clones list; if list is owning, makes copies of all
|
|
|
|
// clones list; if list is owning, makes
|
|
|
|
// the items
|
|
|
|
// copies of all the items
|
|
|
|
|
|
|
|
|
|
|
|
virtual ~BObjectList();
|
|
|
|
virtual ~BObjectList();
|
|
|
|
|
|
|
|
|
|
|
|
BObjectList& operator=(const BObjectList& list);
|
|
|
|
BObjectList& operator=(const BObjectList& list);
|
|
|
|
// clones list; if list is owning, makes copies of all
|
|
|
|
// clones list; if list is owning, makes
|
|
|
|
// the items
|
|
|
|
// copies of all the items
|
|
|
|
|
|
|
|
|
|
|
|
// adding and removing
|
|
|
|
// adding and removing
|
|
|
|
// ToDo:
|
|
|
|
|
|
|
|
// change Add calls to return const item
|
|
|
|
|
|
|
|
bool AddItem(T*);
|
|
|
|
bool AddItem(T*);
|
|
|
|
bool AddItem(T*, int32);
|
|
|
|
bool AddItem(T*, int32);
|
|
|
|
bool AddList(BObjectList*);
|
|
|
|
bool AddList(BObjectList*);
|
|
|
@@ -165,10 +148,12 @@ public:
|
|
|
|
T* ItemAt(int32) const;
|
|
|
|
T* ItemAt(int32) const;
|
|
|
|
|
|
|
|
|
|
|
|
bool ReplaceItem(int32 index, T*);
|
|
|
|
bool ReplaceItem(int32 index, T*);
|
|
|
|
// if list is owning, deletes the item at <index> first
|
|
|
|
// if list is owning, deletes the item
|
|
|
|
|
|
|
|
// at <index> first
|
|
|
|
T* SwapWithItem(int32 index, T* newItem);
|
|
|
|
T* SwapWithItem(int32 index, T* newItem);
|
|
|
|
// same as ReplaceItem, except does not delete old item at <index>,
|
|
|
|
// same as ReplaceItem, except does not
|
|
|
|
// returns it instead
|
|
|
|
// delete old item at <index>, returns it
|
|
|
|
|
|
|
|
// instead
|
|
|
|
|
|
|
|
|
|
|
|
T* FirstItem() const;
|
|
|
|
T* FirstItem() const;
|
|
|
|
T* LastItem() const;
|
|
|
|
T* LastItem() const;
|
|
|
@@ -183,97 +168,123 @@ public:
|
|
|
|
const T* EachElement(ConstEachFunction, void*) const;
|
|
|
|
const T* EachElement(ConstEachFunction, void*) const;
|
|
|
|
|
|
|
|
|
|
|
|
void SortItems(CompareFunction);
|
|
|
|
void SortItems(CompareFunction);
|
|
|
|
void SortItems(CompareFunctionWithState, void *state);
|
|
|
|
void SortItems(CompareFunctionWithState,
|
|
|
|
|
|
|
|
void* state);
|
|
|
|
void HSortItems(CompareFunction);
|
|
|
|
void HSortItems(CompareFunction);
|
|
|
|
void HSortItems(CompareFunctionWithState, void *state);
|
|
|
|
void HSortItems(CompareFunctionWithState,
|
|
|
|
|
|
|
|
void* state);
|
|
|
|
|
|
|
|
|
|
|
|
// linear search, returns first item that matches predicate
|
|
|
|
// linear search, returns first item that
|
|
|
|
|
|
|
|
// matches predicate
|
|
|
|
const T* FindIf(const UnaryPredicate<T>&) const;
|
|
|
|
const T* FindIf(const UnaryPredicate<T>&) const;
|
|
|
|
T* FindIf(const UnaryPredicate<T>&);
|
|
|
|
T* FindIf(const UnaryPredicate<T>&);
|
|
|
|
|
|
|
|
|
|
|
|
// list must be sorted with CompareFunction for these to work
|
|
|
|
// list must be sorted with CompareFunction for
|
|
|
|
|
|
|
|
// these to work
|
|
|
|
T* BinarySearch(const T&, CompareFunction) const;
|
|
|
|
T* BinarySearch(const T&, CompareFunction) const;
|
|
|
|
T *BinarySearch(const T &, CompareFunctionWithState, void *state) const;
|
|
|
|
T* BinarySearch(const T&, CompareFunctionWithState,
|
|
|
|
|
|
|
|
void* state) const;
|
|
|
|
template<typename Key>
|
|
|
|
|
|
|
|
T *BinarySearchByKey(const Key &key, int (*compare)(const Key *, const T *))
|
|
|
|
|
|
|
|
const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename Key>
|
|
|
|
template<typename Key>
|
|
|
|
T* BinarySearchByKey(const Key& key,
|
|
|
|
T* BinarySearchByKey(const Key& key,
|
|
|
|
int (*compare)(const Key *, const T *, void *), void *state) const;
|
|
|
|
int (*compare)(const Key*, const T*)) const;
|
|
|
|
|
|
|
|
|
|
|
|
int32 BinarySearchIndex(const T &item, CompareFunction compare) const;
|
|
|
|
template<typename Key>
|
|
|
|
int32 BinarySearchIndex(const T &item, CompareFunctionWithState compare,
|
|
|
|
T* BinarySearchByKey(const Key& key,
|
|
|
|
|
|
|
|
int (*compare)(const Key*, const T*, void*),
|
|
|
|
|
|
|
|
void* state) const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int32 BinarySearchIndex(const T&item,
|
|
|
|
|
|
|
|
CompareFunction compare) const;
|
|
|
|
|
|
|
|
int32 BinarySearchIndex(const T&item,
|
|
|
|
|
|
|
|
CompareFunctionWithState compare,
|
|
|
|
void* state) const;
|
|
|
|
void* state) const;
|
|
|
|
|
|
|
|
|
|
|
|
template<typename Key>
|
|
|
|
template<typename Key>
|
|
|
|
int32 BinarySearchIndexByKey(const Key& key,
|
|
|
|
int32 BinarySearchIndexByKey(const Key& key,
|
|
|
|
int (*compare)(const Key*, const T*)) const;
|
|
|
|
int (*compare)(const Key*, const T*)) const;
|
|
|
|
|
|
|
|
|
|
|
|
// Binary insertion - list must be sorted with CompareFunction for
|
|
|
|
// Binary insertion - list must be sorted with
|
|
|
|
// these to work
|
|
|
|
// CompareFunction for these to work
|
|
|
|
|
|
|
|
|
|
|
|
// simple insert
|
|
|
|
// simple insert
|
|
|
|
bool BinaryInsert(T*, CompareFunction);
|
|
|
|
bool BinaryInsert(T*, CompareFunction);
|
|
|
|
bool BinaryInsert(T *, CompareFunctionWithState, void *state);
|
|
|
|
bool BinaryInsert(T*, CompareFunctionWithState,
|
|
|
|
|
|
|
|
void* state);
|
|
|
|
bool BinaryInsert(T*, const UnaryPredicate<T>&);
|
|
|
|
bool BinaryInsert(T*, const UnaryPredicate<T>&);
|
|
|
|
|
|
|
|
|
|
|
|
// unique insert, returns false if item already in list
|
|
|
|
// unique insert, returns false if item already
|
|
|
|
|
|
|
|
// in list
|
|
|
|
bool BinaryInsertUnique(T*, CompareFunction);
|
|
|
|
bool BinaryInsertUnique(T*, CompareFunction);
|
|
|
|
bool BinaryInsertUnique(T *, CompareFunctionWithState, void *state);
|
|
|
|
bool BinaryInsertUnique(T*, CompareFunctionWithState,
|
|
|
|
bool BinaryInsertUnique(T *, const UnaryPredicate<T> &);
|
|
|
|
void* state);
|
|
|
|
|
|
|
|
bool BinaryInsertUnique(T*,
|
|
|
|
|
|
|
|
const UnaryPredicate<T>&);
|
|
|
|
|
|
|
|
|
|
|
|
// insert a copy of the item, returns new inserted item
|
|
|
|
// insert a copy of the item, returns new
|
|
|
|
T *BinaryInsertCopy(const T ©This, CompareFunction);
|
|
|
|
// inserted item
|
|
|
|
T *BinaryInsertCopy(const T ©This, CompareFunctionWithState, void *state);
|
|
|
|
T* BinaryInsertCopy(const T& copyThis,
|
|
|
|
|
|
|
|
CompareFunction);
|
|
|
|
|
|
|
|
T* BinaryInsertCopy(const T& copyThis,
|
|
|
|
|
|
|
|
CompareFunctionWithState, void* state);
|
|
|
|
|
|
|
|
|
|
|
|
// insert a copy of the item if not in list already
|
|
|
|
// insert a copy of the item if not in list
|
|
|
|
// returns new inserted item or existing item in case of a conflict
|
|
|
|
// already returns new inserted item or existing
|
|
|
|
T *BinaryInsertCopyUnique(const T ©This, CompareFunction);
|
|
|
|
// item in case of a conflict
|
|
|
|
T *BinaryInsertCopyUnique(const T ©This, CompareFunctionWithState, void *state);
|
|
|
|
T* BinaryInsertCopyUnique(const T& copyThis,
|
|
|
|
|
|
|
|
CompareFunction);
|
|
|
|
|
|
|
|
T* BinaryInsertCopyUnique(const T& copyThis,
|
|
|
|
|
|
|
|
CompareFunctionWithState, void* state);
|
|
|
|
|
|
|
|
|
|
|
|
int32 FindBinaryInsertionIndex(const UnaryPredicate<T> &, bool *alreadyInList = 0) const;
|
|
|
|
int32 FindBinaryInsertionIndex(
|
|
|
|
// returns either the index into which a new item should be inserted
|
|
|
|
const UnaryPredicate<T>&,
|
|
|
|
// or index of an existing item that matches the predicate
|
|
|
|
bool* alreadyInList = 0) const;
|
|
|
|
|
|
|
|
// returns either the index into which a new
|
|
|
|
|
|
|
|
// item should be inserted or index of an
|
|
|
|
|
|
|
|
// existing item that matches the predicate
|
|
|
|
|
|
|
|
|
|
|
|
// deprecated API, will go away
|
|
|
|
class Private;
|
|
|
|
BList *AsBList()
|
|
|
|
|
|
|
|
{ return this; }
|
|
|
|
|
|
|
|
const BList *AsBList() const
|
|
|
|
|
|
|
|
{ return this; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
void SetItem(int32, T *);
|
|
|
|
friend class Private;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void _SetItem(int32, T*);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class Item, class Result, class Param1>
|
|
|
|
template<class Item, class Result, class Param1>
|
|
|
|
Result
|
|
|
|
Result
|
|
|
|
WhileEachListItem(BObjectList<Item> *list, Result (Item::*func)(Param1), Param1 p1)
|
|
|
|
WhileEachListItem(BObjectList<Item>* list, Result (Item::*func)(Param1),
|
|
|
|
|
|
|
|
Param1 p1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Result result = 0;
|
|
|
|
Result result = 0;
|
|
|
|
int32 count = list->CountItems();
|
|
|
|
int32 count = list->CountItems();
|
|
|
|
|
|
|
|
|
|
|
|
for (int32 index = 0; index < count; index++)
|
|
|
|
for (int32 index = 0; index < count; index++) {
|
|
|
|
if ((result = (list->ItemAt(index)->*func)(p1)) != 0)
|
|
|
|
if ((result = (list->ItemAt(index)->*func)(p1)) != 0)
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class Item, class Result, class Param1>
|
|
|
|
template<class Item, class Result, class Param1>
|
|
|
|
Result
|
|
|
|
Result
|
|
|
|
WhileEachListItem(BObjectList<Item> *list, Result (*func)(Item *, Param1), Param1 p1)
|
|
|
|
WhileEachListItem(BObjectList<Item>* list, Result (*func)(Item*, Param1),
|
|
|
|
|
|
|
|
Param1 p1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Result result = 0;
|
|
|
|
Result result = 0;
|
|
|
|
int32 count = list->CountItems();
|
|
|
|
int32 count = list->CountItems();
|
|
|
|
|
|
|
|
|
|
|
|
for (int32 index = 0; index < count; index++)
|
|
|
|
for (int32 index = 0; index < count; index++) {
|
|
|
|
if ((result = (*func)(list->ItemAt(index), p1)) != 0)
|
|
|
|
if ((result = (*func)(list->ItemAt(index), p1)) != 0)
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class Item, class Result, class Param1, class Param2>
|
|
|
|
template<class Item, class Result, class Param1, class Param2>
|
|
|
|
Result
|
|
|
|
Result
|
|
|
|
WhileEachListItem(BObjectList<Item>* list, Result (Item::*func)(Param1, Param2),
|
|
|
|
WhileEachListItem(BObjectList<Item>* list, Result (Item::*func)(Param1, Param2),
|
|
|
@@ -282,43 +293,51 @@ WhileEachListItem(BObjectList<Item> *list, Result (Item::*func)(Param1, Param2),
|
|
|
|
Result result = 0;
|
|
|
|
Result result = 0;
|
|
|
|
int32 count = list->CountItems();
|
|
|
|
int32 count = list->CountItems();
|
|
|
|
|
|
|
|
|
|
|
|
for (int32 index = 0; index < count; index++)
|
|
|
|
for (int32 index = 0; index < count; index++) {
|
|
|
|
if ((result = (list->ItemAt(index)->*func)(p1, p2)) != 0)
|
|
|
|
if ((result = (list->ItemAt(index)->*func)(p1, p2)) != 0)
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class Item, class Result, class Param1, class Param2>
|
|
|
|
template<class Item, class Result, class Param1, class Param2>
|
|
|
|
Result
|
|
|
|
Result
|
|
|
|
WhileEachListItem(BObjectList<Item> *list, Result (*func)(Item *, Param1, Param2),
|
|
|
|
WhileEachListItem(BObjectList<Item>* list,
|
|
|
|
Param1 p1, Param2 p2)
|
|
|
|
Result (*func)(Item*, Param1, Param2), Param1 p1, Param2 p2)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Result result = 0;
|
|
|
|
Result result = 0;
|
|
|
|
int32 count = list->CountItems();
|
|
|
|
int32 count = list->CountItems();
|
|
|
|
|
|
|
|
|
|
|
|
for (int32 index = 0; index < count; index++)
|
|
|
|
for (int32 index = 0; index < count; index++) {
|
|
|
|
if ((result = (*func)(list->ItemAt(index), p1, p2)) != 0)
|
|
|
|
if ((result = (*func)(list->ItemAt(index), p1, p2)) != 0)
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<class Item, class Result, class Param1, class Param2, class Param3, class Param4>
|
|
|
|
|
|
|
|
|
|
|
|
template<class Item, class Result, class Param1, class Param2, class Param3,
|
|
|
|
|
|
|
|
class Param4>
|
|
|
|
Result
|
|
|
|
Result
|
|
|
|
WhileEachListItem(BObjectList<Item> *list, Result (*func)(Item *, Param1, Param2,
|
|
|
|
WhileEachListItem(BObjectList<Item>* list,
|
|
|
|
Param3, Param4), Param1 p1, Param2 p2, Param3 p3, Param4 p4)
|
|
|
|
Result (*func)(Item*, Param1, Param2, Param3, Param4), Param1 p1, Param2 p2,
|
|
|
|
|
|
|
|
Param3 p3, Param4 p4)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Result result = 0;
|
|
|
|
Result result = 0;
|
|
|
|
int32 count = list->CountItems();
|
|
|
|
int32 count = list->CountItems();
|
|
|
|
|
|
|
|
|
|
|
|
for (int32 index = 0; index < count; index++)
|
|
|
|
for (int32 index = 0; index < count; index++) {
|
|
|
|
if ((result = (*func)(list->ItemAt(index), p1, p2, p3, p4)) != 0)
|
|
|
|
if ((result = (*func)(list->ItemAt(index), p1, p2, p3, p4)) != 0)
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class Item, class Result>
|
|
|
|
template<class Item, class Result>
|
|
|
|
void
|
|
|
|
void
|
|
|
|
EachListItemIgnoreResult(BObjectList<Item>* list, Result (Item::*func)())
|
|
|
|
EachListItemIgnoreResult(BObjectList<Item>* list, Result (Item::*func)())
|
|
|
@@ -328,6 +347,7 @@ EachListItemIgnoreResult(BObjectList<Item> *list, Result (Item::*func)())
|
|
|
|
(list->ItemAt(index)->*func)();
|
|
|
|
(list->ItemAt(index)->*func)();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class Item, class Param1>
|
|
|
|
template<class Item, class Param1>
|
|
|
|
void
|
|
|
|
void
|
|
|
|
EachListItem(BObjectList<Item>* list, void (*func)(Item*, Param1), Param1 p1)
|
|
|
|
EachListItem(BObjectList<Item>* list, void (*func)(Item*, Param1), Param1 p1)
|
|
|
@@ -337,6 +357,7 @@ EachListItem(BObjectList<Item> *list, void (*func)(Item *, Param1), Param1 p1)
|
|
|
|
(func)(list->ItemAt(index), p1);
|
|
|
|
(func)(list->ItemAt(index), p1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class Item, class Param1, class Param2>
|
|
|
|
template<class Item, class Param1, class Param2>
|
|
|
|
void
|
|
|
|
void
|
|
|
|
EachListItem(BObjectList<Item>* list, void (Item::*func)(Param1, Param2),
|
|
|
|
EachListItem(BObjectList<Item>* list, void (Item::*func)(Param1, Param2),
|
|
|
@@ -347,6 +368,7 @@ EachListItem(BObjectList<Item> *list, void (Item::*func)(Param1, Param2),
|
|
|
|
(list->ItemAt(index)->*func)(p1, p2);
|
|
|
|
(list->ItemAt(index)->*func)(p1, p2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class Item, class Param1, class Param2>
|
|
|
|
template<class Item, class Param1, class Param2>
|
|
|
|
void
|
|
|
|
void
|
|
|
|
EachListItem(BObjectList<Item>* list, void (*func)(Item*,Param1, Param2),
|
|
|
|
EachListItem(BObjectList<Item>* list, void (*func)(Item*,Param1, Param2),
|
|
|
@@ -357,10 +379,11 @@ EachListItem(BObjectList<Item> *list, void (*func)(Item *,Param1, Param2),
|
|
|
|
(func)(list->ItemAt(index), p1, p2);
|
|
|
|
(func)(list->ItemAt(index), p1, p2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class Item, class Param1, class Param2, class Param3>
|
|
|
|
template<class Item, class Param1, class Param2, class Param3>
|
|
|
|
void
|
|
|
|
void
|
|
|
|
EachListItem(BObjectList<Item> *list, void (*func)(Item *,Param1, Param2,
|
|
|
|
EachListItem(BObjectList<Item>* list,
|
|
|
|
Param3), Param1 p1, Param2 p2, Param3 p3)
|
|
|
|
void (*func)(Item*,Param1, Param2, Param3), Param1 p1, Param2 p2, Param3 p3)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int32 count = list->CountItems();
|
|
|
|
int32 count = list->CountItems();
|
|
|
|
for (int32 index = 0; index < count; index++)
|
|
|
|
for (int32 index = 0; index < count; index++)
|
|
|
@@ -370,31 +393,38 @@ EachListItem(BObjectList<Item> *list, void (*func)(Item *,Param1, Param2,
|
|
|
|
|
|
|
|
|
|
|
|
template<class Item, class Param1, class Param2, class Param3, class Param4>
|
|
|
|
template<class Item, class Param1, class Param2, class Param3, class Param4>
|
|
|
|
void
|
|
|
|
void
|
|
|
|
EachListItem(BObjectList<Item> *list, void (*func)(Item *,Param1, Param2,
|
|
|
|
EachListItem(BObjectList<Item>* list,
|
|
|
|
Param3, Param4), Param1 p1, Param2 p2, Param3 p3, Param4 p4)
|
|
|
|
void (*func)(Item*,Param1, Param2, Param3, Param4), Param1 p1, Param2 p2,
|
|
|
|
|
|
|
|
Param3 p3, Param4 p4)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int32 count = list->CountItems();
|
|
|
|
int32 count = list->CountItems();
|
|
|
|
for (int32 index = 0; index < count; index++)
|
|
|
|
for (int32 index = 0; index < count; index++)
|
|
|
|
(func)(list->ItemAt(index), p1, p2, p3, p4);
|
|
|
|
(func)(list->ItemAt(index), p1, p2, p3, p4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// inline code
|
|
|
|
// inline code
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
inline bool
|
|
|
|
_PointerList_::Owning() const
|
|
|
|
_PointerList_::Owning() const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return owning;
|
|
|
|
return owning;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
BObjectList<T>::BObjectList(int32 itemsPerBlock, bool owning)
|
|
|
|
BObjectList<T>::BObjectList(int32 itemsPerBlock, bool owning)
|
|
|
|
: _PointerList_(itemsPerBlock, owning)
|
|
|
|
:
|
|
|
|
|
|
|
|
_PointerList_(itemsPerBlock, owning)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
BObjectList<T>::BObjectList(const BObjectList<T> &list)
|
|
|
|
BObjectList<T>::BObjectList(const BObjectList<T> &list)
|
|
|
|
: _PointerList_(list)
|
|
|
|
:
|
|
|
|
|
|
|
|
_PointerList_(list)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
owning = list.owning;
|
|
|
|
owning = list.owning;
|
|
|
|
if (owning) {
|
|
|
|
if (owning) {
|
|
|
@@ -403,19 +433,22 @@ BObjectList<T>::BObjectList(const BObjectList<T> &list)
|
|
|
|
for (int32 index = 0; index < count; index++) {
|
|
|
|
for (int32 index = 0; index < count; index++) {
|
|
|
|
T* item = list.ItemAt(index);
|
|
|
|
T* item = list.ItemAt(index);
|
|
|
|
if (item)
|
|
|
|
if (item)
|
|
|
|
item = new T(*item);
|
|
|
|
item = new (std::nothrow) T(*item);
|
|
|
|
SetItem(index, item);
|
|
|
|
_SetItem(index, item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
BObjectList<T>::~BObjectList()
|
|
|
|
BObjectList<T>::~BObjectList()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (Owning())
|
|
|
|
if (Owning()) {
|
|
|
|
// have to nuke elements first
|
|
|
|
// have to nuke elements first
|
|
|
|
MakeEmpty();
|
|
|
|
MakeEmpty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
BObjectList<T>&
|
|
|
|
BObjectList<T>&
|
|
|
@@ -429,13 +462,14 @@ BObjectList<T>::operator=(const BObjectList<T> &list)
|
|
|
|
for (int32 index = 0; index < count; index++) {
|
|
|
|
for (int32 index = 0; index < count; index++) {
|
|
|
|
T* item = list.ItemAt(index);
|
|
|
|
T* item = list.ItemAt(index);
|
|
|
|
if (item)
|
|
|
|
if (item)
|
|
|
|
item = new T(*item);
|
|
|
|
item = new (std::nothrow) T(*item);
|
|
|
|
SetItem(index, item);
|
|
|
|
_SetItem(index, item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
bool
|
|
|
|
bool
|
|
|
|
BObjectList<T>::AddItem(T* item)
|
|
|
|
BObjectList<T>::AddItem(T* item)
|
|
|
@@ -444,6 +478,7 @@ BObjectList<T>::AddItem(T *item)
|
|
|
|
return _PointerList_::AddItem((void*)item);
|
|
|
|
return _PointerList_::AddItem((void*)item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
bool
|
|
|
|
bool
|
|
|
|
BObjectList<T>::AddItem(T* item, int32 atIndex)
|
|
|
|
BObjectList<T>::AddItem(T* item, int32 atIndex)
|
|
|
@@ -451,6 +486,7 @@ BObjectList<T>::AddItem(T *item, int32 atIndex)
|
|
|
|
return _PointerList_::AddItem((void*)item, atIndex);
|
|
|
|
return _PointerList_::AddItem((void*)item, atIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
bool
|
|
|
|
bool
|
|
|
|
BObjectList<T>::AddList(BObjectList<T>* newItems)
|
|
|
|
BObjectList<T>::AddList(BObjectList<T>* newItems)
|
|
|
@@ -458,6 +494,7 @@ BObjectList<T>::AddList(BObjectList<T> *newItems)
|
|
|
|
return _PointerList_::AddList(newItems);
|
|
|
|
return _PointerList_::AddList(newItems);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
bool
|
|
|
|
bool
|
|
|
|
BObjectList<T>::AddList(BObjectList<T>* newItems, int32 atIndex)
|
|
|
|
BObjectList<T>::AddList(BObjectList<T>* newItems, int32 atIndex)
|
|
|
@@ -478,6 +515,7 @@ BObjectList<T>::RemoveItem(T *item, bool deleteIfOwning)
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
T*
|
|
|
|
T*
|
|
|
|
BObjectList<T>::RemoveItemAt(int32 index)
|
|
|
|
BObjectList<T>::RemoveItemAt(int32 index)
|
|
|
@@ -485,6 +523,7 @@ BObjectList<T>::RemoveItemAt(int32 index)
|
|
|
|
return (T*)_PointerList_::RemoveItem(index);
|
|
|
|
return (T*)_PointerList_::RemoveItem(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
inline T*
|
|
|
|
inline T*
|
|
|
|
BObjectList<T>::ItemAt(int32 index) const
|
|
|
|
BObjectList<T>::ItemAt(int32 index) const
|
|
|
@@ -492,6 +531,7 @@ BObjectList<T>::ItemAt(int32 index) const
|
|
|
|
return (T*)_PointerList_::ItemAt(index);
|
|
|
|
return (T*)_PointerList_::ItemAt(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
bool
|
|
|
|
bool
|
|
|
|
BObjectList<T>::ReplaceItem(int32 index, T* item)
|
|
|
|
BObjectList<T>::ReplaceItem(int32 index, T* item)
|
|
|
@@ -501,6 +541,7 @@ BObjectList<T>::ReplaceItem(int32 index, T *item)
|
|
|
|
return _PointerList_::ReplaceItem(index, (void*)item);
|
|
|
|
return _PointerList_::ReplaceItem(index, (void*)item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
T*
|
|
|
|
T*
|
|
|
|
BObjectList<T>::SwapWithItem(int32 index, T* newItem)
|
|
|
|
BObjectList<T>::SwapWithItem(int32 index, T* newItem)
|
|
|
@@ -510,13 +551,15 @@ BObjectList<T>::SwapWithItem(int32 index, T *newItem)
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
void
|
|
|
|
void
|
|
|
|
BObjectList<T>::SetItem(int32 index, T *newItem)
|
|
|
|
BObjectList<T>::_SetItem(int32 index, T* newItem)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_PointerList_::ReplaceItem(index, (void*)newItem);
|
|
|
|
_PointerList_::ReplaceItem(index, (void*)newItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
int32
|
|
|
|
int32
|
|
|
|
BObjectList<T>::IndexOf(const T* item) const
|
|
|
|
BObjectList<T>::IndexOf(const T* item) const
|
|
|
@@ -524,6 +567,7 @@ BObjectList<T>::IndexOf(const T *item) const
|
|
|
|
return _PointerList_::IndexOf((void*)item);
|
|
|
|
return _PointerList_::IndexOf((void*)item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
T*
|
|
|
|
T*
|
|
|
|
BObjectList<T>::FirstItem() const
|
|
|
|
BObjectList<T>::FirstItem() const
|
|
|
@@ -531,6 +575,7 @@ BObjectList<T>::FirstItem() const
|
|
|
|
return (T*)_PointerList_::FirstItem();
|
|
|
|
return (T*)_PointerList_::FirstItem();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
T*
|
|
|
|
T*
|
|
|
|
BObjectList<T>::LastItem() const
|
|
|
|
BObjectList<T>::LastItem() const
|
|
|
@@ -538,6 +583,7 @@ BObjectList<T>::LastItem() const
|
|
|
|
return (T*)_PointerList_::LastItem();
|
|
|
|
return (T*)_PointerList_::LastItem();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
bool
|
|
|
|
bool
|
|
|
|
BObjectList<T>::HasItem(const T* item) const
|
|
|
|
BObjectList<T>::HasItem(const T* item) const
|
|
|
@@ -545,6 +591,7 @@ BObjectList<T>::HasItem(const T *item) const
|
|
|
|
return _PointerList_::HasItem((void*)item);
|
|
|
|
return _PointerList_::HasItem((void*)item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
bool
|
|
|
|
bool
|
|
|
|
BObjectList<T>::IsEmpty() const
|
|
|
|
BObjectList<T>::IsEmpty() const
|
|
|
@@ -552,6 +599,7 @@ BObjectList<T>::IsEmpty() const
|
|
|
|
return _PointerList_::IsEmpty();
|
|
|
|
return _PointerList_::IsEmpty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
int32
|
|
|
|
int32
|
|
|
|
BObjectList<T>::CountItems() const
|
|
|
|
BObjectList<T>::CountItems() const
|
|
|
@@ -559,6 +607,7 @@ BObjectList<T>::CountItems() const
|
|
|
|
return _PointerList_::CountItems();
|
|
|
|
return _PointerList_::CountItems();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
void
|
|
|
|
void
|
|
|
|
BObjectList<T>::MakeEmpty(bool deleteIfOwning)
|
|
|
|
BObjectList<T>::MakeEmpty(bool deleteIfOwning)
|
|
|
@@ -571,6 +620,7 @@ BObjectList<T>::MakeEmpty(bool deleteIfOwning)
|
|
|
|
_PointerList_::MakeEmpty();
|
|
|
|
_PointerList_::MakeEmpty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
T*
|
|
|
|
T*
|
|
|
|
BObjectList<T>::EachElement(EachFunction func, void* params)
|
|
|
|
BObjectList<T>::EachElement(EachFunction func, void* params)
|
|
|
@@ -593,9 +643,10 @@ const T *
|
|
|
|
BObjectList<T>::FindIf(const UnaryPredicate<T>& predicate) const
|
|
|
|
BObjectList<T>::FindIf(const UnaryPredicate<T>& predicate) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int32 count = CountItems();
|
|
|
|
int32 count = CountItems();
|
|
|
|
for (int32 index = 0; index < count; index++)
|
|
|
|
for (int32 index = 0; index < count; index++) {
|
|
|
|
if (predicate.operator()(ItemAt(index)) == 0)
|
|
|
|
if (predicate.operator()(ItemAt(index)) == 0)
|
|
|
|
return ItemAt(index);
|
|
|
|
return ItemAt(index);
|
|
|
|
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@@ -604,9 +655,10 @@ T *
|
|
|
|
BObjectList<T>::FindIf(const UnaryPredicate<T>& predicate)
|
|
|
|
BObjectList<T>::FindIf(const UnaryPredicate<T>& predicate)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int32 count = CountItems();
|
|
|
|
int32 count = CountItems();
|
|
|
|
for (int32 index = 0; index < count; index++)
|
|
|
|
for (int32 index = 0; index < count; index++) {
|
|
|
|
if (predicate.operator()(ItemAt(index)) == 0)
|
|
|
|
if (predicate.operator()(ItemAt(index)) == 0)
|
|
|
|
return ItemAt(index);
|
|
|
|
return ItemAt(index);
|
|
|
|
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@@ -618,6 +670,7 @@ BObjectList<T>::SortItems(CompareFunction function)
|
|
|
|
_PointerList_::SortItems((GenericCompareFunction)function);
|
|
|
|
_PointerList_::SortItems((GenericCompareFunction)function);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
void
|
|
|
|
void
|
|
|
|
BObjectList<T>::SortItems(CompareFunctionWithState function, void* state)
|
|
|
|
BObjectList<T>::SortItems(CompareFunctionWithState function, void* state)
|
|
|
@@ -625,6 +678,7 @@ BObjectList<T>::SortItems(CompareFunctionWithState function, void *state)
|
|
|
|
_PointerList_::SortItems((GenericCompareFunctionWithState)function, state);
|
|
|
|
_PointerList_::SortItems((GenericCompareFunctionWithState)function, state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
void
|
|
|
|
void
|
|
|
|
BObjectList<T>::HSortItems(CompareFunction function)
|
|
|
|
BObjectList<T>::HSortItems(CompareFunction function)
|
|
|
@@ -632,6 +686,7 @@ BObjectList<T>::HSortItems(CompareFunction function)
|
|
|
|
_PointerList_::HSortItems((GenericCompareFunction)function);
|
|
|
|
_PointerList_::HSortItems((GenericCompareFunction)function);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
void
|
|
|
|
void
|
|
|
|
BObjectList<T>::HSortItems(CompareFunctionWithState function, void* state)
|
|
|
|
BObjectList<T>::HSortItems(CompareFunctionWithState function, void* state)
|
|
|
@@ -639,17 +694,18 @@ BObjectList<T>::HSortItems(CompareFunctionWithState function, void *state)
|
|
|
|
_PointerList_::HSortItems((GenericCompareFunctionWithState)function, state);
|
|
|
|
_PointerList_::HSortItems((GenericCompareFunctionWithState)function, state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
T*
|
|
|
|
T*
|
|
|
|
BObjectList<T>::BinarySearch(const T& key, CompareFunction func) const
|
|
|
|
BObjectList<T>::BinarySearch(const T& key, CompareFunction func) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return (T*)_PointerList_::BinarySearch(&key,
|
|
|
|
return (T*)_PointerList_::BinarySearch(&key, (GenericCompareFunction)func);
|
|
|
|
(GenericCompareFunction)func);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
T*
|
|
|
|
T*
|
|
|
|
BObjectList<T>::BinarySearch(const T &key, CompareFunctionWithState func, void *state) const
|
|
|
|
BObjectList<T>::BinarySearch(const T& key, CompareFunctionWithState func,
|
|
|
|
|
|
|
|
void* state) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return (T*)_PointerList_::BinarySearch(&key,
|
|
|
|
return (T*)_PointerList_::BinarySearch(&key,
|
|
|
|
(GenericCompareFunctionWithState)func, state);
|
|
|
|
(GenericCompareFunctionWithState)func, state);
|
|
|
@@ -722,9 +778,11 @@ BObjectList<T>::BinaryInsert(T *item, CompareFunction func)
|
|
|
|
return AddItem(item, -index - 1);
|
|
|
|
return AddItem(item, -index - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
bool
|
|
|
|
bool
|
|
|
|
BObjectList<T>::BinaryInsert(T *item, CompareFunctionWithState func, void *state)
|
|
|
|
BObjectList<T>::BinaryInsert(T* item, CompareFunctionWithState func,
|
|
|
|
|
|
|
|
void* state)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int32 index = _PointerList_::BinarySearchIndex(item,
|
|
|
|
int32 index = _PointerList_::BinarySearchIndex(item,
|
|
|
|
(GenericCompareFunctionWithState)func, state);
|
|
|
|
(GenericCompareFunctionWithState)func, state);
|
|
|
@@ -736,6 +794,7 @@ BObjectList<T>::BinaryInsert(T *item, CompareFunctionWithState func, void *state
|
|
|
|
return AddItem(item, -index - 1);
|
|
|
|
return AddItem(item, -index - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
bool
|
|
|
|
bool
|
|
|
|
BObjectList<T>::BinaryInsertUnique(T* item, CompareFunction func)
|
|
|
|
BObjectList<T>::BinaryInsertUnique(T* item, CompareFunction func)
|
|
|
@@ -748,9 +807,11 @@ BObjectList<T>::BinaryInsertUnique(T *item, CompareFunction func)
|
|
|
|
return AddItem(item, -index - 1);
|
|
|
|
return AddItem(item, -index - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
bool
|
|
|
|
bool
|
|
|
|
BObjectList<T>::BinaryInsertUnique(T *item, CompareFunctionWithState func, void *state)
|
|
|
|
BObjectList<T>::BinaryInsertUnique(T* item, CompareFunctionWithState func,
|
|
|
|
|
|
|
|
void* state)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int32 index = _PointerList_::BinarySearchIndex(item,
|
|
|
|
int32 index = _PointerList_::BinarySearchIndex(item,
|
|
|
|
(GenericCompareFunctionWithState)func, state);
|
|
|
|
(GenericCompareFunctionWithState)func, state);
|
|
|
@@ -773,14 +834,16 @@ BObjectList<T>::BinaryInsertCopy(const T ©This, CompareFunction func)
|
|
|
|
else
|
|
|
|
else
|
|
|
|
index = -index - 1;
|
|
|
|
index = -index - 1;
|
|
|
|
|
|
|
|
|
|
|
|
T *newItem = new T(copyThis);
|
|
|
|
T* newItem = new (std::nothrow) T(copyThis);
|
|
|
|
AddItem(newItem, index);
|
|
|
|
AddItem(newItem, index);
|
|
|
|
return newItem;
|
|
|
|
return newItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
T*
|
|
|
|
T*
|
|
|
|
BObjectList<T>::BinaryInsertCopy(const T ©This, CompareFunctionWithState func, void *state)
|
|
|
|
BObjectList<T>::BinaryInsertCopy(const T& copyThis,
|
|
|
|
|
|
|
|
CompareFunctionWithState func, void* state)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int32 index = _PointerList_::BinarySearchIndex(©This,
|
|
|
|
int32 index = _PointerList_::BinarySearchIndex(©This,
|
|
|
|
(GenericCompareFunctionWithState)func, state);
|
|
|
|
(GenericCompareFunctionWithState)func, state);
|
|
|
@@ -790,11 +853,12 @@ BObjectList<T>::BinaryInsertCopy(const T ©This, CompareFunctionWithState fun
|
|
|
|
else
|
|
|
|
else
|
|
|
|
index = -index - 1;
|
|
|
|
index = -index - 1;
|
|
|
|
|
|
|
|
|
|
|
|
T *newItem = new T(copyThis);
|
|
|
|
T* newItem = new (std::nothrow) T(copyThis);
|
|
|
|
AddItem(newItem, index);
|
|
|
|
AddItem(newItem, index);
|
|
|
|
return newItem;
|
|
|
|
return newItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
T*
|
|
|
|
T*
|
|
|
|
BObjectList<T>::BinaryInsertCopyUnique(const T& copyThis, CompareFunction func)
|
|
|
|
BObjectList<T>::BinaryInsertCopyUnique(const T& copyThis, CompareFunction func)
|
|
|
@@ -805,15 +869,16 @@ BObjectList<T>::BinaryInsertCopyUnique(const T ©This, CompareFunction func)
|
|
|
|
return ItemAt(index);
|
|
|
|
return ItemAt(index);
|
|
|
|
|
|
|
|
|
|
|
|
index = -index - 1;
|
|
|
|
index = -index - 1;
|
|
|
|
T *newItem = new T(copyThis);
|
|
|
|
T* newItem = new (std::nothrow) T(copyThis);
|
|
|
|
AddItem(newItem, index);
|
|
|
|
AddItem(newItem, index);
|
|
|
|
return newItem;
|
|
|
|
return newItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
T*
|
|
|
|
T*
|
|
|
|
BObjectList<T>::BinaryInsertCopyUnique(const T ©This, CompareFunctionWithState func,
|
|
|
|
BObjectList<T>::BinaryInsertCopyUnique(const T& copyThis,
|
|
|
|
void *state)
|
|
|
|
CompareFunctionWithState func, void* state)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int32 index = _PointerList_::BinarySearchIndex(©This,
|
|
|
|
int32 index = _PointerList_::BinarySearchIndex(©This,
|
|
|
|
(GenericCompareFunctionWithState)func, state);
|
|
|
|
(GenericCompareFunctionWithState)func, state);
|
|
|
@@ -821,15 +886,16 @@ BObjectList<T>::BinaryInsertCopyUnique(const T ©This, CompareFunctionWithSta
|
|
|
|
return ItemAt(index);
|
|
|
|
return ItemAt(index);
|
|
|
|
|
|
|
|
|
|
|
|
index = -index - 1;
|
|
|
|
index = -index - 1;
|
|
|
|
T *newItem = new T(copyThis);
|
|
|
|
T* newItem = new (std::nothrow) T(copyThis);
|
|
|
|
AddItem(newItem, index);
|
|
|
|
AddItem(newItem, index);
|
|
|
|
return newItem;
|
|
|
|
return newItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
int32
|
|
|
|
int32
|
|
|
|
BObjectList<T>::FindBinaryInsertionIndex(const UnaryPredicate<T> &pred, bool *alreadyInList)
|
|
|
|
BObjectList<T>::FindBinaryInsertionIndex(const UnaryPredicate<T>& pred,
|
|
|
|
const
|
|
|
|
bool* alreadyInList) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int32 index = _PointerList_::BinarySearchIndexByPredicate(&pred,
|
|
|
|
int32 index = _PointerList_::BinarySearchIndexByPredicate(&pred,
|
|
|
|
(UnaryPredicateGlue)&UnaryPredicate<T>::_unary_predicate_glue);
|
|
|
|
(UnaryPredicateGlue)&UnaryPredicate<T>::_unary_predicate_glue);
|
|
|
@@ -843,6 +909,7 @@ BObjectList<T>::FindBinaryInsertionIndex(const UnaryPredicate<T> &pred, bool *al
|
|
|
|
return index;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
bool
|
|
|
|
bool
|
|
|
|
BObjectList<T>::BinaryInsert(T* item, const UnaryPredicate<T>& pred)
|
|
|
|
BObjectList<T>::BinaryInsert(T* item, const UnaryPredicate<T>& pred)
|
|
|
@@ -850,6 +917,7 @@ BObjectList<T>::BinaryInsert(T *item, const UnaryPredicate<T> &pred)
|
|
|
|
return AddItem(item, FindBinaryInsertionIndex(pred));
|
|
|
|
return AddItem(item, FindBinaryInsertionIndex(pred));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
template<class T>
|
|
|
|
bool
|
|
|
|
bool
|
|
|
|
BObjectList<T>::BinaryInsertUnique(T* item, const UnaryPredicate<T>& pred)
|
|
|
|
BObjectList<T>::BinaryInsertUnique(T* item, const UnaryPredicate<T>& pred)
|
|
|
@@ -863,4 +931,5 @@ BObjectList<T>::BinaryInsertUnique(T *item, const UnaryPredicate<T> &pred)
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* __OBJECT_LIST__ */
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* _OBJECT_LIST_H */
|