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.
31 struct item_range item_range_all = { type_none, type_last };
34 struct item_name item_names[]={
35 #define ITEM2(x,y) ITEM(y)
36 #define ITEM(x) { type_##x, #x },
43 item_coord_rewind(struct item *it)
45 it->meth->item_coord_rewind(it->priv_data);
49 item_coord_get(struct item *it, struct coord *c, int count)
51 return it->meth->item_coord_get(it->priv_data, c, count);
55 item_coord_get_pro(struct item *it, struct coord *c, int count, enum projection to)
57 int ret=item_coord_get(it, c, count);
59 enum projection from=map_projection(it->map);
61 for (i = 0 ; i < count ; i++)
62 transform_from_to(c+i, from, c+i, to);
67 item_coord_is_node(struct item *it)
69 if (it->meth->item_coord_is_node)
70 return it->meth->item_coord_is_node(it->priv_data);
75 item_attr_rewind(struct item *it)
77 it->meth->item_attr_rewind(it->priv_data);
80 item_attr_get(struct item *it, enum attr_type attr_type, struct attr *attr)
82 return it->meth->item_attr_get(it->priv_data, attr_type, attr);
85 struct item * item_new(char *type, int zoom)
89 it = g_new0(struct item, 1);
91 /* FIXME evaluate arguments */
97 item_from_name(const char *name)
101 for (i=0 ; i < sizeof(item_names)/sizeof(struct item_name) ; i++) {
102 if (! strcmp(item_names[i].name, name))
103 return item_names[i].item;
109 item_to_name(enum item_type item)
113 for (i=0 ; i < sizeof(item_names)/sizeof(struct item_name) ; i++) {
114 if (item_names[i].item == item)
115 return item_names[i].name;
125 item_hash_hash(gconstpointer key)
127 const struct item *itm=key;
128 gconstpointer hashkey=(gconstpointer)(itm->id_hi^itm->id_lo^((int) itm->map));
129 return g_direct_hash(hashkey);
133 item_hash_equal(gconstpointer a, gconstpointer b)
135 const struct item *itm_a=a;
136 const struct item *itm_b=b;
137 if (item_is_equal(*itm_a, *itm_b))
147 struct item_hash *ret=g_new(struct item_hash, 1);
149 ret->h=g_hash_table_new_full(item_hash_hash, item_hash_equal, g_free, NULL);
154 item_hash_insert(struct item_hash *h, struct item *item, void *val)
156 struct item *hitem=g_new(struct item, 1);
158 dbg(2,"inserting (0x%x,0x%x) into %p\n", item->id_hi, item->id_lo, h->h);
159 g_hash_table_insert(h->h, hitem, val);
163 item_hash_remove(struct item_hash *h, struct item *item)
167 dbg(2,"removing (0x%x,0x%x) from %p\n", item->id_hi, item->id_lo, h->h);
168 ret=g_hash_table_remove(h->h, item);
169 dbg(2,"ret=%d\n", ret);
175 item_hash_lookup(struct item_hash *h, struct item *item)
177 return g_hash_table_lookup(h->h, item);
182 item_hash_destroy(struct item_hash *h)
184 g_hash_table_destroy(h->h);
189 item_range_intersects_range(struct item_range *range1, struct item_range *range2)
191 if (range1->max < range2->min)
193 if (range1->min > range2->max)
198 item_range_contains_item(struct item_range *range, enum item_type type)
200 if (type >= range->min && type <= range->max)