#ifndef UCX_LIST_H
#define UCX_LIST_H
#include "common.h"
#include "collection.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct cx_list_class_s cx_list_class;
struct cx_list_s {
CX_COLLECTION_MEMBERS
cx_list_class
const *cl;
cx_list_class
const *climpl;
};
struct cx_list_class_s {
void (*destructor)(
struct cx_list_s *list);
int (*insert_element)(
struct cx_list_s *list,
size_t index,
void const *data
);
size_t (*insert_array)(
struct cx_list_s *list,
size_t index,
void const *data,
size_t n
);
int (*insert_iter)(
struct cx_mut_iterator_s *iter,
void const *elem,
int prepend
);
int (*remove)(
struct cx_list_s *list,
size_t index
);
void (*clear)(
struct cx_list_s *list);
int (*swap)(
struct cx_list_s *list,
size_t i,
size_t j
);
void *(*at)(
struct cx_list_s
const *list,
size_t index
);
ssize_t (*find)(
struct cx_list_s
const *list,
void const *elem
);
void (*sort)(
struct cx_list_s *list);
int (*compare)(
struct cx_list_s
const *list,
struct cx_list_s
const *other
);
void (*reverse)(
struct cx_list_s *list);
struct cx_iterator_s (*iterator)(
struct cx_list_s
const *list,
size_t index,
bool backward
);
};
typedef struct cx_list_s CxList;
__attribute__((__nonnull__))
void cxListStoreObjects(CxList *list);
__attribute__((__nonnull__))
void cxListStorePointers(CxList *list);
__attribute__((__nonnull__))
static inline bool cxListIsStoringPointers(CxList
const *list) {
return list->store_pointer;
}
__attribute__((__nonnull__))
static inline
size_t cxListSize(CxList
const *list) {
return list->size;
}
__attribute__((__nonnull__))
static inline
int cxListAdd(
CxList *list,
void const *elem
) {
return list->cl->insert_element(list, list->size, elem);
}
__attribute__((__nonnull__))
static inline
size_t cxListAddArray(
CxList *list,
void const *array,
size_t n
) {
return list->cl->insert_array(list, list->size, array, n);
}
__attribute__((__nonnull__))
static inline
int cxListInsert(
CxList *list,
size_t index,
void const *elem
) {
return list->cl->insert_element(list, index, elem);
}
__attribute__((__nonnull__))
static inline
size_t cxListInsertArray(
CxList *list,
size_t index,
void const *array,
size_t n
) {
return list->cl->insert_array(list, index, array, n);
}
__attribute__((__nonnull__))
static inline
int cxListInsertAfter(
CxMutIterator *iter,
void const *elem
) {
return ((
struct cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem,
0);
}
__attribute__((__nonnull__))
static inline
int cxListInsertBefore(
CxMutIterator *iter,
void const *elem
) {
return ((
struct cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem,
1);
}
__attribute__((__nonnull__))
static inline
int cxListRemove(
CxList *list,
size_t index
) {
return list->cl->remove(list, index);
}
__attribute__((__nonnull__))
static inline
void cxListClear(CxList *list) {
list->cl->clear(list);
}
__attribute__((__nonnull__))
static inline
int cxListSwap(
CxList *list,
size_t i,
size_t j
) {
return list->cl->swap(list, i, j);
}
__attribute__((__nonnull__))
static inline
void *cxListAt(
CxList *list,
size_t index
) {
return list->cl->at(list, index);
}
__attribute__((__nonnull__, __warn_unused_result__))
static inline CxIterator cxListIteratorAt(
CxList
const *list,
size_t index
) {
return list->cl->iterator(list, index, false);
}
__attribute__((__nonnull__, __warn_unused_result__))
static inline CxIterator cxListBackwardsIteratorAt(
CxList
const *list,
size_t index
) {
return list->cl->iterator(list, index, true);
}
__attribute__((__nonnull__, __warn_unused_result__))
CxMutIterator cxListMutIteratorAt(
CxList *list,
size_t index
);
__attribute__((__nonnull__, __warn_unused_result__))
CxMutIterator cxListMutBackwardsIteratorAt(
CxList *list,
size_t index
);
__attribute__((__nonnull__, __warn_unused_result__))
static inline CxIterator cxListIterator(CxList
const *list) {
return list->cl->iterator(list,
0, false);
}
__attribute__((__nonnull__, __warn_unused_result__))
static inline CxMutIterator cxListMutIterator(CxList *list) {
return cxListMutIteratorAt(list,
0);
}
__attribute__((__nonnull__, __warn_unused_result__))
static inline CxIterator cxListBackwardsIterator(CxList
const *list) {
return list->cl->iterator(list, list->size -
1, true);
}
__attribute__((__nonnull__, __warn_unused_result__))
static inline CxMutIterator cxListMutBackwardsIterator(CxList *list) {
return cxListMutBackwardsIteratorAt(list, list->size -
1);
}
__attribute__((__nonnull__))
static inline
ssize_t cxListFind(
CxList
const *list,
void const *elem
) {
return list->cl->find(list, elem);
}
__attribute__((__nonnull__))
static inline
void cxListSort(CxList *list) {
list->cl->sort(list);
}
__attribute__((__nonnull__))
static inline
void cxListReverse(CxList *list) {
list->cl->reverse(list);
}
__attribute__((__nonnull__))
int cxListCompare(
CxList
const *list,
CxList
const *other
);
__attribute__((__nonnull__))
void cxListDestroy(CxList *list);
extern CxList *
const cxEmptyList;
#ifdef __cplusplus
}
#endif
#endif