From d431059d580c6e2ba62fcd237c19a20202d88ed7 Mon Sep 17 00:00:00 2001 From: barbieri Date: Wed, 15 Feb 2012 14:08:01 +0000 Subject: [PATCH] review animal as example for other example files. git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/eina@67986 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/examples/eina_model_04_animal.c | 53 ++++++++++++++++++++++--------------- src/examples/eina_model_04_animal.h | 9 +++---- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/examples/eina_model_04_animal.c b/src/examples/eina_model_04_animal.c index f18e180..8e5f71f 100644 --- a/src/examples/eina_model_04_animal.c +++ b/src/examples/eina_model_04_animal.c @@ -22,46 +22,57 @@ _animal_breathe(Eina_Model *mdl) printf("\t\t Breathe Animal\n"); } -static Animal_Type _ANIMAL_TYPE; +const char *ANIMAL_MODEL_TYPE_NAME = NULL; +static Animal_Type _ANIMAL_TYPE = { + EINA_MODEL_TYPE_INIT_NOPRIVATE("Animal_Model_Type", + Animal_Type, + NULL, + NULL, + NULL), + NULL, + NULL +}; + const Eina_Model_Type * const ANIMAL_TYPE = (Eina_Model_Type *) &_ANIMAL_TYPE; -void animal_init() +void +animal_init(void) { if (initialized) return; initialized = EINA_TRUE; - Eina_Model_Type *type = (Eina_Model_Type *) &_ANIMAL_TYPE; - type->version = EINA_MODEL_TYPE_VERSION; - type->parent = EINA_MODEL_TYPE_BASE; - type->type_size = sizeof(Animal_Type); - type->name = ANIMAL_MODEL_TYPE_NAME; - type->parent = EINA_MODEL_TYPE_GENERIC; + ANIMAL_MODEL_TYPE_NAME = _ANIMAL_TYPE.parent_class.name; + + eina_model_type_subclass_setup(&_ANIMAL_TYPE.parent_class, + EINA_MODEL_TYPE_GENERIC); - ANIMAL_TYPE(type)->breathe = _animal_breathe; - ANIMAL_TYPE(type)->eat = _animal_eat; + /* define extra methods */ + + _ANIMAL_TYPE.parent_class.type_size = sizeof(Animal_Type); + _ANIMAL_TYPE.breathe = _animal_breathe; + _ANIMAL_TYPE.eat = _animal_eat; } void -animal_breathe(Eina_Model *mdl) +animal_breathe(Eina_Model *m) { - EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(mdl, ANIMAL_TYPE)); + EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(m, ANIMAL_TYPE)); - void (*pf)(Eina_Model *mdl); - pf = eina_model_method_resolve(mdl, Animal_Type, breathe); + void (*pf)(Eina_Model *m); + pf = eina_model_method_resolve(m, Animal_Type, breathe); EINA_SAFETY_ON_NULL_RETURN(pf); printf("%s() \t", __func__); - pf(mdl); + pf(m); } void -animal_eat(Eina_Model *mdl) +animal_eat(Eina_Model *m) { - EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(mdl, ANIMAL_TYPE)); + EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(m, ANIMAL_TYPE)); - void (*pf)(Eina_Model *mdl); - pf = eina_model_method_resolve(mdl, Animal_Type, eat); + void (*pf)(Eina_Model *m); + pf = eina_model_method_resolve(m, Animal_Type, eat); EINA_SAFETY_ON_NULL_RETURN(pf); printf("%s() \t", __func__); - pf(mdl); + pf(m); } - diff --git a/src/examples/eina_model_04_animal.h b/src/examples/eina_model_04_animal.h index 7c415d2..7dac640 100644 --- a/src/examples/eina_model_04_animal.h +++ b/src/examples/eina_model_04_animal.h @@ -6,12 +6,11 @@ #define ANIMAL_H_ #include -#include - -#define ANIMAL_MODEL_TYPE_NAME "Animal_Model_Type" +extern const char *ANIMAL_MODEL_TYPE_NAME; extern const Eina_Model_Type * const ANIMAL_TYPE; -#define ANIMAL_TYPE(x) ((Animal_Type *) x) + +#define ANIMAL_TYPE(x) ((Animal_Type *)(eina_model_type_subclass_check((x), ANIMAL_TYPE) ? (x) : NULL)) typedef struct _Animal_Type { @@ -20,7 +19,7 @@ typedef struct _Animal_Type void (*breathe)(Eina_Model *mdl); } Animal_Type; -void animal_init(); +void animal_init(void); void animal_breathe(Eina_Model *mdl); void animal_eat(Eina_Model *mdl); -- 2.7.4