1/*
2 * Copyright 2001-2009 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _BE_LIST_H
6#define _BE_LIST_H
7
8
9#include <SupportDefs.h>
10
11
12class BList {
13public:
14								BList(int32 count = 20);
15								BList(const BList& other);
16	virtual						~BList();
17
18			BList&				operator=(const BList& other);
19			bool				operator==(const BList& other) const;
20			bool				operator!=(const BList& other) const;
21
22	// Adding and removing items
23			bool				AddItem(void* item, int32 index);
24			bool				AddItem(void* item);
25			bool				AddList(const BList* list, int32 index);
26			bool				AddList(const BList* list);
27
28			bool				RemoveItem(void* item);
29			void*				RemoveItem(int32 index);
30			bool				RemoveItems(int32 index, int32 count);
31			bool				ReplaceItem(int32 index, void* item);
32
33			void				MakeEmpty();
34
35	// Reorder items
36			void				SortItems(int (*compareFunc)(const void*,
37									const void*));
38			bool				SwapItems(int32 indexA, int32 indexB);
39			bool				MoveItem(int32 from, int32 to);
40
41	// Retrieve items
42			void*				ItemAt(int32 index) const;
43			void*				FirstItem() const;
44			void*				ItemAtFast(int32 index) const;
45									// does not check the array bounds!
46
47			void*				LastItem() const;
48			void*				Items() const;
49
50	// Query
51			bool				HasItem(void* item) const;
52			bool				HasItem(const void* item) const;
53			int32				IndexOf(void* item) const;
54			int32				IndexOf(const void* item) const;
55			int32				CountItems() const;
56			bool				IsEmpty() const;
57
58	// Iteration
59			void				DoForEach(bool (*func)(void* item));
60			void				DoForEach(bool (*func)(void* item,
61									void* arg2), void* arg2);
62
63private:
64	virtual	void				_ReservedList1();
65	virtual	void				_ReservedList2();
66
67			bool				_ResizeArray(int32 count);
68
69private:
70			void**				fObjectList;
71			int32				fPhysicalSize;
72			int32				fItemCount;
73			int32				fBlockSize;
74			int32				fResizeThreshold;
75
76			uint32				_reserved[1];
77};
78
79
80#endif // _BE_LIST_H
81