cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=2e41a13166789670602bc005a7e6a9f0815ecd77

commit 2e41a13166789670602bc005a7e6a9f0815ecd77
Author: Cedric BAIL <[email protected]>
Date:   Fri Jan 24 11:01:03 2020 -0800

    efl: add Efl.Model.Children_Index_Get.
    
    This allow for fetching random children in a model. A simple fallback is
    provided by Efl.Loop_Model that will allow all model to provide this
    feature in a non optimized way. Later on this can be speeded up.
    
    Reviewed-by: Marcel Hollerbach <[email protected]>
    Differential Revision: https://phab.enlightenment.org/D11185
---
 src/lib/ecore/efl_loop_model.c      | 36 ++++++++++++++++++++++++++++++++++++
 src/lib/ecore/efl_loop_model.eo     |  1 +
 src/lib/efl/interfaces/efl_model.eo | 12 ++++++++++++
 3 files changed, 49 insertions(+)

diff --git a/src/lib/ecore/efl_loop_model.c b/src/lib/ecore/efl_loop_model.c
index d3e52a63fb..88d8574285 100644
--- a/src/lib/ecore/efl_loop_model.c
+++ b/src/lib/ecore/efl_loop_model.c
@@ -108,6 +108,42 @@ _efl_loop_model_efl_model_property_ready_get(Eo *obj, void 
*pd EINA_UNUSED, cons
    return efl_future_then(obj, f);
 }
 
+static Eina_Value
+_unpack_from_array(void *data EINA_UNUSED, Eina_Value v, const Eina_Future *f 
EINA_UNUSED)
+{
+   Eo *object = NULL;
+
+   if (eina_value_type_get(&v) == EINA_VALUE_TYPE_ERROR) return v;
+   if (eina_value_type_get(&v) != EINA_VALUE_TYPE_ARRAY) return 
eina_value_error_init(EINVAL);
+   if (eina_value_array_count(&v) != 1) return eina_value_error_init(EINVAL);
+
+   eina_value_array_get(&v, 0, &object);
+
+   return eina_value_object_init(object);
+}
+
+static Eina_Future *
+_efl_loop_model_efl_model_children_index_get(Eo *obj, void *pd EINA_UNUSED, 
Eina_Iterator *indexes)
+{
+   Eina_Future *r;
+   Eina_Array futures;
+   unsigned int idx;
+
+   eina_array_step_set(&futures, sizeof (Eina_Array), 8);
+
+   EINA_ITERATOR_FOREACH(indexes, idx)
+     eina_array_push(&futures, 
eina_future_then(efl_model_children_slice_get(obj, idx, 1), _unpack_from_array, 
NULL));
+   eina_iterator_free(indexes);
+
+   r = efl_future_then(obj, 
eina_future_all_iterator(eina_array_iterator_new(&futures)),
+                       .success = _efl_future_all_repack,
+                       .success_type = EINA_VALUE_TYPE_ARRAY);
+
+   eina_array_flush(&futures);
+
+   return r;
+}
+
 static void
 _noref_death(void *data EINA_UNUSED, const Efl_Event *event)
 {
diff --git a/src/lib/ecore/efl_loop_model.eo b/src/lib/ecore/efl_loop_model.eo
index 2285b56f1b..06af337ecf 100644
--- a/src/lib/ecore/efl_loop_model.eo
+++ b/src/lib/ecore/efl_loop_model.eo
@@ -20,5 +20,6 @@ abstract Efl.Loop_Model extends Efl.Loop_Consumer implements 
Efl.Model
       Efl.Object.invalidate;
       Efl.Model.property_ready_get;
       Efl.Model.property { get; set; }
+      Efl.Model.children_index_get;
    }
 }
diff --git a/src/lib/efl/interfaces/efl_model.eo 
b/src/lib/efl/interfaces/efl_model.eo
index ee04879f68..e669d50ade 100644
--- a/src/lib/efl/interfaces/efl_model.eo
+++ b/src/lib/efl/interfaces/efl_model.eo
@@ -141,6 +141,18 @@ interface Efl.Model
             /* XXX: is this right? */
             return: future<array<Efl.Object>>; [[Array of children]]
          }
+         children_index_get {
+              [[Get children as specified by iterator.
+
+                Provided index have to be between 0 and @.children_count.get.
+
+                This function might rely on @.children_slice_get as a fallback.
+              ]]
+            params {
+               @in indices: iterator<uint>; [[Indices of the requested 
children.]]
+            }
+            return: future<array<Efl.Object>>; [[Array of children]]
+         }
          @property children_count {
             [[Number of children.
 

-- 


Reply via email to