28 #ifndef SYSTEM_LIBRARIES_INC_OC_LIST_H_ 29 #define SYSTEM_LIBRARIES_INC_OC_LIST_H_ 32 #include <oc_stdlib.h> 36 #if !defined(oC_CORE_SPACE) && !defined(oC_USER_SPACE) && !defined(oC_LIBRARIES_SPACE) 37 # error List library can be used only in CORE , USER or LIBRARIES space! 45 #define _________________________________________TYPES_SECTION______________________________________________________________________________ 67 oC_List_ElementHandle_t First;
68 oC_List_ElementHandle_t Last;
76 #undef _________________________________________TYPES_SECTION______________________________________________________________________________ 83 #define _________________________________________MACROS_SECTION_____________________________________________________________________________ 85 #define oC_List(Type) Type* 87 #define oC_List_TypeAssert( List , Variable ) oC_STATIC_ASSERT( sizeof(__typeof__(*List)) == sizeof(__typeof__(Variable)) , "Object " #Variable " is not in correct type" ); 92 #define oC_List_New(Allocator,Flags) (void*)List_New( Allocator , Flags ) 95 #define oC_List_Delete(List,Flags) List_Delete((oC_List_t*)(&(List)),Flags) 99 #define oC_List_New() List_New( getcurallocator() , oC_MemMan_AllocationFlags_CanWaitForever ) 102 #define oC_List_Delete(List) List_Delete((oC_List_t*)&List , oC_MemMan_AllocationFlags_CanWaitForever) 107 #define oC_List_IsCorrect(List) List_IsCorrect((oC_List_t)List) 111 #define oC_List_IsEmpty(List) (oC_List_Count((oC_List_t)List) == 0) 115 #define oC_List_Clear(List) List_Clear((oC_List_t)List) 119 #define oC_List_Count(List) List_Count((oC_List_t)List) 123 #define oC_List_Contains(List,Variable) List_Contains((oC_List_t)List,&(Variable),sizeof(Variable));\ 124 oC_List_TypeAssert(List,Variable) 128 #define oC_List_CountObjects(List,Variable) List_CountObjects((oC_List_t)List,&(Variable),sizeof(Variable));\ 129 oC_List_TypeAssert(List,Variable) 133 #define oC_List_IndexOf(List,Variable) List_IndexOf((oC_List_t)List,&(Variable),sizeof(Variable));\ 134 oC_List_TypeAssert(List,Variable) 138 #define oC_List_ElementHandleOf(List,Variable) List_ElementHandleOf((oC_List_t)List,&(Variable),sizeof(Variable));\ 139 oC_List_TypeAssert(List,Variable) 143 #define oC_List_PushBack(List,Variable,Allocator) List_PushBack((oC_List_t)List,&(Variable),sizeof(Variable),Allocator);\ 144 oC_List_TypeAssert(List,Variable) 148 #define oC_List_PushFront(List,Variable,Allocator) List_PushFront((oC_List_t)List,&(Variable),sizeof(Variable),Allocator);\ 149 oC_List_TypeAssert(List,Variable) 153 #define oC_List_PushCopyBack(List,Variable,Allocator) List_PushBack((oC_List_t)List,&(Variable),sizeof(Variable),Allocator);\ 154 oC_List_TypeAssert(List,Variable) 158 #define oC_List_PushCopyFront(List,Variable,Allocator) List_PushFront((oC_List_t)List,&(Variable),sizeof(Variable),Allocator);\ 159 oC_List_TypeAssert(List,Variable) 163 #define oC_List_InsertAfter(List,Variable,Index,Allocator) List_InsertAfter((oC_List_t)List,&(Variable),sizeof(Variable),List_ElementOfIndex((oC_List_t)List,Index),Allocator);\ 164 oC_List_TypeAssert(List,Variable) 168 #define oC_List_InsertBefore(List,Variable,Index,Allocator) List_InsertBefore((oC_List_t)List,&(Variable),sizeof(Variable),List_ElementOfIndex((oC_List_t)List,Index),Allocator);\ 169 oC_List_TypeAssert(List,Variable) 173 #define oC_List_InsertCopyAfter(List,Variable,Index,Allocator) List_InsertAfter((oC_List_t)List,&(Variable),sizeof(Variable),List_ElementOfIndex((oC_List_t)List,Index),Allocator);\ 174 oC_List_TypeAssert(List,Variable) 178 #define oC_List_InsertCopyBefore(List,Variable,Index,Allocator) List_InsertBefore((oC_List_t)List,$(Variable),sizeof(Variable),List_ElementOfIndex((oC_List_t)List,Index),Allocator);\ 179 oC_List_TypeAssert(List,Variable) 183 #define oC_List_Replace(List,Variable,Index,Allocator) List_Replace((oC_List_t)List,&(Variable),sizeof(Variable),List_ElementOfIndex(List,Index),Allocator);\ 184 oC_List_TypeAssert(List,Variable) 188 #define oC_List_ReplaceByCopy(List,Variable,Index,Allocator) List_Replace((oC_List_t)List,&(Variable),sizeof(Variable),List_ElementOfIndex((oC_List_t)List,Index),Allocator);\ 189 oC_List_TypeAssert(List,Variable) 193 #define oC_List_Remove(List,Index) List_Remove((oC_List_t)List,List_ElementOfIndex((oC_List_t)List,Index)) 197 #define oC_List_RemoveAll(List,Variable) List_RemoveAll((oC_List_t)List,&(Variable),sizeof(Variable));\ 198 oC_List_TypeAssert(List,Variable) 202 #define oC_List_At(List,Index,Output) List_At((oC_List_t)List,List_ElementOfIndex((oC_List_t)List,Index),&(Output),sizeof(Output));\ 203 oC_List_TypeAssert(List,Output) 207 #define oC_List_AtWithDefault(List,Index,Default,Output) List_AtWithDefault((oC_List_t)List,&Default,sizeof(Default),List_ElementOfIndex((oC_List_t)List,Index),&(Output),sizeof(Output));\ 208 oC_List_TypeAssert(List,Default);\ 209 oC_List_TypeAssert(List,Output) 213 #define oC_List_Move(List,From,To,Allocator) List_Move((oC_List_t)List,List_ElementOfIndex((oC_List_t)List,From),List_ElementOfIndex((oC_List_t)List,To),Allocator) 217 #define oC_List_PopBack(List) List_PopBack((oC_List_t)List) 221 #define oC_List_PopFront(List) List_PopBack((oC_List_t)List) 225 #define oC_List_Swap(List,I,J) List_Swap((oC_List_t)List,List_ElementHandleOf((oC_List_t)List,&I,sizeof(I)),List_ElementHandleOf((oC_List_t)List,&J,sizeof(J))) 229 #define oC_List_TakeAt(List,Index,Output) List_TakeAt((oC_List_t)List,List_ElementOfIndex((oC_List_t)List,Index),&(Output),sizeof(Output));\ 230 oC_List_TypeAssert(List,Output) 234 #define oC_List_Take(List,Variable,Output) List_TakeAt((oC_List_t)List,List_ElementHandleOf((oC_List_t)List,&(Variable),sizeof(Variable)),&(Output),sizeof(Output));\ 235 oC_List_TypeAssert(List,Variable);\ 236 oC_List_TypeAssert(List,Output) 240 #define oC_List_TakeFirst(List,Output) List_TakeFirst((oC_List_t)List,&(Output),sizeof(Output));\ 241 oC_List_TypeAssert(List,Output) 245 #define oC_List_TakeLast(List,Output) List_TakeLast((oC_List_t)List,&(Output),sizeof(Output));\ 246 oC_List_TypeAssert(List,Output) 248 #define oC_List_Verify(List) List_Verify((oC_List_t)List) 252 #define List_Foreach_ElementHandle( ElementName ) ElementName##Handle 256 #define List_Foreach(List,ElementName) if(List_IsCorrect((oC_List_t)List) && List_Count((oC_List_t)List)) \ 257 for(bool ElementName##Execute=true;ElementName##Execute;ElementName##Execute=false)\ 258 for(oC_List_ElementHandle_t List_Foreach_ElementHandle(ElementName) = ((oC_List_t)List)->First ; (List_Foreach_ElementHandle(ElementName) != NULL) && ElementName##Execute ; ElementName##Execute = false ) \ 259 for(__typeof__(*List) ElementName = *((__typeof__(List))List_Foreach_ElementHandle(ElementName)->Object);(List_Foreach_ElementHandle(ElementName) != NULL) && (ElementName != NULL);ElementName = NULL , List_Foreach_ElementHandle(ElementName) = List_Foreach_ElementHandle(ElementName)->Next , ElementName =(List_Foreach_ElementHandle(ElementName) == NULL) ? NULL : *((__typeof__(List))List_Foreach_ElementHandle(ElementName)->Object)) 263 #define oC_List_Foreach(List,VariableName) List_Foreach(List,VariableName) 265 #define oC_List_GetFirstElementHandle(List) ((oC_List_IsCorrect(List)) ? ((oC_List_t)List)->First : NULL) 266 #define oC_List_GetLastElementHandle(List) ((oC_List_IsCorrect(List)) ? ((oC_List_t)List)->Last : NULL) 267 #define oC_List_ElementHandle_Value(ElementHandle,Type) (*((Type*)((ElementHandle)->Object))) 268 #define oC_List_ElementHandle_Next(ElementHandle) ( (ElementHandle != NULL) ? (ElementHandle)->Next : NULL ) 269 #define oC_List_ElementHandle_Previous(ElementHandle) ( (ElementHandle != NULL) ? (ElementHandle)->Previous : NULL ) 271 #define oC_List_RemoveCurrentElement(List,VariableName) \ 273 oC_List_ElementHandle_t current = List_Foreach_ElementHandle(VariableName);\ 274 List_Remove((oC_List_t)List,current);\ 279 #define foreach(list,variable) List_Foreach(list,variable) 282 #undef _________________________________________MACROS_SECTION_____________________________________________________________________________ 289 #define _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________ 293 extern bool List_IsCorrect ( oC_List_t List );
294 extern bool List_Delete ( oC_List_t * List , AllocationFlags_t Flags );
295 extern bool List_DeleteElement ( oC_List_ElementHandle_t Element );
296 extern oC_List_ElementHandle_t List_NewElement (
const void * Object , oC_UInt_t Size ,
Allocator_t Allocator);
297 extern bool List_Clear ( oC_List_t List );
298 extern uint32_t List_Count ( oC_List_t List );
299 extern bool List_Contains ( oC_List_t List ,
void * Object , oC_UInt_t Size );
300 extern uint32_t List_CountObjects ( oC_List_t List ,
void * Object , oC_UInt_t Size );
301 extern int List_IndexOf ( oC_List_t List ,
void * Object , oC_UInt_t Size );
302 extern int List_IndexOfElement ( oC_List_t List , oC_List_ElementHandle_t ElementHandle );
303 extern oC_List_ElementHandle_t List_ElementHandleOf ( oC_List_t List ,
void * Object , oC_UInt_t Size );
304 extern oC_List_ElementHandle_t List_ElementOfIndex ( oC_List_t List ,
int Index );
305 extern bool List_PushBack ( oC_List_t List ,
const void * Object , oC_UInt_t Size ,
Allocator_t Allocator);
306 extern bool List_PushFront ( oC_List_t List ,
const void * Object , oC_UInt_t Size ,
Allocator_t Allocator);
307 extern bool List_InsertAfter ( oC_List_t List ,
void * Object , oC_UInt_t Size , oC_List_ElementHandle_t ElementHandle ,
Allocator_t Allocator);
308 extern bool List_InsertBefore ( oC_List_t List ,
void * Object , oC_UInt_t Size , oC_List_ElementHandle_t ElementHandle ,
Allocator_t Allocator);
309 extern bool List_Replace ( oC_List_t List ,
void * Object , oC_UInt_t Size , oC_List_ElementHandle_t ElementHandle ,
Allocator_t Allocator , AllocationFlags_t Flags );
310 extern bool List_Remove ( oC_List_t List , oC_List_ElementHandle_t ElementHandle );
311 extern uint32_t List_RemoveAll ( oC_List_t List ,
void * Object , oC_UInt_t Size );
312 extern void * List_At ( oC_List_t List , oC_List_ElementHandle_t ElementHandle ,
void * outObject , oC_UInt_t Size );
313 extern void * List_AtWithDefault ( oC_List_t List ,
void * DefaultObject , oC_UInt_t DefaultSize , oC_List_ElementHandle_t ElementHandle ,
void * outObject , oC_UInt_t Size );
314 extern bool List_Move ( oC_List_t List , oC_List_ElementHandle_t From , oC_List_ElementHandle_t To ,
Allocator_t Allocator );
315 extern bool List_PopBack ( oC_List_t List );
316 extern bool List_PopFront ( oC_List_t List );
317 extern bool List_Swap ( oC_List_t List , oC_List_ElementHandle_t I , oC_List_ElementHandle_t J );
318 extern bool List_TakeAt ( oC_List_t List , oC_List_ElementHandle_t ElementHandle ,
void * outObject , oC_UInt_t Size );
319 extern bool List_TakeFirst ( oC_List_t List ,
void * outObject , oC_UInt_t Size );
320 extern bool List_TakeLast ( oC_List_t List ,
void * outObject , oC_UInt_t Size );
321 extern bool List_Verify ( oC_List_t List );
322 extern bool List_Repair ( oC_List_t List ,
void * SavedListAddress , uint32_t MaximumNumberOfObjects );
324 #undef _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________ 332 #define _________________________________________STATIC_INLINE_SECTION______________________________________________________________________ 335 #undef _________________________________________STATIC_INLINE_SECTION______________________________________________________________________
identifier for allocations
The file with helper macros for managing objects.
uint32_t oC_ObjectControl_t
stores object control value
static const oC_Allocator_t Allocator