model: add helper for common pattern

SVN revision: 67845
This commit is contained in:
Gustavo Sverzut Barbieri 2012-02-11 00:48:42 +00:00
parent 5c0041f6ad
commit 4915aeb8db
2 changed files with 44 additions and 0 deletions

View File

@ -1444,8 +1444,30 @@ EAPI extern const Eina_Model_Type *EINA_MODEL_TYPE_GENERIC;
*/
EAPI extern const Eina_Model_Type *EINA_MODEL_TYPE_STRUCT;
/**
* @brief Create and setup an instance of #EINA_MODEL_TYPE_STRUCT.
* @param desc struct description to use for properties.
* @return newly created and set model, or @c NULL on errors.
*
* @see eina_model_type_struct_new()
* @since 1.2
*/
EAPI Eina_Model *eina_model_struct_new(const Eina_Value_Struct_Desc *desc) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_MALLOC;
/**
* @brief Create and setup an instance of type subclass of #EINA_MODEL_TYPE_STRUCT.
* @param type a type which is subclass of #EINA_MODEL_TYPE_STRUCT.
* @param desc struct description to use for properties.
* @return newly created and set model, or @c NULL on errors.
*
* @see eina_model_struct_new()
* @since 1.2
*/
EAPI Eina_Model *eina_model_type_struct_new(const Eina_Model_Type *type,
const Eina_Value_Struct_Desc *desc) EINA_ARG_NONNULL(1, 2) EINA_WARN_UNUSED_RESULT EINA_MALLOC;
/**
* @var EINA_MODEL_INTERFACE_NAME_PROPERTIES

View File

@ -5302,6 +5302,28 @@ eina_model_struct_new(const Eina_Value_Struct_Desc *desc)
return NULL;
}
EAPI Eina_Model *
eina_model_type_struct_new(const Eina_Model_Type *type, const Eina_Value_Struct_Desc *desc)
{
Eina_Model *m;
EINA_SAFETY_ON_FALSE_RETURN_VAL
(eina_model_type_subclass_check(type, EINA_MODEL_TYPE_STRUCT), NULL);
EINA_SAFETY_ON_NULL_RETURN_VAL(desc, NULL);
EINA_SAFETY_ON_FALSE_RETURN_VAL
(desc->version == EINA_VALUE_STRUCT_DESC_VERSION, NULL);
m = eina_model_new(type);
EINA_SAFETY_ON_NULL_RETURN_VAL(m, NULL);
EINA_SAFETY_ON_FALSE_GOTO(_eina_model_struct_set(m, desc, NULL), error);
return m;
error:
eina_model_del(m);
return NULL;
}
EAPI Eina_Bool
eina_model_struct_set(Eina_Model *model, const Eina_Value_Struct_Desc *desc, void *memory)
{