src/cx/list.h

changeset 469
0458bff0b1cd
parent 464
7fafc95968fc
child 474
9c1fccda16bc
     1.1 --- a/src/cx/list.h	Tue Oct 05 16:33:11 2021 +0200
     1.2 +++ b/src/cx/list.h	Wed Oct 06 14:10:19 2021 +0200
     1.3 @@ -87,6 +87,11 @@
     1.4       * Member function for retrieving the last element.
     1.5       */
     1.6      void *(*last)(cx_list_s *list);
     1.7 +
     1.8 +    /**
     1.9 +     * Member function for sorting the list in place.
    1.10 +     */
    1.11 +    void (*sort)(cx_list_s *list);
    1.12  } cx_list_class;
    1.13  
    1.14  /**
    1.15 @@ -136,7 +141,9 @@
    1.16   * @param elem a pointer to the element to add
    1.17   * @return zero on success, non-zero on memory allocation failure
    1.18   */
    1.19 -int cxListAdd(CxList list, void *elem);
    1.20 +static inline int cxListAdd(CxList list, void *elem) {
    1.21 +    return list->cl->add(list, elem);
    1.22 +}
    1.23  
    1.24  /**
    1.25   * Inserts an item at the specified index.
    1.26 @@ -154,7 +161,9 @@
    1.27   * @return zero on success, non-zero on memory allocation failure
    1.28   * or when the index is out of bounds
    1.29   */
    1.30 -int cxListInsert(CxList list, size_t index, void *elem);
    1.31 +static inline int cxListInsert(CxList list, size_t index, void *elem) {
    1.32 +    return list->cl->insert(list, index, elem);
    1.33 +}
    1.34  
    1.35  /**
    1.36   * Removes the element at the specified index.
    1.37 @@ -162,7 +171,9 @@
    1.38   * @param index the index of the element
    1.39   * @return zero on success, non-zero if the index is out of bounds
    1.40   */
    1.41 -int cxListRemove(CxList list, size_t index);
    1.42 +static inline int cxListRemove(CxList list, size_t index) {
    1.43 +    return list->cl->remove(list, index);
    1.44 +}
    1.45  
    1.46  /**
    1.47   * Returns a pointer to the element at the specified index.
    1.48 @@ -171,7 +182,9 @@
    1.49   * @param index the index of the element
    1.50   * @return a pointer to the element or \c NULL if the index is out of bounds
    1.51   */
    1.52 -void *cxListAt(CxList list, size_t index);
    1.53 +static inline void *cxListAt(CxList list, size_t index) {
    1.54 +    return list->cl->at(list, index);
    1.55 +}
    1.56  
    1.57  /**
    1.58   * Returns the index of the first element that equals \p elem.
    1.59 @@ -182,7 +195,9 @@
    1.60   * @param elem the element to find
    1.61   * @return the index of the element or \c (size+1) if the element is not found
    1.62   */
    1.63 -size_t cxListFind(CxList list, void *elem);
    1.64 +static inline size_t cxListFind(CxList list, void *elem) {
    1.65 +    return list->cl->find(list, elem);
    1.66 +}
    1.67  
    1.68  /**
    1.69   * Returns a pointer to the last element of the list.
    1.70 @@ -194,7 +209,20 @@
    1.71   * @param list the list
    1.72   * @return a pointer to the last element or \c NULL if the list is empty
    1.73   */
    1.74 -void *cxListLast(CxList list);
    1.75 +static inline void *cxListLast(CxList list) {
    1.76 +    return list->cl->last(list);
    1.77 +}
    1.78 +
    1.79 +/**
    1.80 + * Sorts the list in place.
    1.81 + *
    1.82 + * \remark The underlying sort algorithm is implementation defined.
    1.83 + *
    1.84 + * @param list the list
    1.85 + */
    1.86 +static inline void cxListSort(CxList list) {
    1.87 +    list->cl->sort(list);
    1.88 +}
    1.89  
    1.90  #ifdef __cplusplus
    1.91  } /* extern "C" */

mercurial