Make BObjectList<> publically available:

* cleaned up ObjectList.h
* switched several uses of new() to new(std::nothrow)
* moved ugly AsBList() hack into BObjectList<>::Private class and
  adjusted all callers accordingly


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40252 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Tappe
2011-01-20 12:09:16 +00:00
parent 260f2d0994
commit 915a7b8c24
10 changed files with 373 additions and 257 deletions
@@ -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.
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,
// 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>
struct UnaryPredicate {
@@ -84,6 +63,7 @@ private:
friend class BObjectList<T>;
};
template<class T>
int
UnaryPredicate<T>::_unary_predicate_glue(const void *item, void *context)
@@ -111,10 +91,12 @@ public:
void HSortItems(GenericCompareFunctionWithState, void *state);
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 *, GenericCompareFunctionWithState, void *state) const;
int32 BinarySearchIndex(const void *, GenericCompareFunctionWithState,
void *state) const;
int32 BinarySearchIndexByPredicate(const void *, UnaryPredicateGlue) const;
bool Owning() const;
@@ -125,6 +107,7 @@ protected:
};
template<class T>
class BObjectList : private _PointerList_ {
public:
@@ -133,22 +116,22 @@ public:
typedef T* (*EachFunction)(T*, void*);
typedef const T* (*ConstEachFunction)(const T*, void*);
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);
// clones list; if list is owning, makes copies of all
// the items
// clones list; if list is owning, makes
// copies of all the items
virtual ~BObjectList();
BObjectList& operator=(const BObjectList& list);
// clones list; if list is owning, makes copies of all
// the items
// clones list; if list is owning, makes
// copies of all the items
// adding and removing
// ToDo:
// change Add calls to return const item
bool AddItem(T*);
bool AddItem(T*, int32);
bool AddList(BObjectList*);
@@ -165,10 +148,12 @@ public:
T* ItemAt(int32) const;
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);
// same as ReplaceItem, except does not delete old item at <index>,
// returns it instead
// same as ReplaceItem, except does not
// delete old item at <index>, returns it
// instead
T* FirstItem() const;
T* LastItem() const;
@@ -183,97 +168,123 @@ public:
const T* EachElement(ConstEachFunction, void*) const;
void SortItems(CompareFunction);
void SortItems(CompareFunctionWithState, void *state);
void SortItems(CompareFunctionWithState,
void* state);
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;
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 &, CompareFunctionWithState, void *state) const;
template<typename Key>
T *BinarySearchByKey(const Key &key, int (*compare)(const Key *, const T *))
const;
T* BinarySearch(const T&, CompareFunctionWithState,
void* state) const;
template<typename 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;
int32 BinarySearchIndex(const T &item, CompareFunctionWithState compare,
template<typename Key>
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;
template<typename Key>
int32 BinarySearchIndexByKey(const Key& key,
int (*compare)(const Key*, const T*)) const;
// Binary insertion - list must be sorted with CompareFunction for
// these to work
// Binary insertion - list must be sorted with
// CompareFunction for these to work
// simple insert
bool BinaryInsert(T*, CompareFunction);
bool BinaryInsert(T *, CompareFunctionWithState, void *state);
bool BinaryInsert(T*, CompareFunctionWithState,
void* state);
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 *, CompareFunctionWithState, void *state);
bool BinaryInsertUnique(T *, const UnaryPredicate<T> &);
bool BinaryInsertUnique(T*, CompareFunctionWithState,
void* state);
bool BinaryInsertUnique(T*,
const UnaryPredicate<T>&);
// insert a copy of the item, returns new inserted item
T *BinaryInsertCopy(const T &copyThis, CompareFunction);
T *BinaryInsertCopy(const T &copyThis, CompareFunctionWithState, void *state);
// insert a copy of the item, returns new
// inserted item
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
// returns new inserted item or existing item in case of a conflict
T *BinaryInsertCopyUnique(const T &copyThis, CompareFunction);
T *BinaryInsertCopyUnique(const T &copyThis, CompareFunctionWithState, void *state);
// insert a copy of the item if not in list
// already returns new inserted item or existing
// item in case of a conflict
T* BinaryInsertCopyUnique(const T& copyThis,
CompareFunction);
T* BinaryInsertCopyUnique(const T& copyThis,
CompareFunctionWithState, void* state);
int32 FindBinaryInsertionIndex(const UnaryPredicate<T> &, 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
int32 FindBinaryInsertionIndex(
const UnaryPredicate<T>&,
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
BList *AsBList()
{ return this; }
const BList *AsBList() const
{ return this; }
class Private;
private:
void SetItem(int32, T *);
friend class Private;
void _SetItem(int32, T*);
};
template<class Item, class Result, class Param1>
Result
WhileEachListItem(BObjectList<Item> *list, Result (Item::*func)(Param1), Param1 p1)
WhileEachListItem(BObjectList<Item>* list, Result (Item::*func)(Param1),
Param1 p1)
{
Result result = 0;
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)
break;
}
return result;
}
template<class Item, class Result, class Param1>
Result
WhileEachListItem(BObjectList<Item> *list, Result (*func)(Item *, Param1), Param1 p1)
WhileEachListItem(BObjectList<Item>* list, Result (*func)(Item*, Param1),
Param1 p1)
{
Result result = 0;
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)
break;
}
return result;
}
template<class Item, class Result, class Param1, class Param2>
Result
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;
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)
break;
}
return result;
}
template<class Item, class Result, class Param1, class Param2>
Result
WhileEachListItem(BObjectList<Item> *list, Result (*func)(Item *, Param1, Param2),
Param1 p1, Param2 p2)
WhileEachListItem(BObjectList<Item>* list,
Result (*func)(Item*, Param1, Param2), Param1 p1, Param2 p2)
{
Result result = 0;
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)
break;
}
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
WhileEachListItem(BObjectList<Item> *list, Result (*func)(Item *, Param1, Param2,
Param3, Param4), Param1 p1, Param2 p2, Param3 p3, Param4 p4)
WhileEachListItem(BObjectList<Item>* list,
Result (*func)(Item*, Param1, Param2, Param3, Param4), Param1 p1, Param2 p2,
Param3 p3, Param4 p4)
{
Result result = 0;
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)
break;
}
return result;
}
template<class Item, class Result>
void
EachListItemIgnoreResult(BObjectList<Item>* list, Result (Item::*func)())
@@ -328,6 +347,7 @@ EachListItemIgnoreResult(BObjectList<Item> *list, Result (Item::*func)())
(list->ItemAt(index)->*func)();
}
template<class Item, class Param1>
void
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);
}
template<class Item, class Param1, class Param2>
void
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);
}
template<class Item, class Param1, class Param2>
void
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);
}
template<class Item, class Param1, class Param2, class Param3>
void
EachListItem(BObjectList<Item> *list, void (*func)(Item *,Param1, Param2,
Param3), Param1 p1, Param2 p2, Param3 p3)
EachListItem(BObjectList<Item>* list,
void (*func)(Item*,Param1, Param2, Param3), Param1 p1, Param2 p2, Param3 p3)
{
int32 count = list->CountItems();
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>
void
EachListItem(BObjectList<Item> *list, void (*func)(Item *,Param1, Param2,
Param3, Param4), Param1 p1, Param2 p2, Param3 p3, Param4 p4)
EachListItem(BObjectList<Item>* list,
void (*func)(Item*,Param1, Param2, Param3, Param4), Param1 p1, Param2 p2,
Param3 p3, Param4 p4)
{
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
(func)(list->ItemAt(index), p1, p2, p3, p4);
}
// inline code
inline bool
_PointerList_::Owning() const
{
return owning;
}
template<class T>
BObjectList<T>::BObjectList(int32 itemsPerBlock, bool owning)
: _PointerList_(itemsPerBlock, owning)
:
_PointerList_(itemsPerBlock, owning)
{
}
template<class T>
BObjectList<T>::BObjectList(const BObjectList<T> &list)
: _PointerList_(list)
:
_PointerList_(list)
{
owning = list.owning;
if (owning) {
@@ -403,19 +433,22 @@ BObjectList<T>::BObjectList(const BObjectList<T> &list)
for (int32 index = 0; index < count; index++) {
T* item = list.ItemAt(index);
if (item)
item = new T(*item);
SetItem(index, item);
item = new (std::nothrow) T(*item);
_SetItem(index, item);
}
}
}
template<class T>
BObjectList<T>::~BObjectList()
{
if (Owning())
if (Owning()) {
// have to nuke elements first
MakeEmpty();
}
}
template<class T>
BObjectList<T>&
@@ -429,13 +462,14 @@ BObjectList<T>::operator=(const BObjectList<T> &list)
for (int32 index = 0; index < count; index++) {
T* item = list.ItemAt(index);
if (item)
item = new T(*item);
SetItem(index, item);
item = new (std::nothrow) T(*item);
_SetItem(index, item);
}
}
return result;
}
template<class T>
bool
BObjectList<T>::AddItem(T* item)
@@ -444,6 +478,7 @@ BObjectList<T>::AddItem(T *item)
return _PointerList_::AddItem((void*)item);
}
template<class T>
bool
BObjectList<T>::AddItem(T* item, int32 atIndex)
@@ -451,6 +486,7 @@ BObjectList<T>::AddItem(T *item, int32 atIndex)
return _PointerList_::AddItem((void*)item, atIndex);
}
template<class T>
bool
BObjectList<T>::AddList(BObjectList<T>* newItems)
@@ -458,6 +494,7 @@ BObjectList<T>::AddList(BObjectList<T> *newItems)
return _PointerList_::AddList(newItems);
}
template<class T>
bool
BObjectList<T>::AddList(BObjectList<T>* newItems, int32 atIndex)
@@ -478,6 +515,7 @@ BObjectList<T>::RemoveItem(T *item, bool deleteIfOwning)
return result;
}
template<class T>
T*
BObjectList<T>::RemoveItemAt(int32 index)
@@ -485,6 +523,7 @@ BObjectList<T>::RemoveItemAt(int32 index)
return (T*)_PointerList_::RemoveItem(index);
}
template<class T>
inline T*
BObjectList<T>::ItemAt(int32 index) const
@@ -492,6 +531,7 @@ BObjectList<T>::ItemAt(int32 index) const
return (T*)_PointerList_::ItemAt(index);
}
template<class T>
bool
BObjectList<T>::ReplaceItem(int32 index, T* item)
@@ -501,6 +541,7 @@ BObjectList<T>::ReplaceItem(int32 index, T *item)
return _PointerList_::ReplaceItem(index, (void*)item);
}
template<class T>
T*
BObjectList<T>::SwapWithItem(int32 index, T* newItem)
@@ -510,13 +551,15 @@ BObjectList<T>::SwapWithItem(int32 index, T *newItem)
return result;
}
template<class T>
void
BObjectList<T>::SetItem(int32 index, T *newItem)
BObjectList<T>::_SetItem(int32 index, T* newItem)
{
_PointerList_::ReplaceItem(index, (void*)newItem);
}
template<class T>
int32
BObjectList<T>::IndexOf(const T* item) const
@@ -524,6 +567,7 @@ BObjectList<T>::IndexOf(const T *item) const
return _PointerList_::IndexOf((void*)item);
}
template<class T>
T*
BObjectList<T>::FirstItem() const
@@ -531,6 +575,7 @@ BObjectList<T>::FirstItem() const
return (T*)_PointerList_::FirstItem();
}
template<class T>
T*
BObjectList<T>::LastItem() const
@@ -538,6 +583,7 @@ BObjectList<T>::LastItem() const
return (T*)_PointerList_::LastItem();
}
template<class T>
bool
BObjectList<T>::HasItem(const T* item) const
@@ -545,6 +591,7 @@ BObjectList<T>::HasItem(const T *item) const
return _PointerList_::HasItem((void*)item);
}
template<class T>
bool
BObjectList<T>::IsEmpty() const
@@ -552,6 +599,7 @@ BObjectList<T>::IsEmpty() const
return _PointerList_::IsEmpty();
}
template<class T>
int32
BObjectList<T>::CountItems() const
@@ -559,6 +607,7 @@ BObjectList<T>::CountItems() const
return _PointerList_::CountItems();
}
template<class T>
void
BObjectList<T>::MakeEmpty(bool deleteIfOwning)
@@ -571,6 +620,7 @@ BObjectList<T>::MakeEmpty(bool deleteIfOwning)
_PointerList_::MakeEmpty();
}
template<class T>
T*
BObjectList<T>::EachElement(EachFunction func, void* params)
@@ -593,9 +643,10 @@ const T *
BObjectList<T>::FindIf(const UnaryPredicate<T>& predicate) const
{
int32 count = CountItems();
for (int32 index = 0; index < count; index++)
for (int32 index = 0; index < count; index++) {
if (predicate.operator()(ItemAt(index)) == 0)
return ItemAt(index);
}
return 0;
}
@@ -604,9 +655,10 @@ T *
BObjectList<T>::FindIf(const UnaryPredicate<T>& predicate)
{
int32 count = CountItems();
for (int32 index = 0; index < count; index++)
for (int32 index = 0; index < count; index++) {
if (predicate.operator()(ItemAt(index)) == 0)
return ItemAt(index);
}
return 0;
}
@@ -618,6 +670,7 @@ BObjectList<T>::SortItems(CompareFunction function)
_PointerList_::SortItems((GenericCompareFunction)function);
}
template<class T>
void
BObjectList<T>::SortItems(CompareFunctionWithState function, void* state)
@@ -625,6 +678,7 @@ BObjectList<T>::SortItems(CompareFunctionWithState function, void *state)
_PointerList_::SortItems((GenericCompareFunctionWithState)function, state);
}
template<class T>
void
BObjectList<T>::HSortItems(CompareFunction function)
@@ -632,6 +686,7 @@ BObjectList<T>::HSortItems(CompareFunction function)
_PointerList_::HSortItems((GenericCompareFunction)function);
}
template<class T>
void
BObjectList<T>::HSortItems(CompareFunctionWithState function, void* state)
@@ -639,17 +694,18 @@ BObjectList<T>::HSortItems(CompareFunctionWithState function, void *state)
_PointerList_::HSortItems((GenericCompareFunctionWithState)function, state);
}
template<class T>
T*
BObjectList<T>::BinarySearch(const T& key, CompareFunction func) const
{
return (T*)_PointerList_::BinarySearch(&key,
(GenericCompareFunction)func);
return (T*)_PointerList_::BinarySearch(&key, (GenericCompareFunction)func);
}
template<class 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,
(GenericCompareFunctionWithState)func, state);
@@ -722,9 +778,11 @@ BObjectList<T>::BinaryInsert(T *item, CompareFunction func)
return AddItem(item, -index - 1);
}
template<class T>
bool
BObjectList<T>::BinaryInsert(T *item, CompareFunctionWithState func, void *state)
BObjectList<T>::BinaryInsert(T* item, CompareFunctionWithState func,
void* state)
{
int32 index = _PointerList_::BinarySearchIndex(item,
(GenericCompareFunctionWithState)func, state);
@@ -736,6 +794,7 @@ BObjectList<T>::BinaryInsert(T *item, CompareFunctionWithState func, void *state
return AddItem(item, -index - 1);
}
template<class T>
bool
BObjectList<T>::BinaryInsertUnique(T* item, CompareFunction func)
@@ -748,9 +807,11 @@ BObjectList<T>::BinaryInsertUnique(T *item, CompareFunction func)
return AddItem(item, -index - 1);
}
template<class T>
bool
BObjectList<T>::BinaryInsertUnique(T *item, CompareFunctionWithState func, void *state)
BObjectList<T>::BinaryInsertUnique(T* item, CompareFunctionWithState func,
void* state)
{
int32 index = _PointerList_::BinarySearchIndex(item,
(GenericCompareFunctionWithState)func, state);
@@ -773,14 +834,16 @@ BObjectList<T>::BinaryInsertCopy(const T &copyThis, CompareFunction func)
else
index = -index - 1;
T *newItem = new T(copyThis);
T* newItem = new (std::nothrow) T(copyThis);
AddItem(newItem, index);
return newItem;
}
template<class T>
T*
BObjectList<T>::BinaryInsertCopy(const T &copyThis, CompareFunctionWithState func, void *state)
BObjectList<T>::BinaryInsertCopy(const T& copyThis,
CompareFunctionWithState func, void* state)
{
int32 index = _PointerList_::BinarySearchIndex(&copyThis,
(GenericCompareFunctionWithState)func, state);
@@ -790,11 +853,12 @@ BObjectList<T>::BinaryInsertCopy(const T &copyThis, CompareFunctionWithState fun
else
index = -index - 1;
T *newItem = new T(copyThis);
T* newItem = new (std::nothrow) T(copyThis);
AddItem(newItem, index);
return newItem;
}
template<class T>
T*
BObjectList<T>::BinaryInsertCopyUnique(const T& copyThis, CompareFunction func)
@@ -805,15 +869,16 @@ BObjectList<T>::BinaryInsertCopyUnique(const T &copyThis, CompareFunction func)
return ItemAt(index);
index = -index - 1;
T *newItem = new T(copyThis);
T* newItem = new (std::nothrow) T(copyThis);
AddItem(newItem, index);
return newItem;
}
template<class T>
T*
BObjectList<T>::BinaryInsertCopyUnique(const T &copyThis, CompareFunctionWithState func,
void *state)
BObjectList<T>::BinaryInsertCopyUnique(const T& copyThis,
CompareFunctionWithState func, void* state)
{
int32 index = _PointerList_::BinarySearchIndex(&copyThis,
(GenericCompareFunctionWithState)func, state);
@@ -821,15 +886,16 @@ BObjectList<T>::BinaryInsertCopyUnique(const T &copyThis, CompareFunctionWithSta
return ItemAt(index);
index = -index - 1;
T *newItem = new T(copyThis);
T* newItem = new (std::nothrow) T(copyThis);
AddItem(newItem, index);
return newItem;
}
template<class T>
int32
BObjectList<T>::FindBinaryInsertionIndex(const UnaryPredicate<T> &pred, bool *alreadyInList)
const
BObjectList<T>::FindBinaryInsertionIndex(const UnaryPredicate<T>& pred,
bool* alreadyInList) const
{
int32 index = _PointerList_::BinarySearchIndexByPredicate(&pred,
(UnaryPredicateGlue)&UnaryPredicate<T>::_unary_predicate_glue);
@@ -843,6 +909,7 @@ BObjectList<T>::FindBinaryInsertionIndex(const UnaryPredicate<T> &pred, bool *al
return index;
}
template<class T>
bool
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));
}
template<class T>
bool
BObjectList<T>::BinaryInsertUnique(T* item, const UnaryPredicate<T>& pred)
@@ -863,4 +931,5 @@ BObjectList<T>::BinaryInsertUnique(T *item, const UnaryPredicate<T> &pred)
return true;
}
#endif /* __OBJECT_LIST__ */
#endif /* _OBJECT_LIST_H */
@@ -0,0 +1,38 @@
/*
* Copyright 2011, Oliver Tappe <[email protected]>
* Distributed under the terms of the MIT License.
*/
#ifndef _OBJECT_LIST_PRIVATE_H
#define _OBJECT_LIST_PRIVATE_H
#include <ObjectList.h>
template<class T>
class BObjectList<T>::Private {
public:
Private(BObjectList<T>* objectList)
:
fObjectList(objectList)
{
}
BList*
AsBList()
{
return fObjectList;
}
const BList*
AsBList() const
{
return fObjectList;
}
private:
BObjectList<T>* fObjectList;
};
#endif // _OBJECT_LIST_PRIVATE_H
+4 -1
View File
@@ -64,6 +64,8 @@ All rights reserved.
#include <String.h>
#include <Window.h>
#include <ObjectListPrivate.h>
#include "ColorTools.h"
#include "ObjectList.h"
@@ -4520,7 +4522,8 @@ OutlineView::SortList(BRowContainer* list, bool isVisible)
{
if (list) {
// Shellsort
BRow** items = (BRow**) list->AsBList()->Items();
BRow** items
= (BRow**) BObjectList<BRow>::Private(list).AsBList()->Items();
int32 numItems = list->CountItems();
int h;
for (h = 1; h < numItems / 9; h = 3 * h + 1)
+1 -1
View File
@@ -25,7 +25,7 @@ if ! $(TARGET_PLATFORM_HAIKU_COMPATIBLE) {
SetSubDirSupportedPlatforms haiku libbe_test ;
UseLibraryHeaders agg icon ;
UsePrivateHeaders app input print interface libbe shared tracker ;
UsePrivateHeaders app input print interface libbe shared support tracker ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) textview_support ] ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) layouter ] ;
+1 -1
View File
@@ -3,7 +3,7 @@ SubDir HAIKU_TOP src kits tracker ;
SetSubDirSupportedPlatformsBeOSCompatible ;
AddSubDirSupportedPlatforms libbe_test ;
UsePrivateHeaders interface mount shared storage tracker ;
UsePrivateHeaders interface mount shared storage support tracker ;
UseLibraryHeaders icon ;
+6 -2
View File
@@ -68,6 +68,8 @@ All rights reserved.
#include <Volume.h>
#include <Window.h>
#include <ObjectListPrivate.h>
#include "Attributes.h"
#include "AttributeStream.h"
#include "AutoLock.h"
@@ -8776,10 +8778,12 @@ BPoseView::SortPoses()
PRINT(("===================\n"));
#endif
BPose **poses = reinterpret_cast<BPose **>(fPoseList->AsBList()->Items());
BPose **poses = reinterpret_cast<BPose **>(
PoseList::Private(fPoseList).AsBList()->Items());
std::stable_sort(poses, &poses[fPoseList->CountItems()], PoseComparator(this));
if (fFiltering) {
poses = reinterpret_cast<BPose **>(fFilteredPoseList->AsBList()->Items());
poses = reinterpret_cast<BPose **>(
PoseList::Private(fFilteredPoseList).AsBList()->Items());
std::stable_sort(poses, &poses[fPoseList->CountItems()],
PoseComparator(this));
}
+1 -1
View File
@@ -1,7 +1,7 @@
SubDir HAIKU_TOP src servers app ;
UseLibraryHeaders agg ;
UsePrivateHeaders app graphics input interface kernel shared storage ;
UsePrivateHeaders app graphics input interface kernel shared storage support ;
UseHeaders [ FDirName $(HAIKU_TOP) src servers app drawing ] ;
UseHeaders [ FDirName $(HAIKU_TOP) src servers app drawing Painter ] ;
+2 -1
View File
@@ -25,6 +25,7 @@
#include <LinkReceiver.h>
#include <OffsetFile.h>
#include <ObjectListPrivate.h>
#include <PicturePlayer.h>
#include <PictureProtocol.h>
#include <PortLink.h>
@@ -1071,7 +1072,7 @@ ServerPicture::Play(View* view)
return;
BPrivate::PicturePlayer player(mallocIO->Buffer(),
mallocIO->BufferLength(), fPictures->AsBList());
mallocIO->BufferLength(), PictureList::Private(fPictures).AsBList());
player.Play(const_cast<void**>(kTableEntries),
sizeof(kTableEntries) / sizeof(void*), view);
}
+2 -1
View File
@@ -14,6 +14,7 @@
#include <AppServerLink.h>
#include <MessagePrivate.h>
#include <ObjectListPrivate.h>
#include <Autolock.h>
#include <Deskbar.h>
@@ -1729,7 +1730,7 @@ InputServer::_FilterEvent(BInputServerFilter* filter, EventList& events,
if (result == B_DISPATCH_MESSAGE) {
EventList addedEvents;
addedEvents.AsBList()->AddList(&newEvents);
EventList::Private(&addedEvents).AsBList()->AddList(&newEvents);
_SanitizeEvents(addedEvents);
// add the new events - but don't methodize them again
events.AddList(&addedEvents, index);
+1 -1
View File
@@ -25,7 +25,7 @@ SEARCH on US-International.keymap += [ FDirName $(HAIKU_TOP) src data keymaps ]
AddResources input_server : input_server.rdef ;
UsePrivateHeaders app input interface shared storage ;
UsePrivateHeaders app input interface shared storage support ;
UsePrivateSystemHeaders ;
if $(TARGET_PLATFORM) != haiku {