diff --git a/headers/private/shared/ObjectList.h b/headers/os/support/ObjectList.h similarity index 53% rename from headers/private/shared/ObjectList.h rename to headers/os/support/ObjectList.h index bfa1832df7..40792297d0 100644 --- a/headers/private/shared/ObjectList.h +++ b/headers/os/support/ObjectList.h @@ -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 + +#include +#include -/**************************************************************************** -** 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 -#endif - -#include - - template class BObjectList; + template struct UnaryPredicate { @@ -81,9 +60,10 @@ struct UnaryPredicate { private: static int _unary_predicate_glue(const void *item, void *context); -friend class BObjectList; + friend class BObjectList; }; + template int UnaryPredicate::_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,221 +107,260 @@ protected: }; + template class BObjectList : private _PointerList_ { public: // iteration and sorting - 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 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); - BObjectList(int32 itemsPerBlock = 20, bool owning = false); - BObjectList(const BObjectList &list); - // clones list; if list is owning, makes copies of all - // the items + BObjectList(int32 itemsPerBlock = 20, + bool owning = false); + BObjectList(const BObjectList& list); + // clones list; if list is owning, makes + // copies of all the items - virtual ~BObjectList(); + virtual ~BObjectList(); - BObjectList &operator=(const BObjectList &list); - // clones list; if list is owning, makes copies of all - // the items + BObjectList& operator=(const BObjectList& list); + // 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 *); - bool AddList(BObjectList *, int32); + // adding and removing + bool AddItem(T*); + bool AddItem(T*, int32); + bool AddList(BObjectList*); + bool AddList(BObjectList*, int32); - bool RemoveItem(T *, bool deleteIfOwning = true); - // if owning, deletes the removed item - T *RemoveItemAt(int32); - // returns the removed item + bool RemoveItem(T*, bool deleteIfOwning = true); + // if owning, deletes the removed item + T* RemoveItemAt(int32); + // returns the removed item - void MakeEmpty(bool deleteIfOwning = true); + void MakeEmpty(bool deleteIfOwning = true); - // item access - T *ItemAt(int32) const; + // item access + T* ItemAt(int32) const; - bool ReplaceItem(int32 index, T *); - // if list is owning, deletes the item at first - T *SwapWithItem(int32 index, T *newItem); - // same as ReplaceItem, except does not delete old item at , - // returns it instead + bool ReplaceItem(int32 index, T*); + // if list is owning, deletes the item + // at first + T* SwapWithItem(int32 index, T* newItem); + // same as ReplaceItem, except does not + // delete old item at , returns it + // instead - T *FirstItem() const; - T *LastItem() const; + T* FirstItem() const; + T* LastItem() const; - // misc. getters - int32 IndexOf(const T *) const; - bool HasItem(const T *) const; - bool IsEmpty() const; - int32 CountItems() const; + // misc. getters + int32 IndexOf(const T*) const; + bool HasItem(const T*) const; + bool IsEmpty() const; + int32 CountItems() const; - T *EachElement(EachFunction, void *); - const T *EachElement(ConstEachFunction, void *) const; + T* EachElement(EachFunction, void*); + const T* EachElement(ConstEachFunction, void*) const; - void SortItems(CompareFunction); - void SortItems(CompareFunctionWithState, void *state); - void HSortItems(CompareFunction); - void HSortItems(CompareFunctionWithState, void *state); + void SortItems(CompareFunction); + void SortItems(CompareFunctionWithState, + void* state); + void HSortItems(CompareFunction); + void HSortItems(CompareFunctionWithState, + void* state); - // linear search, returns first item that matches predicate - const T *FindIf(const UnaryPredicate &) const; - T *FindIf(const UnaryPredicate &); + // linear search, returns first item that + // matches predicate + const T* FindIf(const UnaryPredicate&) const; + T* FindIf(const UnaryPredicate&); - // list must be sorted with CompareFunction for these to work - T *BinarySearch(const T &, CompareFunction) const; - T *BinarySearch(const T &, CompareFunctionWithState, void *state) const; + // 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 - T *BinarySearchByKey(const Key &key, int (*compare)(const Key *, const T *)) - const; + template + T* BinarySearchByKey(const Key& key, + int (*compare)(const Key*, const T*)) const; - template - T *BinarySearchByKey(const Key &key, - int (*compare)(const Key *, const T *, void *), void *state) const; + template + 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; + int32 BinarySearchIndex(const T&item, + CompareFunction compare) const; + int32 BinarySearchIndex(const T&item, + CompareFunctionWithState compare, + void* state) const; - template - int32 BinarySearchIndexByKey(const Key &key, - int (*compare)(const Key *, const T *)) const; + template + 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 *, const UnaryPredicate &); + // simple insert + bool BinaryInsert(T*, CompareFunction); + bool BinaryInsert(T*, CompareFunctionWithState, + void* state); + bool BinaryInsert(T*, const UnaryPredicate&); - // unique insert, returns false if item already in list - bool BinaryInsertUnique(T *, CompareFunction); - bool BinaryInsertUnique(T *, CompareFunctionWithState, void *state); - bool BinaryInsertUnique(T *, const UnaryPredicate &); + // unique insert, returns false if item already + // in list + bool BinaryInsertUnique(T*, CompareFunction); + bool BinaryInsertUnique(T*, CompareFunctionWithState, + void* state); + bool BinaryInsertUnique(T*, + const UnaryPredicate&); - // insert a copy of the item, returns new inserted item - T *BinaryInsertCopy(const T ©This, CompareFunction); - T *BinaryInsertCopy(const T ©This, 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 ©This, CompareFunction); - T *BinaryInsertCopyUnique(const T ©This, 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 &, 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&, + 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 Result -WhileEachListItem(BObjectList *list, Result (Item::*func)(Param1), Param1 p1) +WhileEachListItem(BObjectList* 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 Result -WhileEachListItem(BObjectList *list, Result (*func)(Item *, Param1), Param1 p1) +WhileEachListItem(BObjectList* 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 Result -WhileEachListItem(BObjectList *list, Result (Item::*func)(Param1, Param2), +WhileEachListItem(BObjectList* list, Result (Item::*func)(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 = (list->ItemAt(index)->*func)(p1, p2)) != 0) break; + } return result; } + template Result -WhileEachListItem(BObjectList *list, Result (*func)(Item *, Param1, Param2), - Param1 p1, Param2 p2) +WhileEachListItem(BObjectList* 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 + +template Result -WhileEachListItem(BObjectList *list, Result (*func)(Item *, Param1, Param2, - Param3, Param4), Param1 p1, Param2 p2, Param3 p3, Param4 p4) +WhileEachListItem(BObjectList* 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 void -EachListItemIgnoreResult(BObjectList *list, Result (Item::*func)()) +EachListItemIgnoreResult(BObjectList* list, Result (Item::*func)()) { int32 count = list->CountItems(); for (int32 index = 0; index < count; index++) (list->ItemAt(index)->*func)(); } + template void -EachListItem(BObjectList *list, void (*func)(Item *, Param1), Param1 p1) +EachListItem(BObjectList* list, void (*func)(Item*, Param1), Param1 p1) { int32 count = list->CountItems(); for (int32 index = 0; index < count; index++) (func)(list->ItemAt(index), p1); } + template void -EachListItem(BObjectList *list, void (Item::*func)(Param1, Param2), +EachListItem(BObjectList* list, void (Item::*func)(Param1, Param2), Param1 p1, Param2 p2) { int32 count = list->CountItems(); @@ -347,9 +368,10 @@ EachListItem(BObjectList *list, void (Item::*func)(Param1, Param2), (list->ItemAt(index)->*func)(p1, p2); } + template void -EachListItem(BObjectList *list, void (*func)(Item *,Param1, Param2), +EachListItem(BObjectList* list, void (*func)(Item*,Param1, Param2), Param1 p1, Param2 p2) { int32 count = list->CountItems(); @@ -357,10 +379,11 @@ EachListItem(BObjectList *list, void (*func)(Item *,Param1, Param2), (func)(list->ItemAt(index), p1, p2); } + template void -EachListItem(BObjectList *list, void (*func)(Item *,Param1, Param2, - Param3), Param1 p1, Param2 p2, Param3 p3) +EachListItem(BObjectList* 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,97 +393,111 @@ EachListItem(BObjectList *list, void (*func)(Item *,Param1, Param2, template void -EachListItem(BObjectList *list, void (*func)(Item *,Param1, Param2, - Param3, Param4), Param1 p1, Param2 p2, Param3 p3, Param4 p4) +EachListItem(BObjectList* 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 BObjectList::BObjectList(int32 itemsPerBlock, bool owning) - : _PointerList_(itemsPerBlock, owning) + : + _PointerList_(itemsPerBlock, owning) { } + template BObjectList::BObjectList(const BObjectList &list) - : _PointerList_(list) + : + _PointerList_(list) { owning = list.owning; if (owning) { // make our own copies in an owning list int32 count = list.CountItems(); for (int32 index = 0; index < count; index++) { - T *item = list.ItemAt(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 BObjectList::~BObjectList() { - if (Owning()) + if (Owning()) { // have to nuke elements first MakeEmpty(); + } } + template -BObjectList & -BObjectList::operator=(const BObjectList &list) +BObjectList& +BObjectList::operator=(const BObjectList& list) { owning = list.owning; - BObjectList &result = (BObjectList &)_PointerList_::operator=(list); + BObjectList &result = (BObjectList&)_PointerList_::operator=(list); if (owning) { // make our own copies in an owning list int32 count = list.CountItems(); for (int32 index = 0; index < count; index++) { - T *item = list.ItemAt(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 -bool -BObjectList::AddItem(T *item) -{ - // need to cast to void * to make T work for const pointers - return _PointerList_::AddItem((void *)item); -} template bool -BObjectList::AddItem(T *item, int32 atIndex) +BObjectList::AddItem(T* item) { - return _PointerList_::AddItem((void *)item, atIndex); + // need to cast to void* to make T work for const pointers + return _PointerList_::AddItem((void*)item); } + template bool -BObjectList::AddList(BObjectList *newItems) +BObjectList::AddItem(T* item, int32 atIndex) +{ + return _PointerList_::AddItem((void*)item, atIndex); +} + + +template +bool +BObjectList::AddList(BObjectList* newItems) { return _PointerList_::AddList(newItems); } + template bool -BObjectList::AddList(BObjectList *newItems, int32 atIndex) +BObjectList::AddList(BObjectList* newItems, int32 atIndex) { return _PointerList_::AddList(newItems, atIndex); } @@ -468,9 +505,9 @@ BObjectList::AddList(BObjectList *newItems, int32 atIndex) template bool -BObjectList::RemoveItem(T *item, bool deleteIfOwning) +BObjectList::RemoveItem(T* item, bool deleteIfOwning) { - bool result = _PointerList_::RemoveItem((void *)item); + bool result = _PointerList_::RemoveItem((void*)item); if (result && Owning() && deleteIfOwning) delete item; @@ -478,73 +515,83 @@ BObjectList::RemoveItem(T *item, bool deleteIfOwning) return result; } -template -T * -BObjectList::RemoveItemAt(int32 index) -{ - return (T *)_PointerList_::RemoveItem(index); -} template -inline T * +T* +BObjectList::RemoveItemAt(int32 index) +{ + return (T*)_PointerList_::RemoveItem(index); +} + + +template +inline T* BObjectList::ItemAt(int32 index) const { - return (T *)_PointerList_::ItemAt(index); + return (T*)_PointerList_::ItemAt(index); } + template bool -BObjectList::ReplaceItem(int32 index, T *item) +BObjectList::ReplaceItem(int32 index, T* item) { if (owning) delete ItemAt(index); - return _PointerList_::ReplaceItem(index, (void *)item); + return _PointerList_::ReplaceItem(index, (void*)item); } + template -T * -BObjectList::SwapWithItem(int32 index, T *newItem) +T* +BObjectList::SwapWithItem(int32 index, T* newItem) { - T *result = ItemAt(index); - _PointerList_::ReplaceItem(index, (void *)newItem); + T* result = ItemAt(index); + _PointerList_::ReplaceItem(index, (void*)newItem); return result; } + template void -BObjectList::SetItem(int32 index, T *newItem) +BObjectList::_SetItem(int32 index, T* newItem) { - _PointerList_::ReplaceItem(index, (void *)newItem); + _PointerList_::ReplaceItem(index, (void*)newItem); } + template int32 -BObjectList::IndexOf(const T *item) const +BObjectList::IndexOf(const T* item) const { - return _PointerList_::IndexOf((void *)item); + return _PointerList_::IndexOf((void*)item); } + template -T * +T* BObjectList::FirstItem() const { - return (T *)_PointerList_::FirstItem(); + return (T*)_PointerList_::FirstItem(); } + template -T * +T* BObjectList::LastItem() const { - return (T *)_PointerList_::LastItem(); + return (T*)_PointerList_::LastItem(); } + template bool -BObjectList::HasItem(const T *item) const +BObjectList::HasItem(const T* item) const { - return _PointerList_::HasItem((void *)item); + return _PointerList_::HasItem((void*)item); } + template bool BObjectList::IsEmpty() const @@ -552,6 +599,7 @@ BObjectList::IsEmpty() const return _PointerList_::IsEmpty(); } + template int32 BObjectList::CountItems() const @@ -559,6 +607,7 @@ BObjectList::CountItems() const return _PointerList_::CountItems(); } + template void BObjectList::MakeEmpty(bool deleteIfOwning) @@ -571,42 +620,45 @@ BObjectList::MakeEmpty(bool deleteIfOwning) _PointerList_::MakeEmpty(); } + template -T * -BObjectList::EachElement(EachFunction func, void *params) +T* +BObjectList::EachElement(EachFunction func, void* params) { - return (T *)_PointerList_::EachElement((GenericEachFunction)func, params); + return (T*)_PointerList_::EachElement((GenericEachFunction)func, params); } template -const T * -BObjectList::EachElement(ConstEachFunction func, void *params) const +const T* +BObjectList::EachElement(ConstEachFunction func, void* params) const { - return (const T *) - const_cast *>(this)->_PointerList_::EachElement( - (GenericEachFunction)func, params); + return (const T*) + const_cast*>(this)->_PointerList_::EachElement( + (GenericEachFunction)func, params); } template -const T * -BObjectList::FindIf(const UnaryPredicate &predicate) const +const T* +BObjectList::FindIf(const UnaryPredicate& 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; } template -T * -BObjectList::FindIf(const UnaryPredicate &predicate) +T* +BObjectList::FindIf(const UnaryPredicate& 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,13 +670,15 @@ BObjectList::SortItems(CompareFunction function) _PointerList_::SortItems((GenericCompareFunction)function); } + template void -BObjectList::SortItems(CompareFunctionWithState function, void *state) +BObjectList::SortItems(CompareFunctionWithState function, void* state) { _PointerList_::SortItems((GenericCompareFunctionWithState)function, state); } + template void BObjectList::HSortItems(CompareFunction function) @@ -632,24 +686,26 @@ BObjectList::HSortItems(CompareFunction function) _PointerList_::HSortItems((GenericCompareFunction)function); } + template void -BObjectList::HSortItems(CompareFunctionWithState function, void *state) +BObjectList::HSortItems(CompareFunctionWithState function, void* state) { _PointerList_::HSortItems((GenericCompareFunctionWithState)function, state); } + template -T * -BObjectList::BinarySearch(const T &key, CompareFunction func) const +T* +BObjectList::BinarySearch(const T& key, CompareFunction func) const { - return (T*)_PointerList_::BinarySearch(&key, - (GenericCompareFunction)func); + return (T*)_PointerList_::BinarySearch(&key, (GenericCompareFunction)func); } template -T * -BObjectList::BinarySearch(const T &key, CompareFunctionWithState func, void *state) const +T* +BObjectList::BinarySearch(const T& key, CompareFunctionWithState func, + void* state) const { return (T*)_PointerList_::BinarySearch(&key, (GenericCompareFunctionWithState)func, state); @@ -658,9 +714,9 @@ BObjectList::BinarySearch(const T &key, CompareFunctionWithState func, void * template template -T * -BObjectList::BinarySearchByKey(const Key &key, - int (*compare)(const Key *, const T *)) const +T* +BObjectList::BinarySearchByKey(const Key& key, + int (*compare)(const Key*, const T*)) const { return (T*)_PointerList_::BinarySearch(&key, (GenericCompareFunction)compare); @@ -669,9 +725,9 @@ BObjectList::BinarySearchByKey(const Key &key, template template -T * +T* BObjectList::BinarySearchByKey(const Key &key, - int (*compare)(const Key *, const T *, void *), void *state) const + int (*compare)(const Key*, const T*, void*), void* state) const { return (T*)_PointerList_::BinarySearch(&key, (GenericCompareFunctionWithState)compare, state); @@ -680,7 +736,7 @@ BObjectList::BinarySearchByKey(const Key &key, template int32 -BObjectList::BinarySearchIndex(const T &item, CompareFunction compare) const +BObjectList::BinarySearchIndex(const T& item, CompareFunction compare) const { return _PointerList_::BinarySearchIndex(&item, (GenericCompareFunction)compare); @@ -689,8 +745,8 @@ BObjectList::BinarySearchIndex(const T &item, CompareFunction compare) const template int32 -BObjectList::BinarySearchIndex(const T &item, - CompareFunctionWithState compare, void *state) const +BObjectList::BinarySearchIndex(const T& item, + CompareFunctionWithState compare, void* state) const { return _PointerList_::BinarySearchIndex(&item, (GenericCompareFunctionWithState)compare, state); @@ -700,8 +756,8 @@ BObjectList::BinarySearchIndex(const T &item, template template int32 -BObjectList::BinarySearchIndexByKey(const Key &key, - int (*compare)(const Key *, const T *)) const +BObjectList::BinarySearchIndexByKey(const Key& key, + int (*compare)(const Key*, const T*)) const { return _PointerList_::BinarySearchIndex(&key, (GenericCompareFunction)compare); @@ -710,7 +766,7 @@ BObjectList::BinarySearchIndexByKey(const Key &key, template bool -BObjectList::BinaryInsert(T *item, CompareFunction func) +BObjectList::BinaryInsert(T* item, CompareFunction func) { int32 index = _PointerList_::BinarySearchIndex(item, (GenericCompareFunction)func); @@ -722,9 +778,11 @@ BObjectList::BinaryInsert(T *item, CompareFunction func) return AddItem(item, -index - 1); } + template bool -BObjectList::BinaryInsert(T *item, CompareFunctionWithState func, void *state) +BObjectList::BinaryInsert(T* item, CompareFunctionWithState func, + void* state) { int32 index = _PointerList_::BinarySearchIndex(item, (GenericCompareFunctionWithState)func, state); @@ -736,9 +794,10 @@ BObjectList::BinaryInsert(T *item, CompareFunctionWithState func, void *state return AddItem(item, -index - 1); } + template bool -BObjectList::BinaryInsertUnique(T *item, CompareFunction func) +BObjectList::BinaryInsertUnique(T* item, CompareFunction func) { int32 index = _PointerList_::BinarySearchIndex(item, (GenericCompareFunction)func); @@ -748,9 +807,11 @@ BObjectList::BinaryInsertUnique(T *item, CompareFunction func) return AddItem(item, -index - 1); } + template bool -BObjectList::BinaryInsertUnique(T *item, CompareFunctionWithState func, void *state) +BObjectList::BinaryInsertUnique(T* item, CompareFunctionWithState func, + void* state) { int32 index = _PointerList_::BinarySearchIndex(item, (GenericCompareFunctionWithState)func, state); @@ -762,8 +823,8 @@ BObjectList::BinaryInsertUnique(T *item, CompareFunctionWithState func, void template -T * -BObjectList::BinaryInsertCopy(const T ©This, CompareFunction func) +T* +BObjectList::BinaryInsertCopy(const T& copyThis, CompareFunction func) { int32 index = _PointerList_::BinarySearchIndex(©This, (GenericCompareFunction)func); @@ -773,14 +834,16 @@ BObjectList::BinaryInsertCopy(const T ©This, CompareFunction func) else index = -index - 1; - T *newItem = new T(copyThis); + T* newItem = new (std::nothrow) T(copyThis); AddItem(newItem, index); return newItem; } + template -T * -BObjectList::BinaryInsertCopy(const T ©This, CompareFunctionWithState func, void *state) +T* +BObjectList::BinaryInsertCopy(const T& copyThis, + CompareFunctionWithState func, void* state) { int32 index = _PointerList_::BinarySearchIndex(©This, (GenericCompareFunctionWithState)func, state); @@ -790,14 +853,15 @@ BObjectList::BinaryInsertCopy(const T ©This, CompareFunctionWithState fun else index = -index - 1; - T *newItem = new T(copyThis); + T* newItem = new (std::nothrow) T(copyThis); AddItem(newItem, index); return newItem; } + template -T * -BObjectList::BinaryInsertCopyUnique(const T ©This, CompareFunction func) +T* +BObjectList::BinaryInsertCopyUnique(const T& copyThis, CompareFunction func) { int32 index = _PointerList_::BinarySearchIndex(©This, (GenericCompareFunction)func); @@ -805,15 +869,16 @@ BObjectList::BinaryInsertCopyUnique(const T ©This, 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 -T * -BObjectList::BinaryInsertCopyUnique(const T ©This, CompareFunctionWithState func, - void *state) +T* +BObjectList::BinaryInsertCopyUnique(const T& copyThis, + CompareFunctionWithState func, void* state) { int32 index = _PointerList_::BinarySearchIndex(©This, (GenericCompareFunctionWithState)func, state); @@ -821,15 +886,16 @@ BObjectList::BinaryInsertCopyUnique(const T ©This, 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 int32 -BObjectList::FindBinaryInsertionIndex(const UnaryPredicate &pred, bool *alreadyInList) - const +BObjectList::FindBinaryInsertionIndex(const UnaryPredicate& pred, + bool* alreadyInList) const { int32 index = _PointerList_::BinarySearchIndexByPredicate(&pred, (UnaryPredicateGlue)&UnaryPredicate::_unary_predicate_glue); @@ -843,16 +909,18 @@ BObjectList::FindBinaryInsertionIndex(const UnaryPredicate &pred, bool *al return index; } + template bool -BObjectList::BinaryInsert(T *item, const UnaryPredicate &pred) +BObjectList::BinaryInsert(T* item, const UnaryPredicate& pred) { return AddItem(item, FindBinaryInsertionIndex(pred)); } + template bool -BObjectList::BinaryInsertUnique(T *item, const UnaryPredicate &pred) +BObjectList::BinaryInsertUnique(T* item, const UnaryPredicate& pred) { bool alreadyInList; int32 index = FindBinaryInsertionIndex(pred, &alreadyInList); @@ -863,4 +931,5 @@ BObjectList::BinaryInsertUnique(T *item, const UnaryPredicate &pred) return true; } -#endif /* __OBJECT_LIST__ */ + +#endif /* _OBJECT_LIST_H */ diff --git a/headers/private/support/ObjectListPrivate.h b/headers/private/support/ObjectListPrivate.h new file mode 100644 index 0000000000..017c033f42 --- /dev/null +++ b/headers/private/support/ObjectListPrivate.h @@ -0,0 +1,38 @@ +/* + * Copyright 2011, Oliver Tappe + * Distributed under the terms of the MIT License. + */ +#ifndef _OBJECT_LIST_PRIVATE_H +#define _OBJECT_LIST_PRIVATE_H + + +#include + + +template +class BObjectList::Private { +public: + Private(BObjectList* objectList) + : + fObjectList(objectList) + { + } + + BList* + AsBList() + { + return fObjectList; + } + + const BList* + AsBList() const + { + return fObjectList; + } + +private: + BObjectList* fObjectList; +}; + + +#endif // _OBJECT_LIST_PRIVATE_H diff --git a/src/kits/interface/ColumnListView.cpp b/src/kits/interface/ColumnListView.cpp index 5cfbf005d6..0b034f1a74 100644 --- a/src/kits/interface/ColumnListView.cpp +++ b/src/kits/interface/ColumnListView.cpp @@ -64,6 +64,8 @@ All rights reserved. #include #include +#include + #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::Private(list).AsBList()->Items(); int32 numItems = list->CountItems(); int h; for (h = 1; h < numItems / 9; h = 3 * h + 1) diff --git a/src/kits/interface/Jamfile b/src/kits/interface/Jamfile index 23ffe4b206..47ac826e29 100644 --- a/src/kits/interface/Jamfile +++ b/src/kits/interface/Jamfile @@ -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 ] ; diff --git a/src/kits/tracker/Jamfile b/src/kits/tracker/Jamfile index 8caeec3919..308aa74da2 100644 --- a/src/kits/tracker/Jamfile +++ b/src/kits/tracker/Jamfile @@ -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 ; diff --git a/src/kits/tracker/PoseView.cpp b/src/kits/tracker/PoseView.cpp index 2aabf60fb5..9052fc907b 100644 --- a/src/kits/tracker/PoseView.cpp +++ b/src/kits/tracker/PoseView.cpp @@ -68,6 +68,8 @@ All rights reserved. #include #include +#include + #include "Attributes.h" #include "AttributeStream.h" #include "AutoLock.h" @@ -8743,7 +8745,7 @@ PoseCompareAddWidgetBinder(const BPose *p1, const BPose *p2, void *castToPoseVie } -struct PoseComparator : public std::binary_function { PoseComparator(BPoseView *poseView): fPoseView(poseView) { } @@ -8752,7 +8754,7 @@ struct PoseComparator : public std::binary_function(fPoseList->AsBList()->Items()); + BPose **poses = reinterpret_cast( + PoseList::Private(fPoseList).AsBList()->Items()); std::stable_sort(poses, &poses[fPoseList->CountItems()], PoseComparator(this)); if (fFiltering) { - poses = reinterpret_cast(fFilteredPoseList->AsBList()->Items()); - std::stable_sort(poses, &poses[fPoseList->CountItems()], + poses = reinterpret_cast( + PoseList::Private(fFilteredPoseList).AsBList()->Items()); + std::stable_sort(poses, &poses[fPoseList->CountItems()], PoseComparator(this)); } } diff --git a/src/servers/app/Jamfile b/src/servers/app/Jamfile index e7d1963085..0eca58afa8 100644 --- a/src/servers/app/Jamfile +++ b/src/servers/app/Jamfile @@ -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 ] ; diff --git a/src/servers/app/ServerPicture.cpp b/src/servers/app/ServerPicture.cpp index e0c19837c3..72d81f27c9 100644 --- a/src/servers/app/ServerPicture.cpp +++ b/src/servers/app/ServerPicture.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -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(kTableEntries), sizeof(kTableEntries) / sizeof(void*), view); } diff --git a/src/servers/input/InputServer.cpp b/src/servers/input/InputServer.cpp index 247144cff9..a2f87e2f4f 100644 --- a/src/servers/input/InputServer.cpp +++ b/src/servers/input/InputServer.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -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); diff --git a/src/servers/input/Jamfile b/src/servers/input/Jamfile index af9dde5cae..37737970fd 100644 --- a/src/servers/input/Jamfile +++ b/src/servers/input/Jamfile @@ -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 {