ajwillia-ms pushed a commit to branch master.

http://git.enlightenment.org/tools/examples.git/commit/?id=fb84558bde2642f58d6b7f2edb741b5f557cfb6d

commit fb84558bde2642f58d6b7f2edb741b5f557cfb6d
Author: Andy Williams <[email protected]>
Date:   Wed Nov 15 21:43:51 2017 +0000

    eina: Add a first pass for value reference
---
 reference/c/eina/src/eina_value.c | 87 +++++++++++++++++++++++++++++++++++++++
 reference/c/eina/src/meson.build  |  7 ++++
 2 files changed, 94 insertions(+)

diff --git a/reference/c/eina/src/eina_value.c 
b/reference/c/eina/src/eina_value.c
new file mode 100644
index 0000000..79c8650
--- /dev/null
+++ b/reference/c/eina/src/eina_value.c
@@ -0,0 +1,87 @@
+#define EFL_EO_API_SUPPORT 1
+#define EFL_BETA_API_SUPPORT 1
+
+#include <stdio.h>
+
+#include <Eina.h>
+#include <Efl_Core.h>
+
+static void
+_value_int()
+{
+   Eina_Value int_val;
+   char *str;
+   int i;
+
+   eina_value_setup(&int_val, EINA_VALUE_TYPE_INT);
+   eina_value_set(&int_val, 123);
+   eina_value_get(&int_val, &i);
+   printf("int_val value is %d\n", i);
+
+   str = eina_value_to_string(&int_val);
+   printf("int_val to string is \"%s\"\n", str);
+   free(str); // it was allocated by eina_value_to_string()
+   eina_value_flush(&int_val);
+}
+
+static void
+_value_string()
+{
+   Eina_Value str_val;
+   const char *str;
+   char *newstr;
+
+   eina_value_setup(&str_val, EINA_VALUE_TYPE_STRING);
+   eina_value_set(&str_val, "My string");
+   eina_value_get(&str_val, &str);
+   printf("str_val value is \"%s\" (pointer: %p)\n", str, str);
+
+   newstr = eina_value_to_string(&str_val);
+   printf("str_val to string is \"%s\" (pointer: %p)\n", newstr, newstr);
+   free(newstr); // it was allocated by eina_value_to_string()
+   eina_value_flush(&str_val);
+}
+
+static void
+_value_convert()
+{
+   Eina_Value str_val, int_val;
+   int i;
+   char *str;
+
+   eina_value_setup(&str_val, EINA_VALUE_TYPE_STRING);
+   eina_value_setup(&int_val, EINA_VALUE_TYPE_INT);
+
+   // convert from int to string:
+   eina_value_set(&int_val, 123);
+   eina_value_get(&int_val, &i);
+   eina_value_convert(&int_val, &str_val);
+   eina_value_get(&str_val, &str);
+   printf("int_val was %d, converted to string is \"%s\"\n", i, str);
+
+   // and the other way around!
+   eina_value_set(&str_val, "33");
+   eina_value_get(&str_val, &str);
+   eina_value_convert(&str_val, &int_val);
+   eina_value_get(&int_val, &i);
+   printf("str_val was \"%s\", converted to int is %d\n", str, i);
+
+   eina_value_flush(&str_val);
+   eina_value_flush(&int_val);
+}
+
+EAPI_MAIN void
+efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
+{
+   _value_int();
+   printf("\n");
+
+   _value_string();
+   printf("\n");
+
+   _value_convert();
+
+   efl_exit(0);
+}
+EFL_MAIN()
+
diff --git a/reference/c/eina/src/meson.build b/reference/c/eina/src/meson.build
index d2c1ebb..6872fbd 100644
--- a/reference/c/eina/src/meson.build
+++ b/reference/c/eina/src/meson.build
@@ -27,3 +27,10 @@ executable('efl_reference_eina_hash',
   include_directories : inc,
   install : true
 )
+
+executable('efl_reference_eina_value',
+  files(['eina_value.c']),
+  dependencies : deps,
+  include_directories : inc,
+  install : true
+)

-- 


Reply via email to