From: Enlightenment S. <no-...@en...> - 2012-02-08 15:37:19
|
Log: Eina model: Made _method_resolve a macro to remove the need for offsetof. This will also hopefully remove the likelihood for hacks. Previous functions are still available as method_offset_resolve. Author: tasn Date: 2012-02-08 07:37:07 -0800 (Wed, 08 Feb 2012) New Revision: 67765 Trac: http://trac.enlightenment.org/e/changeset/67765 Modified: trunk/eina/src/include/eina_model.h trunk/eina/src/lib/eina_model.c Modified: trunk/eina/src/include/eina_model.h =================================================================== --- trunk/eina/src/include/eina_model.h 2012-02-08 15:13:25 UTC (rev 67764) +++ trunk/eina/src/include/eina_model.h 2012-02-08 15:37:07 UTC (rev 67765) @@ -800,6 +800,9 @@ * @return address to resolved method, or @c NULL if method is not * implemented. * + * The use of this function is discouraged, you should use + * #eina_model_method_resolve instead. + * * When implementing new types that augments the basic methods from * Eina_Model_Type, the recommended structure layout is as follow: * @code @@ -827,7 +830,7 @@ * * EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(model, MY_TYPE), -1); * - * meth = eina_model_method_resolve(model, offsetof(My_Type, my_method)); + * meth = eina_model_method_offset_resolve(model, offsetof(My_Type, my_method)); * EINA_SAFETY_ON_NULL_RETURN(meth, -1); * return meth(model); * } @@ -836,15 +839,18 @@ * @note offset must be bigger than Eina_Model_Type, otherwise use * specific functions such as eina_model_property_get(). * + * @see eina_model_method_resolve + * @see eina_model_type_method_resolve * @since 1.2 */ -EAPI const void *eina_model_method_resolve(const Eina_Model *model, - unsigned int offset) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_PURE; +EAPI const void *eina_model_method_offset_resolve(const Eina_Model *model, unsigned int offset) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_PURE; -EAPI const void *eina_model_type_method_resolve(const Eina_Model_Type *type, - const Eina_Model *model, - unsigned int offset) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT EINA_PURE; +EAPI const void *eina_model_type_method_offset_resolve(const Eina_Model_Type *type, const Eina_Model *model, unsigned int offset) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT EINA_PURE; +#define eina_model_method_resolve(model, struct_type, method) eina_model_method_offset_resolve((model), offsetof(struct_type, method)) + +#define eina_model_type_method_resolve(type, model, struct_type, method) eina_model_type_method_offset_resolve((type), (model), offsetof(struct_type, method)) + /** * @struct _Eina_Model_Interface * Modified: trunk/eina/src/lib/eina_model.c =================================================================== --- trunk/eina/src/lib/eina_model.c 2012-02-08 15:13:25 UTC (rev 67764) +++ trunk/eina/src/lib/eina_model.c 2012-02-08 15:37:07 UTC (rev 67765) @@ -4673,7 +4673,7 @@ } EAPI const void * -eina_model_method_resolve(const Eina_Model *model, unsigned int offset) +eina_model_method_offset_resolve(const Eina_Model *model, unsigned int offset) { const Eina_Model_Description *desc; @@ -4691,7 +4691,7 @@ } EAPI const void * -eina_model_type_method_resolve(const Eina_Model_Type *type, const Eina_Model *model, unsigned int offset) +eina_model_type_method_offset_resolve(const Eina_Model_Type *type, const Eina_Model *model, unsigned int offset) { const Eina_Model_Description *desc; |