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.
36 * Members should be treated as private and not accessed directly. Instead
37 * all access should be through the defined u_arraylist_*() functions.
39 typedef struct u_arraylist_t
47 * API to creates array list and initializes the elements.
48 * @return u_arraylist_t if Success, NULL otherwise.
50 u_arraylist_t *u_arraylist_create();
53 * Resets and deletes the array list.
54 * Arraylist elements are deleted. Calling function must take care of free
55 * dynamic memory allocated before freeing the arraylist.
56 * @param[in] list u_arraylist pointer
58 void u_arraylist_free(u_arraylist_t **list);
61 * Request that the list prepare room for the specified number of entries.
62 * If count is greater than the current internal storage size then an
63 * an attempt will be made to reallocate room for at least count items.
65 * In other cases there will be no effect.
67 * This call will not affect the length used and cannot be used to remove
69 * @param list the list to operate on.
70 * @param count the size to attempt to reserve room for.
71 * @return true if success, false otherwise.
73 bool u_arraylist_reserve(u_arraylist_t *list, size_t count);
76 * Request that the storage in the list be reduced to fit its current length.
78 * The request is non-binding, and may not affect the entries in the list.
79 * @param list the list to operate on.
81 void u_arraylist_shrink_to_fit(u_arraylist_t *list);
84 * Returns the data of the index from the array list.
85 * @param[in] list pointer of array list.
86 * @param[in] index index of array list.
87 * @return void pointer of data if success or NULL pointer otherwise.
89 void *u_arraylist_get(const u_arraylist_t *list, uint32_t index);
92 * Add data in the array list.
93 * @param[in] list pointer of array list.
94 * @param[in] data pointer of data.
95 * @return true if success, false otherwise.
97 bool u_arraylist_add(u_arraylist_t *list, void *data);
100 * Remove the data of the index from the array list.
101 * @param[in] list pointer of array list.
102 * @param[in] index index of array list.
103 * @return void pointer of the data if success or NULL pointer otherwise.
105 void *u_arraylist_remove(u_arraylist_t *list, uint32_t index);
108 * Returns the length of the array list.
109 * @param[in] list pointer of array list.
110 * @return length of the array list.
112 uint32_t u_arraylist_length(const u_arraylist_t *list);
115 * Returns whether the data exists or not.
116 * @param[in] list pointer of array list.
117 * @param[in] data pointer of data.
118 * @return true if exists, false otherwise.
120 bool u_arraylist_contains(const u_arraylist_t *list,const void *data);
123 * Destroys array list and elements (assuming elements are shallow).
124 * @param[in] list pointer of array list.
126 void u_arraylist_destroy(u_arraylist_t *list);
132 #endif /* U_ARRAYLIST_H_ */