From 523a1d37d7040620a81b55f7e78474b23b695bdc Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Fri, 22 Mar 2013 20:25:44 -0700 Subject: [PATCH] object: Introduced sdb_object_clone(). --- src/core/object.c | 8 ++++++++ src/include/core/object.h | 13 +++++++++++++ 2 files changed, 21 insertions(+) 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 -- 2.30.2