13 struct item_name item_names[]={
14 #define ITEM2(x,y) ITEM(y)
15 #define ITEM(x) { type_##x, #x },
22 item_coord_rewind(struct item *it)
24 it->meth->item_coord_rewind(it->priv_data);
28 item_coord_get(struct item *it, struct coord *c, int count)
30 return it->meth->item_coord_get(it->priv_data, c, count);
34 item_attr_rewind(struct item *it)
36 it->meth->item_attr_rewind(it->priv_data);
39 item_attr_get(struct item *it, enum attr_type attr_type, struct attr *attr)
41 return it->meth->item_attr_get(it->priv_data, attr_type, attr);
44 struct item * item_new(char *type, int zoom)
48 it = g_new0(struct item, 1);
50 /* FIXME evaluate arguments */
56 item_from_name(char *name)
60 for (i=0 ; i < sizeof(item_names)/sizeof(struct item_name) ; i++) {
61 if (! strcmp(item_names[i].name, name))
62 return item_names[i].item;
68 item_to_name(enum item_type item)
72 for (i=0 ; i < sizeof(item_names)/sizeof(struct item_name) ; i++) {
73 if (item_names[i].item == item)
74 return item_names[i].name;
84 item_hash_hash(gconstpointer key)
86 const struct item *itm=key;
87 gconstpointer hashkey=(gconstpointer)(itm->id_hi^itm->id_lo^((int) itm->map));
88 return g_direct_hash(hashkey);
92 item_hash_equal(gconstpointer a, gconstpointer b)
94 const struct item *itm_a=a;
95 const struct item *itm_b=b;
96 if (item_is_equal(*itm_a, *itm_b))
106 struct item_hash *ret=g_new(struct item_hash, 1);
108 ret->h=g_hash_table_new_full(item_hash_hash, item_hash_equal, g_free, NULL);
113 item_hash_insert(struct item_hash *h, struct item *item, void *val)
115 struct item *hitem=g_new(struct item, 1);
117 g_hash_table_insert(h->h, hitem, val);
121 item_hash_lookup(struct item_hash *h, struct item *item)
123 return g_hash_table_lookup(h->h, item);
128 item_hash_destroy(struct item_hash *h)
130 g_hash_table_destroy(h->h);