X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Finclude%2Futils%2Fllist.h;h=298c6ceb8779e9238ade411ca1a3ffb622a41545;hb=c1abeae76c2135185e553dda6d9bec78a41fa894;hp=c115bf2e5107f3cfaa11a540da07b8e7c0c23ade;hpb=bf3b8e60b2fdc493c4e04b05ce67abf69ca9a4ff;p=sysdb.git diff --git a/src/include/utils/llist.h b/src/include/utils/llist.h index c115bf2..298c6ce 100644 --- a/src/include/utils/llist.h +++ b/src/include/utils/llist.h @@ -1,5 +1,5 @@ /* - * syscollector - src/include/utils/llist.h + * SysDB - src/include/utils/llist.h * Copyright (C) 2012 Sebastian 'tokkee' Harl * All rights reserved. * @@ -25,8 +25,8 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SC_UTILS_LLIST_H -#define SC_UTILS_LLIST_H 1 +#ifndef SDB_UTILS_LLIST_H +#define SDB_UTILS_LLIST_H 1 #include "core/object.h" @@ -34,27 +34,30 @@ extern "C" { #endif -struct sc_llist; -typedef struct sc_llist sc_llist_t; +struct sdb_llist; +typedef struct sdb_llist sdb_llist_t; -struct sc_llist_iter; -typedef struct sc_llist_iter sc_llist_iter_t; +struct sdb_llist_iter; +typedef struct sdb_llist_iter sdb_llist_iter_t; + +typedef int (*sdb_llist_cmp_cb)(const sdb_object_t *, const sdb_object_t *); +typedef int (*sdb_llist_lookup_cb)(const sdb_object_t *, void *user_data); /* - * sc_llist_create, sc_llist_destroy: + * sdb_llist_create, sdb_llist_destroy: * Create and destroy a doubly linked list object. * - * sc_llist_create returns NULL on error. - * sc_llist_destroy will also destroy all remaining elements, thus releasing + * sdb_llist_create returns NULL on error. + * sdb_llist_destroy will also destroy all remaining elements, thus releasing * the included objects (decrement the ref-count). */ -sc_llist_t * -sc_llist_create(void); +sdb_llist_t * +sdb_llist_create(void); void -sc_llist_destroy(sc_llist_t *list); +sdb_llist_destroy(sdb_llist_t *list); /* - * sc_llist_clone: + * sdb_llist_clone: * Clone an existing list. The objects stored in the list will not be copied * but rather their reference count incremented. * @@ -62,11 +65,11 @@ sc_llist_destroy(sc_llist_t *list); * - the copied list on success * - NULL else */ -sc_llist_t * -sc_llist_clone(sc_llist_t *list); +sdb_llist_t * +sdb_llist_clone(sdb_llist_t *list); /* - * sc_llist_append: + * sdb_llist_append: * Append the given 'obj' to the end of 'list'. The list will take ownership * of the object, that is, increment the reference count by one. In case the * caller does not longer use the object for other purposes, it should thus @@ -77,10 +80,10 @@ sc_llist_clone(sc_llist_t *list); * - a negative value on failure */ int -sc_llist_append(sc_llist_t *list, sc_object_t *obj); +sdb_llist_append(sdb_llist_t *list, sdb_object_t *obj); /* - * sc_llist_insert: + * sdb_llist_insert: * Insert the new element at the specified position (zero being the head of * the list; the length of the list being the tail)). If the index is greater * than the length of the list (i.e. past the tail of the list), an error is @@ -93,10 +96,10 @@ sc_llist_append(sc_llist_t *list, sc_object_t *obj); * - a negative value on failure */ int -sc_llist_insert(sc_llist_t *list, sc_object_t *obj, size_t index); +sdb_llist_insert(sdb_llist_t *list, sdb_object_t *obj, size_t idx); /* - * sc_llist_insert_sorted: + * sdb_llist_insert_sorted: * Insert the given 'obj' in the 'list' using a sort order as determined by * the 'compare' function. The function will insert the new entry before the * first entry which sorts later than the new entry. It will not ensure that @@ -113,55 +116,69 @@ sc_llist_insert(sc_llist_t *list, sc_object_t *obj, size_t index); * - a negative value on failure */ int -sc_llist_insert_sorted(sc_llist_t *list, sc_object_t *obj, - int (*compare)(const sc_object_t *, const sc_object_t *)); +sdb_llist_insert_sorted(sdb_llist_t *list, + sdb_object_t *obj, sdb_llist_cmp_cb); + +/* + * sdb_llist_search: + * Search for a object in the given 'list'. The function will return the first + * entry for which the 'lookup' callback returns 0. The 'user_data' is passed + * on to the lookup function on each invocation. + * + * Returns: + * - a pointer to the first matching object + * - NULL else + */ +sdb_object_t * +sdb_llist_search(sdb_llist_t *list, + sdb_llist_lookup_cb lookup, void *user_data); -/* sc_llist_search: - * Search for a 'key' in the given 'list'. The function will return the first - * entry that matches the specified 'key'. For that purpose, the 'compare' - * function is used. It should return 0 iff the two arguments compare equal. +/* + * sdb_llist_search_by_name: + * Search for an object named 'key' in the given 'list'. The function will + * return the first entry whose name matches the specified 'key' ignoring the + * case of the characters. * * Returns: - * - a pointer the sc_object_t containing the matching entry + * - a pointer to the first matching object * - NULL else */ -sc_object_t * -sc_llist_search(sc_llist_t *list, const sc_object_t *key, - int (*compare)(const sc_object_t *, const sc_object_t *)); +sdb_object_t * +sdb_llist_search_by_name(sdb_llist_t *list, const char *key); /* - * sc_llist_shift: + * sdb_llist_shift: * Removes and returns the first element of the list. The ref-count of the * item will not be changed, that is, if the element will not be used any - * further, it should be re-referenced by the caller. + * further, it should be de-referenced by the caller. * * Returns: * - the former first element of the list * - NULL if the list is empty */ -sc_object_t * -sc_llist_shift(sc_llist_t *list); +sdb_object_t * +sdb_llist_shift(sdb_llist_t *list); -/* sc_llist_get_iter, sc_llist_iter_has_next, sc_llist_iter_get_next: +/* sdb_llist_get_iter, sdb_llist_iter_has_next, sdb_llist_iter_get_next: * Iterate through the list, element by element. * - * sc_llist_iter_get_next returns NULL if there is no next element. + * sdb_llist_iter_get_next returns NULL if there is no next element. */ -sc_llist_iter_t * -sc_llist_get_iter(sc_llist_t *list); +sdb_llist_iter_t * +sdb_llist_get_iter(sdb_llist_t *list); void -sc_llist_iter_destroy(sc_llist_iter_t *iter); +sdb_llist_iter_destroy(sdb_llist_iter_t *iter); _Bool -sc_llist_iter_has_next(sc_llist_iter_t *iter); -sc_object_t * -sc_llist_iter_get_next(sc_llist_iter_t *iter); +sdb_llist_iter_has_next(sdb_llist_iter_t *iter); +sdb_object_t * +sdb_llist_iter_get_next(sdb_llist_iter_t *iter); #ifdef __cplusplus } /* extern "C" */ #endif -#endif /* ! SC_UTILS_LLIST_H */ +#endif /* ! SDB_UTILS_LLIST_H */ /* vim: set tw=78 sw=4 ts=4 noexpandtab : */