src/cx/list.h

changeset 489
af6be1e123aa
parent 488
9138acaa494b
child 490
e66551b47466
     1.1 --- a/src/cx/list.h	Tue Dec 28 17:24:18 2021 +0100
     1.2 +++ b/src/cx/list.h	Tue Dec 28 17:38:02 2021 +0100
     1.3 @@ -47,7 +47,10 @@
     1.4  /**
     1.5   * A comparator function comparing two list elements.
     1.6   */
     1.7 -typedef int(*CxListComparator)(void const *left, void const *right);
     1.8 +typedef int(*CxListComparator)(
     1.9 +        void const *left,
    1.10 +        void const *right
    1.11 +);
    1.12  
    1.13  /**
    1.14   * Internal type for the list structure - use CxList instead.
    1.15 @@ -61,29 +64,42 @@
    1.16      /**
    1.17       * Member function for adding an element.
    1.18       */
    1.19 -    int (*add)(cx_list_s *list, void *elem);
    1.20 +    int (*add)(
    1.21 +            cx_list_s *list,
    1.22 +            void const *elem
    1.23 +    );
    1.24  
    1.25      /**
    1.26       * Member function for inserting an element.
    1.27       */
    1.28 -    int (*insert)(cx_list_s *list, size_t index, void *elem);
    1.29 +    int (*insert)(
    1.30 +            cx_list_s *list,
    1.31 +            size_t index,
    1.32 +            void const *elem
    1.33 +    );
    1.34  
    1.35      /**
    1.36       * Member function for removing an element.
    1.37       */
    1.38 -    int (*remove)(cx_list_s *list, size_t index);
    1.39 +    int (*remove)(
    1.40 +            cx_list_s *list,
    1.41 +            size_t index
    1.42 +    );
    1.43  
    1.44      /**
    1.45       * Member function for element lookup.
    1.46       */
    1.47 -    void *(*at)(cx_list_s *list, size_t index);
    1.48 +    void *(*at)(
    1.49 +            cx_list_s const *list,
    1.50 +            size_t index
    1.51 +    );
    1.52  
    1.53      /**
    1.54       * Member function for finding an element.
    1.55       */
    1.56      size_t (*find)(
    1.57 -            cx_list_s *list,
    1.58 -            void *elem
    1.59 +            cx_list_s const *list,
    1.60 +            void const *elem
    1.61      );
    1.62  
    1.63      /**
    1.64 @@ -95,8 +111,8 @@
    1.65       * Member function for comparing this list to another list of the same type.
    1.66       */
    1.67      int (*compare)(
    1.68 -            cx_list_s *list,
    1.69 -            cx_list_s *other
    1.70 +            cx_list_s const *list,
    1.71 +            cx_list_s const *other
    1.72      );
    1.73  } cx_list_class;
    1.74  
    1.75 @@ -147,7 +163,10 @@
    1.76   * @param elem a pointer to the element to add
    1.77   * @return zero on success, non-zero on memory allocation failure
    1.78   */
    1.79 -static inline int cxListAdd(CxList list, void *elem) {
    1.80 +static inline int cxListAdd(
    1.81 +        CxList list,
    1.82 +        void const *elem
    1.83 +) {
    1.84      return list->cl->add(list, elem);
    1.85  }
    1.86  
    1.87 @@ -167,7 +186,11 @@
    1.88   * @return zero on success, non-zero on memory allocation failure
    1.89   * or when the index is out of bounds
    1.90   */
    1.91 -static inline int cxListInsert(CxList list, size_t index, void *elem) {
    1.92 +static inline int cxListInsert(
    1.93 +        CxList list,
    1.94 +        size_t index,
    1.95 +        void const *elem
    1.96 +) {
    1.97      return list->cl->insert(list, index, elem);
    1.98  }
    1.99  
   1.100 @@ -177,7 +200,10 @@
   1.101   * @param index the index of the element
   1.102   * @return zero on success, non-zero if the index is out of bounds
   1.103   */
   1.104 -static inline int cxListRemove(CxList list, size_t index) {
   1.105 +static inline int cxListRemove(
   1.106 +        CxList list,
   1.107 +        size_t index
   1.108 +) {
   1.109      return list->cl->remove(list, index);
   1.110  }
   1.111  
   1.112 @@ -188,7 +214,10 @@
   1.113   * @param index the index of the element
   1.114   * @return a pointer to the element or \c NULL if the index is out of bounds
   1.115   */
   1.116 -static inline void *cxListAt(CxList list, size_t index) {
   1.117 +static inline void *cxListAt(
   1.118 +        CxList list,
   1.119 +        size_t index
   1.120 +) {
   1.121      return list->cl->at(list, index);
   1.122  }
   1.123  
   1.124 @@ -201,7 +230,10 @@
   1.125   * @param elem the element to find
   1.126   * @return the index of the element or \c (size+1) if the element is not found
   1.127   */
   1.128 -static inline size_t cxListFind(CxList list, void *elem) {
   1.129 +static inline size_t cxListFind(
   1.130 +        CxList list,
   1.131 +        void const *elem
   1.132 +) {
   1.133      return list->cl->find(list, elem);
   1.134  }
   1.135  

mercurial