1
0
Fork 0
mirror of https://github.com/deltachat/deltachat-core.git synced 2025-10-05 19:42:04 +02:00

add/get mrarray-items as uint/id/ptr

This commit is contained in:
B. Petersen 2018-01-07 01:25:58 +01:00
parent a6a003b30a
commit f37bbe12ae
2 changed files with 82 additions and 24 deletions

View file

@ -99,7 +99,7 @@ void mrarray_empty(mrarray_t* array)
/**
* Add an ID-item to the array.
* Add an unsigned integer to the array.
* After calling this function the size of the array grows by one.
* It is okay to add the ID 0, event in this case, the array grows by one.
*
@ -109,7 +109,7 @@ void mrarray_empty(mrarray_t* array)
*
* @return None.
*/
void mrarray_add_id(mrarray_t* array, uint32_t item)
void mrarray_add_uint(mrarray_t* array, uintptr_t item)
{
if( array == NULL || array->m_magic != MR_ARRAY_MAGIC ) {
return;
@ -128,6 +128,40 @@ void mrarray_add_id(mrarray_t* array, uint32_t item)
}
/**
* Add an ID to the array.
* After calling this function the size of the array grows by one.
* It is okay to add the ID 0, event in this case, the array grows by one.
*
* @param array The array to add the item to.
*
* @param item The item to add.
*
* @return None.
*/
void mrarray_add_id(mrarray_t* array, uint32_t item)
{
mrarray_add_uint(array, item);
}
/**
* Add an pointer to the array.
* After calling this function the size of the array grows by one.
* It is okay to add the ID 0, event in this case, the array grows by one.
*
* @param array The array to add the item to.
*
* @param item The item to add.
*
* @return None.
*/
void mrarray_add_ptr(mrarray_t* array, void* item)
{
mrarray_add_uint(array, (uintptr_t)item);
}
/**
* Find out the number of items in an array.
*
@ -147,26 +181,6 @@ size_t mrarray_get_cnt(mrarray_t* array)
}
/**
* Get the item at the given index as an ID.
*
* @memberof mrarray_t
*
* @param array The array object.
* @param index Index of the item to get. Must be between 0 and mrarray_get_cnt()-1.
*
* @return Returns the item at the given index. Returns 0 on errors or if the array is empty.
*/
uint32_t mrarray_get_id(mrarray_t* array, size_t index)
{
if( array == NULL || array->m_magic != MR_ARRAY_MAGIC || index < 0 || index >= array->m_count ) {
return 0;
}
return array->m_array[index];
}
/**
* Get the item at the given index as an unsigned integer.
* The size of the integer is always larget enough to hold a pointer.
@ -188,6 +202,46 @@ uintptr_t mrarray_get_uint(mrarray_t* array, size_t index)
}
/**
* Get the item at the given index as an ID.
*
* @memberof mrarray_t
*
* @param array The array object.
* @param index Index of the item to get. Must be between 0 and mrarray_get_cnt()-1.
*
* @return Returns the item at the given index. Returns 0 on errors or if the array is empty.
*/
uint32_t mrarray_get_id(mrarray_t* array, size_t index)
{
if( array == NULL || array->m_magic != MR_ARRAY_MAGIC || index < 0 || index >= array->m_count ) {
return 0;
}
return (uint32_t)array->m_array[index];
}
/**
* Get the item at the given index as an ID.
*
* @memberof mrarray_t
*
* @param array The array object.
* @param index Index of the item to get. Must be between 0 and mrarray_get_cnt()-1.
*
* @return Returns the item at the given index. Returns 0 on errors or if the array is empty.
*/
void* mrarray_get_ptr(mrarray_t* array, size_t index)
{
if( array == NULL || array->m_magic != MR_ARRAY_MAGIC || index < 0 || index >= array->m_count ) {
return 0;
}
return (void*)array->m_array[index];
}
/**
* Check if a given ID is present in an array.
*

View file

@ -45,11 +45,15 @@ mrarray_t* mrarray_new (mrmailbox_t*, size_t initsize);
void mrarray_empty (mrarray_t*);
void mrarray_unref (mrarray_t*);
void mrarray_add_id (mrarray_t*, uint32_t id);
void mrarray_add_uint (mrarray_t*, uintptr_t);
void mrarray_add_id (mrarray_t*, uint32_t);
void mrarray_add_ptr (mrarray_t*, void*);
size_t mrarray_get_cnt (mrarray_t*);
uint32_t mrarray_get_id (mrarray_t*, size_t index);
uintptr_t mrarray_get_uint (mrarray_t*, size_t index);
uint32_t mrarray_get_id (mrarray_t*, size_t index);
void* mrarray_get_ptr (mrarray_t*, size_t index);
int mrarray_search_id (mrarray_t*, uint32_t needle, size_t* indx);
const uintptr_t* mrarray_get_raw (mrarray_t*);