summaryrefslogtreecommitdiff
path: root/src/examples
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 /src/examples
parentcff3ec04b4d234c8ef59f9d6235e85b725e0bcf3 (diff)
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>
Diffstat (limited to 'src/examples')
-rw-r--r--src/examples/eet/eet-data-file_descriptor_02.c98
1 files changed, 96 insertions, 2 deletions
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
23 EET_UNKNOWN = 0, 23 EET_UNKNOWN = 0,
24 EET_STRUCT1, 24 EET_STRUCT1,
25 EET_STRUCT2, 25 EET_STRUCT2,
26 EET_STRUCT3 26 EET_STRUCT3,
27 EET_BASIC_FLOAT,
28 EET_BASIC_STRING
27}; 29};
28 30
29struct 31struct
@@ -34,6 +36,8 @@ struct
34 { EET_STRUCT1, "ST1" }, 36 { EET_STRUCT1, "ST1" },
35 { EET_STRUCT2, "ST2" }, 37 { EET_STRUCT2, "ST2" },
36 { EET_STRUCT3, "ST3" }, 38 { EET_STRUCT3, "ST3" },
39 { EET_BASIC_FLOAT, "float" },
40 { EET_BASIC_STRING, "string" },
37 { EET_UNKNOWN, NULL } 41 { EET_UNKNOWN, NULL }
38}; 42};
39 43
@@ -63,6 +67,8 @@ struct _Example_Union
63 Example_Struct1 st1; 67 Example_Struct1 st1;
64 Example_Struct2 st2; 68 Example_Struct2 st2;
65 Example_Struct3 st3; 69 Example_Struct3 st3;
70 float f;
71 const char* string;
66 } u; 72 } u;
67}; 73};
68 74
@@ -288,6 +294,10 @@ _data_descriptors_init(void)
288 _union_unified_descriptor, "ST2", _struct_2_descriptor); 294 _union_unified_descriptor, "ST2", _struct_2_descriptor);
289 EET_DATA_DESCRIPTOR_ADD_MAPPING( 295 EET_DATA_DESCRIPTOR_ADD_MAPPING(
290 _union_unified_descriptor, "ST3", _struct_3_descriptor); 296 _union_unified_descriptor, "ST3", _struct_3_descriptor);
297 EET_DATA_DESCRIPTOR_ADD_MAPPING_BASIC(
298 _union_unified_descriptor, "float", EET_T_FLOAT);
299 EET_DATA_DESCRIPTOR_ADD_MAPPING_BASIC(
300 _union_unified_descriptor, "string", EET_T_STRING);
291 301
292 EET_DATA_DESCRIPTOR_ADD_UNION( 302 EET_DATA_DESCRIPTOR_ADD_UNION(
293 _union_descriptor, Example_Union, "u", u, type, 303 _union_descriptor, Example_Union, "u", u, type,
@@ -404,6 +414,40 @@ _union_3_new(const char *v1)
404 return un; 414 return un;
405} 415}
406 416
417static Example_Union *
418_union_float_new(const char *v1)
419{
420 Example_Union *un = calloc(1, sizeof(Example_Union));
421 if (!un)
422 {
423 fprintf(
424 stderr, "ERROR: could not allocate an Example_Union struct.\n");
425 return NULL;
426 }
427
428 un->type = EET_BASIC_FLOAT;
429 un->u.f = atof(v1);
430
431 return un;
432}
433
434static Example_Union *
435_union_string_new(const char *v1)
436{
437 Example_Union *un = calloc(1, sizeof(Example_Union));
438 if (!un)
439 {
440 fprintf(
441 stderr, "ERROR: could not allocate an Example_Union struct.\n");
442 return NULL;
443 }
444
445 un->type = EET_BASIC_STRING;
446 un->u.string = v1;
447
448 return un;
449}
450
407static Example_Variant * 451static Example_Variant *
408_variant_1_new(const char *v1, 452_variant_1_new(const char *v1,
409 const char *v2, 453 const char *v2,
@@ -624,6 +668,14 @@ _print_union(const Example_Union *un)
624 printf("\t\t val1: %i\n", un->u.st3.body); 668 printf("\t\t val1: %i\n", un->u.st3.body);
625 break; 669 break;
626 670
671 case EET_BASIC_FLOAT:
672 printf("\t\t float: %f\n", un->u.f);
673 break;
674
675 case EET_BASIC_STRING:
676 printf("\t\t string: %s\n", un->u.string);
677 break;
678
627 default: 679 default:
628 return; 680 return;
629 } 681 }
@@ -712,7 +764,7 @@ main(int argc,
712 int type = atoi(argv[4]); 764 int type = atoi(argv[4]);
713 Example_Union *un; 765 Example_Union *un;
714 766
715 if (type < EET_STRUCT1 || type > EET_STRUCT3) 767 if (type < EET_STRUCT1 || type > EET_BASIC_STRING)
716 { 768 {
717 fprintf(stderr, 769 fprintf(stderr,
718 "ERROR: invalid type parameter (%s).\n", 770 "ERROR: invalid type parameter (%s).\n",
@@ -786,6 +838,48 @@ main(int argc,
786 eina_list_append(data_lists->union_list, un); 838 eina_list_append(data_lists->union_list, un);
787 break; 839 break;
788 840
841 case EET_BASIC_FLOAT:
842 if (argc != 6)
843 {
844 fprintf(
845 stderr, "ERROR: wrong number of parameters"
846 " (%d).\n", argc);
847 goto cont;
848 }
849
850 un = _union_float_new(argv[5]);
851 if (!un)
852 {
853 fprintf(
854 stderr, "ERROR: could not create the "
855 "requested union.\n");
856 goto cont;
857 }
858 data_lists->union_list =
859 eina_list_append(data_lists->union_list, un);
860 break;
861
862 case EET_BASIC_STRING:
863 if (argc != 6)
864 {
865 fprintf(
866 stderr, "ERROR: wrong number of parameters"
867 " (%d).\n", argc);
868 goto cont;
869 }
870
871 un = _union_string_new(argv[5]);
872 if (!un)
873 {
874 fprintf(
875 stderr, "ERROR: could not create the "
876 "requested union.\n");
877 goto cont;
878 }
879 data_lists->union_list =
880 eina_list_append(data_lists->union_list, un);
881 break;
882
789 default: 883 default:
790 fprintf( 884 fprintf(
791 stderr, "ERROR: bad type of of struct passed\n"); 885 stderr, "ERROR: bad type of of struct passed\n");