diff options
Diffstat (limited to 'libraries/eina/src/examples/eina_value_02.c')
-rw-r--r-- | libraries/eina/src/examples/eina_value_02.c | 100 |
1 files changed, 0 insertions, 100 deletions
diff --git a/libraries/eina/src/examples/eina_value_02.c b/libraries/eina/src/examples/eina_value_02.c deleted file mode 100644 index 9c659ec..0000000 --- a/libraries/eina/src/examples/eina_value_02.c +++ /dev/null | |||
@@ -1,100 +0,0 @@ | |||
1 | //Compile with: | ||
2 | //gcc eina_value_02.c -o eina_value_02 `pkg-config --cflags --libs eina` | ||
3 | |||
4 | #include <Eina.h> | ||
5 | |||
6 | static Eina_Value_Struct_Desc *V1_DESC = NULL; | ||
7 | static Eina_Value_Struct_Desc *V2_DESC = NULL; | ||
8 | |||
9 | void 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 | |||
57 | void 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 | |||
67 | void 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 | |||
80 | int 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 | } | ||