/[zanavi_public1]/navit/navit/map.c
ZANavi

Contents of /navit/navit/map.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Mon Feb 4 17:41:59 2013 UTC (6 years, 7 months ago) by zoff99
File MIME type: text/plain
File size: 21997 byte(s)
new map version, lots of fixes and experimental new features
1 /**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2011-2012 Zoff <zoff@zoff.cc>
4 *
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.
8 *
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.
13 *
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.
18 */
19
20 /**
21 * Navit, a modular navigation system.
22 * Copyright (C) 2005-2008 Navit Team
23 *
24 * This program is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU General Public License
26 * version 2 as published by the Free Software Foundation.
27 *
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the
35 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
36 * Boston, MA 02110-1301, USA.
37 */
38
39 /** @file
40 *
41 * @brief Contains code that makes navit able to load maps
42 *
43 * This file contains the code that makes navit able to load maps. Because
44 * navit is able to open maps in different formats, this code does not handle
45 * any map format itself. This is done by map plugins which register to this
46 * code by calling plugin_register_map_type().
47 *
48 * When opening a new map, the map plugin will return a pointer to a map_priv
49 * struct, which can be defined by the map plugin and contains whatever private
50 * data the map plugin needs to access the map. This pointer will also be used
51 * as a "handle" to access the map opened.
52 *
53 * A common task is to create a "map rect". A map rect is a rectangular part of
54 * the map, that one can for example retrieve items from. It is not possible to
55 * retrieve items directly from the complete map. Creating a map rect returns a
56 * pointer to a map_rect_priv, which contains private data for the map rect and
57 * will be used as "handle" for this map rect.
58 */
59
60 #include <glib.h>
61 #include <string.h>
62 #include "debug.h"
63 #include "coord.h"
64 #include "projection.h"
65 #include "item.h"
66 #include "map.h"
67 #include "maptype.h"
68 #include "transform.h"
69 #include "plugin.h"
70 #include "callback.h"
71 #include "country.h"
72
73 /**
74 * @brief Opens a new map
75 *
76 * This function opens a new map based on the attributes passed. This function
77 * takes the attribute "attr_type" to determine which type of map to open and passes
78 * all attributes to the map plugin's function that was specified in the
79 * plugin_register_new_map_type()-call.
80 *
81 * Note that every plugin should accept an attribute of type "attr_data" to be passed
82 * with the filename of the map to be opened as value.
83 *
84 * @param attrs Attributes specifying which map to open, see description
85 * @return The opened map or NULL on failure
86 */
87 struct map *
88 map_new(struct attr *parent, struct attr **attrs)
89 {
90 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
91 dbg(0,"+#+:enter\n");
92 #endif
93 struct map *m;
94 struct map_priv *(*maptype_new)(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl);
95 struct attr *type = attr_search(attrs, NULL, attr_type);
96
97 if (!type)
98 {
99 dbg(0, "missing type\n");
100 return NULL;
101 }
102 //dbg(0,"type='%s'\n", type->u.str);
103 maptype_new = plugin_get_map_type(type->u.str);
104 if (!maptype_new)
105 {
106 dbg(0, "invalid type '%s'\n", type->u.str);
107 return NULL;
108 }
109 //dbg(0,"MM 1");
110
111 m=g_new0(struct map, 1);
112 m->attrs = attr_list_dup(attrs);
113 m->attr_cbl = callback_list_new();
114 //dbg(0,"MM 2");
115 m->priv = maptype_new(&m->meth, attrs, m->attr_cbl);
116 //dbg(0,"MM 3");
117 if (!m->priv)
118 {
119 m->refcount = 1;
120 //dbg(0,"MM 4");
121 map_destroy(m);
122 //dbg(0,"MM 5");
123 m = NULL;
124 }
125 else
126 {
127 m->refcount = 0;
128 }
129 //dbg(0,"MM 6");
130 return m;
131 }
132
133 void map_ref(struct map* m)
134 {
135 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
136 dbg(0,"+#+:enter\n");
137 #endif
138 m->refcount++;
139 }
140
141 /**
142 * @brief Gets an attribute from a map
143 *
144 * @param this_ The map the attribute should be read from
145 * @param type The type of the attribute to be read
146 * @param attr Pointer to an attrib-structure where the attribute should be written to
147 * @param iter (NOT IMPLEMENTED) Used to iterate through all attributes of a type. Set this to NULL to get the first attribute, set this to an attr_iter to get the next attribute
148 * @return True if the attribute type was found, false if not
149 */
150 int map_get_attr(struct map *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
151 {
152 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
153 dbg(0,"+#+:enter\n");
154 #endif
155 int ret = 0;
156 if (this_->meth.map_get_attr)
157 ret = this_->meth.map_get_attr(this_->priv, type, attr);
158 if (!ret)
159 ret = attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
160 return ret;
161 }
162
163 /**
164 * @brief Sets an attribute of a map
165 *
166 * This sets an attribute of a map, overwriting an attribute of the same type if it
167 * already exists. This function also calls all the callbacks that are registred
168 * to be called when attributes change.
169 *
170 * @param this_ The map to set the attribute of
171 * @param attr The attribute to set
172 * @return True if the attr could be set, false otherwise
173 */
174 int map_set_attr(struct map *this_, struct attr *attr)
175 {
176 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
177 dbg(0,"+#+:enter\n");
178 #endif
179 this_->attrs = attr_generic_set_attr(this_->attrs, attr);
180 if (this_->meth.map_set_attr)
181 this_->meth.map_set_attr(this_->priv, attr);
182 callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
183 return 1;
184 }
185
186 /**
187 * @brief Registers a new callback for attribute-change
188 *
189 * This function registers a new callback function that should be called if the attributes
190 * of the map change.
191 *
192 * @param this_ The map to associate the callback with
193 * @param cb The callback to add
194 */
195 void map_add_callback(struct map *this_, struct callback *cb)
196 {
197 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
198 dbg(0,"+#+:enter\n");
199 #endif
200 callback_list_add(this_->attr_cbl, cb);
201 }
202
203 /**
204 * @brief Removes a callback from the list of attribute-change callbacks
205 *
206 * This function removes one callback from the list of callbacks functions that should be called
207 * when attributes of the map change.
208 *
209 * @param this_ The map to remove the callback from
210 * @param cb The callback to remove
211 */
212 void map_remove_callback(struct map *this_, struct callback *cb)
213 {
214 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
215 dbg(0,"+#+:enter\n");
216 #endif
217 callback_list_remove(this_->attr_cbl, cb);
218 }
219
220 /**
221 * @brief Checks if strings from a map have to be converted
222 *
223 * @param this_ Map to be checked for the need to convert strings
224 * @return True if strings from the map have to be converted, false otherwise
225 */
226 int map_requires_conversion(struct map *this_)
227 {
228 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
229 dbg(0,"+#+:enter\n");
230 #endif
231 return (this_->meth.charset != NULL && strcmp(this_->meth.charset, "utf-8"));
232 }
233
234 /**
235 * @brief Converts a string from a map
236 *
237 * @param this_ The map the string to be converted is from
238 * @param str The string to be converted
239 * @return The converted string. It has to be map_convert_free()d after use.
240 */
241 char *
242 map_convert_string(struct map *this_, char *str)
243 {
244 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
245 dbg(0,"+#+:enter\n");
246 #endif
247 return g_convert(str, -1, "utf-8", this_->meth.charset, NULL, NULL, NULL);
248 }
249
250 /**
251 * @brief Frees the memory allocated for a converted string
252 *
253 * @param str The string to be freed
254 */
255 void map_convert_free(char *str)
256 {
257 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
258 dbg(0,"+#+:enter\n");
259 #endif
260 g_free(str);
261 }
262
263 /**
264 * @brief Returns the projection of a map
265 *
266 * @param this_ The map to return the projection of
267 * @return The projection of the map
268 */
269 enum projection map_projection(struct map *this_)
270 {
271 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
272 dbg(0,"+#+:enter\n");
273 #endif
274 return this_->meth.pro;
275 }
276
277 /**
278 * @brief Sets the projection of a map
279 *
280 * @param this_ The map to set the projection of
281 * @param pro The projection to be set
282 */
283 void map_set_projection(struct map *this_, enum projection pro)
284 {
285 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
286 dbg(0,"+#+:enter\n");
287 #endif
288 this_->meth.pro = pro;
289 }
290
291 void map_destroy_do(struct map *m)
292 {
293 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
294 dbg(0,"+#+:enter\n");
295 #endif
296 if (m->priv)
297 m->meth.map_destroy(m->priv);
298 attr_list_free(m->attrs);
299 callback_list_destroy(m->attr_cbl);
300 g_free(m);
301 }
302
303 /**
304 * @brief Destroys an opened map
305 *
306 * @param m The map to be destroyed
307 */
308 void map_destroy(struct map *m)
309 {
310 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
311 dbg(0,"+#+:enter\n");
312 #endif
313 if (!m)
314 return;
315
316 if (0 < m->refcount)
317 {
318 m->refcount--;
319 }
320 if (0 == m->refcount)
321 {
322 map_destroy_do(m);
323 }
324 }
325
326 /**
327 * @brief Creates a new map rect
328 *
329 * This creates a new map rect, which can be used to retrieve items from a map. If
330 * sel is a linked-list of selections, all of them will be used. If you pass NULL as
331 * sel, this means "get me the whole map".
332 *
333 * @param m The map to build the rect on
334 * @param sel Map selection to choose the rectangle - may be NULL, see description
335 * @return A new map rect
336 */
337 struct map_rect *
338 map_rect_new(struct map *m, struct map_selection *sel)
339 {
340 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
341 dbg(0,"+#+:enter\n");
342 #endif
343 struct map_rect *mr;
344
345 #if 0
346 printf("map_rect_new 0x%x,0x%x-0x%x,0x%x\n", r->lu.x, r->lu.y, r->rl.x, r->rl.y);
347 #endif
348 //if (sel!=NULL)
349 //{
350 // dbg(0,"map_rect_new 0x%x,0x%x-0x%x,0x%x\n", sel->u.c_rect.lu.x, sel->u.c_rect.lu.y, sel->u.c_rect.rl.x, sel->u.c_rect.rl.y);
351 //}
352 mr=g_new0(struct map_rect, 1);
353 mr->m = m;
354 mr->priv = m->meth.map_rect_new(m->priv, sel);
355 if (!mr->priv)
356 {
357 g_free(mr);
358 mr = NULL;
359 }
360
361 return mr;
362 }
363
364 /**
365 * @brief Gets the next item from a map rect
366 *
367 * Returns an item from a map rect and advances the "item pointer" one step further,
368 * so that at the next call the next item is returned. Returns NULL if there are no more items.
369 *
370 * @param mr The map rect to return an item from
371 * @return An item from the map rect
372 */
373 struct item *
374 map_rect_get_item(struct map_rect *mr)
375 {
376 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
377 dbg(0,"+#+:enter\n");
378 #endif
379 struct item *ret;
380 dbg_assert(mr != NULL);
381 dbg_assert(mr->m != NULL);
382 dbg_assert(mr->m->meth.map_rect_get_item != NULL);
383 ret = mr->m->meth.map_rect_get_item(mr->priv);
384 if (ret)
385 ret->map = mr->m;
386 return ret;
387 }
388
389 /**
390 * @brief Returns the item specified by the ID
391 *
392 * @param mr The map rect to search for the item
393 * @param id_hi High part of the ID to be found
394 * @param id_lo Low part of the ID to be found
395 * @return The item with the specified ID or NULL if not found
396 */
397 struct item *
398 map_rect_get_item_byid(struct map_rect *mr, int id_hi, int id_lo)
399 {
400 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
401 dbg(0,"+#+:enter\n");
402 #endif
403 struct item *ret = NULL;
404 dbg_assert(mr != NULL);
405 dbg_assert(mr->m != NULL);
406 if (mr->m->meth.map_rect_get_item_byid)
407 ret = mr->m->meth.map_rect_get_item_byid(mr->priv, id_hi, id_lo);
408 if (ret)
409 ret->map = mr->m;
410 return ret;
411 }
412
413 /**
414 * @brief Destroys a map rect
415 *
416 * @param mr The map rect to be destroyed
417 */
418 void map_rect_destroy(struct map_rect *mr)
419 {
420 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
421 dbg(0,"+#+:enter\n");
422 #endif
423 if (mr)
424 {
425 mr->m->meth.map_rect_destroy(mr->priv);
426 g_free(mr);
427 }
428 }
429
430 /**
431 * @brief Holds information about a search on a map
432 *
433 * This structure holds information about a search performed on a map. This can be
434 * used as "handle" to retrieve items from a search.
435 */
436 struct map_search
437 {
438 struct map *m;
439 struct attr search_attr;
440 void *priv;
441 };
442
443 /**
444 * @brief Starts a search on a map
445 *
446 * This function starts a search on a map. What attributes one can search for depends on the
447 * map plugin.
448 *
449 * The OSM/binfile plugin currently supports: attr_town_name, attr_street_name
450 * The MG plugin currently supports: attr_town_postal, attr_town_name, attr_street_name
451 *
452 * If you enable partial matches bear in mind that the search matches only the begin of the
453 * strings - a search for a street named "street" would match to "streetfoo", but not to
454 * "somestreet". Search is case insensitive.
455 *
456 * The item passed to this function specifies a "superior item" to "search within" - e.g. a town
457 * in which we want to search for a street, or a country in which to search for a town.
458 *
459 * Please also note that the search for countries is not handled by map plugins but by navit internally -
460 * have a look into country.c for details. Because of that every map plugin has to accept a country item
461 * to be passed as "superior item".
462 *
463 * Note: If you change something here, please make sure to also update the documentation of mapset_search_new()
464 * in mapset.c!
465 *
466 * @param m The map that should be searched
467 * @param item Specifies a superior item to "search within" (see description)
468 * @param search_attr Attribute specifying what to search for. See description.
469 * @param partial Set this to true to also have partial matches. See description.
470 * @return A new map search struct for this search
471 */
472 struct map_search *
473 map_search_new(struct map *m, struct item *item, struct attr *search_attr, int partial)
474 {
475 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
476 dbg(0,"+#+:enter\n");
477 #endif
478 struct map_search *this_;
479 dbg(1, "enter(%p,%p,%p,%d)\n", m, item, search_attr, partial);
480 dbg(1, "0x%x 0x%x 0x%x\n", attr_country_all, search_attr->type, attr_country_name);
481 this_=g_new0(struct map_search,1);
482 this_->m = m;
483 this_->search_attr = *search_attr;
484 if ((search_attr->type >= attr_country_all && search_attr->type <= attr_country_name) || search_attr->type == attr_country_id)
485 {
486 this_->priv = country_search_new(&this_->search_attr, partial);
487 }
488 else
489 {
490 if (m->meth.map_search_new)
491 {
492 if (m->meth.charset)
493 {
494 this_->search_attr.u.str = g_convert(this_->search_attr.u.str, -1, m->meth.charset, "utf-8", NULL, NULL, NULL);
495 }
496 this_->priv = m->meth.map_search_new(m->priv, item, &this_->search_attr, partial);
497 if (!this_->priv)
498 {
499 g_free(this_);
500 this_ = NULL;
501 }
502 }
503 else
504 {
505 g_free(this_);
506 this_ = NULL;
507 }
508 }
509 return this_;
510 }
511
512 /**
513 * @brief Returns an item from a map search
514 *
515 * This returns an item of the result of a search on a map and advances the "item pointer" one step,
516 * so that at the next call the next item will be returned. If there are no more items in the result
517 * NULL is returned.
518 *
519 * @param this_ Map search struct of the search
520 * @return One item of the result
521 */
522 struct item *
523 map_search_get_item(struct map_search *this_)
524 {
525 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
526 dbg(0,"+#+:enter\n");
527 #endif
528 struct item *ret;
529
530 if (!this_)
531 return NULL;
532 if ((this_->search_attr.type >= attr_country_all && this_->search_attr.type <= attr_country_name) || this_->search_attr.type == attr_country_id)
533 return country_search_get_item(this_->priv);
534 ret = this_->m->meth.map_search_get_item(this_->priv);
535 if (ret)
536 ret->map = this_->m;
537 return ret;
538 }
539
540 /**
541 * @brief Destroys a map search struct
542 *
543 * @param this_ The map search struct to be destroyed
544 */
545 void map_search_destroy(struct map_search *this_)
546 {
547 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
548 dbg(0,"+#+:enter\n");
549 #endif
550 if (!this_)
551 return;
552 if (this_->search_attr.type >= attr_country_all && this_->search_attr.type <= attr_country_name)
553 country_search_destroy(this_->priv);
554 else
555 {
556 if (this_->m->meth.charset)
557 g_free(this_->search_attr.u.str);
558 this_->m->meth.map_search_destroy(this_->priv);
559 }
560 g_free(this_);
561 }
562
563 /**
564 * @brief Creates a new rectangular map selection
565 *
566 * @param center Coordinates of the center of the new rectangle
567 * @param distance Distance of the rectangle's borders from the center
568 * @param order Desired order of the new selection
569 * @return The new map selection
570 */
571 struct map_selection *
572 map_selection_rect_new(struct pcoord *center, int distance, int order)
573 {
574 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
575 dbg(0,"+#+:enter\n");
576 #endif
577 struct map_selection *ret=g_new0(struct map_selection, 1);
578 ret->order = order;
579 ret->range = item_range_all;
580 ret->u.c_rect.lu.x = center->x - distance;
581 ret->u.c_rect.lu.y = center->y + distance;
582 ret->u.c_rect.rl.x = center->x + distance;
583 ret->u.c_rect.rl.y = center->y - distance;
584 return ret;
585 }
586
587 /**
588 * @brief Duplicates a map selection, transforming coordinates
589 *
590 * This duplicates a map selection and at the same time transforms the internal
591 * coordinates of the selection from one projection to another.
592 *
593 * @param sel The map selection to be duplicated
594 * @param from The projection used for the selection at the moment
595 * @param to The projection that should be used for the duplicated selection
596 * @return A duplicated, transformed map selection
597 */
598 struct map_selection *
599 map_selection_dup_pro(struct map_selection *sel, enum projection from, enum projection to)
600 {
601 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
602 dbg(0,"+#+:enter\n");
603 #endif
604 struct map_selection *next, **last;
605 struct map_selection *ret = NULL;
606 last = &ret;
607 while (sel)
608 {
609 next = g_new(struct map_selection, 1);
610 *next = *sel;
611 if (from != projection_none || to != projection_none)
612 {
613 transform_from_to(&sel->u.c_rect.lu, from, &next->u.c_rect.lu, to);
614 transform_from_to(&sel->u.c_rect.rl, from, &next->u.c_rect.rl, to);
615 }
616 *last = next;
617 last = &next->next;
618 sel = sel->next;
619 }
620 return ret;
621 }
622
623 /**
624 * @brief Duplicates a map selection
625 *
626 * @param sel The map selection to duplicate
627 * @return The duplicated map selection
628 */
629 struct map_selection *
630 map_selection_dup(struct map_selection *sel)
631 {
632 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
633 dbg(0,"+#+:enter\n");
634 #endif
635 return map_selection_dup_pro(sel, projection_none, projection_none);
636 }
637
638 /**
639 * @brief Destroys a map selection
640 *
641 * @param sel The map selection to be destroyed
642 */
643 void map_selection_destroy(struct map_selection *sel)
644 {
645 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
646 dbg(0,"+#+:enter\n");
647 #endif
648 struct map_selection *next;
649 while (sel)
650 {
651 next = sel->next;
652 g_free(sel);
653 sel = next;
654 }
655 }
656
657 /**
658 * @brief Checks if a selection contains a rectangle containing an item
659 *
660 * This function checks if a selection contains a rectangle which exactly contains
661 * an item. The rectangle is automatically built around the given item.
662 *
663 * @param sel The selection to be checked
664 * @param item The item that the rectangle should be built around
665 * @return True if the rectangle is within the selection, false otherwise
666 */
667 int map_selection_contains_item_rect(struct map_selection *sel, struct item *item)
668 {
669 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
670 dbg(0,"+#+:enter\n");
671 #endif
672 struct coord c;
673 struct coord_rect r;
674 int count = 0;
675 while (item_coord_get(item, &c, 1))
676 {
677 if (!count)
678 {
679 r.lu = c;
680 r.rl = c;
681 }
682 else
683 coord_rect_extend(&r, &c);
684 count++;
685 }
686 if (!count)
687 return 0;
688 return map_selection_contains_rect(sel, &r);
689
690 }
691
692 /**
693 * @brief Checks if a selection contains a item range
694 *
695 * This function checks if a selection contains at least one of the items in range
696 *
697 * @param sel The selection to be checked
698 * @param follow Whether the next pointer of the selection should be followed
699 * @param ranges The item ranges to be checked
700 * @count the number of elements in ranges
701 * @return True if there is a match, false otherwise
702 */
703
704 int map_selection_contains_item_range(struct map_selection *sel, int follow, struct item_range *range, int count)
705 {
706 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
707 dbg(0,"+#+:enter\n");
708 #endif
709 int i;
710 if (!sel)
711 return 1;
712 while (sel)
713 {
714 for (i = 0; i < count; i++)
715 {
716 if (item_range_intersects_range(&sel->range, &range[i]))
717 return 1;
718 }
719 if (!follow)
720 break;
721 sel = sel->next;
722 }
723 return 0;
724 }
725 /**
726 * @brief Checks if a selection contains a item
727 *
728 * This function checks if a selection contains a item type
729 *
730 * @param sel The selection to be checked
731 * @param follow Whether the next pointer of the selection should be followed
732 * @param item The item type to be checked
733 * @return True if there is a match, false otherwise
734 */
735
736 int map_selection_contains_item(struct map_selection *sel, int follow, enum item_type type)
737 {
738 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
739 dbg(0,"+#+:enter\n");
740 #endif
741 if (!sel)
742 return 1;
743 while (sel)
744 {
745 if (item_range_contains_item(&sel->range, type))
746 return 1;
747 if (!follow)
748 break;
749 sel = sel->next;
750 }
751 return 0;
752 }
753
754 /**
755 * @brief Checks if a pointer points to the private data of a map
756 *
757 * @param map The map whose private data should be checked.
758 * @param priv The private data that should be checked.
759 * @return True if priv is the private data of map
760 */
761 int map_priv_is(struct map *map, struct map_priv *priv)
762 {
763 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
764 dbg(0,"+#+:enter\n");
765 #endif
766 return (map->priv == priv);
767 }
768
769 void map_dump_filedesc(struct map *map, FILE *out)
770 {
771 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
772 dbg(0,"+#+:enter\n");
773 #endif
774 struct map_rect *mr = map_rect_new(map, NULL);
775 struct item *item;
776
777 while ((item = map_rect_get_item(mr)))
778 item_dump_filedesc(item, map, out);
779 map_rect_destroy(mr);
780 }
781
782 void map_dump_file(struct map *map, const char *file)
783 {
784 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
785 dbg(0,"+#+:enter\n");
786 #endif
787 FILE *f;
788 f = fopen(file, "w");
789 if (f)
790 {
791 map_dump_filedesc(map, f);
792 fclose(f);
793 }
794 else
795 dbg(0, "failed to open file '%s'\n", file);
796 }
797
798 void map_dump(struct map *map)
799 {
800 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
801 dbg(0,"+#+:enter\n");
802 #endif
803 map_dump_filedesc(map, stdout);
804 }
805
806 struct item *
807 map_rect_create_item(struct map_rect *mr, enum item_type type_)
808 {
809 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
810 dbg(0,"+#+:enter\n");
811 #endif
812 if (mr && mr->priv && mr->m)
813 {
814 return mr->m->meth.map_rect_create_item(mr->priv, type_);
815 }
816 else
817 {
818 return NULL;
819 }
820 }
821

   
Visit the ZANavi Wiki