Commit e945050f authored by Chris Müller's avatar Chris Müller

lib: use const_pointer in cry_array methods.

lib: add cry_array_clone functions.
parent f8525c13
......@@ -104,7 +104,7 @@ cry_array_trim(struct CryArray* array)
void
cry_array_append(struct CryArray* array, pointer data, size_t size)
cry_array_append(struct CryArray* array, const_pointer data, size_t size)
{
assert(array != 0);
......@@ -117,7 +117,7 @@ cry_array_append(struct CryArray* array, pointer data, size_t size)
return_code
cry_array_insert(struct CryArray* array, size_t index, pointer data, size_t size)
cry_array_insert(struct CryArray* array, size_t index, const_pointer data, size_t size)
{
assert(array != 0);
......@@ -136,7 +136,7 @@ cry_array_insert(struct CryArray* array, size_t index, pointer data, size_t size
return_code
cry_array_replace(struct CryArray* array, size_t index, pointer data, size_t size)
cry_array_replace(struct CryArray* array, size_t index, const_pointer data, size_t size)
{
assert(array != 0);
......@@ -165,6 +165,16 @@ cry_array_remove(struct CryArray* array, size_t index, size_t size)
void
cry_array_clear(struct CryArray* array)
{
assert(array != 0);
array->length = 0;
}
pointer
cry_array_get(struct CryArray* array, size_t index)
{
......@@ -177,6 +187,22 @@ cry_array_get(struct CryArray* array, size_t index)
}
pointer
cry_array_clone(struct CryArray* array)
{
assert(array != 0);
uint8_t* ptr = 0;
if(array->length > 0) {
ptr = cry_calloc(uint8_t, array->length);
memcpy(ptr, array->data, array->length);
}
return ptr;
}
struct CryPtrArray
{
pointer* data;
......
......@@ -51,11 +51,13 @@ size_t cry_array_capacity(struct CryArray* array);
size_t cry_array_ensure(struct CryArray* array, size_t min_capacity);
size_t cry_array_trim(struct CryArray* array);
void cry_array_append(struct CryArray* array, pointer data, size_t size);
return_code cry_array_insert(struct CryArray* array, size_t index, pointer data, size_t size);
void cry_array_append(struct CryArray* array, const_pointer data, size_t size);
return_code cry_array_insert(struct CryArray* array, size_t index, const_pointer data, size_t size);
return_code cry_array_remove(struct CryArray* array, size_t index, size_t size);
return_code cry_array_replace(struct CryArray* array, size_t index, pointer data, size_t size);
return_code cry_array_replace(struct CryArray* array, size_t index, const_pointer data, size_t size);
void cry_array_clear(struct CryArray* array);
pointer cry_array_clone(struct CryArray* array);
pointer cry_array_get(struct CryArray* array, size_t index);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment