diff options
author | Dmitri Pal <dpal@redhat.com> | 2010-11-25 17:36:36 -0500 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2010-12-21 11:16:08 -0500 |
commit | 8c201905d5f0720b62d036eb2308f81f4530cfad (patch) | |
tree | 3a556b7c4881e04bbd266a92d322005918223b0a /refarray/ref_array.h | |
parent | 86564695945fa1892fe990ba8b7bbc1af70cc48a (diff) | |
download | ding-libs-8c201905d5f0720b62d036eb2308f81f4530cfad.tar.gz ding-libs-8c201905d5f0720b62d036eb2308f81f4530cfad.tar.xz ding-libs-8c201905d5f0720b62d036eb2308f81f4530cfad.zip |
Adding ref_array copy method
* Added a method to copy ref array
* Added unit test to check copy functionality
* Took advantage of the new trace macros
* Reworked the debug function to be able to
trace arrays with different types of data.
Diffstat (limited to 'refarray/ref_array.h')
-rw-r--r-- | refarray/ref_array.h | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/refarray/ref_array.h b/refarray/ref_array.h index 0040fe4..d271d38 100644 --- a/refarray/ref_array.h +++ b/refarray/ref_array.h @@ -83,11 +83,34 @@ typedef enum * * Callback that can be provided by a caller * to free data when the storage is actually destroyed. + * + * @param[in] elem Pointer to the array element. + * @param[in] type Type of the operation performed. + * @param[in] data Application data that can be used + * inside the callback. + * No return value. */ typedef void (*ref_array_fn)(void *elem, ref_array_del_enum type, void *data); +/** + * @brief Copy callback + * + * Callback that can be provided by a caller + * to copy elements of the array. + * + * @param[in] elem Pointer to the array element. + * @param[out] new_elem Pointer to pointer to the new element. + * + * @return 0 - Success. + * @return ENOMEM - No memory. + * @return EINVAL - Invalid argument. + * + * Callback can return other errors and the implementor's discretion. + */ +typedef int (*ref_array_copy_cb)(void *elem, + void *new_elem); /** * @brief Create referenced array @@ -313,6 +336,33 @@ int ref_array_swap(struct ref_array *ra, */ void ref_array_reset(struct ref_array *ra); + +/** + * @brief Copy array + * + * Function copies all contents calling a provided + * callback for every entry of the array. + * + * + * @param[in] ra Existing array object to copy. + * @param[in] copy_cb Copy callback. + * @param[in] cb Cleanup callback, will be used + * to clean data in the array copy. + * @param[in] data Caller supplied data + * passed to cleanup callback. + * @param[out] copy_ra Newly allocated copy. + * + * @return 0 - Success. + * @return ENOMEM - No memory. + * @return EINVAL - Invalid argument. + */ +int ref_array_copy(struct ref_array *ra, + ref_array_copy_cb copy_cb, + ref_array_fn cb, + void *data, + struct ref_array **copy_ra); + + /** * @} */ |