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

Diff of /navit/navit/map.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 27 Revision 28
49#include "transform.h" 49#include "transform.h"
50#include "plugin.h" 50#include "plugin.h"
51#include "callback.h" 51#include "callback.h"
52#include "country.h" 52#include "country.h"
53 53
54
55
56/** 54/**
57 * @brief Opens a new map 55 * @brief Opens a new map
58 * 56 *
59 * This function opens a new map based on the attributes passed. This function 57 * This function opens a new map based on the attributes passed. This function
60 * takes the attribute "attr_type" to determine which type of map to open and passes 58 * takes the attribute "attr_type" to determine which type of map to open and passes
68 * @return The opened map or NULL on failure 66 * @return The opened map or NULL on failure
69 */ 67 */
70struct map * 68struct map *
71map_new(struct attr *parent, struct attr **attrs) 69map_new(struct attr *parent, struct attr **attrs)
72{ 70{
71#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
72 dbg(0,"+#+:enter\n");
73#endif
73 struct map *m; 74 struct map *m;
74 struct map_priv *(*maptype_new)(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl); 75 struct map_priv *(*maptype_new)(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl);
75 struct attr *type=attr_search(attrs, NULL, attr_type); 76 struct attr *type = attr_search(attrs, NULL, attr_type);
76 77
77 if (! type) 78 if (!type)
78 { 79 {
79 dbg(0,"missing type\n"); 80 dbg(0, "missing type\n");
80 return NULL; 81 return NULL;
81 } 82 }
82 //dbg(0,"type='%s'\n", type->u.str); 83 //dbg(0,"type='%s'\n", type->u.str);
83 maptype_new=plugin_get_map_type(type->u.str); 84 maptype_new = plugin_get_map_type(type->u.str);
84 if (! maptype_new) 85 if (!maptype_new)
85 { 86 {
86 dbg(0,"invalid type '%s'\n", type->u.str); 87 dbg(0, "invalid type '%s'\n", type->u.str);
87 return NULL; 88 return NULL;
88 } 89 }
89 //dbg(0,"MM 1"); 90 //dbg(0,"MM 1");
90 91
91 m=g_new0(struct map, 1); 92 m=g_new0(struct map, 1);
92 m->attrs=attr_list_dup(attrs); 93 m->attrs = attr_list_dup(attrs);
93 m->attr_cbl=callback_list_new(); 94 m->attr_cbl = callback_list_new();
94 //dbg(0,"MM 2"); 95 //dbg(0,"MM 2");
95 m->priv=maptype_new(&m->meth, attrs, m->attr_cbl); 96 m->priv = maptype_new(&m->meth, attrs, m->attr_cbl);
96 //dbg(0,"MM 3"); 97 //dbg(0,"MM 3");
97 if (! m->priv) 98 if (!m->priv)
98 { 99 {
99 m->refcount = 1; 100 m->refcount = 1;
100 //dbg(0,"MM 4"); 101 //dbg(0,"MM 4");
101 map_destroy(m); 102 map_destroy(m);
102 //dbg(0,"MM 5"); 103 //dbg(0,"MM 5");
103 m=NULL; 104 m = NULL;
104 } 105 }
105 else { 106 else
107 {
106 m->refcount = 0; 108 m->refcount = 0;
107 } 109 }
108 //dbg(0,"MM 6"); 110 //dbg(0,"MM 6");
109 return m; 111 return m;
110} 112}
111 113
112void
113map_ref(struct map* m) 114void map_ref(struct map* m)
114{ 115{
116#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
117 dbg(0,"+#+:enter\n");
118#endif
115 m->refcount++; 119 m->refcount++;
116} 120}
117
118 121
119/** 122/**
120 * @brief Gets an attribute from a map 123 * @brief Gets an attribute from a map
121 * 124 *
122 * @param this_ The map the attribute should be read from 125 * @param this_ The map the attribute should be read from
123 * @param type The type of the attribute to be read 126 * @param type The type of the attribute to be read
124 * @param attr Pointer to an attrib-structure where the attribute should be written to 127 * @param attr Pointer to an attrib-structure where the attribute should be written to
125 * @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 128 * @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
126 * @return True if the attribute type was found, false if not 129 * @return True if the attribute type was found, false if not
127 */ 130 */
128int
129map_get_attr(struct map *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter) 131int map_get_attr(struct map *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
130{ 132{
133#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
134 dbg(0,"+#+:enter\n");
135#endif
131 int ret=0; 136 int ret = 0;
132 if (this_->meth.map_get_attr) 137 if (this_->meth.map_get_attr)
133 ret=this_->meth.map_get_attr(this_->priv, type, attr); 138 ret = this_->meth.map_get_attr(this_->priv, type, attr);
134 if (!ret) 139 if (!ret)
135 ret=attr_generic_get_attr(this_->attrs, NULL, type, attr, iter); 140 ret = attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
136 return ret; 141 return ret;
137} 142}
138 143
139/** 144/**
140 * @brief Sets an attribute of a map 145 * @brief Sets an attribute of a map
145 * 150 *
146 * @param this_ The map to set the attribute of 151 * @param this_ The map to set the attribute of
147 * @param attr The attribute to set 152 * @param attr The attribute to set
148 * @return True if the attr could be set, false otherwise 153 * @return True if the attr could be set, false otherwise
149 */ 154 */
150int
151map_set_attr(struct map *this_, struct attr *attr) 155int map_set_attr(struct map *this_, struct attr *attr)
152{ 156{
157#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
158 dbg(0,"+#+:enter\n");
159#endif
153 this_->attrs=attr_generic_set_attr(this_->attrs, attr); 160 this_->attrs = attr_generic_set_attr(this_->attrs, attr);
154 if (this_->meth.map_set_attr) 161 if (this_->meth.map_set_attr)
155 this_->meth.map_set_attr(this_->priv, attr); 162 this_->meth.map_set_attr(this_->priv, attr);
156 callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr); 163 callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
157 return 1; 164 return 1;
158} 165}
164 * of the map change. 171 * of the map change.
165 * 172 *
166 * @param this_ The map to associate the callback with 173 * @param this_ The map to associate the callback with
167 * @param cb The callback to add 174 * @param cb The callback to add
168 */ 175 */
169void
170map_add_callback(struct map *this_, struct callback *cb) 176void map_add_callback(struct map *this_, struct callback *cb)
171{ 177{
178#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
179 dbg(0,"+#+:enter\n");
180#endif
172 callback_list_add(this_->attr_cbl, cb); 181 callback_list_add(this_->attr_cbl, cb);
173} 182}
174 183
175/** 184/**
176 * @brief Removes a callback from the list of attribute-change callbacks 185 * @brief Removes a callback from the list of attribute-change callbacks
179 * when attributes of the map change. 188 * when attributes of the map change.
180 * 189 *
181 * @param this_ The map to remove the callback from 190 * @param this_ The map to remove the callback from
182 * @param cb The callback to remove 191 * @param cb The callback to remove
183 */ 192 */
184void
185map_remove_callback(struct map *this_, struct callback *cb) 193void map_remove_callback(struct map *this_, struct callback *cb)
186{ 194{
195#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
196 dbg(0,"+#+:enter\n");
197#endif
187 callback_list_remove(this_->attr_cbl, cb); 198 callback_list_remove(this_->attr_cbl, cb);
188} 199}
189
190 200
191/** 201/**
192 * @brief Checks if strings from a map have to be converted 202 * @brief Checks if strings from a map have to be converted
193 * 203 *
194 * @param this_ Map to be checked for the need to convert strings 204 * @param this_ Map to be checked for the need to convert strings
195 * @return True if strings from the map have to be converted, false otherwise 205 * @return True if strings from the map have to be converted, false otherwise
196 */ 206 */
197int
198map_requires_conversion(struct map *this_) 207int map_requires_conversion(struct map *this_)
199{ 208{
209#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
210 dbg(0,"+#+:enter\n");
211#endif
200 return (this_->meth.charset != NULL && strcmp(this_->meth.charset, "utf-8")); 212 return (this_->meth.charset != NULL && strcmp(this_->meth.charset, "utf-8"));
201} 213}
202 214
203/** 215/**
204 * @brief Converts a string from a map 216 * @brief Converts a string from a map
208 * @return The converted string. It has to be map_convert_free()d after use. 220 * @return The converted string. It has to be map_convert_free()d after use.
209 */ 221 */
210char * 222char *
211map_convert_string(struct map *this_, char *str) 223map_convert_string(struct map *this_, char *str)
212{ 224{
225#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
226 dbg(0,"+#+:enter\n");
227#endif
213 return g_convert(str, -1,"utf-8",this_->meth.charset,NULL,NULL,NULL); 228 return g_convert(str, -1, "utf-8", this_->meth.charset, NULL, NULL, NULL);
214} 229}
215 230
216/** 231/**
217 * @brief Frees the memory allocated for a converted string 232 * @brief Frees the memory allocated for a converted string
218 * 233 *
219 * @param str The string to be freed 234 * @param str The string to be freed
220 */ 235 */
221void
222map_convert_free(char *str) 236void map_convert_free(char *str)
223{ 237{
238#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
239 dbg(0,"+#+:enter\n");
240#endif
224 g_free(str); 241 g_free(str);
225} 242}
226 243
227/** 244/**
228 * @brief Returns the projection of a map 245 * @brief Returns the projection of a map
229 * 246 *
230 * @param this_ The map to return the projection of 247 * @param this_ The map to return the projection of
231 * @return The projection of the map 248 * @return The projection of the map
232 */ 249 */
233enum projection
234map_projection(struct map *this_) 250enum projection map_projection(struct map *this_)
235{ 251{
252#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
253 dbg(0,"+#+:enter\n");
254#endif
236 return this_->meth.pro; 255 return this_->meth.pro;
237} 256}
238 257
239/** 258/**
240 * @brief Sets the projection of a map 259 * @brief Sets the projection of a map
241 * 260 *
242 * @param this_ The map to set the projection of 261 * @param this_ The map to set the projection of
243 * @param pro The projection to be set 262 * @param pro The projection to be set
244 */ 263 */
245void
246map_set_projection(struct map *this_, enum projection pro) 264void map_set_projection(struct map *this_, enum projection pro)
247{ 265{
266#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
267 dbg(0,"+#+:enter\n");
268#endif
248 this_->meth.pro=pro; 269 this_->meth.pro = pro;
249} 270}
250 271
251void
252map_destroy_do(struct map *m) 272void map_destroy_do(struct map *m)
253{ 273{
274#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
275 dbg(0,"+#+:enter\n");
276#endif
254 if (m->priv) 277 if (m->priv)
255 m->meth.map_destroy(m->priv); 278 m->meth.map_destroy(m->priv);
256 attr_list_free(m->attrs); 279 attr_list_free(m->attrs);
257 callback_list_destroy(m->attr_cbl); 280 callback_list_destroy(m->attr_cbl);
258 g_free(m); 281 g_free(m);
261/** 284/**
262 * @brief Destroys an opened map 285 * @brief Destroys an opened map
263 * 286 *
264 * @param m The map to be destroyed 287 * @param m The map to be destroyed
265 */ 288 */
266void
267map_destroy(struct map *m) 289void map_destroy(struct map *m)
268{ 290{
291#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
292 dbg(0,"+#+:enter\n");
293#endif
269 if (!m) 294 if (!m)
270 return; 295 return;
271 296
272 if(0<m->refcount) { 297 if (0 < m->refcount)
298 {
273 m->refcount--; 299 m->refcount--;
274 } 300 }
275 if(0 == m->refcount) { 301 if (0 == m->refcount)
302 {
276 map_destroy_do(m); 303 map_destroy_do(m);
277 } 304 }
278} 305}
279 306
280/** 307/**
289 * @return A new map rect 316 * @return A new map rect
290 */ 317 */
291struct map_rect * 318struct map_rect *
292map_rect_new(struct map *m, struct map_selection *sel) 319map_rect_new(struct map *m, struct map_selection *sel)
293{ 320{
321#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
322 dbg(0,"+#+:enter\n");
323#endif
294 struct map_rect *mr; 324 struct map_rect *mr;
295 325
296#if 0 326#if 0
297 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); 327 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);
298#endif 328#endif
299 //if (sel!=NULL) 329 //if (sel!=NULL)
300 //{ 330 //{
301 // 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); 331 // 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);
302 //} 332 //}
303 mr=g_new0(struct map_rect, 1); 333 mr=g_new0(struct map_rect, 1);
304 mr->m=m; 334 mr->m = m;
305 mr->priv=m->meth.map_rect_new(m->priv, sel); 335 mr->priv = m->meth.map_rect_new(m->priv, sel);
306 if (! mr->priv) { 336 if (!mr->priv)
337 {
307 g_free(mr); 338 g_free(mr);
308 mr=NULL; 339 mr = NULL;
309 } 340 }
310 341
311 return mr; 342 return mr;
312} 343}
313 344
321 * @return An item from the map rect 352 * @return An item from the map rect
322 */ 353 */
323struct item * 354struct item *
324map_rect_get_item(struct map_rect *mr) 355map_rect_get_item(struct map_rect *mr)
325{ 356{
357#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
358 dbg(0,"+#+:enter\n");
359#endif
326 struct item *ret; 360 struct item *ret;
327 dbg_assert(mr != NULL); 361 dbg_assert(mr != NULL);
328 dbg_assert(mr->m != NULL); 362 dbg_assert(mr->m != NULL);
329 dbg_assert(mr->m->meth.map_rect_get_item != NULL); 363 dbg_assert(mr->m->meth.map_rect_get_item != NULL);
330 ret=mr->m->meth.map_rect_get_item(mr->priv); 364 ret = mr->m->meth.map_rect_get_item(mr->priv);
331 if (ret) 365 if (ret)
332 ret->map=mr->m; 366 ret->map = mr->m;
333 return ret; 367 return ret;
334} 368}
335 369
336/** 370/**
337 * @brief Returns the item specified by the ID 371 * @brief Returns the item specified by the ID
342 * @return The item with the specified ID or NULL if not found 376 * @return The item with the specified ID or NULL if not found
343 */ 377 */
344struct item * 378struct item *
345map_rect_get_item_byid(struct map_rect *mr, int id_hi, int id_lo) 379map_rect_get_item_byid(struct map_rect *mr, int id_hi, int id_lo)
346{ 380{
381#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
382 dbg(0,"+#+:enter\n");
383#endif
347 struct item *ret=NULL; 384 struct item *ret = NULL;
348 dbg_assert(mr != NULL); 385 dbg_assert(mr != NULL);
349 dbg_assert(mr->m != NULL); 386 dbg_assert(mr->m != NULL);
350 if (mr->m->meth.map_rect_get_item_byid) 387 if (mr->m->meth.map_rect_get_item_byid)
351 ret=mr->m->meth.map_rect_get_item_byid(mr->priv, id_hi, id_lo); 388 ret = mr->m->meth.map_rect_get_item_byid(mr->priv, id_hi, id_lo);
352 if (ret) 389 if (ret)
353 ret->map=mr->m; 390 ret->map = mr->m;
354 return ret; 391 return ret;
355} 392}
356 393
357/** 394/**
358 * @brief Destroys a map rect 395 * @brief Destroys a map rect
359 * 396 *
360 * @param mr The map rect to be destroyed 397 * @param mr The map rect to be destroyed
361 */ 398 */
362void
363map_rect_destroy(struct map_rect *mr) 399void map_rect_destroy(struct map_rect *mr)
364{ 400{
401#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
402 dbg(0,"+#+:enter\n");
403#endif
365 if (mr) { 404 if (mr)
405 {
366 mr->m->meth.map_rect_destroy(mr->priv); 406 mr->m->meth.map_rect_destroy(mr->priv);
367 g_free(mr); 407 g_free(mr);
368 } 408 }
369} 409}
370 410
372 * @brief Holds information about a search on a map 412 * @brief Holds information about a search on a map
373 * 413 *
374 * This structure holds information about a search performed on a map. This can be 414 * This structure holds information about a search performed on a map. This can be
375 * used as "handle" to retrieve items from a search. 415 * used as "handle" to retrieve items from a search.
376 */ 416 */
377struct map_search { 417struct map_search
418{
378 struct map *m; 419 struct map *m;
379 struct attr search_attr; 420 struct attr search_attr;
380 void *priv; 421 void *priv;
381}; 422};
382 423
383/** 424/**
384 * @brief Starts a search on a map 425 * @brief Starts a search on a map
385 * 426 *
386 * This function starts a search on a map. What attributes one can search for depends on the 427 * This function starts a search on a map. What attributes one can search for depends on the
387 * map plugin. 428 * map plugin.
388 * 429 *
389 * The OSM/binfile plugin currently supports: attr_town_name, attr_street_name 430 * The OSM/binfile plugin currently supports: attr_town_name, attr_street_name
390 * The MG plugin currently supports: ttr_town_postal, attr_town_name, attr_street_name 431 * The MG plugin currently supports: attr_town_postal, attr_town_name, attr_street_name
391 * 432 *
392 * If you enable partial matches bear in mind that the search matches only the begin of the 433 * If you enable partial matches bear in mind that the search matches only the begin of the
393 * strings - a search for a street named "street" would match to "streetfoo", but not to 434 * strings - a search for a street named "street" would match to "streetfoo", but not to
394 * "somestreet". Search is case insensitive. 435 * "somestreet". Search is case insensitive.
395 * 436 *
410 * @return A new map search struct for this search 451 * @return A new map search struct for this search
411 */ 452 */
412struct map_search * 453struct map_search *
413map_search_new(struct map *m, struct item *item, struct attr *search_attr, int partial) 454map_search_new(struct map *m, struct item *item, struct attr *search_attr, int partial)
414{ 455{
456#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
457 dbg(0,"+#+:enter\n");
458#endif
415 struct map_search *this_; 459 struct map_search *this_;
416 dbg(1,"enter(%p,%p,%p,%d)\n", m, item, search_attr, partial); 460 dbg(1, "enter(%p,%p,%p,%d)\n", m, item, search_attr, partial);
417 dbg(1,"0x%x 0x%x 0x%x\n", attr_country_all, search_attr->type, attr_country_name); 461 dbg(1, "0x%x 0x%x 0x%x\n", attr_country_all, search_attr->type, attr_country_name);
418 this_=g_new0(struct map_search,1); 462 this_=g_new0(struct map_search,1);
419 this_->m=m; 463 this_->m = m;
420 this_->search_attr=*search_attr; 464 this_->search_attr = *search_attr;
421 if ((search_attr->type >= attr_country_all && search_attr->type <= attr_country_name) || search_attr->type == attr_country_id) 465 if ((search_attr->type >= attr_country_all && search_attr->type <= attr_country_name) || search_attr->type == attr_country_id)
466 {
422 this_->priv=country_search_new(&this_->search_attr, partial); 467 this_->priv = country_search_new(&this_->search_attr, partial);
468 }
423 else { 469 else
470 {
424 if (m->meth.map_search_new) { 471 if (m->meth.map_search_new)
472 {
425 if (m->meth.charset) 473 if (m->meth.charset)
474 {
426 this_->search_attr.u.str=g_convert(this_->search_attr.u.str, -1,m->meth.charset,"utf-8",NULL,NULL,NULL); 475 this_->search_attr.u.str = g_convert(this_->search_attr.u.str, -1, m->meth.charset, "utf-8", NULL, NULL, NULL);
476 }
427 this_->priv=m->meth.map_search_new(m->priv, item, &this_->search_attr, partial); 477 this_->priv = m->meth.map_search_new(m->priv, item, &this_->search_attr, partial);
428 if (! this_->priv) { 478 if (!this_->priv)
479 {
429 g_free(this_); 480 g_free(this_);
430 this_=NULL; 481 this_ = NULL;
431 } 482 }
483 }
432 } else { 484 else
485 {
433 g_free(this_); 486 g_free(this_);
434 this_=NULL; 487 this_ = NULL;
435 } 488 }
436 } 489 }
437 return this_; 490 return this_;
438} 491}
439 492
448 * @return One item of the result 501 * @return One item of the result
449 */ 502 */
450struct item * 503struct item *
451map_search_get_item(struct map_search *this_) 504map_search_get_item(struct map_search *this_)
452{ 505{
506#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
507 dbg(0,"+#+:enter\n");
508#endif
453 struct item *ret; 509 struct item *ret;
454 510
455 if (! this_) 511 if (!this_)
456 return NULL; 512 return NULL;
457 if ((this_->search_attr.type >= attr_country_all && this_->search_attr.type <= attr_country_name) || this_->search_attr.type == attr_country_id) 513 if ((this_->search_attr.type >= attr_country_all && this_->search_attr.type <= attr_country_name) || this_->search_attr.type == attr_country_id)
458 return country_search_get_item(this_->priv); 514 return country_search_get_item(this_->priv);
459 ret=this_->m->meth.map_search_get_item(this_->priv); 515 ret = this_->m->meth.map_search_get_item(this_->priv);
460 if (ret) 516 if (ret)
461 ret->map=this_->m; 517 ret->map = this_->m;
462 return ret; 518 return ret;
463} 519}
464 520
465/** 521/**
466 * @brief Destroys a map search struct 522 * @brief Destroys a map search struct
467 * 523 *
468 * @param this_ The map search struct to be destroyed 524 * @param this_ The map search struct to be destroyed
469 */ 525 */
470void
471map_search_destroy(struct map_search *this_) 526void map_search_destroy(struct map_search *this_)
472{ 527{
528#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
529 dbg(0,"+#+:enter\n");
530#endif
473 if (! this_) 531 if (!this_)
474 return; 532 return;
475 if (this_->search_attr.type >= attr_country_all && this_->search_attr.type <= attr_country_name) 533 if (this_->search_attr.type >= attr_country_all && this_->search_attr.type <= attr_country_name)
476 country_search_destroy(this_->priv); 534 country_search_destroy(this_->priv);
477 else { 535 else
536 {
478 if (this_->m->meth.charset) 537 if (this_->m->meth.charset)
479 g_free(this_->search_attr.u.str); 538 g_free(this_->search_attr.u.str);
480 this_->m->meth.map_search_destroy(this_->priv); 539 this_->m->meth.map_search_destroy(this_->priv);
481 } 540 }
482 g_free(this_); 541 g_free(this_);
483} 542}
484 543
491 * @return The new map selection 550 * @return The new map selection
492 */ 551 */
493struct map_selection * 552struct map_selection *
494map_selection_rect_new(struct pcoord *center, int distance, int order) 553map_selection_rect_new(struct pcoord *center, int distance, int order)
495{ 554{
555#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
556 dbg(0,"+#+:enter\n");
557#endif
496 struct map_selection *ret=g_new0(struct map_selection, 1); 558 struct map_selection *ret=g_new0(struct map_selection, 1);
497 ret->order=order; 559 ret->order = order;
498 ret->range=item_range_all; 560 ret->range = item_range_all;
499 ret->u.c_rect.lu.x=center->x-distance; 561 ret->u.c_rect.lu.x = center->x - distance;
500 ret->u.c_rect.lu.y=center->y+distance; 562 ret->u.c_rect.lu.y = center->y + distance;
501 ret->u.c_rect.rl.x=center->x+distance; 563 ret->u.c_rect.rl.x = center->x + distance;
502 ret->u.c_rect.rl.y=center->y-distance; 564 ret->u.c_rect.rl.y = center->y - distance;
503 return ret; 565 return ret;
504} 566}
505 567
506/** 568/**
507 * @brief Duplicates a map selection, transforming coordinates 569 * @brief Duplicates a map selection, transforming coordinates
515 * @return A duplicated, transformed map selection 577 * @return A duplicated, transformed map selection
516 */ 578 */
517struct map_selection * 579struct map_selection *
518map_selection_dup_pro(struct map_selection *sel, enum projection from, enum projection to) 580map_selection_dup_pro(struct map_selection *sel, enum projection from, enum projection to)
519{ 581{
582#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
583 dbg(0,"+#+:enter\n");
584#endif
520 struct map_selection *next,**last; 585 struct map_selection *next, **last;
521 struct map_selection *ret=NULL; 586 struct map_selection *ret = NULL;
522 last=&ret; 587 last = &ret;
523 while (sel) { 588 while (sel)
589 {
524 next = g_new(struct map_selection, 1); 590 next = g_new(struct map_selection, 1);
525 *next=*sel; 591 *next = *sel;
526 if (from != projection_none || to != projection_none) { 592 if (from != projection_none || to != projection_none)
593 {
527 transform_from_to(&sel->u.c_rect.lu, from, &next->u.c_rect.lu, to); 594 transform_from_to(&sel->u.c_rect.lu, from, &next->u.c_rect.lu, to);
528 transform_from_to(&sel->u.c_rect.rl, from, &next->u.c_rect.rl, to); 595 transform_from_to(&sel->u.c_rect.rl, from, &next->u.c_rect.rl, to);
529 } 596 }
530 *last=next; 597 *last = next;
531 last=&next->next; 598 last = &next->next;
532 sel = sel->next; 599 sel = sel->next;
533 } 600 }
534 return ret; 601 return ret;
535} 602}
536 603
541 * @return The duplicated map selection 608 * @return The duplicated map selection
542 */ 609 */
543struct map_selection * 610struct map_selection *
544map_selection_dup(struct map_selection *sel) 611map_selection_dup(struct map_selection *sel)
545{ 612{
613#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
614 dbg(0,"+#+:enter\n");
615#endif
546 return map_selection_dup_pro(sel, projection_none, projection_none); 616 return map_selection_dup_pro(sel, projection_none, projection_none);
547} 617}
548 618
549/** 619/**
550 * @brief Destroys a map selection 620 * @brief Destroys a map selection
551 * 621 *
552 * @param sel The map selection to be destroyed 622 * @param sel The map selection to be destroyed
553 */ 623 */
554void
555map_selection_destroy(struct map_selection *sel) 624void map_selection_destroy(struct map_selection *sel)
556{ 625{
626#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
627 dbg(0,"+#+:enter\n");
628#endif
557 struct map_selection *next; 629 struct map_selection *next;
558 while (sel) { 630 while (sel)
631 {
559 next = sel->next; 632 next = sel->next;
560 g_free(sel); 633 g_free(sel);
561 sel = next; 634 sel = next;
562 } 635 }
563} 636}
570 * 643 *
571 * @param sel The selection to be checked 644 * @param sel The selection to be checked
572 * @param item The item that the rectangle should be built around 645 * @param item The item that the rectangle should be built around
573 * @return True if the rectangle is within the selection, false otherwise 646 * @return True if the rectangle is within the selection, false otherwise
574 */ 647 */
575int
576map_selection_contains_item_rect(struct map_selection *sel, struct item *item) 648int map_selection_contains_item_rect(struct map_selection *sel, struct item *item)
577{ 649{
650#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
651 dbg(0,"+#+:enter\n");
652#endif
578 struct coord c; 653 struct coord c;
579 struct coord_rect r; 654 struct coord_rect r;
580 int count=0; 655 int count = 0;
581 while (item_coord_get(item, &c, 1)) { 656 while (item_coord_get(item, &c, 1))
657 {
582 if (! count) { 658 if (!count)
659 {
583 r.lu=c; 660 r.lu = c;
584 r.rl=c; 661 r.rl = c;
662 }
585 } else 663 else
586 coord_rect_extend(&r, &c); 664 coord_rect_extend(&r, &c);
587 count++; 665 count++;
588 } 666 }
589 if (! count) 667 if (!count)
590 return 0; 668 return 0;
591 return map_selection_contains_rect(sel, &r); 669 return map_selection_contains_rect(sel, &r);
592 670
593} 671}
594
595 672
596/** 673/**
597 * @brief Checks if a selection contains a item range 674 * @brief Checks if a selection contains a item range
598 * 675 *
599 * This function checks if a selection contains at least one of the items in range 676 * This function checks if a selection contains at least one of the items in range
603 * @param ranges The item ranges to be checked 680 * @param ranges The item ranges to be checked
604 * @count the number of elements in ranges 681 * @count the number of elements in ranges
605 * @return True if there is a match, false otherwise 682 * @return True if there is a match, false otherwise
606 */ 683 */
607 684
608int
609map_selection_contains_item_range(struct map_selection *sel, int follow, struct item_range *range, int count) 685int map_selection_contains_item_range(struct map_selection *sel, int follow, struct item_range *range, int count)
610{ 686{
687#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
688 dbg(0,"+#+:enter\n");
689#endif
611 int i; 690 int i;
612 if (! sel) 691 if (!sel)
613 return 1; 692 return 1;
614 while (sel) { 693 while (sel)
694 {
615 for (i = 0 ; i < count ; i++) { 695 for (i = 0; i < count; i++)
696 {
616 if (item_range_intersects_range(&sel->range, &range[i])) 697 if (item_range_intersects_range(&sel->range, &range[i]))
617 return 1; 698 return 1;
618 } 699 }
619 if (! follow) 700 if (!follow)
620 break; 701 break;
621 sel=sel->next; 702 sel = sel->next;
622 } 703 }
623 return 0; 704 return 0;
624} 705}
625/** 706/**
626 * @brief Checks if a selection contains a item 707 * @brief Checks if a selection contains a item
631 * @param follow Whether the next pointer of the selection should be followed 712 * @param follow Whether the next pointer of the selection should be followed
632 * @param item The item type to be checked 713 * @param item The item type to be checked
633 * @return True if there is a match, false otherwise 714 * @return True if there is a match, false otherwise
634 */ 715 */
635 716
636int
637map_selection_contains_item(struct map_selection *sel, int follow, enum item_type type) 717int map_selection_contains_item(struct map_selection *sel, int follow, enum item_type type)
638{ 718{
719#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
720 dbg(0,"+#+:enter\n");
721#endif
639 if (! sel) 722 if (!sel)
640 return 1; 723 return 1;
641 while (sel) { 724 while (sel)
725 {
642 if (item_range_contains_item(&sel->range, type)) 726 if (item_range_contains_item(&sel->range, type))
643 return 1; 727 return 1;
644 if (! follow) 728 if (!follow)
645 break; 729 break;
646 sel=sel->next; 730 sel = sel->next;
647 } 731 }
648 return 0; 732 return 0;
649} 733}
650
651
652 734
653/** 735/**
654 * @brief Checks if a pointer points to the private data of a map 736 * @brief Checks if a pointer points to the private data of a map
655 * 737 *
656 * @param map The map whose private data should be checked. 738 * @param map The map whose private data should be checked.
657 * @param priv The private data that should be checked. 739 * @param priv The private data that should be checked.
658 * @return True if priv is the private data of map 740 * @return True if priv is the private data of map
659 */ 741 */
660int
661map_priv_is(struct map *map, struct map_priv *priv) 742int map_priv_is(struct map *map, struct map_priv *priv)
662{ 743{
744#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
745 dbg(0,"+#+:enter\n");
746#endif
663 return (map->priv == priv); 747 return (map->priv == priv);
664} 748}
665 749
666void
667map_dump_filedesc(struct map *map, FILE *out) 750void map_dump_filedesc(struct map *map, FILE *out)
668{ 751{
752#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
753 dbg(0,"+#+:enter\n");
754#endif
669 struct map_rect *mr=map_rect_new(map, NULL); 755 struct map_rect *mr = map_rect_new(map, NULL);
670 struct item *item; 756 struct item *item;
671 757
672 while ((item = map_rect_get_item(mr))) 758 while ((item = map_rect_get_item(mr)))
673 item_dump_filedesc(item, map, out); 759 item_dump_filedesc(item, map, out);
674 map_rect_destroy(mr); 760 map_rect_destroy(mr);
675} 761}
676 762
677void
678map_dump_file(struct map *map, const char *file) 763void map_dump_file(struct map *map, const char *file)
679{ 764{
765#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
766 dbg(0,"+#+:enter\n");
767#endif
680 FILE *f; 768 FILE *f;
681 f=fopen(file,"w"); 769 f = fopen(file, "w");
682 if (f) { 770 if (f)
771 {
683 map_dump_filedesc(map, f); 772 map_dump_filedesc(map, f);
684 fclose(f); 773 fclose(f);
774 }
685 } else 775 else
686 dbg(0,"failed to open file '%s'\n",file); 776 dbg(0, "failed to open file '%s'\n", file);
687} 777}
688 778
689void
690map_dump(struct map *map) 779void map_dump(struct map *map)
691{ 780{
781#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
782 dbg(0,"+#+:enter\n");
783#endif
692 map_dump_filedesc(map, stdout); 784 map_dump_filedesc(map, stdout);
693} 785}
694 786
695struct item * 787struct item *
696map_rect_create_item(struct map_rect *mr, enum item_type type_) 788map_rect_create_item(struct map_rect *mr, enum item_type type_)
697{ 789{
790#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
791 dbg(0,"+#+:enter\n");
792#endif
698 if(mr && mr->priv && mr->m) { 793 if (mr && mr->priv && mr->m)
794 {
699 return mr->m->meth.map_rect_create_item(mr->priv, type_) ; 795 return mr->m->meth.map_rect_create_item(mr->priv, type_);
700 } 796 }
701 else { 797 else
798 {
702 return NULL; 799 return NULL;
703 } 800 }
704} 801}
705 802
706
707

Legend:
Removed from v.27  
changed lines
  Added in v.28

   
Visit the ZANavi Wiki