2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
32 struct item_name item_names[]={
33 #define ITEM2(x,y) ITEM(y)
34 #define ITEM(x) { type_##x, #x },
41 item_coord_rewind(struct item *it)
43 it->meth->item_coord_rewind(it->priv_data);
47 item_coord_get(struct item *it, struct coord *c, int count)
49 return it->meth->item_coord_get(it->priv_data, c, count);
53 item_coord_get_pro(struct item *it, struct coord *c, int count, enum projection to)
55 int ret=item_coord_get(it, c, count);
57 enum projection from=map_projection(it->map);
59 for (i = 0 ; i < count ; i++)
60 transform_from_to(c+i, from, c+i, to);
65 item_coord_is_segment(struct item *it)
67 if (it->meth->item_coord_is_segment)
68 return it->meth->item_coord_is_segment(it->priv_data);
73 item_attr_rewind(struct item *it)
75 it->meth->item_attr_rewind(it->priv_data);
78 item_attr_get(struct item *it, enum attr_type attr_type, struct attr *attr)
80 return it->meth->item_attr_get(it->priv_data, attr_type, attr);
83 struct item * item_new(char *type, int zoom)
87 it = g_new0(struct item, 1);
89 /* FIXME evaluate arguments */
95 item_from_name(const char *name)
99 for (i=0 ; i < sizeof(item_names)/sizeof(struct item_name) ; i++) {
100 if (! strcmp(item_names[i].name, name))
101 return item_names[i].item;
107 item_to_name(enum item_type item)
111 for (i=0 ; i < sizeof(item_names)/sizeof(struct item_name) ; i++) {
112 if (item_names[i].item == item)
113 return item_names[i].name;
123 item_hash_hash(gconstpointer key)
125 const struct item *itm=key;
126 gconstpointer hashkey=(gconstpointer)(itm->id_hi^itm->id_lo^((int) itm->map));
127 return g_direct_hash(hashkey);
131 item_hash_equal(gconstpointer a, gconstpointer b)
133 const struct item *itm_a=a;
134 const struct item *itm_b=b;
135 if (item_is_equal(*itm_a, *itm_b))
145 struct item_hash *ret=g_new(struct item_hash, 1);
147 ret->h=g_hash_table_new_full(item_hash_hash, item_hash_equal, g_free, NULL);
152 item_hash_insert(struct item_hash *h, struct item *item, void *val)
154 struct item *hitem=g_new(struct item, 1);
156 dbg(2,"inserting (0x%x,0x%x) into %p\n", item->id_hi, item->id_lo, h->h);
157 g_hash_table_insert(h->h, hitem, val);
161 item_hash_remove(struct item_hash *h, struct item *item)
165 dbg(2,"removing (0x%x,0x%x) from %p\n", item->id_hi, item->id_lo, h->h);
166 ret=g_hash_table_remove(h->h, item);
167 dbg(2,"ret=%d\n", ret);
173 item_hash_lookup(struct item_hash *h, struct item *item)
175 return g_hash_table_lookup(h->h, item);
180 item_hash_destroy(struct item_hash *h)
182 g_hash_table_destroy(h->h);