]> git.babelmonkeys.de Git - jubjub.git/blob - src/gui/gtk/JubGObjectMap.h
Initial commit
[jubjub.git] / src / gui / gtk / JubGObjectMap.h
1 #import <ObjFW/ObjFW.h>
2 #include <gtk/gtk.h>
3
4 static void *copy(void *value)
5 {
6         return [(id)value copy];
7 }
8
9 static void release(void *value)
10 {
11         [(id)value release];
12 }
13
14 static uint32_t hash(void *value)
15 {
16         return [(id)value hash];
17 }
18
19 static BOOL equal(void *value1, void *value2)
20 {
21         return [(id)value1 isEqual: (id)value2];
22 }
23
24 static void *g_retain(void *value)
25 {
26         return g_object_ref(value);
27 }
28
29 static void g_release(void *value)
30 {
31         g_object_unref(value);
32 }
33
34 static void *default_retain(void *value)
35 {
36         return value;
37 }
38
39 static uint32_t default_hash(void *value)
40 {
41 #define NUM (sizeof(void*)/sizeof(uint32_t))
42         int i;
43         uint32_t hash = 0;
44         union {
45                 void *v;
46                 uint32_t i[NUM];
47         } u = { value };
48
49         for (i = 0; i < NUM; i++)
50                 hash ^= u.i[i];
51
52         return hash;
53 #undef NUM
54 }
55
56 static BOOL default_equal(void *value1, void *value2)
57 {
58         return (value1 == value2);
59 }
60
61
62 static void rowref_release(void *value)
63 {
64         gtk_tree_row_reference_free(value);
65 }
66
67 static of_map_table_functions_t keyFunctions = {
68         .retain = copy,
69         .release = release,
70         .hash = hash,
71         .equal = equal
72 };
73
74 static of_map_table_functions_t gObjectFunctions __attribute__((unused)) = {
75         .retain = g_retain,
76         .release = g_release,
77         .hash = default_hash,
78         .equal = default_equal
79 };
80
81 static of_map_table_functions_t rowRefFunctions = {
82         .retain = default_retain,
83         .release = rowref_release,
84         .hash = default_hash,
85         .equal = default_equal
86 };