193 list->cl = &cx_pointer_list_class; |
193 list->cl = &cx_pointer_list_class; |
194 } |
194 } |
195 |
195 |
196 // </editor-fold> |
196 // </editor-fold> |
197 |
197 |
|
198 // <editor-fold desc="empty list implementation"> |
|
199 |
|
200 static void cx_emptyl_noop(__attribute__((__unused__)) CxList *list) { |
|
201 // this is a noop, but MUST be implemented |
|
202 } |
|
203 |
|
204 static void *cx_emptyl_at( |
|
205 __attribute__((__unused__)) struct cx_list_s const *list, |
|
206 __attribute__((__unused__)) size_t index |
|
207 ) { |
|
208 return NULL; |
|
209 } |
|
210 |
|
211 static ssize_t cx_emptyl_find( |
|
212 __attribute__((__unused__)) struct cx_list_s const *list, |
|
213 __attribute__((__unused__)) void const *elem |
|
214 ) { |
|
215 return -1; |
|
216 } |
|
217 |
|
218 static int cx_emptyl_compare( |
|
219 __attribute__((__unused__)) struct cx_list_s const *list, |
|
220 struct cx_list_s const *other |
|
221 ) { |
|
222 if (other->size == 0) return 0; |
|
223 return -1; |
|
224 } |
|
225 |
|
226 static bool cx_emptyl_iter_valid(__attribute__((__unused__)) void const *iter) { |
|
227 return false; |
|
228 } |
|
229 |
|
230 static CxIterator cx_emptyl_iterator( |
|
231 struct cx_list_s const *list, |
|
232 size_t index, |
|
233 __attribute__((__unused__)) bool backwards |
|
234 ) { |
|
235 CxIterator iter = {0}; |
|
236 iter.src_handle = list; |
|
237 iter.index = index; |
|
238 iter.base.valid = cx_emptyl_iter_valid; |
|
239 return iter; |
|
240 } |
|
241 |
|
242 static cx_list_class cx_empty_list_class = { |
|
243 cx_emptyl_noop, |
|
244 NULL, |
|
245 NULL, |
|
246 NULL, |
|
247 NULL, |
|
248 cx_emptyl_noop, |
|
249 NULL, |
|
250 cx_emptyl_at, |
|
251 cx_emptyl_find, |
|
252 cx_emptyl_noop, |
|
253 cx_emptyl_compare, |
|
254 cx_emptyl_noop, |
|
255 cx_emptyl_iterator, |
|
256 }; |
|
257 |
|
258 CxList cx_empty_list = { |
|
259 NULL, |
|
260 NULL, |
|
261 0, |
|
262 0, |
|
263 NULL, |
|
264 NULL, |
|
265 NULL, |
|
266 false, |
|
267 &cx_empty_list_class, |
|
268 NULL |
|
269 }; |
|
270 |
|
271 CxList *const cxEmptyList = &cx_empty_list; |
|
272 |
|
273 // </editor-fold> |
|
274 |
198 void cxListDestroy(CxList *list) { |
275 void cxListDestroy(CxList *list) { |
199 if (list->simple_destructor) { |
276 if (list->simple_destructor) { |
200 CxIterator iter = cxListIterator(list); |
277 CxIterator iter = cxListIterator(list); |
201 cx_foreach(void*, elem, iter) { |
278 cx_foreach(void*, elem, iter) { |
202 // already correctly resolved pointer - immediately invoke dtor |
279 // already correctly resolved pointer - immediately invoke dtor |