forked from enlightenment/efl
eina: remove tests, examples and docs for eina_model
Summary: Since eina_model was dropped some years ago. Also a few other points where related stuff is just commented out. Reviewers: iscaro, barbieri Reviewed By: barbieri Subscribers: cedric, jpeg Differential Revision: https://phab.enlightenment.org/D4442
This commit is contained in:
parent
887be4d4e5
commit
adb95630ef
|
@ -30,15 +30,6 @@
|
|||
* @li @ref eina_log_02.c
|
||||
* @li @ref eina_log_03.c
|
||||
* @li @ref eina_magic_01.c
|
||||
* @li @ref eina_model_01.c
|
||||
* @li @ref eina_model_02.c
|
||||
* @li @ref eina_model_03.c
|
||||
* @li @ref eina_model_04_animal.c
|
||||
* @li @ref eina_model_04_child.c
|
||||
* @li @ref eina_model_04_human.c
|
||||
* @li @ref eina_model_04_main.c
|
||||
* @li @ref eina_model_04_parrot.c
|
||||
* @li @ref eina_model_04_whistler.c
|
||||
* @li @ref eina_simple_xml_parser_01.c
|
||||
* @li @ref eina_str_01.c
|
||||
* @li @ref eina_strbuf_01.c
|
||||
|
@ -87,15 +78,6 @@
|
|||
* @example eina_log_02.c
|
||||
* @example eina_log_03.c
|
||||
* @example eina_magic_01.c
|
||||
* @example eina_model_01.c
|
||||
* @example eina_model_02.c
|
||||
* @example eina_model_03.c
|
||||
* @example eina_model_04_animal.c
|
||||
* @example eina_model_04_child.c
|
||||
* @example eina_model_04_human.c
|
||||
* @example eina_model_04_main.c
|
||||
* @example eina_model_04_parrot.c
|
||||
* @example eina_model_04_whistler.c
|
||||
* @example eina_simple_xml_parser_01.c
|
||||
* @example eina_str_01.c
|
||||
* @example eina_strbuf_01.c
|
||||
|
|
|
@ -58,10 +58,6 @@ eina_magic_01.c \
|
|||
eina_xattr_01.c \
|
||||
eina_xattr_02.c
|
||||
|
||||
#eina_model_01.c \
|
||||
#eina_model_02.c \
|
||||
#eina_model_03.c
|
||||
|
||||
EXTRA_PROGRAMS = \
|
||||
eina_accessor_01 \
|
||||
eina_array_01 \
|
||||
|
@ -103,24 +99,6 @@ eina_inarray_03 \
|
|||
eina_xattr_01 \
|
||||
eina_xattr_02
|
||||
|
||||
#eina_model_01 \
|
||||
#eina_model_02 \
|
||||
#eina_model_03 \
|
||||
#eina_model_04
|
||||
|
||||
#eina_model_04_SOURCES = \
|
||||
#eina_model_04_animal.c \
|
||||
#eina_model_04_child.c \
|
||||
#eina_model_04_human.c \
|
||||
#eina_model_04_main.c \
|
||||
#eina_model_04_parrot.c \
|
||||
#eina_model_04_whistler.c \
|
||||
#eina_model_04_animal.h \
|
||||
#eina_model_04_child.h \
|
||||
#eina_model_04_human.h \
|
||||
#eina_model_04_parrot.h \
|
||||
#eina_model_04_whistler.h
|
||||
|
||||
EXTRA_PROGRAMS += eina_tiler_01
|
||||
|
||||
eina_tiler_01_CPPFLAGS = \
|
||||
|
|
|
@ -1,235 +0,0 @@
|
|||
/*
|
||||
* Compile with:
|
||||
* gcc -o eina_model_01 eina_model_01.c `pkg-config --cflags --libs eina`
|
||||
*/
|
||||
|
||||
/*
|
||||
* This example demonstrates the usage of Eina Model by implementing
|
||||
* Bank Account Class, which is inherited from Base Class;
|
||||
* and Credit Card Class, which is inherited from Bank Account Class.
|
||||
*
|
||||
* Base Class(Eina_Model_Type) --> Bank Account Class --> Credit Card Class
|
||||
*
|
||||
* Bank Account Class implements "bank_account_data_set()" and "print()" methods;
|
||||
* Credit Card Class inherits these two and implements "credit_card_data_set()"
|
||||
*
|
||||
*
|
||||
* Bank Account Class::print() calls for "_bank_account_data_print"
|
||||
* Credit Card Class ::print() is reloaded with "_credit_card_data_print()"
|
||||
* which calls for parent function "_bank_account_data_print"
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <Eina.h>
|
||||
#include <eina_safety_checks.h>
|
||||
|
||||
/*
|
||||
* Defining type for new model type
|
||||
* Model will have two methods
|
||||
*/
|
||||
typedef struct _Bank_Account_Type
|
||||
{
|
||||
Eina_Model_Type parent_class;
|
||||
void (*bank_account_data_set)(Eina_Model *, const char *name, const char *number);
|
||||
void (*print)(Eina_Model *);
|
||||
} Bank_Account_Type;
|
||||
|
||||
/*
|
||||
* Defining type for Bank Account private data
|
||||
*/
|
||||
typedef struct _Bank_Account_Data
|
||||
{
|
||||
char name[30];
|
||||
char number[30];
|
||||
} Bank_Account_Data;
|
||||
|
||||
/*
|
||||
* Defining type for Credit Card model type, which will be inherited from Bank Account model type
|
||||
* Model will have two parent's methods and additional one
|
||||
*/
|
||||
typedef struct _Credit_Card_Type
|
||||
{
|
||||
Bank_Account_Type parent_class;
|
||||
void (*credit_card_data_set)(Eina_Model *, const char *, const char *, int) ;
|
||||
} Credit_Card_Type;
|
||||
|
||||
/*
|
||||
* Defining type for Credit Card private data
|
||||
*/
|
||||
typedef struct _Credit_Card_Data
|
||||
{
|
||||
char number[30];
|
||||
char expiry_date[30];
|
||||
int pin;
|
||||
} Credit_Card_Data;
|
||||
|
||||
static Bank_Account_Type _BANK_ACCOUNT_TYPE;
|
||||
static Credit_Card_Type _CREDIT_CARD_TYPE;
|
||||
static Eina_Model_Type *BANK_ACCOUNT_TYPE = (Eina_Model_Type *) &_BANK_ACCOUNT_TYPE;
|
||||
static Eina_Model_Type *CREDIT_CARD_TYPE = (Eina_Model_Type *) &_CREDIT_CARD_TYPE;
|
||||
|
||||
|
||||
/*
|
||||
* Defining method for for Bank Account data
|
||||
*/
|
||||
static void
|
||||
_bank_account_data_set(Eina_Model *mdl, const char *name, const char *number)
|
||||
{
|
||||
Bank_Account_Data *bdata = eina_model_type_private_data_get(mdl, BANK_ACCOUNT_TYPE);
|
||||
|
||||
if (!bdata)
|
||||
printf("ERROR\n");
|
||||
|
||||
if (name != NULL)
|
||||
{
|
||||
strncpy(bdata->name, name, sizeof(bdata->name));
|
||||
bdata->name[sizeof(bdata->number) - 1] = '\0';
|
||||
}
|
||||
|
||||
if (number != NULL)
|
||||
{
|
||||
strncpy(bdata->number, number, sizeof(bdata->number));
|
||||
bdata->number[sizeof(bdata->number) - 1] = '\0';
|
||||
}
|
||||
|
||||
printf("%s :: %s %p\n", eina_model_type_name_get(eina_model_type_get(mdl)) ,__func__, mdl);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
_credit_card_data_set(Eina_Model *mdl, const char *number, const char *expiry_date, int pin)
|
||||
{
|
||||
Credit_Card_Data *cdata = eina_model_type_private_data_get(mdl, CREDIT_CARD_TYPE);
|
||||
|
||||
if (!cdata)
|
||||
printf("ERROR\n");
|
||||
|
||||
if (number != NULL)
|
||||
{
|
||||
strncpy(cdata->number, number, sizeof(cdata->number));
|
||||
cdata->number[sizeof(cdata->number) - 1] = '\0';
|
||||
}
|
||||
|
||||
if (expiry_date != NULL)
|
||||
{
|
||||
strncpy(cdata->expiry_date, expiry_date, sizeof(cdata->expiry_date));
|
||||
cdata->expiry_date[sizeof(cdata->expiry_date) - 1] = '\0';
|
||||
}
|
||||
|
||||
cdata->pin = pin;
|
||||
printf("%s :: %s %p\n", eina_model_type_name_get(eina_model_type_get(mdl)) ,__func__, mdl);
|
||||
}
|
||||
|
||||
static void
|
||||
_bank_account_data_print(Eina_Model *mdl)
|
||||
{
|
||||
const Bank_Account_Data *bdata = eina_model_type_private_data_get(mdl, BANK_ACCOUNT_TYPE);
|
||||
|
||||
printf("\n%s :: %s %p \n\tName: %s(%p)\n\tAccount: %s(%p)\n", eina_model_type_name_get(eina_model_type_get(mdl)) ,__func__, mdl
|
||||
, bdata->name, bdata->name, bdata->number, bdata->number);
|
||||
}
|
||||
|
||||
static void
|
||||
_credit_card_data_print(Eina_Model *mdl)
|
||||
{
|
||||
void (*pf)(Eina_Model *);
|
||||
const Eina_Model_Type *ptype = eina_model_type_parent_get(eina_model_type_get(mdl));
|
||||
//const Eina_Model_Type *ptype = eina_model_type_get(mdl);
|
||||
|
||||
pf = eina_model_type_method_resolve(ptype, mdl, Bank_Account_Type, print);
|
||||
if (pf)
|
||||
pf(mdl);
|
||||
else
|
||||
printf("ERROR: %d", __LINE__);
|
||||
const Credit_Card_Data *cdata = eina_model_type_private_data_get(mdl, CREDIT_CARD_TYPE);
|
||||
printf("%s :: %s %p \n\tNumber: %s(%p)\n\tCC Expiry Date: %s(%p)\n\tCC PIN: %d(%p)\n", eina_model_type_name_get(eina_model_type_get(mdl)) ,__func__, mdl
|
||||
, cdata->number, cdata->number, cdata->expiry_date, cdata->expiry_date, cdata->pin, &cdata->pin);
|
||||
}
|
||||
|
||||
#define BANK_ACCOUNT(x) ((Bank_Account_Type *) x)
|
||||
#define CREDIT_CARD(x) ((Credit_Card_Type *) x)
|
||||
|
||||
void
|
||||
bank_account_data_set(Eina_Model *mdl, const char *name, char *number)
|
||||
{
|
||||
|
||||
EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(mdl, BANK_ACCOUNT_TYPE));
|
||||
|
||||
void (*pf)(Eina_Model *, const char *, const char *);
|
||||
pf = eina_model_method_resolve(mdl, Bank_Account_Type, bank_account_data_set);
|
||||
if (pf)
|
||||
pf(mdl, name, number);
|
||||
else
|
||||
printf("ERROR %d\n", __LINE__);
|
||||
}
|
||||
|
||||
void
|
||||
data_print(Eina_Model *mdl)
|
||||
{
|
||||
EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(mdl, BANK_ACCOUNT_TYPE));
|
||||
|
||||
void (*pf)(Eina_Model *);
|
||||
pf = eina_model_method_resolve(mdl, Bank_Account_Type, print);
|
||||
if (pf)
|
||||
pf(mdl);
|
||||
else
|
||||
printf("ERROR %d\n", __LINE__);
|
||||
}
|
||||
|
||||
void
|
||||
credit_card_data_set(Eina_Model *mdl, const char *number, const char *expiry_date, int pin)
|
||||
{
|
||||
EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(mdl, CREDIT_CARD_TYPE));
|
||||
|
||||
void (*pf)(Eina_Model *, const char *, const char *, int);
|
||||
pf = eina_model_method_resolve(mdl, Credit_Card_Type, credit_card_data_set);
|
||||
if (pf)
|
||||
pf(mdl, number, expiry_date, pin);
|
||||
else
|
||||
printf("ERROR %d\n", __LINE__);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
Eina_Model *b, *cc;
|
||||
|
||||
eina_init();
|
||||
|
||||
memset(&_BANK_ACCOUNT_TYPE, 0, sizeof(_BANK_ACCOUNT_TYPE));
|
||||
memset(&_CREDIT_CARD_TYPE, 0, sizeof(_CREDIT_CARD_TYPE));
|
||||
|
||||
BANK_ACCOUNT_TYPE->version = EINA_MODEL_TYPE_VERSION;
|
||||
BANK_ACCOUNT_TYPE->type_size = sizeof(Bank_Account_Type);
|
||||
BANK_ACCOUNT_TYPE->private_size = sizeof(Bank_Account_Data);
|
||||
BANK_ACCOUNT_TYPE->name = "Bank_Account_Model";
|
||||
BANK_ACCOUNT_TYPE->parent = EINA_MODEL_TYPE_GENERIC;
|
||||
BANK_ACCOUNT(BANK_ACCOUNT_TYPE)->bank_account_data_set = _bank_account_data_set;
|
||||
BANK_ACCOUNT(BANK_ACCOUNT_TYPE)->print = _bank_account_data_print;
|
||||
|
||||
CREDIT_CARD_TYPE->version = EINA_MODEL_TYPE_VERSION;
|
||||
CREDIT_CARD_TYPE->type_size = sizeof(Credit_Card_Type);
|
||||
CREDIT_CARD_TYPE->private_size = sizeof(Credit_Card_Data);
|
||||
CREDIT_CARD_TYPE->name = "Credit_Card_Model";
|
||||
CREDIT_CARD_TYPE->parent = BANK_ACCOUNT_TYPE;
|
||||
CREDIT_CARD(CREDIT_CARD_TYPE)->credit_card_data_set = _credit_card_data_set;
|
||||
BANK_ACCOUNT(CREDIT_CARD_TYPE)->print = _credit_card_data_print;
|
||||
|
||||
b = eina_model_new(BANK_ACCOUNT_TYPE); //creating object of bank class
|
||||
cc = eina_model_new(CREDIT_CARD_TYPE); //creating object of credit card class
|
||||
|
||||
bank_account_data_set(b, "Bill Clark", "8569214756");
|
||||
bank_account_data_set(cc, "John Smith", "3154789");
|
||||
|
||||
credit_card_data_set(cc, "5803 6589 4786 3279 9173", "01/01/2015", 1234);
|
||||
|
||||
data_print(b);
|
||||
data_print(cc);
|
||||
|
||||
eina_model_unref(b);
|
||||
eina_model_unref(cc);
|
||||
|
||||
eina_shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
//Compile with:
|
||||
//gcc -g eina_model_02.c -o eina_model_02 `pkg-config --cflags --libs eina`
|
||||
|
||||
#include <Eina.h>
|
||||
|
||||
static void _cb_on_deleted(void *data, Eina_Model *model, const Eina_Model_Event_Description *desc, void *event_info);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
Eina_Model *m;
|
||||
char *s;
|
||||
int i;
|
||||
|
||||
eina_init();
|
||||
|
||||
m = eina_model_new(EINA_MODEL_TYPE_GENERIC);
|
||||
|
||||
eina_model_event_callback_add(m, "deleted", _cb_on_deleted, NULL);
|
||||
|
||||
//Adding properties to model
|
||||
for (i = 0; i < 5; i++)
|
||||
{
|
||||
Eina_Value val;
|
||||
char name[2] = {'a'+ i, 0};
|
||||
eina_value_setup(&val, EINA_VALUE_TYPE_INT);
|
||||
eina_value_set(&val, i);
|
||||
eina_model_property_set(m, name, &val);
|
||||
eina_value_flush(&val);
|
||||
}
|
||||
|
||||
//Adding children to model
|
||||
for (i = 0; i < 5; i++)
|
||||
{
|
||||
Eina_Value val;
|
||||
Eina_Model *c = eina_model_new(EINA_MODEL_TYPE_GENERIC);
|
||||
eina_value_setup(&val, EINA_VALUE_TYPE_INT);
|
||||
eina_value_set(&val, i);
|
||||
eina_model_property_set(c, "x", &val);
|
||||
|
||||
eina_model_event_callback_add(c, "deleted", _cb_on_deleted, NULL);
|
||||
|
||||
eina_model_child_append(m, c);
|
||||
//Now that the child has been appended to a model, it's parent will manage it's lifecycle
|
||||
eina_model_unref(c);
|
||||
eina_value_flush(&val);
|
||||
}
|
||||
|
||||
s = eina_model_to_string(m);
|
||||
printf("model as string:\n%s\n", s);
|
||||
|
||||
free(s);
|
||||
eina_model_unref(m);
|
||||
eina_shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void _cb_on_deleted(void *data, Eina_Model *model, const Eina_Model_Event_Description *desc, void *event_info)
|
||||
{
|
||||
printf("deleted %p\n", model);
|
||||
}
|
|
@ -1,236 +0,0 @@
|
|||
//Compile with:
|
||||
//gcc -g eina_model_03.c -o eina_model_03 `pkg-config --cflags --libs eina`
|
||||
|
||||
#include <Eina.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
static Eina_Model_Type *ADDRESS_BOOK_TYPE;
|
||||
static Eina_Model_Type *PERSON_TYPE;
|
||||
|
||||
static void address_book_init(void);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
Eina_Model *address_book;
|
||||
Eina_Value val;
|
||||
int i, count;
|
||||
char *s;
|
||||
|
||||
eina_init();
|
||||
|
||||
address_book_init();
|
||||
|
||||
address_book = eina_model_new(ADDRESS_BOOK_TYPE);
|
||||
|
||||
eina_value_setup(&val, EINA_VALUE_TYPE_STRING);
|
||||
eina_value_set(&val, "addr_book.txt");
|
||||
eina_model_property_set(address_book, "filename", &val);
|
||||
eina_value_flush(&val);
|
||||
|
||||
eina_model_load(address_book);
|
||||
s = eina_model_to_string(address_book);
|
||||
printf("model as string:\n%s\n\n", s);
|
||||
free(s);
|
||||
|
||||
count = eina_model_child_count(address_book);
|
||||
printf("Address Book with %d entries:\n", count);
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
Eina_Model *person = eina_model_child_get(address_book, i);
|
||||
Eina_Value nameval, emailval;
|
||||
const char *name, *email;
|
||||
|
||||
eina_model_property_get(person, "name", &nameval);
|
||||
eina_model_property_get(person, "email", &emailval);
|
||||
|
||||
eina_value_get(&nameval, &name);
|
||||
eina_value_get(&emailval, &email);
|
||||
|
||||
printf("%02d \"%s\" <%s>\n", i, name, email);
|
||||
|
||||
// We don't need property values anymore
|
||||
eina_value_flush(&nameval);
|
||||
eina_value_flush(&emailval);
|
||||
|
||||
// We don't need our reference to person anymore
|
||||
eina_model_unref(person);
|
||||
}
|
||||
|
||||
eina_model_unref(address_book);
|
||||
eina_shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Structure Descriptions are just used internally in the type constructors:
|
||||
static Eina_Value_Struct_Desc *ADDRESS_BOOK_DESC;
|
||||
static Eina_Value_Struct_Desc *PERSON_DESC;
|
||||
|
||||
static Eina_Bool
|
||||
_person_constructor(Eina_Model *model)
|
||||
{
|
||||
// call parent type constructor, like "super" in other languages:
|
||||
if (!eina_model_type_constructor(EINA_MODEL_TYPE_STRUCT, model))
|
||||
return EINA_FALSE;
|
||||
|
||||
// Do specific setup of our internal structure, letting it know about
|
||||
// our description
|
||||
return eina_model_struct_set(model, PERSON_DESC, NULL);
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_address_book_constructor(Eina_Model *model)
|
||||
{
|
||||
// call parent type constructor, like "super" in other languages:
|
||||
if (!eina_model_type_constructor(EINA_MODEL_TYPE_STRUCT, model))
|
||||
return EINA_FALSE;
|
||||
|
||||
// Do specific setup of our internal structure, letting it know about
|
||||
// our description
|
||||
return eina_model_struct_set(model, ADDRESS_BOOK_DESC, NULL);
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_address_book_load(Eina_Model *model)
|
||||
{
|
||||
const char *filename;
|
||||
Eina_Value val;
|
||||
char buf[256];
|
||||
FILE *f;
|
||||
|
||||
// We retrieve filename from property of same name:
|
||||
eina_model_property_get(model, "filename", &val);
|
||||
eina_value_get(&val, &filename);
|
||||
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(filename, EINA_FALSE);
|
||||
|
||||
f = fopen(filename, "rb");
|
||||
|
||||
// Now that we have used filename, we must free its memory holder:
|
||||
eina_value_flush(&val);
|
||||
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(f, EINA_FALSE);
|
||||
|
||||
while (fgets(buf, sizeof(buf), f))
|
||||
{
|
||||
Eina_Model *person;
|
||||
char *name, *email;
|
||||
|
||||
if (strlen(buf) <= 1)
|
||||
continue;
|
||||
|
||||
name = strtok(buf, "\t");
|
||||
email = strtok(NULL, "\n");
|
||||
|
||||
if ((!name) || (!email)) continue;
|
||||
|
||||
// Create person
|
||||
person = eina_model_new(PERSON_TYPE);
|
||||
|
||||
// Setup value type as string, as our properties are strings:
|
||||
eina_value_setup(&val, EINA_VALUE_TYPE_STRING);
|
||||
|
||||
// Set string properties:
|
||||
eina_value_set(&val, name);
|
||||
eina_model_property_set(person, "name", &val);
|
||||
|
||||
eina_value_set(&val, email);
|
||||
eina_model_property_set(person, "email", &val);
|
||||
|
||||
// Flush value, free string
|
||||
eina_value_flush(&val);
|
||||
|
||||
// Add person to the end of model children
|
||||
eina_model_child_append(model, person);
|
||||
|
||||
// Model already holds its reference to person, we release ours
|
||||
eina_model_unref(person);
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
address_book_init(void)
|
||||
{
|
||||
// Declare type for internal struct, this is just used to easily
|
||||
// create Eina_Value_Struct_Member array for Eina_Value_Struct_Desc.
|
||||
//
|
||||
// We don't need this structure outside address_book_init()
|
||||
// as it is managed automatically by Eina_Value_Struct, used by
|
||||
// Eina_Model_Struct! Handy! :-)
|
||||
typedef struct _Person Person;
|
||||
struct _Person
|
||||
{
|
||||
const char *name;
|
||||
const char *email;
|
||||
};
|
||||
static Eina_Value_Struct_Member person_members[] = {
|
||||
// no eina_value_type as they are not constant initializers, see below.
|
||||
EINA_VALUE_STRUCT_MEMBER(NULL, Person, name),
|
||||
EINA_VALUE_STRUCT_MEMBER(NULL, Person, email)
|
||||
};
|
||||
// Values that cannot be set on static declarations since they are not
|
||||
// constant initializers. It is a nitpick from C that we need to deal with
|
||||
// here and on all our other declarations.
|
||||
person_members[0].type = EINA_VALUE_TYPE_STRING;
|
||||
person_members[1].type = EINA_VALUE_TYPE_STRING;
|
||||
|
||||
static Eina_Value_Struct_Desc person_desc = {
|
||||
EINA_VALUE_STRUCT_DESC_VERSION,
|
||||
NULL, // no special operations
|
||||
person_members,
|
||||
EINA_C_ARRAY_LENGTH(person_members),
|
||||
sizeof(Person)
|
||||
};
|
||||
static Eina_Model_Type person_type = EINA_MODEL_TYPE_INIT_NOPRIVATE
|
||||
("Person_Type",
|
||||
Eina_Model_Type,
|
||||
NULL, // no type as EINA_MODEL_TYPE_STRUCT is not constant initializer!
|
||||
NULL, // no extra interfaces
|
||||
NULL // no extra events);
|
||||
);
|
||||
person_type.parent = EINA_MODEL_TYPE_STRUCT;
|
||||
// Set our overloaded methods:
|
||||
person_type.constructor = _person_constructor;
|
||||
|
||||
typedef struct _Address_Book Address_Book;
|
||||
struct _Address_Book
|
||||
{
|
||||
const char *filename;
|
||||
};
|
||||
static Eina_Value_Struct_Member address_book_members[] = {
|
||||
// no eina_value_type as they are not constant initializers, see below.
|
||||
EINA_VALUE_STRUCT_MEMBER(NULL, Address_Book, filename)
|
||||
};
|
||||
address_book_members[0].type = EINA_VALUE_TYPE_STRING;
|
||||
static Eina_Value_Struct_Desc address_book_desc = {
|
||||
EINA_VALUE_STRUCT_DESC_VERSION,
|
||||
NULL, // no special operations
|
||||
address_book_members,
|
||||
EINA_C_ARRAY_LENGTH(address_book_members),
|
||||
sizeof(Address_Book)
|
||||
};
|
||||
static Eina_Model_Type address_book_type = EINA_MODEL_TYPE_INIT_NOPRIVATE
|
||||
("Address_Book_Type",
|
||||
Eina_Model_Type,
|
||||
NULL, // no type as EINA_MODEL_TYPE_STRUCT is not constant initializer!
|
||||
NULL, // no extra interfaces
|
||||
NULL // no extra events);
|
||||
);
|
||||
address_book_type.parent = EINA_MODEL_TYPE_STRUCT;
|
||||
// Set our overloaded methods:
|
||||
address_book_type.constructor = _address_book_constructor;
|
||||
address_book_type.load = _address_book_load;
|
||||
|
||||
// Expose the configured pointers to public usage:
|
||||
// NOTE: they are static, so they live after this function returns!
|
||||
PERSON_TYPE = &person_type;
|
||||
PERSON_DESC = &person_desc;
|
||||
|
||||
ADDRESS_BOOK_TYPE = &address_book_type;
|
||||
ADDRESS_BOOK_DESC = &address_book_desc;
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
/*
|
||||
* animal.c
|
||||
*/
|
||||
|
||||
#include "eina_model_04_animal.h"
|
||||
|
||||
static Eina_Bool initialized = EINA_FALSE;
|
||||
|
||||
static void
|
||||
_animal_eat(Eina_Model *m)
|
||||
{
|
||||
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 *m)
|
||||
{
|
||||
printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)),
|
||||
__func__);
|
||||
printf("\t\t Breathe Animal\n");
|
||||
}
|
||||
|
||||
const char *ANIMAL_MODEL_TYPE_NAME = NULL;
|
||||
static Animal_Type _ANIMAL_TYPE;
|
||||
|
||||
const Eina_Model_Type * const ANIMAL_TYPE = (Eina_Model_Type *) &_ANIMAL_TYPE;
|
||||
|
||||
void
|
||||
animal_init(void)
|
||||
{
|
||||
Eina_Model_Type *type;
|
||||
|
||||
if (initialized) return;
|
||||
initialized = EINA_TRUE;
|
||||
|
||||
ANIMAL_MODEL_TYPE_NAME = "Animal_Model_Type";
|
||||
|
||||
type = (Eina_Model_Type *)&_ANIMAL_TYPE;
|
||||
type->version = EINA_MODEL_TYPE_VERSION;
|
||||
type->name = ANIMAL_MODEL_TYPE_NAME;
|
||||
type->private_size = 0;
|
||||
|
||||
eina_model_type_subclass_setup(type, EINA_MODEL_TYPE_GENERIC);
|
||||
|
||||
/* define extra methods */
|
||||
|
||||
type->type_size = sizeof(Animal_Type);
|
||||
ANIMAL_TYPE(type)->breathe = _animal_breathe;
|
||||
ANIMAL_TYPE(type)->eat = _animal_eat;
|
||||
}
|
||||
|
||||
void
|
||||
animal_breathe(Eina_Model *m)
|
||||
{
|
||||
EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(m, ANIMAL_TYPE));
|
||||
|
||||
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(m);
|
||||
}
|
||||
|
||||
void
|
||||
animal_eat(Eina_Model *m)
|
||||
{
|
||||
EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(m, ANIMAL_TYPE));
|
||||
|
||||
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(m);
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
* animal.h
|
||||
*/
|
||||
|
||||
#ifndef ANIMAL_H_
|
||||
#define ANIMAL_H_
|
||||
|
||||
#include <Eina.h>
|
||||
|
||||
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))
|
||||
|
||||
typedef struct _Animal_Type
|
||||
{
|
||||
Eina_Model_Type parent_class;
|
||||
void (*eat)(Eina_Model *m);
|
||||
void (*breathe)(Eina_Model *m);
|
||||
} Animal_Type;
|
||||
|
||||
void animal_init(void);
|
||||
void animal_breathe(Eina_Model *m);
|
||||
void animal_eat(Eina_Model *m);
|
||||
|
||||
#endif /* ANIMAL_H_ */
|
|
@ -1,81 +0,0 @@
|
|||
/*
|
||||
* child.c
|
||||
*/
|
||||
|
||||
#include "eina_model_04_child.h"
|
||||
#include "eina_model_04_whistler.h"
|
||||
|
||||
static Eina_Bool initialized = EINA_FALSE;
|
||||
|
||||
static void
|
||||
_child_cry(Eina_Model *m)
|
||||
{
|
||||
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 *m)
|
||||
{
|
||||
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;
|
||||
|
||||
static const Diver_Interface _DIVER_INTERFACE;
|
||||
static const Eina_Model_Interface * const DIVER_INTERFACE =
|
||||
(Eina_Model_Interface *) &_DIVER_INTERFACE;
|
||||
|
||||
static const Eina_Model_Interface * CLASS_INTERFACE_ARRAY[] =
|
||||
{ &_DIVER_INTERFACE.base_interface, NULL }; //this array is for model
|
||||
|
||||
void
|
||||
child_init()
|
||||
{
|
||||
Eina_Model_Type *type;
|
||||
|
||||
if (initialized) return;
|
||||
initialized = EINA_TRUE;
|
||||
|
||||
human_init();
|
||||
|
||||
//overriding Diver Interface
|
||||
Eina_Model_Interface * iface = (Eina_Model_Interface *) &_DIVER_INTERFACE;
|
||||
iface->version = EINA_MODEL_INTERFACE_VERSION;
|
||||
iface->interface_size = sizeof(Diver_Interface);
|
||||
iface->name = DIVER_INTERFACE_NAME;
|
||||
DIVER_INTERFACE(iface)->dive = _child_dive;
|
||||
|
||||
//creating instance of Child type
|
||||
CHILD_MODEL_TYPE_NAME = "Child_Model_Type";
|
||||
|
||||
type = (Eina_Model_Type *) &_CHILD_TYPE;
|
||||
type->version = EINA_MODEL_TYPE_VERSION;
|
||||
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 *m)
|
||||
{
|
||||
EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(m, CHILD_TYPE));
|
||||
|
||||
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(m);
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
/*
|
||||
* child.h
|
||||
*/
|
||||
|
||||
#ifndef CHILD_H_
|
||||
#define CHILD_H_
|
||||
|
||||
#include "eina_model_04_human.h"
|
||||
|
||||
extern const char *CHILD_MODEL_TYPE_NAME;
|
||||
extern const Eina_Model_Type * const CHILD_TYPE;
|
||||
#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 *m);
|
||||
} Child_Type;
|
||||
|
||||
void child_init();
|
||||
void child_cry(Eina_Model *m);
|
||||
|
||||
#endif /* CHILD_H_ */
|
|
@ -1,157 +0,0 @@
|
|||
/*
|
||||
* human.c
|
||||
*
|
||||
*/
|
||||
|
||||
#include "eina_model_04_human.h"
|
||||
#include "eina_model_04_whistler.h"
|
||||
|
||||
static Eina_Bool initialized = EINA_FALSE;
|
||||
|
||||
static void
|
||||
_human_eat(Eina_Model *m)
|
||||
{
|
||||
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 *m)
|
||||
{
|
||||
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 *m)
|
||||
{
|
||||
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 *m)
|
||||
{
|
||||
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 *m)
|
||||
{
|
||||
printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)),
|
||||
__func__);
|
||||
printf("\t\t Dive Human\n");
|
||||
}
|
||||
/*
|
||||
* defining Human Model Instance
|
||||
* defining Whistler Interface instance
|
||||
* 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;
|
||||
|
||||
static const Whistler_Interface _WHISTLER_INTERFACE;
|
||||
static const Eina_Model_Interface * const WHISTLER_INTERFACE =
|
||||
(Eina_Model_Interface *) &_WHISTLER_INTERFACE;
|
||||
|
||||
static const Swimmer_Interface _SWIMMER_INTERFACE;
|
||||
static const Eina_Model_Interface * const SWIMMER_INTERFACE =
|
||||
(Eina_Model_Interface *) &_SWIMMER_INTERFACE;
|
||||
|
||||
static const Diver_Interface _DIVER_INTERFACE;
|
||||
static const Eina_Model_Interface * const DIVER_INTERFACE =
|
||||
(Eina_Model_Interface *) &_DIVER_INTERFACE;
|
||||
|
||||
/*
|
||||
* defining parent interfaces for Diver Interface instance
|
||||
* defining Interfaces for Human Model instance
|
||||
*/
|
||||
static const Eina_Model_Interface * PARENT_INTERFACES_ARRAY[] =
|
||||
{ &_SWIMMER_INTERFACE.base_interface, NULL }; //this array is for model
|
||||
static const Eina_Model_Interface * MODEL_INTERFACES_ARRAY[] =
|
||||
{ &_WHISTLER_INTERFACE.base_interface, &_DIVER_INTERFACE.base_interface,
|
||||
NULL }; //this array is for model
|
||||
|
||||
void
|
||||
human_init()
|
||||
{
|
||||
Eina_Model_Type *type;
|
||||
|
||||
if (initialized) return;
|
||||
initialized = EINA_TRUE;
|
||||
|
||||
animal_init();
|
||||
|
||||
/*
|
||||
* Initializing Whistler Interface Instance
|
||||
*/
|
||||
Eina_Model_Interface *iface = (Eina_Model_Interface *) &_WHISTLER_INTERFACE;
|
||||
iface->version = EINA_MODEL_INTERFACE_VERSION;
|
||||
iface->interface_size = sizeof(Whistler_Interface);
|
||||
iface->name = WHISTLER_INTERFACE_NAME;
|
||||
WHISTLER_INTERFACE(iface)->whistle = _human_whistle;
|
||||
|
||||
/*
|
||||
* Initializing Swimmer Interface Instance
|
||||
*/
|
||||
iface = (Eina_Model_Interface *) &_SWIMMER_INTERFACE;
|
||||
iface->version = EINA_MODEL_INTERFACE_VERSION;
|
||||
iface->interface_size = sizeof(Swimmer_Interface);
|
||||
iface->name = SWIMMER_INTERFACE_NAME;
|
||||
SWIMMER_INTERFACE(iface)->swim = _human_swim;
|
||||
|
||||
/*
|
||||
* Initializing Diver Interface Instance
|
||||
* Diver_Interface is inherited from Swimmer
|
||||
*/
|
||||
iface = (Eina_Model_Interface *) &_DIVER_INTERFACE;
|
||||
iface->version = EINA_MODEL_INTERFACE_VERSION;
|
||||
iface->interface_size = sizeof(Diver_Interface);
|
||||
iface->name = DIVER_INTERFACE_NAME;
|
||||
iface->interfaces = PARENT_INTERFACES_ARRAY;
|
||||
DIVER_INTERFACE(iface)->dive = _human_dive;
|
||||
|
||||
/*
|
||||
* Initializing instance of Human Model
|
||||
*/
|
||||
|
||||
HUMAN_MODEL_TYPE_NAME = "Human_Model_Type";
|
||||
|
||||
type = (Eina_Model_Type *) &_HUMAN_TYPE;
|
||||
type->version = EINA_MODEL_TYPE_VERSION;
|
||||
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;
|
||||
HUMAN_TYPE(type)->walk =_human_walk;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* call for implemented Human Class function
|
||||
*/
|
||||
void
|
||||
human_walk(Eina_Model *m)
|
||||
{
|
||||
EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(m, HUMAN_TYPE));
|
||||
|
||||
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(m);
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* human.h
|
||||
*/
|
||||
|
||||
#ifndef HUMAN_H_
|
||||
#define HUMAN_H_
|
||||
|
||||
#include "eina_model_04_animal.h"
|
||||
|
||||
extern const char *HUMAN_MODEL_TYPE_NAME;
|
||||
extern const Eina_Model_Type * const HUMAN_TYPE;
|
||||
|
||||
#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 *m);
|
||||
} Human_Type;
|
||||
|
||||
void human_init();
|
||||
void human_walk(Eina_Model *m);
|
||||
|
||||
#endif /* HUMAN_H_ */
|
|
@ -1,110 +0,0 @@
|
|||
/*
|
||||
* main_animal.c
|
||||
* compile with: gcc eina_model_04_*.c -o eina_model_04 `pkg-config --cflags --libs eina`
|
||||
*/
|
||||
|
||||
/*
|
||||
* This example demonstrates the extended usage of Eina Model.
|
||||
* Class inheritance and interface implementation
|
||||
*
|
||||
* Animal Class is inherited from BaseClass and implements
|
||||
* "_breathe_animal()" and "_eat_animal()" methods.
|
||||
*
|
||||
* Human Class is inherited from Animal class.
|
||||
* Parrot Class is inherited from Animal class.
|
||||
*
|
||||
* Child Class is inherited from Human class.
|
||||
*
|
||||
* Human Class and Parrot Class implement Whistler Interface.
|
||||
* Human Class implements Diver Interface. Diver Interface inherited from Swimmer Interface
|
||||
*
|
||||
*
|
||||
* Animal Class (inherited from Base Class)
|
||||
* + _breathe_animal()
|
||||
* + _eat_animal()
|
||||
* / -------/ \-------------\
|
||||
* / \
|
||||
* Human Class Parrot Class
|
||||
* inherits inherits
|
||||
* + animal_breathe() + animal_breathe()
|
||||
* overrides overrides
|
||||
* + animal_eat(); + animal_eat();
|
||||
* implements implements
|
||||
* + human_walk(); + parrot_fly();
|
||||
*
|
||||
* implements Whistler, Swimmer, implements Whistler,
|
||||
* Diver Interfaces: + whistler_whistle()
|
||||
* + whistler_whistle()
|
||||
* + swimmer_swim()
|
||||
* + diver_dive()
|
||||
*
|
||||
* ----------------------------------------------------------
|
||||
* | Swim_Interface |
|
||||
* | + swim() |
|
||||
* | | |
|
||||
* | | |
|
||||
* | Dive Intarface (inherited from Swim Interface) |
|
||||
* | + dive() |
|
||||
* ---------------------------------------------------------
|
||||
* |
|
||||
* |
|
||||
* Child Class
|
||||
* + inherits all parent's methods
|
||||
* + implements cry_child()
|
||||
* + overrides dive() interface method
|
||||
*/
|
||||
|
||||
#include <Eina.h>
|
||||
#include "eina_model_04_human.h"
|
||||
#include "eina_model_04_parrot.h"
|
||||
#include "eina_model_04_child.h"
|
||||
#include "eina_model_04_whistler.h"
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
Eina_Model *h, *p, *c;
|
||||
|
||||
eina_init();
|
||||
|
||||
human_init();
|
||||
parrot_init();
|
||||
child_init();
|
||||
|
||||
h = eina_model_new(HUMAN_TYPE);
|
||||
p = eina_model_new(PARROT_TYPE);
|
||||
c = eina_model_new(CHILD_TYPE);
|
||||
|
||||
animal_breathe(p);
|
||||
animal_eat(p);
|
||||
parrot_fly(p);
|
||||
whistler_whistle(p);
|
||||
|
||||
printf("\n");
|
||||
animal_breathe(h);
|
||||
animal_eat(h);
|
||||
human_walk(h);
|
||||
whistler_whistle(h);
|
||||
swimmer_swim(h);
|
||||
diver_dive(h);
|
||||
|
||||
printf("\n");
|
||||
animal_breathe(c);
|
||||
animal_eat(c);
|
||||
human_walk(c);
|
||||
whistler_whistle(c);
|
||||
swimmer_swim(c);
|
||||
diver_dive(c);
|
||||
child_cry(c);
|
||||
|
||||
eina_model_unref(c);
|
||||
eina_model_unref(h);
|
||||
eina_model_unref(p);
|
||||
|
||||
eina_shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
/*
|
||||
* parrot.c
|
||||
*/
|
||||
|
||||
#include "eina_model_04_parrot.h"
|
||||
#include "eina_model_04_whistler.h"
|
||||
|
||||
static Eina_Bool initialized = EINA_FALSE;
|
||||
|
||||
static void
|
||||
_parrot_fly(Eina_Model *m)
|
||||
{
|
||||
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 *m)
|
||||
{
|
||||
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 *m)
|
||||
{
|
||||
printf("%s\t%s", eina_model_type_name_get(eina_model_type_get(m)),
|
||||
__func__);
|
||||
printf("\t\t Whistle Parrot\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* 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;
|
||||
|
||||
static const Whistler_Interface _WHISTLER_INTERFACE;
|
||||
static const Eina_Model_Interface * const WHISTLER_INTERFACE =
|
||||
(Eina_Model_Interface *) &_WHISTLER_INTERFACE;
|
||||
|
||||
static const Eina_Model_Interface * MODEL_INTERFACES_ARRAY[] =
|
||||
{ &_WHISTLER_INTERFACE.base_interface, NULL }; //this array is for model
|
||||
|
||||
void
|
||||
parrot_init()
|
||||
{
|
||||
Eina_Model_Type *type;
|
||||
if (initialized) return;
|
||||
initialized = EINA_TRUE;
|
||||
|
||||
animal_init();
|
||||
/*
|
||||
*overriding Whistler Interface (creating instance of Whistler Interface)
|
||||
*/
|
||||
Eina_Model_Interface *iface = (Eina_Model_Interface *) &_WHISTLER_INTERFACE;
|
||||
iface->version = EINA_MODEL_INTERFACE_VERSION;
|
||||
iface->interface_size = sizeof(Whistler_Interface);
|
||||
iface->name = WHISTLER_INTERFACE_NAME;
|
||||
WHISTLER_INTERFACE(iface)->whistle = _parrot_whistle;
|
||||
|
||||
PARROT_MODEL_TYPE_NAME = "Parrot_Model_Type";
|
||||
|
||||
type = (Eina_Model_Type *)&_PARROT_TYPE;
|
||||
type->version = EINA_MODEL_TYPE_VERSION;
|
||||
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;
|
||||
PARROT_TYPE(type)->fly = _parrot_fly;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
parrot_fly(Eina_Model *m)
|
||||
{
|
||||
EINA_SAFETY_ON_FALSE_RETURN(eina_model_instance_check(m, PARROT_TYPE));
|
||||
|
||||
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(m);
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* parrot.h
|
||||
*/
|
||||
|
||||
#ifndef PARROT_H_
|
||||
#define PARROT_H_
|
||||
|
||||
#include "eina_model_04_animal.h"
|
||||
|
||||
extern const char *PARROT_MODEL_TYPE_NAME;
|
||||
extern const Eina_Model_Type * const PARROT_TYPE;
|
||||
|
||||
#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 *m);
|
||||
} Parrot_Type;
|
||||
|
||||
void parrot_init();
|
||||
void parrot_fly(Eina_Model *m);
|
||||
|
||||
#endif /* PARROT_H_ */
|
|
@ -1,59 +0,0 @@
|
|||
/*
|
||||
* whistler.c
|
||||
*
|
||||
*/
|
||||
|
||||
#include "eina_model_04_whistler.h"
|
||||
|
||||
void
|
||||
whistler_whistle(Eina_Model *m)
|
||||
{
|
||||
const Eina_Model_Interface *iface = NULL;
|
||||
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, m, Whistler_Interface, whistle);
|
||||
EINA_SAFETY_ON_NULL_RETURN(pf);
|
||||
printf("%s() \t", __func__);
|
||||
pf(m);
|
||||
}
|
||||
/*
|
||||
* call for overridden Swimmer Interface function
|
||||
*/
|
||||
void
|
||||
swimmer_swim(Eina_Model *m)
|
||||
{
|
||||
const Eina_Model_Interface *iface = NULL;
|
||||
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, m, Swimmer_Interface, swim);
|
||||
EINA_SAFETY_ON_NULL_RETURN(pf);
|
||||
printf("%s() \t", __func__);
|
||||
pf(m);
|
||||
}
|
||||
|
||||
/*
|
||||
* call for overridden Diver Interface function
|
||||
*/
|
||||
void
|
||||
diver_dive(Eina_Model *m)
|
||||
{
|
||||
const Eina_Model_Interface *iface = NULL;
|
||||
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, m, Diver_Interface, dive);
|
||||
EINA_SAFETY_ON_NULL_RETURN(pf);
|
||||
printf("%s() \t", __func__);
|
||||
pf(m);
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* whistler.h
|
||||
*/
|
||||
|
||||
#ifndef WHISTLER_H_
|
||||
#define WHISTLER_H_
|
||||
|
||||
#include <Eina.h>
|
||||
#include <eina_safety_checks.h>
|
||||
|
||||
#define WHISTLER_INTERFACE_NAME "Whistler_Interface"
|
||||
#define SWIMMER_INTERFACE_NAME "Swimmer_Interface"
|
||||
#define DIVER_INTERFACE_NAME "Diver_Interface"
|
||||
|
||||
#define WHISTLER_INTERFACE(x) ((Whistler_Interface *) x)
|
||||
#define SWIMMER_INTERFACE(x) ((Swimmer_Interface *) x)
|
||||
#define DIVER_INTERFACE(x) ((Diver_Interface *) x)
|
||||
|
||||
typedef struct _Whistler_Interface
|
||||
{
|
||||
Eina_Model_Interface base_interface;
|
||||
void (*whistle)(Eina_Model *);
|
||||
|
||||
} Whistler_Interface;
|
||||
|
||||
typedef struct _Swimmer_Interface
|
||||
{
|
||||
Eina_Model_Interface base_interface;
|
||||
void (*swim)(Eina_Model *);
|
||||
|
||||
} Swimmer_Interface;
|
||||
|
||||
//Diver Interface will use Swimmer Interface as a parent
|
||||
typedef struct _Diver_Interface
|
||||
{
|
||||
Eina_Model_Interface base_interface;
|
||||
void (*dive)(Eina_Model *);
|
||||
|
||||
} Diver_Interface;
|
||||
|
||||
void whistler_whistle(Eina_Model *m);
|
||||
void swimmer_swim(Eina_Model *m);
|
||||
void diver_dive(Eina_Model *m);
|
||||
|
||||
#endif /* WHISTLER_H_ */
|
|
@ -81,7 +81,6 @@
|
|||
* @li @ref Eina_Tiler_Group split, merge and navigates into 2D tiled regions.
|
||||
* @li @ref Eina_Trash_Group container of unused but allocated data.
|
||||
* @li @ref Eina_Value_Group container for generic value storage and access.
|
||||
* @li @ref Eina_Model_Group container for data with user defined hierarchy/structure.
|
||||
*
|
||||
* The tools that are available are (see @ref Eina_Tools_Group):
|
||||
* @li @ref Eina_Benchmark_Group helper to write benchmarks.
|
||||
|
|
|
@ -69,9 +69,6 @@
|
|||
#include "eina_value.h"
|
||||
#include "eina_evlog.h"
|
||||
#include "eina_freeq.h"
|
||||
/* no model for now
|
||||
#include "eina_model.h"
|
||||
*/
|
||||
|
||||
/*============================================================================*
|
||||
* Local *
|
||||
|
@ -156,9 +153,6 @@ EAPI Eina_Inlist *_eina_tracking = NULL;
|
|||
S(rbtree);
|
||||
S(file);
|
||||
S(safepointer);
|
||||
/* no model for now
|
||||
S(model);
|
||||
*/
|
||||
#undef S
|
||||
|
||||
struct eina_desc_setup
|
||||
|
@ -204,9 +198,6 @@ static const struct eina_desc_setup _eina_desc_setup[] = {
|
|||
S(rbtree),
|
||||
S(file),
|
||||
S(safepointer),
|
||||
/* no model for now
|
||||
S(model)
|
||||
*/
|
||||
#undef S
|
||||
};
|
||||
static const size_t _eina_desc_setup_len = sizeof(_eina_desc_setup) /
|
||||
|
|
|
@ -39,9 +39,6 @@
|
|||
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
|
||||
#include "eina_safety_checks.h"
|
||||
#include "eina_value.h"
|
||||
/* no model for now
|
||||
#include "eina_model.h" // uses eina_value.h
|
||||
*/
|
||||
|
||||
/*============================================================================*
|
||||
* Local *
|
||||
|
@ -4572,128 +4569,6 @@ EAPI const Eina_Value_Type _EINA_VALUE_TYPE_OPTIONAL = {
|
|||
_eina_value_type_optional_pget
|
||||
};
|
||||
|
||||
/* no model for now
|
||||
static Eina_Bool
|
||||
_eina_value_type_model_setup(const Eina_Value_Type *type EINA_UNUSED, void *mem)
|
||||
{
|
||||
Eina_Model **tmem = mem;
|
||||
*tmem = NULL;
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_eina_value_type_model_flush(const Eina_Value_Type *type EINA_UNUSED, void *mem)
|
||||
{
|
||||
Eina_Model **tmem = mem;
|
||||
if (*tmem)
|
||||
{
|
||||
eina_model_unref(*tmem);
|
||||
*tmem = NULL;
|
||||
}
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_eina_value_type_model_copy(const Eina_Value_Type *type EINA_UNUSED, const void *src, void *dst)
|
||||
{
|
||||
const Eina_Model * const *s = src;
|
||||
Eina_Model **d = dst;
|
||||
if (*s)
|
||||
*d = eina_model_copy(*s); // is it better to deep-copy?
|
||||
else
|
||||
*d = NULL;
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
static int
|
||||
_eina_value_type_model_compare(const Eina_Value_Type *type EINA_UNUSED, const void *a, const void *b)
|
||||
{
|
||||
const Eina_Model * const *ta = a;
|
||||
const Eina_Model * const *tb = b;
|
||||
|
||||
if ((!*ta) && (!*tb)) return 0;
|
||||
else if (!*ta) return 1;
|
||||
else if (!*tb) return -1;
|
||||
else return eina_model_compare(*ta, *tb);
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_eina_value_type_model_convert_to(const Eina_Value_Type *type EINA_UNUSED, const Eina_Value_Type *convert, const void *type_mem, void *convert_mem)
|
||||
{
|
||||
const Eina_Model *v = *(const Eina_Model **)type_mem;
|
||||
|
||||
if (convert == EINA_VALUE_TYPE_STRINGSHARE ||
|
||||
convert == EINA_VALUE_TYPE_STRING)
|
||||
{
|
||||
char *other_mem = v ? eina_model_to_string(v) : NULL;
|
||||
Eina_Bool ret = eina_value_type_pset(convert, convert_mem, &other_mem);
|
||||
free(other_mem);
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_eina_value_type_model_vset(const Eina_Value_Type *type EINA_UNUSED, void *mem, va_list args)
|
||||
{
|
||||
Eina_Model **tmem = mem, *tmp;
|
||||
|
||||
tmp = va_arg(args, Eina_Model *);
|
||||
|
||||
if (tmp) eina_model_ref(tmp);
|
||||
if (*tmem) eina_model_unref(*tmem);
|
||||
|
||||
*tmem = tmp;
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_eina_value_type_model_pset(const Eina_Value_Type *type EINA_UNUSED, void *mem, const void *ptr)
|
||||
{
|
||||
Eina_Model **tmem = mem;
|
||||
Eina_Model **p = (Eina_Model **)ptr;
|
||||
|
||||
if (*tmem == *p) return EINA_TRUE;
|
||||
|
||||
if (*p) eina_model_ref(*p);
|
||||
if (*tmem) eina_model_unref(*tmem);
|
||||
|
||||
*tmem = *p;
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_eina_value_type_model_pget(const Eina_Value_Type *type EINA_UNUSED, const void *mem, void *ptr)
|
||||
{
|
||||
Eina_Model **tmem = (Eina_Model **)mem;
|
||||
Eina_Model **p = ptr;
|
||||
*p = *tmem;
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
static const Eina_Value_Type _EINA_VALUE_TYPE_MODEL = {
|
||||
EINA_VALUE_TYPE_VERSION,
|
||||
sizeof(Eina_Model *),
|
||||
"Eina_Model",
|
||||
_eina_value_type_model_setup,
|
||||
_eina_value_type_model_flush,
|
||||
_eina_value_type_model_copy,
|
||||
_eina_value_type_model_compare,
|
||||
_eina_value_type_model_convert_to,
|
||||
NULL, // no convert from
|
||||
_eina_value_type_model_vset,
|
||||
_eina_value_type_model_pset,
|
||||
_eina_value_type_model_pget
|
||||
};
|
||||
*/
|
||||
|
||||
/* keep all basic types inlined in an array so we can compare if it's
|
||||
* a basic type using pointer arithmetic.
|
||||
*
|
||||
|
@ -5130,10 +5005,7 @@ eina_value_init(void)
|
|||
EINA_VALUE_TYPE_TIMEVAL = &_EINA_VALUE_TYPE_TIMEVAL;
|
||||
EINA_VALUE_TYPE_BLOB = &_EINA_VALUE_TYPE_BLOB;
|
||||
EINA_VALUE_TYPE_STRUCT = &_EINA_VALUE_TYPE_STRUCT;
|
||||
/* no model for now
|
||||
EINA_VALUE_TYPE_MODEL = &_EINA_VALUE_TYPE_MODEL;
|
||||
*/
|
||||
|
||||
|
||||
EINA_VALUE_TYPE_OPTIONAL = &_EINA_VALUE_TYPE_OPTIONAL;
|
||||
|
||||
EINA_VALUE_BLOB_OPERATIONS_MALLOC = &_EINA_VALUE_BLOB_OPERATIONS_MALLOC;
|
||||
|
@ -5217,9 +5089,6 @@ EAPI const Eina_Value_Type *EINA_VALUE_TYPE_HASH = NULL;
|
|||
EAPI const Eina_Value_Type *EINA_VALUE_TYPE_TIMEVAL = NULL;
|
||||
EAPI const Eina_Value_Type *EINA_VALUE_TYPE_BLOB = NULL;
|
||||
EAPI const Eina_Value_Type *EINA_VALUE_TYPE_STRUCT = NULL;
|
||||
/* no model for now
|
||||
EAPI const Eina_Value_Type *EINA_VALUE_TYPE_MODEL = NULL;
|
||||
*/
|
||||
EAPI const Eina_Value_Type *EINA_VALUE_TYPE_OPTIONAL = NULL;
|
||||
|
||||
|
||||
|
|
|
@ -62,8 +62,6 @@ static const Efl_Test_Case etc[] = {
|
|||
{ "Simple Xml Parser", eina_test_simple_xml_parser},
|
||||
{ "Value", eina_test_value },
|
||||
{ "COW", eina_test_cow },
|
||||
// Disabling Eina_Model test
|
||||
// { "Model", eina_test_model },
|
||||
{ "Barrier", eina_test_barrier },
|
||||
{ "Tmp String", eina_test_tmpstr },
|
||||
{ "Locking", eina_test_locking },
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -2873,51 +2873,6 @@ START_TEST(eina_value_test_optional_struct_members)
|
|||
}
|
||||
END_TEST
|
||||
|
||||
#if 0
|
||||
START_TEST(eina_value_test_model)
|
||||
{
|
||||
Eina_Value *value, inv;
|
||||
Eina_Model *model, *m;
|
||||
char *str;
|
||||
|
||||
eina_init();
|
||||
|
||||
value = eina_value_new(EINA_VALUE_TYPE_MODEL);
|
||||
fail_unless(value != NULL);
|
||||
|
||||
model = eina_model_new(EINA_MODEL_TYPE_GENERIC);
|
||||
fail_unless(model != NULL);
|
||||
|
||||
fail_unless(eina_value_setup(&inv, EINA_VALUE_TYPE_INT));
|
||||
fail_unless(eina_value_set(&inv, 1234));
|
||||
fail_unless(eina_model_property_set(model, "i", &inv));
|
||||
eina_value_flush(&inv);
|
||||
|
||||
fail_unless(eina_value_set(value, model));
|
||||
fail_unless(eina_model_refcount(model) == 2);
|
||||
|
||||
fail_unless(eina_value_get(value, &m));
|
||||
fail_unless(m == model);
|
||||
fail_unless(eina_model_refcount(m) == 2);
|
||||
|
||||
fail_unless(eina_value_pset(value, &model));
|
||||
fail_unless(eina_model_refcount(model) == 2);
|
||||
|
||||
str = eina_value_to_string(value);
|
||||
fail_unless(str != NULL);
|
||||
ck_assert_str_eq(str, "Eina_Model_Type_Generic({i: 1234}, [])");
|
||||
free(str);
|
||||
|
||||
eina_value_free(value);
|
||||
|
||||
fail_unless(eina_model_refcount(model) == 1);
|
||||
eina_model_unref(model);
|
||||
|
||||
eina_shutdown();
|
||||
}
|
||||
END_TEST
|
||||
#endif
|
||||
|
||||
void
|
||||
eina_test_value(TCase *tc)
|
||||
{
|
||||
|
@ -2946,7 +2901,4 @@ eina_test_value(TCase *tc)
|
|||
tcase_add_test(tc, eina_value_test_optional_int);
|
||||
tcase_add_test(tc, eina_value_test_optional_string);
|
||||
tcase_add_test(tc, eina_value_test_optional_struct_members);
|
||||
#if 0
|
||||
tcase_add_test(tc, eina_value_test_model);
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue