68 lines
1.8 KiB
C
68 lines
1.8 KiB
C
#ifndef SIMPLE_RAYTRACER_LIST_H
|
|
#define SIMPLE_RAYTRACER_LIST_H
|
|
|
|
#include "arrlist.h"
|
|
#include "linkedlist.h"
|
|
|
|
/**
|
|
* This is a generic list interface. It is implemented by
|
|
* ARRLIST_List and LINKEDLIST_List.
|
|
*/
|
|
|
|
#define LIST_new(list) _Generic((list), \
|
|
ARRLIST_List *: ARRLIST_new, \
|
|
LINKEDLIST_List *: LINKEDLIST_new \
|
|
)()
|
|
|
|
#define LIST_add(list, object) _Generic((list), \
|
|
ARRLIST_List *: ARRLIST_add, \
|
|
LINKEDLIST_List *: LINKEDLIST_add \
|
|
)(list, object)
|
|
|
|
#define LIST_safe_get(list, item) _Generic((list), \
|
|
ARRLIST_List *: ARRLIST_safe_get, \
|
|
LINKEDLIST_List *: LINKEDLIST_safe_get \
|
|
)(list, item)
|
|
|
|
#define LIST_item_count(list) _Generic((list), \
|
|
ARRLIST_List *: ARRLIST_item_count, \
|
|
LINKEDLIST_List *: LINKEDLIST_item_count \
|
|
)(list)
|
|
|
|
#define LIST_remove(list, object) _Generic((list), \
|
|
ARRLIST_List *: ARRLIST_remove, \
|
|
LINKEDLIST_List *: LINKEDLIST_remove \
|
|
)(list, object)
|
|
|
|
#define LIST_is_empty(list) _Generic((list), \
|
|
ARRLIST_List *: ARRLIST_is_empty, \
|
|
LINKEDLIST_List *: LINKEDLIST_is_empty \
|
|
)(list)
|
|
|
|
#define LIST_iterator(list, apply_each_ptr, context) _Generic((list), \
|
|
ARRLIST_List *: ARRLIST_iterator, \
|
|
LINKEDLIST_List *: LINKEDLIST_iterator \
|
|
)(list, apply_each_ptr, context)
|
|
|
|
#define LIST_filter(list, apply_each_ptr, context) _Generic((list), \
|
|
ARRLIST_List *: ARRLIST_filter, \
|
|
LINKEDLIST_List *: LINKEDLIST_filter \
|
|
)(list, apply_each_ptr, context)
|
|
|
|
#define LIST_contains(list, object) _Generic((list), \
|
|
ARRLIST_List *: ARRLIST_contains, \
|
|
LINKEDLIST_List *: LINKEDLIST_contains \
|
|
)(list, object)
|
|
|
|
#define LIST_last(list) _Generic((list), \
|
|
ARRLIST_List *: ARRLIST_last, \
|
|
LINKEDLIST_List *: LINKEDLIST_last \
|
|
)(list)
|
|
|
|
#define LIST_delete(list) _Generic((list), \
|
|
ARRLIST_List *: ARRLIST_delete, \
|
|
LINKEDLIST_List *: LINKEDLIST_delete \
|
|
)(list)
|
|
|
|
#endif // SIMPLE_RAYTRACER_LIST_H
|