2007-01-26 19:36:29 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2001-2007, Haiku, Inc. All Rights Reserved.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2002-12-06 17:24:06 +03:00
|
|
|
#ifndef _BE_LIST_H
|
|
|
|
#define _BE_LIST_H
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2007-01-26 19:36:29 +03:00
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
#include <SupportDefs.h>
|
|
|
|
|
2007-01-26 19:36:29 +03:00
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
class BList {
|
2007-01-26 19:36:29 +03:00
|
|
|
public:
|
|
|
|
BList(int32 count = 20);
|
|
|
|
BList(const BList& anotherList);
|
|
|
|
virtual ~BList();
|
|
|
|
|
|
|
|
BList& operator =(const BList &);
|
|
|
|
|
|
|
|
/* Adding and removing items. */
|
|
|
|
bool AddItem(void* item, int32 index);
|
|
|
|
bool AddItem(void* item);
|
|
|
|
bool AddList(const BList* list, int32 index);
|
|
|
|
bool AddList(const BList* list);
|
|
|
|
bool RemoveItem(void* item);
|
|
|
|
void* RemoveItem(int32 index);
|
|
|
|
bool RemoveItems(int32 index, int32 count);
|
|
|
|
bool ReplaceItem(int32 index, void* newItem);
|
|
|
|
void MakeEmpty();
|
|
|
|
|
|
|
|
// Reorder items
|
|
|
|
void SortItems(int (*compareFunc)(const void*, const void*));
|
|
|
|
bool SwapItems(int32 indexA, int32 indexB);
|
|
|
|
bool MoveItem(int32 fromIndex, int32 toIndex);
|
|
|
|
|
|
|
|
// Retrieve items
|
|
|
|
void* ItemAt(int32 index) const;
|
|
|
|
void* FirstItem() const;
|
|
|
|
void* ItemAtFast(int32) const;
|
|
|
|
// does not check the array bounds!
|
2002-12-06 17:24:06 +03:00
|
|
|
|
2007-01-26 19:36:29 +03:00
|
|
|
void* LastItem() const;
|
|
|
|
void* Items() const;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2007-01-26 19:36:29 +03:00
|
|
|
// Query
|
|
|
|
bool HasItem(void* item) const;
|
|
|
|
int32 IndexOf(void* item) const;
|
|
|
|
int32 CountItems() const;
|
|
|
|
bool IsEmpty() const;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2007-01-26 19:36:29 +03:00
|
|
|
// Iteration
|
|
|
|
void DoForEach(bool (*func)(void* item));
|
|
|
|
void DoForEach(bool (*func)(void* item, void* arg2), void *arg2);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2007-01-26 19:36:29 +03:00
|
|
|
private:
|
|
|
|
virtual void _ReservedList1();
|
|
|
|
virtual void _ReservedList2();
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2007-01-26 19:36:29 +03:00
|
|
|
bool Resize(int32 count);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2007-01-26 19:36:29 +03:00
|
|
|
private:
|
|
|
|
void** fObjectList;
|
|
|
|
size_t fPhysicalSize;
|
|
|
|
int32 fItemCount;
|
|
|
|
int32 fBlockSize;
|
|
|
|
uint32 _reserved[2];
|
2002-07-09 16:24:59 +04:00
|
|
|
};
|
|
|
|
|
2002-12-06 17:24:06 +03:00
|
|
|
#endif // _BE_LIST_H
|