diff -r 3dc9075df822 -r eb9e7bd40a8e src/cx/list.h --- a/src/cx/list.h Sat Jan 29 14:32:04 2022 +0100 +++ b/src/cx/list.h Sun Jan 30 14:19:00 2022 +0100 @@ -54,90 +54,9 @@ ); /** - * Internal type for the list structure - use CxList instead. + * List class type. */ -typedef struct cx_list_s cx_list_s; - -/** - * The class definition for arbitrary lists. - */ -typedef struct { - /** - * Member function for adding an element. - */ - int (*add)( - cx_list_s *list, - void const *elem - ); - - /** - * Member function for inserting an element. - */ - int (*insert)( - cx_list_s *list, - size_t index, - void const *elem - ); - - /** - * Member function for inserting an element relative to an iterator position. - */ - int (*insert_iter)( - CxIterator *iter, - void const *elem, - int prepend - ); - - /** - * Member function for removing an element. - */ - int (*remove)( - cx_list_s *list, - size_t index - ); - - /** - * Member function for element lookup. - */ - void *(*at)( - cx_list_s const *list, - size_t index - ); - - /** - * Member function for finding an element. - */ - size_t (*find)( - cx_list_s const *list, - void const *elem - ); - - /** - * Member function for sorting the list in place. - */ - void (*sort)(cx_list_s *list); - - /** - * Member function for comparing this list to another list of the same type. - */ - int (*compare)( - cx_list_s const *list, - cx_list_s const *other - ); - - /** - * Member function for reversing the order of the items. - */ - void (*reverse)(cx_list_s *list); - - /** - * Returns an iterator pointing to the specified index. - */ - CxIterator (*iterator)( - cx_list_s *list, - size_t index - ); -} cx_list_class; +typedef struct cx_list_class_s cx_list_class; /** * Structure for holding the base data of a list. @@ -150,7 +69,7 @@ /** * The allocator to use. */ - CxAllocator allocator; + CxAllocator *allocator; /** * The comparator function for the elements. */ @@ -170,9 +89,90 @@ }; /** + * The class definition for arbitrary lists. + */ +struct cx_list_class_s { + /** + * Member function for adding an element. + */ + int (*add)( + struct cx_list_s *list, + void const *elem + ); + + /** + * Member function for inserting an element. + */ + int (*insert)( + struct cx_list_s *list, + size_t index, + void const *elem + ); + + /** + * Member function for inserting an element relative to an iterator position. + */ + int (*insert_iter)( + struct cx_iterator_s *iter, + void const *elem, + int prepend + ); + + /** + * Member function for removing an element. + */ + int (*remove)( + struct cx_list_s *list, + size_t index + ); + + /** + * Member function for element lookup. + */ + void *(*at)( + struct cx_list_s const *list, + size_t index + ); + + /** + * Member function for finding an element. + */ + size_t (*find)( + struct cx_list_s const *list, + void const *elem + ); + + /** + * Member function for sorting the list in place. + */ + void (*sort)(struct cx_list_s *list); + + /** + * Member function for comparing this list to another list of the same type. + */ + int (*compare)( + struct cx_list_s const *list, + struct cx_list_s const *other + ); + + /** + * Member function for reversing the order of the items. + */ + void (*reverse)(struct cx_list_s *list); + + /** + * Returns an iterator pointing to the specified index. + */ + struct cx_iterator_s (*iterator)( + struct cx_list_s *list, + size_t index + ); +}; + +/** * Common type for all list implementations. */ -typedef cx_list_s *CxList; +typedef struct cx_list_s CxList; /** * Adds an item to the end of the list. @@ -182,7 +182,7 @@ * @return zero on success, non-zero on memory allocation failure */ static inline int cxListAdd( - CxList list, + CxList *list, void const *elem ) { return list->cl->add(list, elem); @@ -202,7 +202,7 @@ * @see cxListInsertBefore() */ static inline int cxListInsert( - CxList list, + CxList *list, size_t index, void const *elem ) { @@ -228,7 +228,7 @@ CxIterator *iter, void const *elem ) { - return ((cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 0); + return ((struct cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 0); } /** @@ -250,7 +250,7 @@ CxIterator *iter, void const *elem ) { - return ((cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 1); + return ((struct cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 1); } /** @@ -260,7 +260,7 @@ * @return zero on success, non-zero if the index is out of bounds */ static inline int cxListRemove( - CxList list, + CxList *list, size_t index ) { return list->cl->remove(list, index); @@ -274,7 +274,7 @@ * @return a pointer to the element or \c NULL if the index is out of bounds */ static inline void *cxListAt( - CxList list, + CxList *list, size_t index ) { return list->cl->at(list, index); @@ -292,7 +292,7 @@ * @return a new iterator */ static inline CxIterator cxListIterator( - CxList list, + CxList *list, size_t index ) { return list->cl->iterator(list, index); @@ -308,7 +308,7 @@ * @param list the list * @return a new iterator */ -static inline CxIterator cxListBegin(CxList list) { +static inline CxIterator cxListBegin(CxList *list) { return list->cl->iterator(list, 0); } @@ -322,7 +322,7 @@ * @return the index of the element or \c (size+1) if the element is not found */ static inline size_t cxListFind( - CxList list, + CxList *list, void const *elem ) { return list->cl->find(list, elem); @@ -335,7 +335,7 @@ * * @param list the list */ -static inline void cxListSort(CxList list) { +static inline void cxListSort(CxList *list) { list->cl->sort(list); } @@ -344,7 +344,7 @@ * * @param list the list */ -static inline void cxListReverse(CxList list) { +static inline void cxListReverse(CxList *list) { list->cl->reverse(list); } @@ -358,8 +358,8 @@ * @return zero, if both lists are equal element wise, negative if the first list is smaller, zero if the first list is larger */ static inline int cxListCompare( - CxList list, - CxList other + CxList *list, + CxList *other ) { return list->cl->compare(list, other); }