forked from enlightenment/efl
Elm model: Updated examples.
Patch by Yakov. SVN revision: 68027
This commit is contained in:
parent
44464df118
commit
e9e9d41cf2
|
@ -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
|
||||
|
|
|
@ -15,12 +15,12 @@ extern const Eina_Model_Type * const ANIMAL_TYPE;
|
|||
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_ */
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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_ */
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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_ */
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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_ */
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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_ */
|
||||
|
|
Loading…
Reference in New Issue