diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-03-03 19:43:54 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-03-04 00:58:53 +0100 |
commit | 44c81eeffe9c8820b1009a7a5c728782aa5ebf40 (patch) | |
tree | 544eceb6dc5633018e5147c88ca9b07dd0fb54d9 /include/sqfs/predef.h | |
parent | 6f47796dc0761fac359ec59ce26c7af5154e538d (diff) |
Add a generic copying mechanism to sqfs_object_t
This patch adds a deep-copy callback to sqfs_object_t and removes the
copying mechanism from sqfs_compressor_t. This is also interesting for
other types.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'include/sqfs/predef.h')
-rw-r--r-- | include/sqfs/predef.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/include/sqfs/predef.h b/include/sqfs/predef.h index 6ca3503..0e81933 100644 --- a/include/sqfs/predef.h +++ b/include/sqfs/predef.h @@ -121,6 +121,8 @@ typedef struct sqfs_xattr_id_table_t sqfs_xattr_id_table_t; */ typedef struct sqfs_object_t { void (*destroy)(struct sqfs_object_t *instance); + + struct sqfs_object_t *(*copy)(const struct sqfs_object_t *orig); } sqfs_object_t; /** @@ -135,4 +137,22 @@ static SQFS_INLINE void sqfs_destroy(void *obj) ((sqfs_object_t *)obj)->destroy(obj); } +/** + * @brief Create a deep copy of an object if possible. + * + * @memberof sqfs_object_t + * + * @param obj A pointer to an object + * + * @return A pointer to a new object, instantiated from the old on success, + * NULL on failure. + */ +static SQFS_INLINE void *sqfs_copy(const void *obj) +{ + if (((sqfs_object_t *)obj)->copy != NULL) + return ((sqfs_object_t *)obj)->copy(obj); + + return NULL; +} + #endif /* SQFS_PREDEF_H */ |