xref: /haiku/headers/os/support/List.h (revision 4f2fd49bdc6078128b1391191e4edac647044c3d)
1 /*
2  * Copyright 2001-2007, 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 
12 class BList {
13 	public:
14 		BList(int32 count = 20);
15 		BList(const BList& anotherList);
16 		virtual ~BList();
17 
18 		BList& operator =(const BList &);
19 
20 		/* Adding and removing items. */
21 		bool AddItem(void* item, int32 index);
22 		bool AddItem(void* item);
23 		bool AddList(const BList* list, int32 index);
24 		bool AddList(const BList* list);
25 		bool RemoveItem(void* item);
26 		void* RemoveItem(int32 index);
27 		bool RemoveItems(int32 index, int32 count);
28 		bool ReplaceItem(int32 index, void* newItem);
29 		void MakeEmpty();
30 
31 		// Reorder items
32 		void SortItems(int (*compareFunc)(const void*, const void*));
33 		bool SwapItems(int32 indexA, int32 indexB);
34 		bool MoveItem(int32 fromIndex, int32 toIndex);
35 
36 		// Retrieve items
37 		void* ItemAt(int32 index) const;
38 		void* FirstItem() const;
39 		void* ItemAtFast(int32) const;
40 			// does not check the array bounds!
41 
42 		void* LastItem() const;
43 		void* Items() const;
44 
45 		// Query
46 		bool HasItem(void* item) const;
47 		int32 IndexOf(void* item) const;
48 		int32 CountItems() const;
49 		bool IsEmpty() const;
50 
51 		// Iteration
52 		void DoForEach(bool (*func)(void* item));
53 		void DoForEach(bool (*func)(void* item, void* arg2), void *arg2);
54 
55 	private:
56 		virtual void _ReservedList1();
57 		virtual void _ReservedList2();
58 
59 		bool _ResizeArray(int32 count);
60 	private:
61 		void**	fObjectList;
62 		int32	fPhysicalSize;
63 		int32	fItemCount;
64 		int32	fBlockSize;
65 		int32	fResizeThreshold;
66 		uint32	_reserved[1];
67 };
68 
69 #endif // _BE_LIST_H
70