model: add helper for common pattern
authorbarbieri <barbieri@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sat, 11 Feb 2012 00:48:42 +0000 (00:48 +0000)
committerbarbieri <barbieri@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Sat, 11 Feb 2012 00:48:42 +0000 (00:48 +0000)
git-svn-id: http://svn.enlightenment.org/svn/e/trunk/eina@67845 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/include/eina_model.h
src/lib/eina_model.c

index 0e536ba..96bea16 100644 (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
index 2e2afd1..ee45a7b 100644 (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)
 {