summaryrefslogtreecommitdiff
path: root/src/lib/ecore
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2019-04-03 14:23:01 -0700
committerCedric BAIL <cedric.bail@free.fr>2019-04-22 19:50:18 -0700
commit75f43ca971bb476f4c3639a198b764e6520fc859 (patch)
tree37f6ad9c777d92a810f6c9edba40f3588a6e316b /src/lib/ecore
parent0c5a0186d18b6b893797d76abb63ab7cad01b815 (diff)
ecore: add an helper for Efl.Boolean_Model to get all the index with a requested value.
Differential Revision: https://phab.enlightenment.org/D8569
Diffstat (limited to 'src/lib/ecore')
-rw-r--r--src/lib/ecore/efl_boolean_model.c117
-rw-r--r--src/lib/ecore/efl_boolean_model.eo8
2 files changed, 125 insertions, 0 deletions
diff --git a/src/lib/ecore/efl_boolean_model.c b/src/lib/ecore/efl_boolean_model.c
index da9d3bdf96..20aed0fe50 100644
--- a/src/lib/ecore/efl_boolean_model.c
+++ b/src/lib/ecore/efl_boolean_model.c
@@ -207,4 +207,121 @@ _efl_boolean_model_boolean_del(Eo *obj EINA_UNUSED,
207 eina_stringshare_del(s); 207 eina_stringshare_del(s);
208} 208}
209 209
210typedef struct _Eina_Iterator_Boolean Eina_Iterator_Boolean;
211
212struct _Eina_Iterator_Boolean
213{
214 Eina_Iterator iterator;
215
216 Eo *obj;
217 Efl_Boolean_Model_Data *pd;
218 Efl_Boolean_Model_Value *v;
219
220 uint64_t index;
221 uint64_t total;
222
223 Eina_Bool request;
224};
225
226static inline Eina_Bool
227_lookup_next_chunk(uint64_t *index, uint64_t total,
228 Efl_Boolean_Model_Value *v, unsigned char pattern)
229{
230 uint64_t upidx = *index >> 3;
231
232 while (upidx < v->buffer_count &&
233 v->buffer[upidx] == pattern)
234 upidx++;
235
236 *index = upidx << 3;
237 if (upidx == v->buffer_count &&
238 *index >= total) return EINA_FALSE;
239 return EINA_TRUE;
240}
241
242static Eina_Bool
243efl_boolean_model_iterator_next(Eina_Iterator_Boolean *it, void **data)
244{
245 uint64_t upidx;
246
247 *data = &it->index;
248 it->index++;
249
250 retry:
251 if (it->index >= it->total) return EINA_FALSE;
252 if ((it->index >> 3) >= it->v->buffer_count)
253 {
254 if (it->v->default_value != it->request)
255 return EINA_FALSE;
256 return EINA_TRUE;
257 }
258
259 upidx = it->index >> 3;
260 while ((it->index >> 3) == upidx)
261 {
262 Eina_Bool flag = it->v->buffer[it->index >> 3] &
263 (((unsigned char)1) << (it->index & 0x7));
264
265 if (it->request == !!flag)
266 break;
267
268 it->index++;
269 }
270
271 if ((it->index >> 3) != upidx)
272 {
273 if (!_lookup_next_chunk(&it->index, it->total, it->v, it->request ? 0x00 : 0xFF))
274 return EINA_FALSE;
275 goto retry;
276 }
277
278 return EINA_TRUE;
279}
280
281static Eo *
282efl_boolean_model_iterator_get_container(Eina_Iterator_Boolean *it)
283{
284 return it->obj;
285}
286
287static void
288efl_boolean_model_iterator_free(Eina_Iterator_Boolean *it)
289{
290 efl_unref(it->obj);
291 EINA_MAGIC_SET(&it->iterator, EINA_MAGIC_NONE);
292 free(it);
293}
294
295static Eina_Iterator *
296_efl_boolean_model_boolean_iterator_get(Eo *obj, Efl_Boolean_Model_Data *pd, const char *name, Eina_Bool request)
297{
298 Eina_Iterator_Boolean *itb;
299 Efl_Boolean_Model_Value *v;
300 Eina_Stringshare *s;
301
302 s = eina_stringshare_add(name);
303 v = eina_hash_find(pd->values, s);
304 eina_stringshare_del(s);
305 if (!v) return NULL;
306
307 itb = calloc(1, sizeof (Eina_Iterator_Boolean));
308 if (!itb) return NULL;
309
310 itb->obj = efl_ref(obj);
311 itb->pd = pd;
312 itb->v = v;
313 itb->index = 0;
314 itb->total = efl_model_children_count_get(obj);
315 itb->request = !!request;
316
317 itb->iterator.version = EINA_ITERATOR_VERSION;
318 itb->iterator.next = FUNC_ITERATOR_NEXT(efl_boolean_model_iterator_next);
319 itb->iterator.get_container = FUNC_ITERATOR_GET_CONTAINER(efl_boolean_model_iterator_get_container);
320 itb->iterator.free = FUNC_ITERATOR_FREE(efl_boolean_model_iterator_free);
321
322 EINA_MAGIC_SET(&itb->iterator, EINA_MAGIC_ITERATOR);
323 return &itb->iterator;
324}
325
326
210#include "efl_boolean_model.eo.c" 327#include "efl_boolean_model.eo.c"
diff --git a/src/lib/ecore/efl_boolean_model.eo b/src/lib/ecore/efl_boolean_model.eo
index 19f8f02935..049344d2bb 100644
--- a/src/lib/ecore/efl_boolean_model.eo
+++ b/src/lib/ecore/efl_boolean_model.eo
@@ -15,6 +15,14 @@ class @beta Efl.Boolean_Model extends Efl.Composite_Model
15 @in name: string; 15 @in name: string;
16 } 16 }
17 } 17 }
18 boolean_iterator_get {
19 [[Get an iterator that will quickly find all the index with the requested value for a specific boolean.]]
20 params {
21 @in name: string;
22 @in request: bool;
23 }
24 return: iterator<ptr(uint64)>; [[The iterator that is valid until any change is made on the model.]]
25 }
18 } 26 }
19 implements { 27 implements {
20 Efl.Model.properties { get; } 28 Efl.Model.properties { get; }