From: Sebastian Harl Date: Sat, 23 Mar 2013 03:25:44 +0000 (-0700) Subject: object: Introduced sdb_object_clone(). X-Git-Tag: sysdb-0.1.0~414 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=523a1d37d7040620a81b55f7e78474b23b695bdc;p=sysdb.git object: Introduced sdb_object_clone(). --- diff --git a/src/core/object.c b/src/core/object.c index e9825b1..65b256f 100644 --- a/src/core/object.c +++ b/src/core/object.c @@ -137,5 +137,13 @@ sdb_object_ref(sdb_object_t *obj) ++obj->ref_cnt; } /* sdb_object_ref */ +sdb_object_t * +sdb_object_clone(const sdb_object_t *obj) +{ + if ((! obj) || (! obj->type.clone)) + return NULL; + return obj->type.clone(obj); +} /* sdb_object_clone */ + /* vim: set tw=78 sw=4 ts=4 noexpandtab : */ diff --git a/src/include/core/object.h b/src/include/core/object.h index dab220b..dce562c 100644 --- a/src/include/core/object.h +++ b/src/include/core/object.h @@ -116,6 +116,19 @@ sdb_object_deref(sdb_object_t *obj); void sdb_object_ref(sdb_object_t *obj); +/* + * sdb_object_clone: + * Clone an existing object using its type's 'clone' callback. The callback is + * responsible for correctly initializing a new object (which may be done + * using the object create function or the object's type's init function). + * + * Returns: + * - the cloned object on success + * - NULL on error or if no clone callback is available + */ +sdb_object_t * +sdb_object_clone(const sdb_object_t *obj); + #ifdef __cplusplus } /* extern "C" */ #endif