forked from enlightenment/efl
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:
parent
cff3ec04b4
commit
6853dbcf23
1
AUTHORS
1
AUTHORS
|
@ -68,6 +68,7 @@ Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
|
||||||
Lionel Orry <lionel.orry@gmail.com>
|
Lionel Orry <lionel.orry@gmail.com>
|
||||||
Jérôme Pinot <ngc891@gmail.com>
|
Jérôme Pinot <ngc891@gmail.com>
|
||||||
Leandro Santiago <leandrosansilva@gmail.com>
|
Leandro Santiago <leandrosansilva@gmail.com>
|
||||||
|
Christophe Sadoine <chris@indefini.org>
|
||||||
|
|
||||||
Eo
|
Eo
|
||||||
--
|
--
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
2013-11-03 Christophe Sadoine
|
||||||
|
|
||||||
|
* Eet: Added EET_DATA_DESCRIPTOR_ADD_MAPPING_BASIC().
|
||||||
|
|
||||||
2013-10-24 Sung W. Park (sung_)
|
2013-10-24 Sung W. Park (sung_)
|
||||||
|
|
||||||
* EvasGL: Fixed direct rendering mode not clipping to its clip region.
|
* EvasGL: Fixed direct rendering mode not clipping to its clip region.
|
||||||
|
|
1
NEWS
1
NEWS
|
@ -47,6 +47,7 @@ Additions:
|
||||||
- Add eet_data_descriptor_name_get()
|
- Add eet_data_descriptor_name_get()
|
||||||
- Add support EET_T_VALUE
|
- Add support EET_T_VALUE
|
||||||
- Add EET_DATA_DESCRIPTOR_ADD_SUB_NESTED()
|
- Add EET_DATA_DESCRIPTOR_ADD_SUB_NESTED()
|
||||||
|
- Add EET_DATA_DESCRIPTOR_ADD_MAPPING_BASIC()
|
||||||
* Eo:
|
* Eo:
|
||||||
- Add generic efl object infrastructure
|
- Add generic efl object infrastructure
|
||||||
- Add debugging facility
|
- Add debugging facility
|
||||||
|
|
|
@ -23,7 +23,9 @@ enum _Example_Data_Type
|
||||||
EET_UNKNOWN = 0,
|
EET_UNKNOWN = 0,
|
||||||
EET_STRUCT1,
|
EET_STRUCT1,
|
||||||
EET_STRUCT2,
|
EET_STRUCT2,
|
||||||
EET_STRUCT3
|
EET_STRUCT3,
|
||||||
|
EET_BASIC_FLOAT,
|
||||||
|
EET_BASIC_STRING
|
||||||
};
|
};
|
||||||
|
|
||||||
struct
|
struct
|
||||||
|
@ -34,6 +36,8 @@ struct
|
||||||
{ EET_STRUCT1, "ST1" },
|
{ EET_STRUCT1, "ST1" },
|
||||||
{ EET_STRUCT2, "ST2" },
|
{ EET_STRUCT2, "ST2" },
|
||||||
{ EET_STRUCT3, "ST3" },
|
{ EET_STRUCT3, "ST3" },
|
||||||
|
{ EET_BASIC_FLOAT, "float" },
|
||||||
|
{ EET_BASIC_STRING, "string" },
|
||||||
{ EET_UNKNOWN, NULL }
|
{ EET_UNKNOWN, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -63,6 +67,8 @@ struct _Example_Union
|
||||||
Example_Struct1 st1;
|
Example_Struct1 st1;
|
||||||
Example_Struct2 st2;
|
Example_Struct2 st2;
|
||||||
Example_Struct3 st3;
|
Example_Struct3 st3;
|
||||||
|
float f;
|
||||||
|
const char* string;
|
||||||
} u;
|
} u;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -288,6 +294,10 @@ _data_descriptors_init(void)
|
||||||
_union_unified_descriptor, "ST2", _struct_2_descriptor);
|
_union_unified_descriptor, "ST2", _struct_2_descriptor);
|
||||||
EET_DATA_DESCRIPTOR_ADD_MAPPING(
|
EET_DATA_DESCRIPTOR_ADD_MAPPING(
|
||||||
_union_unified_descriptor, "ST3", _struct_3_descriptor);
|
_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(
|
EET_DATA_DESCRIPTOR_ADD_UNION(
|
||||||
_union_descriptor, Example_Union, "u", u, type,
|
_union_descriptor, Example_Union, "u", u, type,
|
||||||
|
@ -404,6 +414,40 @@ _union_3_new(const char *v1)
|
||||||
return un;
|
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 *
|
static Example_Variant *
|
||||||
_variant_1_new(const char *v1,
|
_variant_1_new(const char *v1,
|
||||||
const char *v2,
|
const char *v2,
|
||||||
|
@ -624,6 +668,14 @@ _print_union(const Example_Union *un)
|
||||||
printf("\t\t val1: %i\n", un->u.st3.body);
|
printf("\t\t val1: %i\n", un->u.st3.body);
|
||||||
break;
|
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:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -712,7 +764,7 @@ main(int argc,
|
||||||
int type = atoi(argv[4]);
|
int type = atoi(argv[4]);
|
||||||
Example_Union *un;
|
Example_Union *un;
|
||||||
|
|
||||||
if (type < EET_STRUCT1 || type > EET_STRUCT3)
|
if (type < EET_STRUCT1 || type > EET_BASIC_STRING)
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"ERROR: invalid type parameter (%s).\n",
|
"ERROR: invalid type parameter (%s).\n",
|
||||||
|
@ -786,6 +838,48 @@ main(int argc,
|
||||||
eina_list_append(data_lists->union_list, un);
|
eina_list_append(data_lists->union_list, un);
|
||||||
break;
|
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:
|
default:
|
||||||
fprintf(
|
fprintf(
|
||||||
stderr, "ERROR: bad type of of struct passed\n");
|
stderr, "ERROR: bad type of of struct passed\n");
|
||||||
|
|
|
@ -3462,6 +3462,25 @@ eet_data_descriptor_encode(Eet_Data_Descriptor *edd,
|
||||||
NULL, \
|
NULL, \
|
||||||
subtype)
|
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
|
* @defgroup Eet_Data_Cipher_Group Eet Data Serialization using A Ciphers
|
||||||
*
|
*
|
||||||
|
|
|
@ -4060,6 +4060,10 @@ eet_data_put_union(Eet_Dictionary *ed,
|
||||||
ede->group_type);
|
ede->group_type);
|
||||||
|
|
||||||
sede = &(ede->subtype->elements.set[i]);
|
sede = &(ede->subtype->elements.set[i]);
|
||||||
|
|
||||||
|
if (IS_SIMPLE_TYPE(sede->type))
|
||||||
|
data = eet_data_put_type(ed, sede->type, data_in, &size);
|
||||||
|
else
|
||||||
data = _eet_data_descriptor_encode(ed,
|
data = _eet_data_descriptor_encode(ed,
|
||||||
sede->subtype,
|
sede->subtype,
|
||||||
data_in,
|
data_in,
|
||||||
|
@ -4126,8 +4130,21 @@ eet_data_get_union(Eet_Free_Context *context,
|
||||||
|
|
||||||
/* Yeah we found it ! */
|
/* Yeah we found it ! */
|
||||||
sede = &(ede->subtype->elements.set[i]);
|
sede = &(ede->subtype->elements.set[i]);
|
||||||
EET_ASSERT(sede->subtype, goto on_error);
|
|
||||||
|
|
||||||
|
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,
|
data_ret = _eet_data_descriptor_decode(context,
|
||||||
ed,
|
ed,
|
||||||
sede->subtype,
|
sede->subtype,
|
||||||
|
@ -4137,6 +4154,7 @@ eet_data_get_union(Eet_Free_Context *context,
|
||||||
sede->subtype->size);
|
sede->subtype->size);
|
||||||
if (!data_ret)
|
if (!data_ret)
|
||||||
goto on_error;
|
goto on_error;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set union type. */
|
/* Set union type. */
|
||||||
if ((!ed) || (!ede->subtype->func.str_direct_alloc))
|
if ((!ed) || (!ede->subtype->func.str_direct_alloc))
|
||||||
|
|
Loading…
Reference in New Issue