a055a1ba553f845e5f636a7a6cc055ad6b1ba979
[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 "cacommon.h"
26
27 #ifdef __cplusplus
28 extern "C"
29 {
30 #endif
31
32 /**
33  * array list structure.
34  */
35 typedef struct u_arraylist_t
36 {
37     void **data;
38     uint32_t length;
39     uint32_t size;
40 } u_arraylist_t;
41
42 /**
43  * API to creates array list and initializes the elements.
44  * @return  u_arraylist_t if Success, NULL otherwise.
45  */
46 u_arraylist_t *u_arraylist_create();
47
48 /**
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.
55  */
56 CAResult_t u_arraylist_free(u_arraylist_t **list);
57
58 /**
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.
63  */
64 void *u_arraylist_get(const u_arraylist_t *list, uint32_t index);
65
66 /**
67  * Add data in the array list.
68  * @param[in] list        pointer of array list.
69  * @param[in] data        pointer of data.
70  * @return CAResult_t.
71  * ::CA_STATUS_OK if Success, ::CA_MEMORY_ALLOC_FAILED if memory allocation fails.
72  */
73 CAResult_t u_arraylist_add(u_arraylist_t *list, void *data);
74
75 /**
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.
80  */
81 void *u_arraylist_remove(u_arraylist_t *list, uint32_t index);
82
83 /**
84  * Returns the length of the array list.
85  * @param[in] list       pointer of array list.
86  * @return length of the array list.
87  */
88 uint32_t u_arraylist_length(const u_arraylist_t *list);
89
90 /**
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.
95  */
96 bool u_arraylist_contains(const u_arraylist_t *list,const void *data);
97
98 /**
99  * Destroys array list and elements (assuming elements are shallow).
100  * @param[in] list       pointer of array list.
101  */
102 void u_arraylist_destroy(u_arraylist_t *list);
103
104 #ifdef __cplusplus
105 }
106 #endif
107
108 #endif /* U_ARRAYLIST_H_ */