eina: Add struct value reference
This commit is contained in:
parent
fb84558bde
commit
866bfc8a49
|
@ -70,6 +70,74 @@ _value_convert()
|
|||
eina_value_flush(&int_val);
|
||||
}
|
||||
|
||||
static Eina_Value_Struct_Desc *_STRUCT_DESC = NULL;
|
||||
|
||||
static void
|
||||
_value_struct_define()
|
||||
{
|
||||
typedef struct _Struct {
|
||||
int num;
|
||||
char chr;
|
||||
} Struct;
|
||||
|
||||
static Eina_Value_Struct_Member members[] = {
|
||||
// no eina_value_type as they are not constant initializers, see below.
|
||||
EINA_VALUE_STRUCT_MEMBER(NULL, Struct, num),
|
||||
EINA_VALUE_STRUCT_MEMBER(NULL, Struct, chr)
|
||||
};
|
||||
|
||||
members[0].type = EINA_VALUE_TYPE_INT;
|
||||
members[1].type = EINA_VALUE_TYPE_CHAR;
|
||||
static Eina_Value_Struct_Desc desc = {
|
||||
EINA_VALUE_STRUCT_DESC_VERSION,
|
||||
NULL, // no special operations
|
||||
members,
|
||||
EINA_C_ARRAY_LENGTH(members),
|
||||
sizeof(Struct)
|
||||
};
|
||||
_STRUCT_DESC = &desc;
|
||||
}
|
||||
|
||||
static void
|
||||
_value_struct_rand(Eina_Value *val)
|
||||
{
|
||||
eina_value_struct_set(val, "num", rand());
|
||||
eina_value_struct_set(val, "chr", 32 + rand() % 94);
|
||||
|
||||
// this parameter is not defined but does not error
|
||||
eina_value_struct_set(val, "missing", rand());
|
||||
}
|
||||
|
||||
static void
|
||||
_value_struct_print(Eina_Value *struct_val)
|
||||
{
|
||||
int num;
|
||||
char chr;
|
||||
|
||||
eina_value_struct_get(struct_val, "num", &num);
|
||||
eina_value_struct_get(struct_val, "chr", &chr);
|
||||
|
||||
printf("Struct content\n");
|
||||
printf(" num: %d\n", num);
|
||||
printf(" chr: %c\n", chr);
|
||||
|
||||
if (eina_value_struct_get(struct_val, "missing", &num))
|
||||
printf( "missing: %d\n", num);
|
||||
}
|
||||
|
||||
static void
|
||||
_value_struct()
|
||||
{
|
||||
Eina_Value *struct_val;
|
||||
_value_struct_define();
|
||||
|
||||
struct_val = eina_value_struct_new(_STRUCT_DESC);
|
||||
_value_struct_rand(struct_val);
|
||||
|
||||
_value_struct_print(struct_val);
|
||||
eina_value_free(struct_val);
|
||||
}
|
||||
|
||||
EAPI_MAIN void
|
||||
efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
|
||||
{
|
||||
|
@ -80,6 +148,9 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
|
|||
printf("\n");
|
||||
|
||||
_value_convert();
|
||||
printf("\n");
|
||||
|
||||
_value_struct();
|
||||
|
||||
efl_exit(0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue