-/******************************************************************
+/* ****************************************************************
*
* Copyright 2014 Samsung Electronics All Rights Reserved.
*
*
******************************************************************/
-#ifndef __U_ARRAYLIST_H_
-#define __U_ARRAYLIST_H_
+#ifndef U_ARRAYLIST_H_
+#define U_ARRAYLIST_H_
#include <stdint.h>
-#include "cacommon.h"
+#include <stdbool.h>
#ifdef __cplusplus
extern "C"
#endif
/**
- * Use this default size when initialized
- */
-#define U_ARRAYLIST_DEFAULT_SIZE 1
-
-/**
- * @struct u_arraylist_t
- * @brief array list structure
+ * array list structure.
+ *
+ * @note
+ * Members should be treated as private and not accessed directly. Instead
+ * all access should be through the defined u_arraylist_*() functions.
*/
typedef struct u_arraylist_t
{
void **data;
uint32_t length;
- uint32_t size;
+ uint32_t capacity;
} u_arraylist_t;
/**
- * @brief API to creates array list and initializes the elements.
- * @return u_arraylist_t if Success, NULL otherwise
+ * API to creates array list and initializes the elements.
+ * @return u_arraylist_t if Success, NULL otherwise.
+ */
+u_arraylist_t *u_arraylist_create();
+
+/**
+ * Resets and deletes the array list.
+ * Arraylist elements are deleted. Calling function must take care of free
+ * dynamic memory allocated before freeing the arraylist.
+ * @param[in] list u_arraylist pointer
*/
-u_arraylist_t* u_arraylist_create();
+void u_arraylist_free(u_arraylist_t **list);
/**
- * @brief Resets and deletes the array list
- * application should free the memory of data in array list
- * @param u_arraylist_t- u_arraylist pointer
- * @return CAResult_t
- * CA_STATUS_OK if Success, CA_STATUS_FAILED otherwise
+ * Request that the list prepare room for the specified number of entries.
+ * If count is greater than the current internal storage size then an
+ * an attempt will be made to reallocate room for at least count items.
+ *
+ * In other cases there will be no effect.
+ *
+ * This call will not affect the length used and cannot be used to remove
+ * entries.
+ * @param list the list to operate on.
+ * @param count the size to attempt to reserve room for.
+ * @return true if success, false otherwise.
*/
-CAResult_t u_arraylist_free(u_arraylist_t *list);
+bool u_arraylist_reserve(u_arraylist_t *list, size_t count);
/**
- * @brief Returns the data of the index from the array list
- * @param u_arraylist
- * [IN] pointer of array list
- * @param index
- * [IN] index of array list
- * @return void pointer of the data
+ * Request that the storage in the list be reduced to fit its current length.
+ *
+ * The request is non-binding, and may not affect the entries in the list.
+ * @param list the list to operate on.
*/
-void* u_arraylist_get(const u_arraylist_t *list, uint32_t index);
+void u_arraylist_shrink_to_fit(u_arraylist_t *list);
/**
- * @brief Add data in the array list
- * @param u_arraylist
- * [IN] pointer of array list
- * @param data
- * [IN] pointer of data
- * @return CAResult_t
- * CA_STATUS_OK if Success, CA_STATUS_FAILED otherwise
+ * Returns the data of the index from the array list.
+ * @param[in] list pointer of array list.
+ * @param[in] index index of array list.
+ * @return void pointer of data if success or NULL pointer otherwise.
*/
-CAResult_t u_arraylist_add(u_arraylist_t *list, void *data);
+void *u_arraylist_get(const u_arraylist_t *list, uint32_t index);
/**
- * @brief Remove the data of the index from the array list
- * @param u_arraylist
- * [IN] pointer of array list
- * @param index
- * [IN] index of array list
- * @return void pointer of the data
+ * Returns the index of the data from the array list.
+ * @param[in] list pointer of array list.
+ * @param[in] data pointer of data.
+ * @param[out]index index of array list.
+ * @return true if success, false otherwise.
*/
-void* u_arraylist_remove(u_arraylist_t *list, uint32_t index);
+bool u_arraylist_get_index(const u_arraylist_t *list, const void *data, uint32_t *index);
/**
- * @brief Returns the length of the array list
- * @param u_arraylist
- * [IN] pointer of array list
- * @return length of the array list
+ * Add data in the array list.
+ * @param[in] list pointer of array list.
+ * @param[in] data pointer of data.
+ * @return true if success, false otherwise.
+ */
+bool u_arraylist_add(u_arraylist_t *list, void *data);
+
+/**
+ * Remove the data of the index from the array list.
+ * @param[in] list pointer of array list.
+ * @param[in] index index of array list.
+ * @return void pointer of the data if success or NULL pointer otherwise.
+ */
+void *u_arraylist_remove(u_arraylist_t *list, uint32_t index);
+
+/**
+ * Returns the length of the array list.
+ * @param[in] list pointer of array list.
+ * @return length of the array list.
*/
uint32_t u_arraylist_length(const u_arraylist_t *list);
/**
- * @brief Returns whether the data exists or not
- * @param u_arraylist
- * [IN] pointer of array list
- * @param data
- * [IN] pointer of data
- * @return 1 if exists, 0 otherwise
+ * Returns whether the data exists or not.
+ * @param[in] list pointer of array list.
+ * @param[in] data pointer of data.
+ * @return true if exists, false otherwise.
+ */
+bool u_arraylist_contains(const u_arraylist_t *list,const void *data);
+
+/**
+ * Destroys array list and elements (assuming elements are shallow).
+ * @param[in] list pointer of array list.
*/
-uint8_t u_arraylist_contains(const u_arraylist_t *list, void *data);
+void u_arraylist_destroy(u_arraylist_t *list);
#ifdef __cplusplus
}
#endif
-#endif /* _U_ARRAYLIST_H_ */
+#endif /* U_ARRAYLIST_H_ */