Elm model: Updated examples.
authortasn <tasn@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 16 Feb 2012 12:37:27 +0000 (12:37 +0000)
committertasn <tasn@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 16 Feb 2012 12:37:27 +0000 (12:37 +0000)
Patch by Yakov.

git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/eina@68027 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/examples/eina_model_04_animal.c
src/examples/eina_model_04_animal.h
src/examples/eina_model_04_child.c
src/examples/eina_model_04_child.h
src/examples/eina_model_04_human.c
src/examples/eina_model_04_human.h
src/examples/eina_model_04_parrot.c
src/examples/eina_model_04_parrot.h
src/examples/eina_model_04_whistler.c
src/examples/eina_model_04_whistler.h

index 0f153c6..bc9f06b 100644 (file)
@@ -7,17 +7,17 @@
 static Eina_Bool initialized = EINA_FALSE;
 
 static void
-_animal_eat(Eina_Model *mdl)
+_animal_eat(Eina_Model *m)
 {
-   printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(mdl)),
+   printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)),
          __func__);
    printf("\t\t Eat Animal\n");
 }
 
 static void
-_animal_breathe(Eina_Model *mdl)
+_animal_breathe(Eina_Model *m)
 {
-   printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(mdl)),
+   printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)),
          __func__);
    printf("\t\t Breathe Animal\n");
 }
@@ -47,8 +47,8 @@ animal_init(void)
    /* define extra methods */
 
    type->type_size = sizeof(Animal_Type);
-   _ANIMAL_TYPE.breathe = _animal_breathe;
-   _ANIMAL_TYPE.eat = _animal_eat;
+   ANIMAL_TYPE(type)->breathe = _animal_breathe;
+   ANIMAL_TYPE(type)->eat = _animal_eat;
 }
 
 void
index 7dac640..1af94c3 100644 (file)
 extern const char *ANIMAL_MODEL_TYPE_NAME;
 extern const Eina_Model_Type * const ANIMAL_TYPE;
 
-#define ANIMAL_TYPE(x) ((Animal_Type *)(eina_model_type_subclass_check((x), ANIMAL_TYPE) ? (x) : NULL))
+#define ANIMAL_TYPE(x) ((Animal_Type *) (eina_model_type_subclass_check((x), ANIMAL_TYPE) ? (x) : NULL))
 
 typedef struct _Animal_Type
 {
    Eina_Model_Type parent_class;
-   void (*eat)(Eina_Model *mdl);
-   void (*breathe)(Eina_Model *mdl);
+   void (*eat)(Eina_Model *m);
+   void (*breathe)(Eina_Model *m);
 } Animal_Type;
 
 void animal_init(void);
-void animal_breathe(Eina_Model *mdl);
-void animal_eat(Eina_Model *mdl);
+void animal_breathe(Eina_Model *m);
+void animal_eat(Eina_Model *m);
 
 #endif /* ANIMAL_H_ */
index 8e0b5c6..59b8aa5 100644 (file)
@@ -8,21 +8,23 @@
 static Eina_Bool initialized = EINA_FALSE;
 
 static void
-_child_cry(Eina_Model *mdl)
+_child_cry(Eina_Model *m)
 {
-   printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(mdl)),
+   printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)),
          __func__);
    printf("\t\t Cry Child\n");
 }
 
 static void
-_child_dive(Eina_Model *mdl)
+_child_dive(Eina_Model *m)
 {
-   printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(mdl)),
+   printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)),
          __func__);
    printf("\t\t Dive Child\n");
 }
 
+const char *CHILD_MODEL_TYPE_NAME = NULL;
+
 static Child_Type _CHILD_TYPE;
 const Eina_Model_Type * const CHILD_TYPE = (Eina_Model_Type *) &_CHILD_TYPE;
 
@@ -36,6 +38,8 @@ static const Eina_Model_Interface * CLASS_INTERFACE_ARRAY[] =
 void
 child_init()
 {
+   Eina_Model_Type *type;
+
    if (initialized) return;
    initialized = EINA_TRUE;
 
@@ -49,24 +53,29 @@ child_init()
    DIVER_INTERFACE(iface)->dive = _child_dive;
 
    //creating instance of Child type
-   Eina_Model_Type *type = (Eina_Model_Type *) &_CHILD_TYPE;
+   CHILD_MODEL_TYPE_NAME = "Child_Model_Type";
+
+   type = (Eina_Model_Type *) &_CHILD_TYPE;
    type->version = EINA_MODEL_TYPE_VERSION;
-   type->parent = HUMAN_TYPE;
-   type->type_size = sizeof(Child_Type);
    type->name = CHILD_MODEL_TYPE_NAME;
+
+   eina_model_type_subclass_setup(type, HUMAN_TYPE);
+
+   type->type_size = sizeof(Child_Type);
    type->interfaces = CLASS_INTERFACE_ARRAY;
+
    CHILD_TYPE(type)->cry = _child_cry;
 }
 
 //call for implemented Child Class function
 void
-child_cry(Eina_Model *mdl)
+child_cry(Eina_Model *m)
 {
-   EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(mdl, CHILD_TYPE));
+   EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(m, CHILD_TYPE));
 
-   void (*pf)(Eina_Model *mdl);
-   pf = eina_model_method_resolve(mdl, Child_Type, cry);
+   void (*pf)(Eina_Model *m);
+   pf = eina_model_method_resolve(m, Child_Type, cry);
    EINA_SAFETY_ON_NULL_RETURN(pf);
    printf("%s() \t\t", __func__);
-   pf(mdl);
+   pf(m);
 }
index 8a60f5c..5424217 100644 (file)
@@ -7,18 +7,17 @@
 
 #include "eina_model_04_human.h"
 
-#define CHILD_MODEL_TYPE_NAME "Child_Model_Type"
-
+extern const char *CHILD_MODEL_TYPE_NAME;
 extern const Eina_Model_Type * const CHILD_TYPE;
-#define CHILD_TYPE(x) ((Child_Type *) x)
+#define CHILD_TYPE(x) ((Child_Type *) (eina_model_type_subclass_check((x), CHILD_TYPE) ? (x) : NULL))
 
 typedef struct _Child_Type
 {
    Human_Type parent_class;
-   void (*cry)(Eina_Model *mdl);
+   void (*cry)(Eina_Model *m);
 } Child_Type;
 
 void child_init();
-void child_cry(Eina_Model *mdl);
+void child_cry(Eina_Model *m);
 
 #endif /* CHILD_H_ */
index 5b4f3cb..d9a10ab 100644 (file)
@@ -9,41 +9,41 @@
 static Eina_Bool initialized = EINA_FALSE;
 
 static void
-_human_eat(Eina_Model *mdl)
+_human_eat(Eina_Model *m)
 {
-   printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(mdl)),
+   printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)),
          __func__);
    printf("\t\t Salad\n");
 }
 
 static void
-_human_walk(Eina_Model *mdl)
+_human_walk(Eina_Model *m)
 {
-   printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(mdl)),
+   printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)),
          __func__);
    printf("\t\t Walk\n");
 }
 
 static void
-_human_whistle(Eina_Model *mdl)
+_human_whistle(Eina_Model *m)
 {
-   printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(mdl)),
+   printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)),
          __func__);
    printf("\t\t Whistle Human\n");
 }
 
 static void
-_human_swim(Eina_Model *mdl)
+_human_swim(Eina_Model *m)
 {
-   printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(mdl)),
+   printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)),
          __func__);
    printf("\t\t Swim Human\n");
 }
 
 static void
-_human_dive(Eina_Model *mdl)
+_human_dive(Eina_Model *m)
 {
-   printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(mdl)),
+   printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)),
          __func__);
    printf("\t\t Dive Human\n");
 }
@@ -53,6 +53,9 @@ _human_dive(Eina_Model *mdl)
  * defining Swimmer Interface instance
  * defining Diver Interface instance
  */
+
+const char *HUMAN_MODEL_TYPE_NAME = NULL;
+
 static Human_Type _HUMAN_TYPE;
 const Eina_Model_Type * const HUMAN_TYPE = (Eina_Model_Type *) &_HUMAN_TYPE;
 
@@ -81,6 +84,8 @@ static const Eina_Model_Interface * MODEL_INTERFACES_ARRAY[] =
 void
 human_init()
 {
+   Eina_Model_Type *type;
+
    if (initialized) return;
    initialized = EINA_TRUE;
 
@@ -118,11 +123,17 @@ human_init()
    /*
     * Initializing instance of Human Model
     */
-   Eina_Model_Type *type = (Eina_Model_Type *) &_HUMAN_TYPE;
+
+   HUMAN_MODEL_TYPE_NAME = "Human_Model_Type";
+   
+   type = (Eina_Model_Type *) &_HUMAN_TYPE;
    type->version = EINA_MODEL_TYPE_VERSION;
-   type->parent = ANIMAL_TYPE;
-   type->type_size = sizeof(Human_Type);
    type->name = HUMAN_MODEL_TYPE_NAME;
+   type->private_size = 0;
+
+   eina_model_type_subclass_setup(type, ANIMAL_TYPE);
+
+   type->type_size = sizeof(Human_Type);
    type->interfaces = MODEL_INTERFACES_ARRAY;
 
    ANIMAL_TYPE(type)->eat = _human_eat;
@@ -134,13 +145,13 @@ human_init()
  * call for implemented Human Class function
  */
 void
-human_walk(Eina_Model *mdl)
+human_walk(Eina_Model *m)
 {
-   EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(mdl, HUMAN_TYPE));
+   EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(m, HUMAN_TYPE));
 
-   void (*pf)(Eina_Model *mdl);
-   pf = eina_model_method_resolve(mdl, Human_Type, walk);
+   void (*pf)(Eina_Model *m);
+   pf = eina_model_method_resolve(m, Human_Type, walk);
    EINA_SAFETY_ON_NULL_RETURN(pf);
    printf("%s()    \t", __func__);
-   pf(mdl);
+   pf(m);
 }
index 8cdae3a..1ad7518 100644 (file)
@@ -7,18 +7,18 @@
 
 #include "eina_model_04_animal.h"
 
-#define HUMAN_MODEL_TYPE_NAME "Human_Model_Type"
-
+extern const char *HUMAN_MODEL_TYPE_NAME;
 extern const Eina_Model_Type * const HUMAN_TYPE;
-#define HUMAN_TYPE(x) ((Human_Type *) x)
+
+#define HUMAN_TYPE(x) ((Human_Type *) (eina_model_type_subclass_check((x), ANIMAL_TYPE) ? (x) : NULL))
 
 typedef struct _Human_Type
 {
    Animal_Type parent_class;
-   void (*walk)(Eina_Model *mdl);
+   void (*walk)(Eina_Model *m);
 } Human_Type;
 
 void human_init();
-void human_walk(Eina_Model *mdl);
+void human_walk(Eina_Model *m);
 
 #endif /* HUMAN_H_ */
index 1d4f623..ac619ee 100644 (file)
@@ -8,25 +8,25 @@
 static Eina_Bool initialized = EINA_FALSE;
 
 static void
-_parrot_fly(Eina_Model *mdl)
+_parrot_fly(Eina_Model *m)
 {
-   printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(mdl)),
+   printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)),
          __func__);
    printf("\t\t Fly Parrot\n");
 }
 
 static void
-_parrot_eat(Eina_Model *mdl)
+_parrot_eat(Eina_Model *m)
 {
-   printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(mdl)),
+   printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)),
          __func__);
    printf("\t\t Grain \n");
 }
 
 static void
-_parrot_whistle(Eina_Model *mdl)
+_parrot_whistle(Eina_Model *m)
 {
-   printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(mdl)),
+   printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)),
          __func__);
    printf("\t\t Whistle Parrot\n");
 }
@@ -35,6 +35,8 @@ _parrot_whistle(Eina_Model *mdl)
  * defining Parrot Model Instance
  * defining Whistler Interface instance
  */
+const char *PARROT_MODEL_TYPE_NAME = NULL;
+
 static Parrot_Type _PARROT_TYPE;
 const Eina_Model_Type * const PARROT_TYPE = (Eina_Model_Type *) &_PARROT_TYPE;
 
@@ -48,6 +50,7 @@ static const Eina_Model_Interface * MODEL_INTERFACES_ARRAY[] =
 void
 parrot_init()
 {
+   Eina_Model_Type *type;
    if (initialized) return;
    initialized = EINA_TRUE;
 
@@ -61,11 +64,16 @@ parrot_init()
    iface->name = WHISTLER_INTERFACE_NAME;
    WHISTLER_INTERFACE(iface)->whistle = _parrot_whistle;
 
-   Eina_Model_Type *type = (Eina_Model_Type *) &_PARROT_TYPE;
+   PARROT_MODEL_TYPE_NAME = "Parrot_Model_Type";
+   
+   type = (Eina_Model_Type *)&_PARROT_TYPE;
    type->version = EINA_MODEL_TYPE_VERSION;
-   type->parent = ANIMAL_TYPE;
-   type->type_size = sizeof(Parrot_Type);
    type->name = PARROT_MODEL_TYPE_NAME;
+   type->private_size = 0;
+   
+   eina_model_type_subclass_setup(type, ANIMAL_TYPE);
+
+   type->type_size = sizeof(Parrot_Type);
    type->interfaces = MODEL_INTERFACES_ARRAY;
 
    ANIMAL_TYPE(type)->eat = _parrot_eat;
@@ -74,14 +82,14 @@ parrot_init()
 
 
 void
-parrot_fly(Eina_Model *mdl)
+parrot_fly(Eina_Model *m)
 {
-   EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(mdl, PARROT_TYPE));
+   EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(m, PARROT_TYPE));
 
-   void (*pf)(Eina_Model *mdl);
-   pf = eina_model_method_resolve(mdl, Parrot_Type, fly);
+   void (*pf)(Eina_Model *m);
+   pf = eina_model_method_resolve(m, Parrot_Type, fly);
    EINA_SAFETY_ON_NULL_RETURN(pf);
    printf("%s()    \t", __func__);
-   pf(mdl);
+   pf(m);
 }
 
index 5eafe16..707a391 100644 (file)
@@ -7,18 +7,18 @@
 
 #include "eina_model_04_animal.h"
 
-#define PARROT_MODEL_TYPE_NAME "Parrot_Model_Type"
-
+extern const char *PARROT_MODEL_TYPE_NAME;
 extern const Eina_Model_Type * const PARROT_TYPE;
-#define PARROT_TYPE(x) ((Parrot_Type *) x)
+
+#define PARROT_TYPE(x) ((Parrot_Type *) (eina_model_type_subclass_check((x), PARROT_TYPE) ? (x) : NULL))
 
 typedef struct _Parrot_Type
 {
    Animal_Type parent_class;
-   void (*fly)(Eina_Model *mdl);
+   void (*fly)(Eina_Model *m);
 } Parrot_Type;
 
 void parrot_init();
-void parrot_fly(Eina_Model *mdl);
+void parrot_fly(Eina_Model *m);
 
 #endif /* PARROT_H_ */
index d88dea2..ed9832f 100644 (file)
@@ -6,54 +6,54 @@
 #include "eina_model_04_whistler.h"
 
 void
-whistler_whistle(Eina_Model *mdl)
+whistler_whistle(Eina_Model *m)
 {
    const Eina_Model_Interface *iface = NULL;
-   iface = eina_model_interface_get(mdl, WHISTLER_INTERFACE_NAME);
+   iface = eina_model_interface_get(m, WHISTLER_INTERFACE_NAME);
 
    EINA_SAFETY_ON_NULL_RETURN(iface);
 
    void (*pf)(Eina_Model *);
 
-   pf = eina_model_interface_method_resolve(iface, mdl, Whistler_Interface, whistle);
+   pf = eina_model_interface_method_resolve(iface, m, Whistler_Interface, whistle);
    EINA_SAFETY_ON_NULL_RETURN(pf);
    printf("%s()    \t", __func__);
-   pf(mdl);
+   pf(m);
 }
 /*
  * call for overridden Swimmer Interface function
  */
 void
-swimmer_swim(Eina_Model *mdl)
+swimmer_swim(Eina_Model *m)
 {
    const Eina_Model_Interface *iface = NULL;
-   iface = eina_model_interface_get(mdl, SWIMMER_INTERFACE_NAME);
+   iface = eina_model_interface_get(m, SWIMMER_INTERFACE_NAME);
 
    EINA_SAFETY_ON_NULL_RETURN(iface);
 
    void (*pf)(Eina_Model *);
 
-   pf = eina_model_interface_method_resolve(iface, mdl, Swimmer_Interface, swim);
+   pf = eina_model_interface_method_resolve(iface, m, Swimmer_Interface, swim);
    EINA_SAFETY_ON_NULL_RETURN(pf);
    printf("%s()   \t", __func__);
-   pf(mdl);
+   pf(m);
 }
 
 /*
  * call for overridden Diver Interface function
  */
 void
-diver_dive(Eina_Model *mdl)
+diver_dive(Eina_Model *m)
 {
    const Eina_Model_Interface *iface = NULL;
-   iface = eina_model_interface_get(mdl, DIVER_INTERFACE_NAME);
+   iface = eina_model_interface_get(m, DIVER_INTERFACE_NAME);
 
    EINA_SAFETY_ON_NULL_RETURN(iface);
 
    void (*pf)(Eina_Model *);
 
-   pf = eina_model_interface_method_resolve(iface, mdl, Diver_Interface, dive);
+   pf = eina_model_interface_method_resolve(iface, m, Diver_Interface, dive);
    EINA_SAFETY_ON_NULL_RETURN(pf);
    printf("%s()    \t", __func__);
-   pf(mdl);
+   pf(m);
 }
index 0ac6a8b..0567d78 100644 (file)
@@ -38,8 +38,8 @@ typedef struct _Diver_Interface
 
 } Diver_Interface;
 
-void whistler_whistle(Eina_Model *mdl);
-void swimmer_swim(Eina_Model *mdl);
-void diver_dive(Eina_Model *mdl);
+void whistler_whistle(Eina_Model *m);
+void swimmer_swim(Eina_Model *m);
+void diver_dive(Eina_Model *m);
 
 #endif /* WHISTLER_H_ */