1 /******************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
21 #ifndef U_ARRAYLIST_H_
22 #define U_ARRAYLIST_H_
33 * @struct u_arraylist_t
34 * @brief array list structure
36 typedef struct u_arraylist_t
44 * @brief API to creates array list and initializes the elements.
45 * @return u_arraylist_t if Success, NULL otherwise
47 u_arraylist_t *u_arraylist_create();
50 * @brief Resets and deletes the array list
51 * Arraylist elements are deleted. Calling function must take care of free
52 * dynamic memory allocated before freeing the arraylist
53 * @param list- u_arraylist pointer
55 * CA_STATUS_OK if Success, CA_STATUS_INVALID_PARAM if pointer to list is NULL
57 CAResult_t u_arraylist_free(u_arraylist_t **list);
60 * @brief Returns the data of the index from the array list
62 * [IN] pointer of array list
64 * [IN] index of array list
65 * @return void pointer of data if success or NULL pointer otherwise
67 void *u_arraylist_get(const u_arraylist_t *list, uint32_t index);
70 * @brief Add data in the array list
72 * [IN] pointer of array list
74 * [IN] pointer of data
76 * CA_STATUS_OK if Success, CA_MEMORY_ALLOC_FAILED if memory allocation fails
78 CAResult_t u_arraylist_add(u_arraylist_t *list, void *data);
81 * @brief Remove the data of the index from the array list
83 * [IN] pointer of array list
85 * [IN] index of array list
86 * @return void pointer of the data if success or NULL pointer otherwise
88 void *u_arraylist_remove(u_arraylist_t *list, uint32_t index);
91 * @brief Returns the length of the array list
93 * [IN] pointer of array list
94 * @return length of the array list
96 uint32_t u_arraylist_length(const u_arraylist_t *list);
99 * @brief Returns whether the data exists or not
101 * [IN] pointer of array list
103 * [IN] pointer of data
104 * @return true if exists, false otherwise
106 bool u_arraylist_contains(const u_arraylist_t *list,const void *data);
109 * @brief Destroys array list and elements (assuming elements are shallow)
111 * [IN] pointer of array list
113 void u_arraylist_destroy(u_arraylist_t *list);
119 #endif /* U_ARRAYLIST_H_ */