aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/eo
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2017-06-14 13:40:46 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-06-14 16:54:11 +0900
commitb96722cfb8baf5761295c487faf7396a873a2428 (patch)
tree446048f63cd93e1d92ad54bbc36e088f92b83124 /src/lib/eo
parentscroller: Remove propagate_events to avoid name collision (diff)
downloadefl-b96722cfb8baf5761295c487faf7396a873a2428.tar.gz
eo: Add API efl_data_scope_safe_get
This is a safe version of efl_data_scope_get, meaning that it will return NULL if the object is not of the required type, or if there is no data for that class, or if the given class was used as an interface (and isn't a mixin). @feature
Diffstat (limited to 'src/lib/eo')
-rw-r--r--src/lib/eo/Eo.h29
-rw-r--r--src/lib/eo/eo.c23
2 files changed, 50 insertions, 2 deletions
diff --git a/src/lib/eo/Eo.h b/src/lib/eo/Eo.h
index 32c132edaa..03230015bd 100644
--- a/src/lib/eo/Eo.h
+++ b/src/lib/eo/Eo.h
@@ -1225,18 +1225,47 @@ EAPI Eo * _efl_add_internal_start(const char *file, int line, const Efl_Class *k
/**
* @brief Get a pointer to the data of an object for a specific class.
+ *
* The data reference count is not incremented. The pointer must be used only
* in the scope of the function and its callees.
+ *
* @param obj the object to work on.
* @param klass the klass associated with the data.
* @return a pointer to the data.
*
* @see efl_data_ref()
* @see efl_data_unref()
+ * @see efl_data_scope_safe_get()
*/
EAPI void *efl_data_scope_get(const Eo *obj, const Efl_Class *klass);
/**
+ * @brief Safely get a pointer to the data of an object for a specific class.
+ *
+ * This call runs a dynamic check and returns NULL if there is no valid data
+ * to return.
+ *
+ * The data reference count is not incremented. The pointer must be used only
+ * in the scope of the function and its callees. This function will return NULL
+ * if there is no data for this class, or if this object is not an instance of
+ * the given class. The function will return NULL if the data size is 0.
+ * Note that objects of class A inheriting from another class C as an
+ * interface (like: class A(B, C) {} ) will have no data for class C. This
+ * means that efl_isa(a, C) will return true but there is no data for C. This
+ * function's behaviour is similar to efl_data_scope_get() when running in
+ * debug mode (but this prints less error logs).
+ *
+ * @param obj the object to work on.
+ * @param klass the klass associated with the data.
+ * @return a pointer to the data or NULL in case of error or $obj was NULL.
+ *
+ * @see efl_data_scope_get()
+ *
+ * @since 1.20
+ */
+EAPI void *efl_data_scope_safe_get(const Eo *obj, const Efl_Class *klass);
+
+/**
* @def efl_data_xref(obj, klass, ref_obj)
* Use this macro if you want to associate a referencer object.
* Convenience macro around efl_data_xref_internal()
diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c
index 55f00e1006..e4f767b687 100644
--- a/src/lib/eo/eo.c
+++ b/src/lib/eo/eo.c
@@ -1102,7 +1102,6 @@ _vtable_init(Eo_Vtable *vtable, size_t size)
vtable->chain = calloc(vtable->size, sizeof(*vtable->chain));
}
-#ifdef EO_DEBUG
static Eina_Bool
_eo_class_mro_has(const _Efl_Class *klass, const _Efl_Class *find)
{
@@ -1116,7 +1115,6 @@ _eo_class_mro_has(const _Efl_Class *klass, const _Efl_Class *find)
}
return EINA_FALSE;
}
-#endif
static Eina_List *
_eo_class_list_remove_duplicates(Eina_List* list)
@@ -2003,6 +2001,27 @@ err_klass:
}
EAPI void *
+efl_data_scope_safe_get(const Eo *obj_id, const Efl_Class *klass_id)
+{
+#ifndef EO_DEBUG
+ void *ret = NULL;
+
+ if (!obj_id) return NULL;
+ EO_OBJ_POINTER_RETURN_VAL(obj_id, obj, NULL);
+ EO_CLASS_POINTER_GOTO(klass_id, klass, err_klass);
+
+ if (_eo_class_mro_has(obj->klass, klass))
+ ret = _efl_data_scope_safe_get(obj, klass);
+
+err_klass:
+ EO_OBJ_DONE(obj_id);
+ return ret;
+#else
+ return efl_data_scope_get(obj_id, klass_id);
+#endif
+}
+
+EAPI void *
efl_data_xref_internal(const char *file, int line, const Eo *obj_id, const Efl_Class *klass_id, const Eo *ref_obj_id)
{
void *ret = NULL;