1 //------------------------------------------------------------------------------ 2 // Copyright (c) 2001-2002, OpenBeOS 3 // 4 // Permission is hereby granted, free of charge, to any person obtaining a 5 // copy of this software and associated documentation files (the "Software"), 6 // to deal in the Software without restriction, including without limitation 7 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 // and/or sell copies of the Software, and to permit persons to whom the 9 // Software is furnished to do so, subject to the following conditions: 10 // 11 // The above copyright notice and this permission notice shall be included in 12 // all copies or substantial portions of the Software. 13 // 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 // DEALINGS IN THE SOFTWARE. 21 // 22 // File Name: List.h 23 // Author(s): The Storage kit Team 24 // Description: BList class provides storage for pointers. 25 // Not thread safe.. 26 //------------------------------------------------------------------------------ 27 28 #ifndef _BE_LIST_H 29 #define _BE_LIST_H 30 31 #include <SupportDefs.h> 32 33 /*----- BList class --------------------------------------*/ 34 class BList { 35 36 public: 37 BList(int32 count = 20); 38 BList(const BList& anotherList); 39 virtual ~BList(); 40 41 BList& operator =(const BList &); 42 43 /* Adding and removing items. */ 44 bool AddItem(void *item, int32 index); 45 bool AddItem(void *item); 46 bool AddList(BList *list, int32 index); 47 bool AddList(BList *list); 48 bool RemoveItem(void *item); 49 void *RemoveItem(int32 index); 50 bool RemoveItems(int32 index, int32 count); 51 bool ReplaceItem(int32 index, void *newItem); 52 void MakeEmpty(); 53 54 /* Reordering items. */ 55 void SortItems(int (*compareFunc)(const void *, const void *)); 56 bool SwapItems(int32 indexA, int32 indexB); 57 bool MoveItem(int32 fromIndex, int32 toIndex); 58 59 /* Retrieving items. */ 60 void *ItemAt(int32 index) const; 61 void *FirstItem() const; 62 63 /* Be careful when using this function, since it doesn't */ 64 /* check if the index you pass is valid, and can lead to */ 65 /* unexpected results when it isn't. */ 66 void *ItemAtFast(int32) const; 67 68 void *LastItem() const; 69 void *Items() const; 70 71 /* Querying the list. */ 72 bool HasItem(void *item) const; 73 int32 IndexOf(void *item) const; 74 int32 CountItems() const; 75 bool IsEmpty() const; 76 77 /* Iterating over the list. */ 78 void DoForEach(bool (*func)(void *)); 79 void DoForEach(bool (*func)(void *, void *), void *arg2); 80 81 /*----- Private or reserved ---------------*/ 82 83 private: 84 virtual void _ReservedList1(); 85 virtual void _ReservedList2(); 86 87 // return type differs from BeOS version 88 bool Resize(int32 count); 89 90 private: 91 void** fObjectList; 92 size_t fPhysicalSize; 93 int32 fItemCount; 94 int32 fBlockSize; 95 uint32 _reserved[2]; 96 }; 97 98 #endif // _BE_LIST_H 99