summaryrefslogtreecommitdiff
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
parent97c10e9346837fcd354fe9144d57cd8d63654d00 (diff)
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
1225 1225
1226/** 1226/**
1227 * @brief Get a pointer to the data of an object for a specific class. 1227 * @brief Get a pointer to the data of an object for a specific class.
1228 *
1228 * The data reference count is not incremented. The pointer must be used only 1229 * The data reference count is not incremented. The pointer must be used only
1229 * in the scope of the function and its callees. 1230 * in the scope of the function and its callees.
1231 *
1230 * @param obj the object to work on. 1232 * @param obj the object to work on.
1231 * @param klass the klass associated with the data. 1233 * @param klass the klass associated with the data.
1232 * @return a pointer to the data. 1234 * @return a pointer to the data.
1233 * 1235 *
1234 * @see efl_data_ref() 1236 * @see efl_data_ref()
1235 * @see efl_data_unref() 1237 * @see efl_data_unref()
1238 * @see efl_data_scope_safe_get()
1236 */ 1239 */
1237EAPI void *efl_data_scope_get(const Eo *obj, const Efl_Class *klass); 1240EAPI void *efl_data_scope_get(const Eo *obj, const Efl_Class *klass);
1238 1241
1239/** 1242/**
1243 * @brief Safely get a pointer to the data of an object for a specific class.
1244 *
1245 * This call runs a dynamic check and returns NULL if there is no valid data
1246 * to return.
1247 *
1248 * The data reference count is not incremented. The pointer must be used only
1249 * in the scope of the function and its callees. This function will return NULL
1250 * if there is no data for this class, or if this object is not an instance of
1251 * the given class. The function will return NULL if the data size is 0.
1252 * Note that objects of class A inheriting from another class C as an
1253 * interface (like: class A(B, C) {} ) will have no data for class C. This
1254 * means that efl_isa(a, C) will return true but there is no data for C. This
1255 * function's behaviour is similar to efl_data_scope_get() when running in
1256 * debug mode (but this prints less error logs).
1257 *
1258 * @param obj the object to work on.
1259 * @param klass the klass associated with the data.
1260 * @return a pointer to the data or NULL in case of error or $obj was NULL.
1261 *
1262 * @see efl_data_scope_get()
1263 *
1264 * @since 1.20
1265 */
1266EAPI void *efl_data_scope_safe_get(const Eo *obj, const Efl_Class *klass);
1267
1268/**
1240 * @def efl_data_xref(obj, klass, ref_obj) 1269 * @def efl_data_xref(obj, klass, ref_obj)
1241 * Use this macro if you want to associate a referencer object. 1270 * Use this macro if you want to associate a referencer object.
1242 * Convenience macro around efl_data_xref_internal() 1271 * 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)
1102 vtable->chain = calloc(vtable->size, sizeof(*vtable->chain)); 1102 vtable->chain = calloc(vtable->size, sizeof(*vtable->chain));
1103} 1103}
1104 1104
1105#ifdef EO_DEBUG
1106static Eina_Bool 1105static Eina_Bool
1107_eo_class_mro_has(const _Efl_Class *klass, const _Efl_Class *find) 1106_eo_class_mro_has(const _Efl_Class *klass, const _Efl_Class *find)
1108{ 1107{
@@ -1116,7 +1115,6 @@ _eo_class_mro_has(const _Efl_Class *klass, const _Efl_Class *find)
1116 } 1115 }
1117 return EINA_FALSE; 1116 return EINA_FALSE;
1118} 1117}
1119#endif
1120 1118
1121static Eina_List * 1119static Eina_List *
1122_eo_class_list_remove_duplicates(Eina_List* list) 1120_eo_class_list_remove_duplicates(Eina_List* list)
@@ -2003,6 +2001,27 @@ err_klass:
2003} 2001}
2004 2002
2005EAPI void * 2003EAPI void *
2004efl_data_scope_safe_get(const Eo *obj_id, const Efl_Class *klass_id)
2005{
2006#ifndef EO_DEBUG
2007 void *ret = NULL;
2008
2009 if (!obj_id) return NULL;
2010 EO_OBJ_POINTER_RETURN_VAL(obj_id, obj, NULL);
2011 EO_CLASS_POINTER_GOTO(klass_id, klass, err_klass);
2012
2013 if (_eo_class_mro_has(obj->klass, klass))
2014 ret = _efl_data_scope_safe_get(obj, klass);
2015
2016err_klass:
2017 EO_OBJ_DONE(obj_id);
2018 return ret;
2019#else
2020 return efl_data_scope_get(obj_id, klass_id);
2021#endif
2022}
2023
2024EAPI void *
2006efl_data_xref_internal(const char *file, int line, const Eo *obj_id, const Efl_Class *klass_id, const Eo *ref_obj_id) 2025efl_data_xref_internal(const char *file, int line, const Eo *obj_id, const Efl_Class *klass_id, const Eo *ref_obj_id)
2007{ 2026{
2008 void *ret = NULL; 2027 void *ret = NULL;