replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / connectivity / common / inc / uarraylist.h
1 /* ****************************************************************
2  *
3  * Copyright 2014 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  ******************************************************************/
20
21 #ifndef U_ARRAYLIST_H_
22 #define U_ARRAYLIST_H_
23
24 #include <stdint.h>
25 #include <stdbool.h>
26
27 #ifdef __cplusplus
28 extern "C"
29 {
30 #endif
31
32 /**
33  * array list structure.
34  *
35  * @note
36  * Members should be treated as private and not accessed directly. Instead
37  * all access should be through the defined u_arraylist_*() functions.
38  */
39 typedef struct u_arraylist_t
40 {
41     void **data;
42     uint32_t length;
43     uint32_t capacity;
44 } u_arraylist_t;
45
46 /**
47  * API to creates array list and initializes the elements.
48  * @return  u_arraylist_t if Success, NULL otherwise.
49  */
50 u_arraylist_t *u_arraylist_create();
51
52 /**
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
57  */
58 void u_arraylist_free(u_arraylist_t **list);
59
60 /**
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.
64  *
65  * In other cases there will be no effect.
66  *
67  * This call will not affect the length used and cannot be used to remove
68  * entries.
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.
72  */
73 bool u_arraylist_reserve(u_arraylist_t *list, size_t count);
74
75 /**
76  * Request that the storage in the list be reduced to fit its current length.
77  *
78  * The request is non-binding, and may not affect the entries in the list.
79  * @param list the list to operate on.
80  */
81 void u_arraylist_shrink_to_fit(u_arraylist_t *list);
82
83 /**
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.
88  */
89 void *u_arraylist_get(const u_arraylist_t *list, uint32_t index);
90
91 /**
92  * Returns the index of the data from the array list.
93  * @param[in] list         pointer of array list.
94  * @param[in] data         pointer of data.
95  * @param[out]index        index of array list.
96  * @return true if success, false otherwise.
97  */
98 bool u_arraylist_get_index(const u_arraylist_t *list, const void *data,  uint32_t *index);
99
100 /**
101  * Add data in the array list.
102  * @param[in] list        pointer of array list.
103  * @param[in] data        pointer of data.
104  * @return true if success, false otherwise.
105  */
106 bool u_arraylist_add(u_arraylist_t *list, void *data);
107
108 /**
109  * Remove the data of the index from the array list.
110  * @param[in] list       pointer of array list.
111  * @param[in] index      index of array list.
112  * @return void pointer of the data if success or NULL pointer otherwise.
113  */
114 void *u_arraylist_remove(u_arraylist_t *list, uint32_t index);
115
116 /**
117  * Returns the length of the array list.
118  * @param[in] list       pointer of array list.
119  * @return length of the array list.
120  */
121 uint32_t u_arraylist_length(const u_arraylist_t *list);
122
123 /**
124  * Returns whether the data exists or not.
125  * @param[in] list       pointer of array list.
126  * @param[in] data       pointer of data.
127  * @return true if exists, false otherwise.
128  */
129 bool u_arraylist_contains(const u_arraylist_t *list,const void *data);
130
131 /**
132  * Destroys array list and elements (assuming elements are shallow).
133  * @param[in] list       pointer of array list.
134  */
135 void u_arraylist_destroy(u_arraylist_t *list);
136
137 #ifdef __cplusplus
138 }
139 #endif
140
141 #endif /* U_ARRAYLIST_H_ */