Add a swap function that swaps contents of references.

This commit is contained in:
Danila Fedorin 2018-05-14 19:16:42 -07:00
parent df50579b5c
commit 85f88b909b
2 changed files with 11 additions and 0 deletions

View File

@ -83,6 +83,10 @@ void libab_ref_free(libab_ref* ref);
* Copies this reference, thereby increasing the reference count. * Copies this reference, thereby increasing the reference count.
*/ */
void libab_ref_copy(const libab_ref* ref, libab_ref* into); void libab_ref_copy(const libab_ref* ref, libab_ref* into);
/**
* Swaps the contents of two references.
*/
void libab_ref_swap(libab_ref* left, libab_ref* right);
/** /**
* Function that can be passed in to refcount to simply use free * Function that can be passed in to refcount to simply use free
* when the refcount reaches 0. * when the refcount reaches 0.

View File

@ -57,6 +57,13 @@ void libab_ref_copy(const libab_ref* ref, libab_ref* into) {
memcpy(into, ref, sizeof(*ref)); memcpy(into, ref, sizeof(*ref));
} }
void libab_ref_swap(libab_ref* left, libab_ref* right) {
libab_ref tmp;
tmp = *left;
*left = *right;
*right = tmp;
}
void libab_ref_data_free(void* data) { free(data); } void libab_ref_data_free(void* data) { free(data); }
void* libab_ref_get(const libab_ref* ref) { void* libab_ref_get(const libab_ref* ref) {