aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Williams <andy@andywilliams.me>2017-11-16 08:53:54 +0000
committerAndy Williams <andy@andywilliams.me>2017-11-16 08:53:54 +0000
commit866bfc8a49411d755fbb827344b8f79a9bd0be05 (patch)
tree8ab796bcbf1869d726cbe38bb626a7d3fad5ffc0
parenteina: Add a first pass for value reference (diff)
downloadexamples-866bfc8a49411d755fbb827344b8f79a9bd0be05.tar.gz
eina: Add struct value reference
-rw-r--r--reference/c/eina/src/eina_value.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/reference/c/eina/src/eina_value.c b/reference/c/eina/src/eina_value.c
index 79c86503..0fe7a79d 100644
--- a/reference/c/eina/src/eina_value.c
+++ b/reference/c/eina/src/eina_value.c
@@ -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);
}