aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Sadoine <chris@indefini.org>2013-11-04 15:33:12 +0900
committerCedric Bail <cedric.bail@samsung.com>2013-11-04 15:35:41 +0900
commit6853dbcf23f71038a14fb4e44c0011dbb475821c (patch)
treefa4a7a79e55d4c88b79975d3394e3010db7b365d
parentedje: delete unused images from eet(edj) file. (diff)
downloadefl-6853dbcf23f71038a14fb4e44c0011dbb475821c.tar.gz
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>
-rw-r--r--AUTHORS1
-rw-r--r--ChangeLog4
-rw-r--r--NEWS1
-rw-r--r--src/examples/eet/eet-data-file_descriptor_02.c98
-rw-r--r--src/lib/eet/Eet.h19
-rw-r--r--src/lib/eet/eet_data.c28
6 files changed, 144 insertions, 7 deletions
diff --git a/AUTHORS b/AUTHORS
index b41df9e1e9..83f76663c5 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -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
--
diff --git a/ChangeLog b/ChangeLog
index 4f7ad022a8..ed9fe9d346 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/NEWS b/NEWS
index 2b4f923a81..b7e0b8c1e2 100644
--- a/NEWS
+++ b/NEWS
@@ -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
diff --git a/src/examples/eet/eet-data-file_descriptor_02.c b/src/examples/eet/eet-data-file_descriptor_02.c
index bfd34d13e4..cba0377458 100644
--- a/src/examples/eet/eet-data-file_descriptor_02.c
+++ b/src/examples/eet/eet-data-file_descriptor_02.c
@@ -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");
diff --git a/src/lib/eet/Eet.h b/src/lib/eet/Eet.h
index 12e8c98a89..de57e4a3d7 100644
--- a/src/lib/eet/Eet.h
+++ b/src/lib/eet/Eet.h
@@ -3463,6 +3463,25 @@ eet_data_descriptor_encode(Eet_Data_Descriptor *edd,
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
*
* Most of the @ref Eet_Data_Group have alternative versions that
diff --git a/src/lib/eet/eet_data.c b/src/lib/eet/eet_data.c
index e4a0d26d68..33134b29a0 100644
--- a/src/lib/eet/eet_data.c
+++ b/src/lib/eet/eet_data.c
@@ -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))