From 2575cbc42cf224c81aa3584b6ccc9c3a65194014 Mon Sep 17 00:00:00 2001 From: barbieri Date: Sat, 11 Feb 2012 00:48:42 +0000 Subject: [PATCH] model: add helper for common pattern git-svn-id: http://svn.enlightenment.org/svn/e/trunk/eina@67845 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/include/eina_model.h | 22 ++++++++++++++++++++++ src/lib/eina_model.c | 22 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/include/eina_model.h b/src/include/eina_model.h index 0e536ba..96bea16 100644 --- a/src/include/eina_model.h +++ b/src/include/eina_model.h @@ -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 diff --git a/src/lib/eina_model.c b/src/lib/eina_model.c index 2e2afd1..ee45a7b 100644 --- a/src/lib/eina_model.c +++ b/src/lib/eina_model.c @@ -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) { -- 2.7.4