Code

Moved compare and lookup callback types from utils/llist to core/object.
[sysdb.git] / src / include / core / object.h
index 9169c441383b292803a67efc35e91147528aa1e2..42352b085876b48cbbaca7716670d05c4bc06d14 100644 (file)
@@ -68,6 +68,12 @@ typedef struct {
 #define SDB_OBJ_WRAPPER(obj) ((sdb_object_wrapper_t *)(obj))
 #define SDB_CONST_OBJ_WRAPPER(obj) ((const sdb_object_wrapper_t *)(obj))
 
+/*
+ * Callback types for comparing objects or performing object lookup.
+ */
+typedef int (*sdb_object_cmp_cb)(const sdb_object_t *, const sdb_object_t *);
+typedef int (*sdb_object_lookup_cb)(const sdb_object_t *, const void *user_data);
+
 /*
  * sdb_object_create:
  * Allocates a new sdb_object_t of the specified 'name' and 'type'. The object
@@ -93,6 +99,29 @@ sdb_object_create(const char *name, sdb_type_t type, ...);
 sdb_object_t *
 sdb_object_vcreate(const char *name, sdb_type_t type, va_list ap);
 
+/*
+ * sdb_object_create_simple:
+ * Create a "simple" object without custom initialization and optional
+ * destructor. See the description of sdb_object_create for more details.
+ */
+sdb_object_t *
+sdb_object_create_simple(const char *name, size_t size,
+               void (*destructor)(sdb_object_t *));
+
+/*
+ * sdb_object_create_T:
+ * Create a simple object of type 't'.
+ */
+#define sdb_object_create_T(n,t) \
+       sdb_object_create_simple((n), sizeof(t), NULL)
+
+/*
+ * sdb_object_create_dT:
+ * Create a simple object of dynamic type 't' using destructor 'd'.
+ */
+#define sdb_object_create_dT(n,t,d) \
+       sdb_object_create_simple((n), sizeof(t), d)
+
 /*
  * sdb_object_create_wrapper:
  * Create a new sdb_object_t wrapping some arbitrary other object.