summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2014-02-25 17:22:28 -0300
committerCedric Bail <cedric.bail@free.fr>2014-02-25 18:04:47 -0300
commitd63507446fcd9ee1fd90373f5d1207f71cfb8f74 (patch)
tree02247ce4e11b9f94ae7895e08282789004035da3 /src
parent794bbcbca8b3d501bdc2e78146b5c6af1cecb6dc (diff)
eina: add eina_accessor_clone and update all Eina_Accessor to take advantage of it.
@feature. Signed-off-by: Cedric Bail <cedric.bail@free.fr>
Diffstat (limited to 'src')
-rw-r--r--src/lib/eina/eina_accessor.c12
-rw-r--r--src/lib/eina/eina_accessor.h27
-rw-r--r--src/lib/eina/eina_array.c18
-rw-r--r--src/lib/eina/eina_list.c18
4 files changed, 74 insertions, 1 deletions
diff --git a/src/lib/eina/eina_accessor.c b/src/lib/eina/eina_accessor.c
index fa56a69ab0..9506b86a80 100644
--- a/src/lib/eina/eina_accessor.c
+++ b/src/lib/eina/eina_accessor.c
@@ -167,6 +167,18 @@ eina_accessor_lock(Eina_Accessor *accessor)
167 return EINA_TRUE; 167 return EINA_TRUE;
168} 168}
169 169
170EAPI Eina_Accessor*
171eina_accessor_clone(Eina_Accessor *accessor)
172{
173 EINA_MAGIC_CHECK_ACCESSOR(accessor);
174 EINA_SAFETY_ON_NULL_RETURN_VAL(accessor, NULL);
175
176 if (accessor->clone)
177 return accessor->clone(accessor);
178
179 return NULL;
180}
181
170EAPI Eina_Bool 182EAPI Eina_Bool
171eina_accessor_unlock(Eina_Accessor *accessor) 183eina_accessor_unlock(Eina_Accessor *accessor)
172{ 184{
diff --git a/src/lib/eina/eina_accessor.h b/src/lib/eina/eina_accessor.h
index c51c86da6e..3de6e42106 100644
--- a/src/lib/eina/eina_accessor.h
+++ b/src/lib/eina/eina_accessor.h
@@ -146,6 +146,13 @@ typedef void (*Eina_Accessor_Free_Callback)(Eina_Accessor *it);
146typedef Eina_Bool (*Eina_Accessor_Lock_Callback)(Eina_Accessor *it); 146typedef Eina_Bool (*Eina_Accessor_Lock_Callback)(Eina_Accessor *it);
147 147
148/** 148/**
149 * @typedef Eina_Accessor_Clone_Callback
150 * Type for a callback that returns a clone for the accessor
151 * @since 1.10
152 */
153typedef Eina_Accessor* (*Eina_Accessor_Clone_Callback)(Eina_Accessor *it);
154
155/**
149 * @struct _Eina_Accessor 156 * @struct _Eina_Accessor
150 * Type to provide random access to data structures. 157 * Type to provide random access to data structures.
151 * 158 *
@@ -153,7 +160,7 @@ typedef Eina_Bool (*Eina_Accessor_Lock_Callback)(Eina_Accessor *it);
153 */ 160 */
154struct _Eina_Accessor 161struct _Eina_Accessor
155{ 162{
156#define EINA_ACCESSOR_VERSION 1 163#define EINA_ACCESSOR_VERSION 2
157 int version; /**< Version of the Accessor API. */ 164 int version; /**< Version of the Accessor API. */
158 165
159 Eina_Accessor_Get_At_Callback get_at EINA_ARG_NONNULL(1, 3) EINA_WARN_UNUSED_RESULT; /**< Callback called when a data element is requested. */ 166 Eina_Accessor_Get_At_Callback get_at EINA_ARG_NONNULL(1, 3) EINA_WARN_UNUSED_RESULT; /**< Callback called when a data element is requested. */
@@ -165,6 +172,8 @@ struct _Eina_Accessor
165 172
166#define EINA_MAGIC_ACCESSOR 0x98761232 173#define EINA_MAGIC_ACCESSOR 0x98761232
167 EINA_MAGIC 174 EINA_MAGIC
175
176 Eina_Accessor_Clone_Callback clone EINA_WARN_UNUSED_RESULT; /**< Callback called when the container is to be cloned. @since 1.10 */
168}; 177};
169 178
170/** 179/**
@@ -191,6 +200,13 @@ struct _Eina_Accessor
191 */ 200 */
192#define FUNC_ACCESSOR_LOCK(Function) ((Eina_Accessor_Lock_Callback)Function) 201#define FUNC_ACCESSOR_LOCK(Function) ((Eina_Accessor_Lock_Callback)Function)
193 202
203/**
204 * @def FUNC_ACCESSOR_CLONE(Function)
205 * Helper macro to cast @p Function to a Eina_Iterator_Clone_Callback.
206 * @since 1.10
207 */
208#define FUNC_ACCESSOR_CLONE(Function) ((Eina_Accessor_Clone_Callback)Function)
209
194 210
195/** 211/**
196 * @brief Free an accessor. 212 * @brief Free an accessor.
@@ -268,6 +284,15 @@ EAPI void eina_accessor_over(Eina_Accessor *accessor,
268EAPI Eina_Bool eina_accessor_lock(Eina_Accessor *accessor) EINA_ARG_NONNULL(1); 284EAPI Eina_Bool eina_accessor_lock(Eina_Accessor *accessor) EINA_ARG_NONNULL(1);
269 285
270/** 286/**
287 * @brief Clone the accessor.
288 *
289 * @param accessor The accessor.
290 * @return Another accessor
291 * @since 1.10
292 */
293EAPI Eina_Accessor* eina_accessor_clone(Eina_Accessor *accessor) EINA_ARG_NONNULL(1);
294
295/**
271 * @brief Unlock the container of the accessor. 296 * @brief Unlock the container of the accessor.
272 * 297 *
273 * @param accessor The accessor. 298 * @param accessor The accessor.
diff --git a/src/lib/eina/eina_array.c b/src/lib/eina/eina_array.c
index dddcf732bb..4e8f6fdb86 100644
--- a/src/lib/eina/eina_array.c
+++ b/src/lib/eina/eina_array.c
@@ -172,6 +172,22 @@ eina_array_accessor_free(Eina_Accessor_Array *it)
172 MAGIC_FREE(it); 172 MAGIC_FREE(it);
173} 173}
174 174
175static EAPI Eina_Accessor *
176eina_array_accessor_clone(const Eina_Array *array)
177{
178 Eina_Accessor_Array *ac;
179
180 EINA_SAFETY_ON_NULL_RETURN_VAL(array, NULL);
181 EINA_MAGIC_CHECK_ARRAY(array);
182
183 ac = calloc(1, sizeof (Eina_Accessor_Array));
184 if (!ac) return NULL;
185
186 memcpy(ac, array, sizeof(Eina_Accessor_Array));
187
188 return &ac->accessor;
189}
190
175/* used from eina_inline_array.x, thus a needed symbol */ 191/* used from eina_inline_array.x, thus a needed symbol */
176EAPI Eina_Bool 192EAPI Eina_Bool
177eina_array_grow(Eina_Array *array) 193eina_array_grow(Eina_Array *array)
@@ -419,6 +435,8 @@ eina_array_accessor_new(const Eina_Array *array)
419 ac->accessor.get_container = FUNC_ACCESSOR_GET_CONTAINER( 435 ac->accessor.get_container = FUNC_ACCESSOR_GET_CONTAINER(
420 eina_array_accessor_get_container); 436 eina_array_accessor_get_container);
421 ac->accessor.free = FUNC_ACCESSOR_FREE(eina_array_accessor_free); 437 ac->accessor.free = FUNC_ACCESSOR_FREE(eina_array_accessor_free);
438 ac->accessor.clone = FUNC_ACCESSOR_CLONE(eina_array_accessor_clone);
422 439
423 return &ac->accessor; 440 return &ac->accessor;
424} 441}
442
diff --git a/src/lib/eina/eina_list.c b/src/lib/eina/eina_list.c
index 9162088e6e..aa19ca4b19 100644
--- a/src/lib/eina/eina_list.c
+++ b/src/lib/eina/eina_list.c
@@ -385,6 +385,23 @@ eina_list_accessor_free(Eina_Accessor_List *it)
385 MAGIC_FREE(it); 385 MAGIC_FREE(it);
386} 386}
387 387
388static Eina_Accessor*
389eina_list_accessor_clone(Eina_Accessor_List *list)
390{
391 Eina_Accessor_List *ac;
392
393 EINA_MAGIC_CHECK_LIST_ACCESSOR(list, NULL);
394
395 EINA_SAFETY_ON_NULL_RETURN_VAL(list, NULL);
396
397 ac = calloc(1, sizeof (Eina_Accessor_List));
398 if (!ac) return NULL;
399
400 memcpy(ac, list, sizeof(Eina_Accessor_List));
401
402 return &ac->accessor;
403}
404
388static Eina_List * 405static Eina_List *
389eina_list_sort_rebuild_prev(Eina_List *list) 406eina_list_sort_rebuild_prev(Eina_List *list)
390{ 407{
@@ -1547,6 +1564,7 @@ eina_list_accessor_new(const Eina_List *list)
1547 ac->accessor.get_container = FUNC_ACCESSOR_GET_CONTAINER( 1564 ac->accessor.get_container = FUNC_ACCESSOR_GET_CONTAINER(
1548 eina_list_accessor_get_container); 1565 eina_list_accessor_get_container);
1549 ac->accessor.free = FUNC_ACCESSOR_FREE(eina_list_accessor_free); 1566 ac->accessor.free = FUNC_ACCESSOR_FREE(eina_list_accessor_free);
1567 ac->accessor.clone = FUNC_ACCESSOR_CLONE(eina_list_accessor_clone);
1550 1568
1551 return &ac->accessor; 1569 return &ac->accessor;
1552} 1570}