eet: Adding EET_DATA_DESCRIPTOR_ADD_MAPPING_BASIC to add a basic type to a union.

I added EET_DATA_DESCRIPTOR_ADD_MAPPING_BASIC because I need basic types in unions, and EET_DATA_DESCRIPTOR_ADD_MAPPING is only for structs.
I also modified the example with a float and a string.

Reviewers: cedric

Reviewed By: cedric

Differential Revision: https://phab.enlightenment.org/D313

Signed-off-by: Cedric Bail <cedric.bail@samsung.com>
This commit is contained in:
Christophe Sadoine 2013-11-04 15:33:12 +09:00 committed by Cedric Bail
parent cff3ec04b4
commit 6853dbcf23
6 changed files with 144 additions and 7 deletions

View File

@ -68,6 +68,7 @@ Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Lionel Orry <lionel.orry@gmail.com>
Jérôme Pinot <ngc891@gmail.com>
Leandro Santiago <leandrosansilva@gmail.com>
Christophe Sadoine <chris@indefini.org>
Eo
--

View File

@ -1,3 +1,7 @@
2013-11-03 Christophe Sadoine
* Eet: Added EET_DATA_DESCRIPTOR_ADD_MAPPING_BASIC().
2013-10-24 Sung W. Park (sung_)
* EvasGL: Fixed direct rendering mode not clipping to its clip region.

1
NEWS
View File

@ -47,6 +47,7 @@ Additions:
- Add eet_data_descriptor_name_get()
- Add support EET_T_VALUE
- Add EET_DATA_DESCRIPTOR_ADD_SUB_NESTED()
- Add EET_DATA_DESCRIPTOR_ADD_MAPPING_BASIC()
* Eo:
- Add generic efl object infrastructure
- Add debugging facility

View File

@ -23,7 +23,9 @@ enum _Example_Data_Type
EET_UNKNOWN = 0,
EET_STRUCT1,
EET_STRUCT2,
EET_STRUCT3
EET_STRUCT3,
EET_BASIC_FLOAT,
EET_BASIC_STRING
};
struct
@ -34,6 +36,8 @@ struct
{ EET_STRUCT1, "ST1" },
{ EET_STRUCT2, "ST2" },
{ EET_STRUCT3, "ST3" },
{ EET_BASIC_FLOAT, "float" },
{ EET_BASIC_STRING, "string" },
{ EET_UNKNOWN, NULL }
};
@ -63,6 +67,8 @@ struct _Example_Union
Example_Struct1 st1;
Example_Struct2 st2;
Example_Struct3 st3;
float f;
const char* string;
} u;
};
@ -288,6 +294,10 @@ _data_descriptors_init(void)
_union_unified_descriptor, "ST2", _struct_2_descriptor);
EET_DATA_DESCRIPTOR_ADD_MAPPING(
_union_unified_descriptor, "ST3", _struct_3_descriptor);
EET_DATA_DESCRIPTOR_ADD_MAPPING_BASIC(
_union_unified_descriptor, "float", EET_T_FLOAT);
EET_DATA_DESCRIPTOR_ADD_MAPPING_BASIC(
_union_unified_descriptor, "string", EET_T_STRING);
EET_DATA_DESCRIPTOR_ADD_UNION(
_union_descriptor, Example_Union, "u", u, type,
@ -404,6 +414,40 @@ _union_3_new(const char *v1)
return un;
}
static Example_Union *
_union_float_new(const char *v1)
{
Example_Union *un = calloc(1, sizeof(Example_Union));
if (!un)
{
fprintf(
stderr, "ERROR: could not allocate an Example_Union struct.\n");
return NULL;
}
un->type = EET_BASIC_FLOAT;
un->u.f = atof(v1);
return un;
}
static Example_Union *
_union_string_new(const char *v1)
{
Example_Union *un = calloc(1, sizeof(Example_Union));
if (!un)
{
fprintf(
stderr, "ERROR: could not allocate an Example_Union struct.\n");
return NULL;
}
un->type = EET_BASIC_STRING;
un->u.string = v1;
return un;
}
static Example_Variant *
_variant_1_new(const char *v1,
const char *v2,
@ -624,6 +668,14 @@ _print_union(const Example_Union *un)
printf("\t\t val1: %i\n", un->u.st3.body);
break;
case EET_BASIC_FLOAT:
printf("\t\t float: %f\n", un->u.f);
break;
case EET_BASIC_STRING:
printf("\t\t string: %s\n", un->u.string);
break;
default:
return;
}
@ -712,7 +764,7 @@ main(int argc,
int type = atoi(argv[4]);
Example_Union *un;
if (type < EET_STRUCT1 || type > EET_STRUCT3)
if (type < EET_STRUCT1 || type > EET_BASIC_STRING)
{
fprintf(stderr,
"ERROR: invalid type parameter (%s).\n",
@ -786,6 +838,48 @@ main(int argc,
eina_list_append(data_lists->union_list, un);
break;
case EET_BASIC_FLOAT:
if (argc != 6)
{
fprintf(
stderr, "ERROR: wrong number of parameters"
" (%d).\n", argc);
goto cont;
}
un = _union_float_new(argv[5]);
if (!un)
{
fprintf(
stderr, "ERROR: could not create the "
"requested union.\n");
goto cont;
}
data_lists->union_list =
eina_list_append(data_lists->union_list, un);
break;
case EET_BASIC_STRING:
if (argc != 6)
{
fprintf(
stderr, "ERROR: wrong number of parameters"
" (%d).\n", argc);
goto cont;
}
un = _union_string_new(argv[5]);
if (!un)
{
fprintf(
stderr, "ERROR: could not create the "
"requested union.\n");
goto cont;
}
data_lists->union_list =
eina_list_append(data_lists->union_list, un);
break;
default:
fprintf(
stderr, "ERROR: bad type of of struct passed\n");

View File

@ -3462,6 +3462,25 @@ eet_data_descriptor_encode(Eet_Data_Descriptor *edd,
NULL, \
subtype)
/**
* Add a mapping of a basic type to a data descriptor that will be used by a union type.
* @param unified_type The data descriptor to add the mapping to.
* @param name The string name to get/set type.
* @param basic_type The matching basic type.
*
* @since 1.8
* @ingroup Eet_Data_Group
* @see Eet_Data_Descriptor_Class
*/
#define EET_DATA_DESCRIPTOR_ADD_MAPPING_BASIC(unified_type, name, basic_type) \
eet_data_descriptor_element_add(unified_type, \
name, \
basic_type, \
EET_G_UNKNOWN, \
0, \
0, \
NULL, \
NULL)
/**
* @defgroup Eet_Data_Cipher_Group Eet Data Serialization using A Ciphers
*

View File

@ -4060,7 +4060,11 @@ eet_data_put_union(Eet_Dictionary *ed,
ede->group_type);
sede = &(ede->subtype->elements.set[i]);
data = _eet_data_descriptor_encode(ed,
if (IS_SIMPLE_TYPE(sede->type))
data = eet_data_put_type(ed, sede->type, data_in, &size);
else
data = _eet_data_descriptor_encode(ed,
sede->subtype,
data_in,
&size);
@ -4126,17 +4130,31 @@ eet_data_get_union(Eet_Free_Context *context,
/* Yeah we found it ! */
sede = &(ede->subtype->elements.set[i]);
EET_ASSERT(sede->subtype, goto on_error);
data_ret = _eet_data_descriptor_decode(context,
if (IS_SIMPLE_TYPE(sede->type))
{
ret = eet_data_get_type(ed,
sede->type,
echnk->data,
((char *)echnk->data) + echnk->size,
(char *)data);
if (ret <= 0)
return ret;
}
else
{
EET_ASSERT(sede->subtype, goto on_error);
data_ret = _eet_data_descriptor_decode(context,
ed,
sede->subtype,
echnk->data,
echnk->size,
data,
sede->subtype->size);
if (!data_ret)
goto on_error;
if (!data_ret)
goto on_error;
}
/* Set union type. */
if ((!ed) || (!ede->subtype->func.str_direct_alloc))