Choco OS  V.0.16.9.0
Join to the chocolate world
oc_list.h
Go to the documentation of this file.
1 
28 #ifndef SYSTEM_LIBRARIES_INC_OC_LIST_H_
29 #define SYSTEM_LIBRARIES_INC_OC_LIST_H_
30 
31 #include <oc_object.h>
32 #include <oc_stdlib.h>
33 #include <oc_system.h>
34 #include <oc_assert.h>
35 
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!
38 #endif
39 
45 #define _________________________________________TYPES_SECTION______________________________________________________________________________
46 
47 //==========================================================================================================================================
48 //==========================================================================================================================================
50 {
51  struct List_ElementHandle_t * Previous;
52  struct List_ElementHandle_t * Next;
53  void * Object;
54  oC_UInt_t Size;
55 };
56 
57 //==========================================================================================================================================
58 //==========================================================================================================================================
60 
61 //==========================================================================================================================================
62 //==========================================================================================================================================
63 struct List_t
64 {
65  oC_ObjectControl_t ObjectControl;
66  uint32_t Count;
67  oC_List_ElementHandle_t First;
68  oC_List_ElementHandle_t Last;
69 };
70 
71 //==========================================================================================================================================
72 //==========================================================================================================================================
73 typedef struct List_t * oC_List_t;
74 
75 
76 #undef _________________________________________TYPES_SECTION______________________________________________________________________________
77 
83 #define _________________________________________MACROS_SECTION_____________________________________________________________________________
84 
85 #define oC_List(Type) Type*
86 
87 #define oC_List_TypeAssert( List , Variable ) oC_STATIC_ASSERT( sizeof(__typeof__(*List)) == sizeof(__typeof__(Variable)) , "Object " #Variable " is not in correct type" );
88 
89 #ifdef oC_CORE_SPACE
90 //==========================================================================================================================================
91 //==========================================================================================================================================
92 #define oC_List_New(Allocator,Flags) (void*)List_New( Allocator , Flags )
93 //==========================================================================================================================================
94 //==========================================================================================================================================
95 #define oC_List_Delete(List,Flags) List_Delete((oC_List_t*)(&(List)),Flags)
96 #else
97 //==========================================================================================================================================
98 //==========================================================================================================================================
99 #define oC_List_New() List_New( getcurallocator() , oC_MemMan_AllocationFlags_CanWaitForever )
100 //==========================================================================================================================================
101 //==========================================================================================================================================
102 #define oC_List_Delete(List) List_Delete((oC_List_t*)&List , oC_MemMan_AllocationFlags_CanWaitForever)
103 #endif
104 
105 //==========================================================================================================================================
106 //==========================================================================================================================================
107 #define oC_List_IsCorrect(List) List_IsCorrect((oC_List_t)List)
108 
109 //==========================================================================================================================================
110 //==========================================================================================================================================
111 #define oC_List_IsEmpty(List) (oC_List_Count((oC_List_t)List) == 0)
112 
113 //==========================================================================================================================================
114 //==========================================================================================================================================
115 #define oC_List_Clear(List) List_Clear((oC_List_t)List)
116 
117 //==========================================================================================================================================
118 //==========================================================================================================================================
119 #define oC_List_Count(List) List_Count((oC_List_t)List)
120 
121 //==========================================================================================================================================
122 //==========================================================================================================================================
123 #define oC_List_Contains(List,Variable) List_Contains((oC_List_t)List,&(Variable),sizeof(Variable));\
124  oC_List_TypeAssert(List,Variable)
125 
126 //==========================================================================================================================================
127 //==========================================================================================================================================
128 #define oC_List_CountObjects(List,Variable) List_CountObjects((oC_List_t)List,&(Variable),sizeof(Variable));\
129  oC_List_TypeAssert(List,Variable)
130 
131 //==========================================================================================================================================
132 //==========================================================================================================================================
133 #define oC_List_IndexOf(List,Variable) List_IndexOf((oC_List_t)List,&(Variable),sizeof(Variable));\
134  oC_List_TypeAssert(List,Variable)
135 
136 //==========================================================================================================================================
137 //==========================================================================================================================================
138 #define oC_List_ElementHandleOf(List,Variable) List_ElementHandleOf((oC_List_t)List,&(Variable),sizeof(Variable));\
139  oC_List_TypeAssert(List,Variable)
140 
141 //==========================================================================================================================================
142 //==========================================================================================================================================
143 #define oC_List_PushBack(List,Variable,Allocator) List_PushBack((oC_List_t)List,&(Variable),sizeof(Variable),Allocator);\
144  oC_List_TypeAssert(List,Variable)
145 
146 //==========================================================================================================================================
147 //==========================================================================================================================================
148 #define oC_List_PushFront(List,Variable,Allocator) List_PushFront((oC_List_t)List,&(Variable),sizeof(Variable),Allocator);\
149  oC_List_TypeAssert(List,Variable)
150 
151 //==========================================================================================================================================
152 //==========================================================================================================================================
153 #define oC_List_PushCopyBack(List,Variable,Allocator) List_PushBack((oC_List_t)List,&(Variable),sizeof(Variable),Allocator);\
154  oC_List_TypeAssert(List,Variable)
155 
156 //==========================================================================================================================================
157 //==========================================================================================================================================
158 #define oC_List_PushCopyFront(List,Variable,Allocator) List_PushFront((oC_List_t)List,&(Variable),sizeof(Variable),Allocator);\
159  oC_List_TypeAssert(List,Variable)
160 
161 //==========================================================================================================================================
162 //==========================================================================================================================================
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)
165 
166 //==========================================================================================================================================
167 //==========================================================================================================================================
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)
170 
171 //==========================================================================================================================================
172 //==========================================================================================================================================
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)
175 
176 //==========================================================================================================================================
177 //==========================================================================================================================================
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)
180 
181 //==========================================================================================================================================
182 //==========================================================================================================================================
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)
185 
186 //==========================================================================================================================================
187 //==========================================================================================================================================
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)
190 
191 //==========================================================================================================================================
192 //==========================================================================================================================================
193 #define oC_List_Remove(List,Index) List_Remove((oC_List_t)List,List_ElementOfIndex((oC_List_t)List,Index))
194 
195 //==========================================================================================================================================
196 //==========================================================================================================================================
197 #define oC_List_RemoveAll(List,Variable) List_RemoveAll((oC_List_t)List,&(Variable),sizeof(Variable));\
198  oC_List_TypeAssert(List,Variable)
199 
200 //==========================================================================================================================================
201 //==========================================================================================================================================
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)
204 
205 //==========================================================================================================================================
206 //==========================================================================================================================================
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)
210 
211 //==========================================================================================================================================
212 //==========================================================================================================================================
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)
214 
215 //==========================================================================================================================================
216 //==========================================================================================================================================
217 #define oC_List_PopBack(List) List_PopBack((oC_List_t)List)
218 
219 //==========================================================================================================================================
220 //==========================================================================================================================================
221 #define oC_List_PopFront(List) List_PopBack((oC_List_t)List)
222 
223 //==========================================================================================================================================
224 //==========================================================================================================================================
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)))
226 
227 //==========================================================================================================================================
228 //==========================================================================================================================================
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)
231 
232 //==========================================================================================================================================
233 //==========================================================================================================================================
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)
237 
238 //==========================================================================================================================================
239 //==========================================================================================================================================
240 #define oC_List_TakeFirst(List,Output) List_TakeFirst((oC_List_t)List,&(Output),sizeof(Output));\
241  oC_List_TypeAssert(List,Output)
242 
243 //==========================================================================================================================================
244 //==========================================================================================================================================
245 #define oC_List_TakeLast(List,Output) List_TakeLast((oC_List_t)List,&(Output),sizeof(Output));\
246  oC_List_TypeAssert(List,Output)
247 
248 #define oC_List_Verify(List) List_Verify((oC_List_t)List)
249 
250 //==========================================================================================================================================
251 //==========================================================================================================================================
252 #define List_Foreach_ElementHandle( ElementName ) ElementName##Handle
253 
254 //==========================================================================================================================================
255 //==========================================================================================================================================
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))
260 
261 //==========================================================================================================================================
262 //==========================================================================================================================================
263 #define oC_List_Foreach(List,VariableName) List_Foreach(List,VariableName)
264 
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 )
270 
271 #define oC_List_RemoveCurrentElement(List,VariableName) \
272  { \
273  oC_List_ElementHandle_t current = List_Foreach_ElementHandle(VariableName);\
274  List_Remove((oC_List_t)List,current);\
275  continue;\
276  }
277 
278 #ifndef foreach
279 #define foreach(list,variable) List_Foreach(list,variable)
280 #endif
281 
282 #undef _________________________________________MACROS_SECTION_____________________________________________________________________________
283 
289 #define _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________
290 
291 
292 extern oC_List_t List_New ( Allocator_t Allocator , AllocationFlags_t Flags );
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 );
323 
324 #undef _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________
325 
326 
332 #define _________________________________________STATIC_INLINE_SECTION______________________________________________________________________
333 
334 
335 #undef _________________________________________STATIC_INLINE_SECTION______________________________________________________________________
336 
337 
338 #endif /* SYSTEM_LIBRARIES_INC_OC_LIST_H_ */
FILE__DESCRIPTION
Definition: oc_list.h:63
identifier for allocations
Definition: oc_stdlib.h:159
The file with helper macros for managing objects.
uint32_t oC_ObjectControl_t
stores object control value
Definition: oc_object.h:141
FILE__DESCRIPTION
static const oC_Allocator_t Allocator
Definition: oc_eth.c:152