src/cx/list.h

changeset 469
0458bff0b1cd
parent 464
7fafc95968fc
child 474
9c1fccda16bc
equal deleted inserted replaced
468:75ae1dccd101 469:0458bff0b1cd
85 85
86 /** 86 /**
87 * Member function for retrieving the last element. 87 * Member function for retrieving the last element.
88 */ 88 */
89 void *(*last)(cx_list_s *list); 89 void *(*last)(cx_list_s *list);
90
91 /**
92 * Member function for sorting the list in place.
93 */
94 void (*sort)(cx_list_s *list);
90 } cx_list_class; 95 } cx_list_class;
91 96
92 /** 97 /**
93 * Structure for holding the base data of a list. 98 * Structure for holding the base data of a list.
94 */ 99 */
134 * 139 *
135 * @param list the list 140 * @param list the list
136 * @param elem a pointer to the element to add 141 * @param elem a pointer to the element to add
137 * @return zero on success, non-zero on memory allocation failure 142 * @return zero on success, non-zero on memory allocation failure
138 */ 143 */
139 int cxListAdd(CxList list, void *elem); 144 static inline int cxListAdd(CxList list, void *elem) {
145 return list->cl->add(list, elem);
146 }
140 147
141 /** 148 /**
142 * Inserts an item at the specified index. 149 * Inserts an item at the specified index.
143 * 150 *
144 * If \p index equals the list \c size, this is effectively cxListAdd(). 151 * If \p index equals the list \c size, this is effectively cxListAdd().
152 * @param index the index the element shall have 159 * @param index the index the element shall have
153 * @param elem a pointer to the element to add 160 * @param elem a pointer to the element to add
154 * @return zero on success, non-zero on memory allocation failure 161 * @return zero on success, non-zero on memory allocation failure
155 * or when the index is out of bounds 162 * or when the index is out of bounds
156 */ 163 */
157 int cxListInsert(CxList list, size_t index, void *elem); 164 static inline int cxListInsert(CxList list, size_t index, void *elem) {
165 return list->cl->insert(list, index, elem);
166 }
158 167
159 /** 168 /**
160 * Removes the element at the specified index. 169 * Removes the element at the specified index.
161 * @param list the list 170 * @param list the list
162 * @param index the index of the element 171 * @param index the index of the element
163 * @return zero on success, non-zero if the index is out of bounds 172 * @return zero on success, non-zero if the index is out of bounds
164 */ 173 */
165 int cxListRemove(CxList list, size_t index); 174 static inline int cxListRemove(CxList list, size_t index) {
175 return list->cl->remove(list, index);
176 }
166 177
167 /** 178 /**
168 * Returns a pointer to the element at the specified index. 179 * Returns a pointer to the element at the specified index.
169 * 180 *
170 * @param list the list 181 * @param list the list
171 * @param index the index of the element 182 * @param index the index of the element
172 * @return a pointer to the element or \c NULL if the index is out of bounds 183 * @return a pointer to the element or \c NULL if the index is out of bounds
173 */ 184 */
174 void *cxListAt(CxList list, size_t index); 185 static inline void *cxListAt(CxList list, size_t index) {
186 return list->cl->at(list, index);
187 }
175 188
176 /** 189 /**
177 * Returns the index of the first element that equals \p elem. 190 * Returns the index of the first element that equals \p elem.
178 * 191 *
179 * Determining equality is performed by the list's comparator function. 192 * Determining equality is performed by the list's comparator function.
180 * 193 *
181 * @param list the list 194 * @param list the list
182 * @param elem the element to find 195 * @param elem the element to find
183 * @return the index of the element or \c (size+1) if the element is not found 196 * @return the index of the element or \c (size+1) if the element is not found
184 */ 197 */
185 size_t cxListFind(CxList list, void *elem); 198 static inline size_t cxListFind(CxList list, void *elem) {
199 return list->cl->find(list, elem);
200 }
186 201
187 /** 202 /**
188 * Returns a pointer to the last element of the list. 203 * Returns a pointer to the last element of the list.
189 * 204 *
190 * This is effectively the same as cxListAt() with \c index=size-1, but 205 * This is effectively the same as cxListAt() with \c index=size-1, but
192 * and the conrecte implementation of cxListAt(). 207 * and the conrecte implementation of cxListAt().
193 * 208 *
194 * @param list the list 209 * @param list the list
195 * @return a pointer to the last element or \c NULL if the list is empty 210 * @return a pointer to the last element or \c NULL if the list is empty
196 */ 211 */
197 void *cxListLast(CxList list); 212 static inline void *cxListLast(CxList list) {
213 return list->cl->last(list);
214 }
215
216 /**
217 * Sorts the list in place.
218 *
219 * \remark The underlying sort algorithm is implementation defined.
220 *
221 * @param list the list
222 */
223 static inline void cxListSort(CxList list) {
224 list->cl->sort(list);
225 }
198 226
199 #ifdef __cplusplus 227 #ifdef __cplusplus
200 } /* extern "C" */ 228 } /* extern "C" */
201 #endif 229 #endif
202 230

mercurial