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.

SVN revision: 67765
This commit is contained in:
Tom Hacohen 2012-02-08 15:37:07 +00:00
parent 68d5bb81bc
commit 1dbab17f64
2 changed files with 14 additions and 8 deletions

View File

@ -800,6 +800,9 @@ EAPI char *eina_model_type_to_string(const Eina_Model_Type *type,
* @return address to resolved method, or @c NULL if method is not * @return address to resolved method, or @c NULL if method is not
* implemented. * 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 * When implementing new types that augments the basic methods from
* Eina_Model_Type, the recommended structure layout is as follow: * Eina_Model_Type, the recommended structure layout is as follow:
* @code * @code
@ -827,7 +830,7 @@ EAPI char *eina_model_type_to_string(const Eina_Model_Type *type,
* *
* EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(model, MY_TYPE), -1); * 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); * EINA_SAFETY_ON_NULL_RETURN(meth, -1);
* return meth(model); * return meth(model);
* } * }
@ -836,14 +839,17 @@ EAPI char *eina_model_type_to_string(const Eina_Model_Type *type,
* @note offset must be bigger than Eina_Model_Type, otherwise use * @note offset must be bigger than Eina_Model_Type, otherwise use
* specific functions such as eina_model_property_get(). * specific functions such as eina_model_property_get().
* *
* @see eina_model_method_resolve
* @see eina_model_type_method_resolve
* @since 1.2 * @since 1.2
*/ */
EAPI const void *eina_model_method_resolve(const Eina_Model *model, 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;
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, 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;
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 * @struct _Eina_Model_Interface

View File

@ -4673,7 +4673,7 @@ eina_model_type_private_data_get(const Eina_Model *model, const Eina_Model_Type
} }
EAPI const void * 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; const Eina_Model_Description *desc;
@ -4691,7 +4691,7 @@ eina_model_method_resolve(const Eina_Model *model, unsigned int offset)
} }
EAPI const void * 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; const Eina_Model_Description *desc;