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 * array list structure.
35 typedef struct u_arraylist_t
43 * API to creates array list and initializes the elements.
44 * @return u_arraylist_t if Success, NULL otherwise.
46 u_arraylist_t *u_arraylist_create();
49 * Resets and deletes the array list.
50 * Arraylist elements are deleted. Calling function must take care of free
51 * dynamic memory allocated before freeing the arraylist.
52 * @param[in] list u_arraylist pointer
53 * @return ::CAResult_t.
54 * ::CA_STATUS_OK if Success, ::CA_STATUS_INVALID_PARAM if pointer to list is NULL.
56 CAResult_t u_arraylist_free(u_arraylist_t **list);
59 * Returns the data of the index from the array list.
60 * @param[in] list pointer of array list.
61 * @param[in] index index of array list.
62 * @return void pointer of data if success or NULL pointer otherwise.
64 void *u_arraylist_get(const u_arraylist_t *list, uint32_t index);
67 * Add data in the array list.
68 * @param[in] list pointer of array list.
69 * @param[in] data pointer of data.
71 * ::CA_STATUS_OK if Success, ::CA_MEMORY_ALLOC_FAILED if memory allocation fails.
73 CAResult_t u_arraylist_add(u_arraylist_t *list, void *data);
76 * Remove the data of the index from the array list.
77 * @param[in] list pointer of array list.
78 * @param[in] index index of array list.
79 * @return void pointer of the data if success or NULL pointer otherwise.
81 void *u_arraylist_remove(u_arraylist_t *list, uint32_t index);
84 * Returns the length of the array list.
85 * @param[in] list pointer of array list.
86 * @return length of the array list.
88 uint32_t u_arraylist_length(const u_arraylist_t *list);
91 * Returns whether the data exists or not.
92 * @param[in] list pointer of array list.
93 * @param[in] data pointer of data.
94 * @return true if exists, false otherwise.
96 bool u_arraylist_contains(const u_arraylist_t *list,const void *data);
99 * Destroys array list and elements (assuming elements are shallow).
100 * @param[in] list pointer of array list.
102 void u_arraylist_destroy(u_arraylist_t *list);
108 #endif /* U_ARRAYLIST_H_ */