diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/eina/src/include/eina_inline_array.x | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/libraries/eina/src/include/eina_inline_array.x b/libraries/eina/src/include/eina_inline_array.x new file mode 100644 index 0000000..f9f6026 --- /dev/null +++ b/libraries/eina/src/include/eina_inline_array.x | |||
@@ -0,0 +1,164 @@ | |||
1 | /* EINA - EFL data type library | ||
2 | * Copyright (C) 2008 Cedric Bail | ||
3 | * | ||
4 | * This library is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) any later version. | ||
8 | * | ||
9 | * This library is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | * Lesser General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU Lesser General Public | ||
15 | * License along with this library; | ||
16 | * if not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #ifndef EINA_INLINE_ARRAY_X_ | ||
20 | #define EINA_INLINE_ARRAY_X_ | ||
21 | |||
22 | #include <stdio.h> | ||
23 | |||
24 | /** | ||
25 | * @cond LOCAL | ||
26 | */ | ||
27 | |||
28 | EAPI Eina_Bool eina_array_grow(Eina_Array *array); | ||
29 | |||
30 | /** | ||
31 | * @endcond | ||
32 | */ | ||
33 | |||
34 | /** | ||
35 | * @addtogroup Eina_Array_Group Array | ||
36 | * | ||
37 | * @brief These functions provide array management. | ||
38 | * | ||
39 | * @{ | ||
40 | */ | ||
41 | |||
42 | /** | ||
43 | * @brief Append a data to an array. | ||
44 | * | ||
45 | * @param array The array. | ||
46 | * @param data The data to add. | ||
47 | * @return #EINA_TRUE on success, #EINA_FALSE otherwise. | ||
48 | * | ||
49 | * This function appends @p data to @p array. For performance | ||
50 | * reasons, there is no check of @p array. If it is @c NULL or | ||
51 | * invalid, the program may crash. If @p data is @c NULL, or if an | ||
52 | * allocation is necessary and fails, #EINA_FALSE is returned and | ||
53 | * #EINA_ERROR_OUT_OF_MEMORY is set. Otherwise, #EINA_TRUE is | ||
54 | * returned. | ||
55 | */ | ||
56 | |||
57 | static inline Eina_Bool | ||
58 | eina_array_push(Eina_Array *array, const void *data) | ||
59 | { | ||
60 | if (!data) return EINA_FALSE; | ||
61 | |||
62 | if (EINA_UNLIKELY((array->count + 1) > array->total)) | ||
63 | if (!eina_array_grow(array)) | ||
64 | return EINA_FALSE; | ||
65 | |||
66 | array->data[array->count++] = (void*) data; | ||
67 | |||
68 | return EINA_TRUE; | ||
69 | } | ||
70 | |||
71 | /** | ||
72 | * @brief Remove the last data of an array. | ||
73 | * | ||
74 | * @param array The array. | ||
75 | * @return The retrieved data. | ||
76 | * | ||
77 | * This function removes the last data of @p array, decreases the count | ||
78 | * of @p array and returns the data. For performance reasons, there | ||
79 | * is no check of @p array. If it is @c NULL or invalid, the program | ||
80 | * may crash. If the count member is less or equal than 0, @c NULL is | ||
81 | * returned. | ||
82 | */ | ||
83 | static inline void * | ||
84 | eina_array_pop(Eina_Array *array) | ||
85 | { | ||
86 | void *ret = NULL; | ||
87 | |||
88 | if (array->count <= 0) | ||
89 | goto on_empty; | ||
90 | |||
91 | ret = array->data[--array->count]; | ||
92 | |||
93 | on_empty: | ||
94 | return ret; | ||
95 | } | ||
96 | |||
97 | /** | ||
98 | * @brief Return the data at a given position in an array. | ||
99 | * | ||
100 | * @param array The array. | ||
101 | * @param idx The potition of the data to retrieve. | ||
102 | * @return The retrieved data. | ||
103 | * | ||
104 | * This function returns the data at the position @p idx in @p | ||
105 | * array. For performance reasons, there is no check of @p array or @p | ||
106 | * idx. If it is @c NULL or invalid, the program may crash. | ||
107 | */ | ||
108 | static inline void * | ||
109 | eina_array_data_get(const Eina_Array *array, unsigned int idx) | ||
110 | { | ||
111 | return array->data[idx]; | ||
112 | } | ||
113 | |||
114 | static inline void | ||
115 | eina_array_data_set(const Eina_Array *array, unsigned int idx, const void *data) | ||
116 | { | ||
117 | array->data[idx] = (void*) data; | ||
118 | } | ||
119 | |||
120 | /** | ||
121 | * @brief Return the number of elements in an array. | ||
122 | * | ||
123 | * @param array The array. | ||
124 | * @return The number of elements. | ||
125 | * | ||
126 | * This function returns the number of elements in @p array. For | ||
127 | * performance reasons, there is no check of @p array. If it is | ||
128 | * @c NULL or invalid, the program may crash. | ||
129 | */ | ||
130 | static inline unsigned int | ||
131 | eina_array_count_get(const Eina_Array *array) | ||
132 | { | ||
133 | return array->count; | ||
134 | } | ||
135 | |||
136 | static inline Eina_Bool | ||
137 | eina_array_foreach(Eina_Array *array, Eina_Each_Cb cb, void *fdata) | ||
138 | { | ||
139 | void *data; | ||
140 | Eina_Array_Iterator iterator; | ||
141 | unsigned int i; | ||
142 | Eina_Bool ret = EINA_TRUE; | ||
143 | |||
144 | EINA_ARRAY_ITER_NEXT(array, i, data, iterator) | ||
145 | if (cb(array, data, fdata) != EINA_TRUE) | ||
146 | { | ||
147 | ret = EINA_FALSE; | ||
148 | break; | ||
149 | } | ||
150 | |||
151 | return ret; | ||
152 | } | ||
153 | |||
154 | static inline void | ||
155 | eina_array_clean(Eina_Array *array) | ||
156 | { | ||
157 | array->count = 0; | ||
158 | } | ||
159 | |||
160 | /** | ||
161 | * @} | ||
162 | */ | ||
163 | |||
164 | #endif | ||