aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/eina/src/examples/eina_value_02.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-04-22 09:20:32 +1000
committerDavid Walter Seikel2012-04-22 09:20:32 +1000
commit3ad3455551be0d7859ecb02290376206d5e66498 (patch)
tree497917e12b4d7f458dff9765d9b53f64c4e03fc3 /libraries/eina/src/examples/eina_value_02.c
parentUpdate EFL to latest beta. (diff)
downloadSledjHamr-3ad3455551be0d7859ecb02290376206d5e66498.zip
SledjHamr-3ad3455551be0d7859ecb02290376206d5e66498.tar.gz
SledjHamr-3ad3455551be0d7859ecb02290376206d5e66498.tar.bz2
SledjHamr-3ad3455551be0d7859ecb02290376206d5e66498.tar.xz
And actually include new files, plus elementary libraries.
Diffstat (limited to 'libraries/eina/src/examples/eina_value_02.c')
-rw-r--r--libraries/eina/src/examples/eina_value_02.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/libraries/eina/src/examples/eina_value_02.c b/libraries/eina/src/examples/eina_value_02.c
new file mode 100644
index 0000000..9c659ec
--- /dev/null
+++ b/libraries/eina/src/examples/eina_value_02.c
@@ -0,0 +1,100 @@
1//Compile with:
2//gcc eina_value_02.c -o eina_value_02 `pkg-config --cflags --libs eina`
3
4#include <Eina.h>
5
6static Eina_Value_Struct_Desc *V1_DESC = NULL;
7static Eina_Value_Struct_Desc *V2_DESC = NULL;
8
9void value_init(void)
10{
11 typedef struct _My_Struct_V1 {
12 int param1;
13 char param2;
14 } My_Struct_V1;
15
16
17 static Eina_Value_Struct_Member v1_members[] = {
18 // no eina_value_type as they are not constant initializers, see below.
19 EINA_VALUE_STRUCT_MEMBER(NULL, My_Struct_V1, param1),
20 EINA_VALUE_STRUCT_MEMBER(NULL, My_Struct_V1, param2)
21 };
22 v1_members[0].type = EINA_VALUE_TYPE_INT;
23 v1_members[1].type = EINA_VALUE_TYPE_CHAR;
24 static Eina_Value_Struct_Desc v1_desc = {
25 EINA_VALUE_STRUCT_DESC_VERSION,
26 NULL, // no special operations
27 v1_members,
28 EINA_C_ARRAY_LENGTH(v1_members),
29 sizeof(My_Struct_V1)
30 };
31 V1_DESC = &v1_desc;
32
33 typedef struct _My_Struct_V2 {
34 int param1;
35 char param2;
36 int param3;
37 } My_Struct_V2;
38 static Eina_Value_Struct_Member v2_members[] = {
39 // no eina_value_type as they are not constant initializers, see below.
40 EINA_VALUE_STRUCT_MEMBER(NULL, My_Struct_V2, param1),
41 EINA_VALUE_STRUCT_MEMBER(NULL, My_Struct_V2, param2),
42 EINA_VALUE_STRUCT_MEMBER(NULL, My_Struct_V2, param3)
43 };
44 v2_members[0].type = EINA_VALUE_TYPE_INT;
45 v2_members[1].type = EINA_VALUE_TYPE_CHAR;
46 v2_members[2].type = EINA_VALUE_TYPE_INT;
47 static Eina_Value_Struct_Desc v2_desc = {
48 EINA_VALUE_STRUCT_DESC_VERSION,
49 NULL, // no special operations
50 v2_members,
51 EINA_C_ARRAY_LENGTH(v2_members),
52 sizeof(My_Struct_V2)
53 };
54 V2_DESC = &v2_desc;
55}
56
57void rand_init(Eina_Value *v)
58{
59 if (v->type != EINA_VALUE_TYPE_STRUCT)
60 return;
61
62 eina_value_struct_set(v, "param1", rand());
63 eina_value_struct_set(v, "param2", rand() % 256);
64 eina_value_struct_set(v, "param3", rand());
65}
66
67void my_struct_use(Eina_Value *params)
68{
69 int p1, p3;
70 char p2;
71
72 eina_value_struct_get(params, "param1", &p1);
73 eina_value_struct_get(params, "param2", &p2);
74 printf("param1: %d\nparam2: %c\n", p1, p2);
75
76 if (eina_value_struct_get(params, "param3", &p3))
77 printf("param3: %d\n", p3);
78}
79
80int main(int argc, char **argv)
81{
82 Eina_Value *v1, *v2;
83
84 eina_init();
85 value_init();
86 srand(time(NULL));
87
88 v1 = eina_value_struct_new(V1_DESC);
89 v2 = eina_value_struct_new(V2_DESC);
90
91 rand_init(v1);
92 my_struct_use(v1);
93
94 rand_init(v2);
95 my_struct_use(v2);
96
97 eina_value_free(v1);
98 eina_value_free(v2);
99 eina_shutdown();
100}