1 #include "test.h"
2 
3 const idclass_t obj_a_class = {
4   .ic_class      = "obj_a",
5   .ic_caption    = N_("Object A"),
6   .ic_properties = (const property_t[]){
7     { PROPDEF1("int1",  "Integer 1", PT_INT,  obj_a_t, a_int1)  },
8     { PROPDEF1("bool1", "Boolean 1", PT_BOOL, obj_a_t, a_bool1) },
9     { PROPDEF1("str1",  "String 1",  PT_STR,  obj_a_t, a_str1)  },
10   }
11 };
12 
13 static void obj_b_save ( idnode_t *self );
14 
15 const idclass_t obj_b_class = {
16   .ic_super      = &obj_a_class,
17   .ic_class      = "obj_b",
18   .ic_caption    = N_("Object B"),
19   .ic_save       = obj_b_save,
20   .ic_properties = (const property_t[]){
21     { PROPDEF1("int2",  "Integer 2", PT_INT,  obj_b_t, b_int2)  },
22     { PROPDEF1("bool2", "Boolean 2", PT_BOOL, obj_b_t, b_bool2) },
23     { PROPDEF1("str2",  "String 2",  PT_STR,  obj_b_t, b_str2)  },
24   }
25 };
26 
27 static void
obj_a_func1(void * self)28 obj_a_func1 ( void *self )
29 {
30   obj_a_t *a = self;
31   printf("a->a_int1 = %d\n", a->a_int1);
32 }
33 
34 static obj_a_t *
obj_a_create1(size_t alloc,const idclass_t * class,const char * uuid)35 obj_a_create1 ( size_t alloc, const idclass_t *class, const char *uuid )
36 {
37   obj_a_t *a = idnode_create(alloc, class, uuid);
38   a->a_func1 = obj_a_func1;
39   return a;
40 }
41 
42 #define obj_a_create(type, uuid)\
43   (struct type*)obj_a_create1(sizeof(struct type), &type##_class, uuid)
44 
45 static void
obj_b_func1(void * self)46 obj_b_func1 ( void *self )
47 {
48   obj_b_t *b = self;
49   printf("b->a_int1 = %d\n", b->a_int1);
50   printf("b->b_int2 = %d\n", b->b_int2);
51 }
52 
53 obj_b_t *
obj_b_create(const char * uuid)54 obj_b_create ( const char *uuid )
55 {
56   obj_b_t *b = obj_a_create(obj_b, uuid);
57   b->a_func1 = obj_b_func1;
58   b->a_bool1 = 0;
59   b->b_bool2 = 1;
60   b->a_int1  = 2;
61   b->b_int2  = 3;
62   b->a_str1  = strdup("HELLO");
63   b->b_str2  = strdup("WORLD");
64   return b;
65 }
66 
obj_b_save(idnode_t * self)67 void obj_b_save ( idnode_t *self )
68 {
69   idnode_save(self, "test");
70 }
71 
obj_b_load_all(void)72 void obj_b_load_all ( void )
73 {
74   idnode_load_all("test", (void*(*)(const char*))obj_b_create);
75 }
76