1/* 2 File: CList.h 3 4 Contains: Interface to the CList class 5 6 7*/ 8 9#ifndef __CLIST_H 10#define __CLIST_H 11 12#include "CDynamicArray.h" 13 14class CItemComparer; 15 16//----------------------------------------------------------------------- 17// CList 18//----------------------------------------------------------------------- 19class CList : public CDynamicArray 20{ 21 OSDeclareDefaultStructors(CList); 22 23public: 24 static CList* cList(ArrayIndex size = kDefaultChunkSize); 25 Boolean init(ArrayIndex size = kDefaultChunkSize); 26 void free(void); 27 28 // get 29 30 void* At(ArrayIndex index); 31 void* First(void); 32 void* Last(void); 33 34 // insertion 35 36 IrDAErr Insert(void* item); 37 Boolean InsertUnique(void* item); 38 IrDAErr InsertBefore(ArrayIndex index, void* item); 39 IrDAErr InsertAt(ArrayIndex index, void* item); 40 IrDAErr InsertFirst(void* item); 41 IrDAErr InsertLast(void* item); 42 43 // removal 44 45 IrDAErr Remove(void* item); 46 IrDAErr RemoveAt(ArrayIndex index); 47 IrDAErr RemoveFirst(void); 48 IrDAErr RemoveLast(void); 49 50 // replacement 51 52 IrDAErr Replace(void* oldItem, void* newItem); 53 IrDAErr ReplaceAt(ArrayIndex index, void* newItem); 54 IrDAErr ReplaceFirst(void* newItem); 55 IrDAErr ReplaceLast(void* newItem); 56 57 // indexing 58 59 ArrayIndex GetIdentityIndex(void* item); 60 ArrayIndex GetEqualityIndex(void* item); 61 62 // searching 63 64 void* Search(CItemComparer* test, ArrayIndex& index); 65 Boolean Contains(void* item) { return GetIdentityIndex(item) != kEmptyIndex;} 66 67 // old names from TList (remove when no longer referenced) 68 long Count() { return fSize; }; 69 Boolean Empty() { return (fSize == 0);}; 70// Boolean AddUnique(void* add) { return InsertUnique(add);} 71// ArrayIndex Index(void* item) { return GetIdentityIndex(item);} 72// void* Ith(ArrayIndex index) { return At(index);} 73 74}; // CList 75 76 77//----------------------------------------------------------------------- 78// CList inlines 79//----------------------------------------------------------------------- 80 81inline void* CList::First(void) 82 { return At(0); } 83 84inline void* CList::Last(void) 85 { return At(fSize - 1); } 86 87inline IrDAErr CList::Insert(void* item) 88 { return InsertAt(fSize, item); } 89 90inline IrDAErr CList::InsertBefore(ArrayIndex index, void* item) 91 { return InsertAt(index, item); } 92 93inline IrDAErr CList::InsertFirst(void* item) 94 { return InsertAt(0, item); } 95 96inline IrDAErr CList::InsertLast(void* item) 97 { return InsertAt(fSize, item); } 98 99inline IrDAErr CList::RemoveAt(ArrayIndex index) 100 { return RemoveElementsAt(index, 1); } 101 102inline IrDAErr CList::RemoveFirst() 103 { return RemoveElementsAt(0, 1); } 104 105inline IrDAErr CList::RemoveLast() 106 { return RemoveElementsAt(fSize - 1, 1); } 107 108inline IrDAErr CList::ReplaceFirst(void* newItem) 109 { return ReplaceAt(0, newItem); } 110 111inline IrDAErr CList::ReplaceLast(void* newItem) 112 { return ReplaceAt(fSize - 1, newItem); } 113 114inline ArrayIndex CList::GetEqualityIndex(void* item) 115 { return GetIdentityIndex(item); } 116 117 118#endif /* __CLIST_H */ 119