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

Diff of /navit/navit/mapset.c

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

Revision 27 Revision 28
38/** 38/**
39 * @brief A mapset 39 * @brief A mapset
40 * 40 *
41 * This structure holds a complete mapset 41 * This structure holds a complete mapset
42 */ 42 */
43struct mapset { 43struct mapset
44{
44 GList *maps; /**< Linked list of all the maps in the mapset */ 45 GList *maps; /**< Linked list of all the maps in the mapset */
45}; 46};
46 47
47struct attr_iter { 48struct attr_iter
49{
48 GList *last; 50 GList *last;
49}; 51};
50 52
51/** 53/**
52 * @brief Creates a new, empty mapset 54 * @brief Creates a new, empty mapset
53 * 55 *
54 * @return The new mapset 56 * @return The new mapset
55 */ 57 */
56struct mapset *mapset_new(struct attr *parent, struct attr **attrs) 58struct mapset *mapset_new(struct attr *parent, struct attr **attrs)
57{ 59{
60#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
61 dbg(0,"+#+:enter\n");
62#endif
58 struct mapset *ms; 63 struct mapset *ms;
59 64
60 ms=g_new0(struct mapset, 1); 65 ms=g_new0(struct mapset, 1);
61 66
62 return ms; 67 return ms;
63} 68}
64
65 69
66struct attr_iter * 70struct attr_iter *
67mapset_attr_iter_new(void) 71mapset_attr_iter_new(void)
68{ 72{
73#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
74 dbg(0,"+#+:enter\n");
75#endif
69 return g_new0(struct attr_iter, 1); 76return g_new0(struct attr_iter, 1);
70} 77}
71 78
72void
73mapset_attr_iter_destroy(struct attr_iter *iter) 79void mapset_attr_iter_destroy(struct attr_iter *iter)
74{ 80{
81#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
82 dbg(0,"+#+:enter\n");
83#endif
75 g_free(iter); 84 g_free(iter);
76} 85}
77 86
78/** 87/**
79 * @brief Adds a map to a mapset 88 * @brief Adds a map to a mapset
80 * 89 *
81 * @param ms The mapset to add the map to 90 * @param ms The mapset to add the map to
82 * @param m The map to be added 91 * @param m The map to be added
83 */ 92 */
84int
85mapset_add_attr(struct mapset *ms, struct attr *attr) 93int mapset_add_attr(struct mapset *ms, struct attr *attr)
86{ 94{
95#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
96 dbg(0,"+#+:enter\n");
97#endif
87 switch (attr->type) { 98 switch (attr->type)
99 {
88 case attr_map: 100 case attr_map:
89 ms->maps=g_list_append(ms->maps, attr->u.map); 101 ms->maps = g_list_append(ms->maps, attr->u.map);
90 map_ref(attr->u.map); 102 map_ref(attr->u.map);
91 return 1; 103 return 1;
92 default: 104 default:
93 return 0; 105 return 0;
94 } 106 }
95} 107}
96 108
97int
98mapset_add_attr_name(struct mapset *ms, struct attr *attr) 109int mapset_add_attr_name(struct mapset *ms, struct attr *attr)
99{ 110{
111#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
112 dbg(0,"+#+:enter\n");
113#endif
100 struct attr map_name; 114 struct attr map_name;
101 115
102 dbg(0,"****** ADD MAP from sdcard ******"); 116 dbg(0, "****** ADD MAP from sdcard ******");
103 switch (attr->type) { 117 switch (attr->type)
118 {
104 case attr_map: 119 case attr_map:
105 ms->maps=g_list_append(ms->maps, attr->u.map); 120 ms->maps = g_list_append(ms->maps, attr->u.map);
106 map_ref(attr->u.map); 121 map_ref(attr->u.map);
107 122
108 struct map *m; 123 struct map *m;
109 m=g_new0(struct map, 1); 124 m=g_new0(struct map, 1);
110 m=attr->u.map; 125 m = attr->u.map;
111 struct attr *map_file_name=attr_search(m->attrs, NULL, attr_data); 126 struct attr *map_file_name = attr_search(m->attrs, NULL, attr_data);
112 map_name.type=attr_name; 127 map_name.type = attr_name;
113 map_name.u.str=g_strconcat("_ms_sdcard_map:",map_file_name->u.str,NULL); 128 map_name.u.str = g_strconcat("_ms_sdcard_map:", map_file_name->u.str, NULL);
114 129
115 dbg(0,"====== map name1=%s",map_name.u.str); 130 dbg(0, "====== map name1=%s", map_name.u.str);
116 map_set_attr(attr->u.map, &map_name); 131 map_set_attr(attr->u.map, &map_name);
117 132
118 return 1; 133 return 1;
119 default: 134 default:
120 return 0; 135 return 0;
121 } 136 }
122} 137}
123 138
124int
125mapset_add_attr_name_str(struct mapset *ms, struct attr *attr,char *map_name_str) 139int mapset_add_attr_name_str(struct mapset *ms, struct attr *attr, char *map_name_str)
126{ 140{
141#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
142 dbg(0,"+#+:enter\n");
143#endif
127 struct attr map_name; 144 struct attr map_name;
128 145
129 dbg(0,"****** ADD MAP from sdcard - with name str ******"); 146 dbg(0, "****** ADD MAP from sdcard - with name str ******");
130 switch (attr->type) { 147 switch (attr->type)
148 {
131 case attr_map: 149 case attr_map:
132 ms->maps=g_list_append(ms->maps, attr->u.map); 150 ms->maps = g_list_append(ms->maps, attr->u.map);
133 map_ref(attr->u.map); 151 map_ref(attr->u.map);
134 152
135 struct map *m; 153 struct map *m;
136 m=g_new0(struct map, 1); 154 m=g_new0(struct map, 1);
137 m=attr->u.map; 155 m = attr->u.map;
138 struct attr *map_file_name=attr_search(m->attrs, NULL, attr_data); 156 struct attr *map_file_name = attr_search(m->attrs, NULL, attr_data);
139 map_name.type=attr_name; 157 map_name.type = attr_name;
140 map_name.u.str=g_strconcat("_ms_sdcard_map:",map_name_str,NULL); 158 map_name.u.str = g_strconcat("_ms_sdcard_map:", map_name_str, NULL);
141 159
142 dbg(0,"====== map name2=%s",map_name.u.str); 160 dbg(0, "====== map name2=%s", map_name.u.str);
143 map_set_attr(attr->u.map, &map_name); 161 map_set_attr(attr->u.map, &map_name);
144 162
145 return 1; 163 return 1;
146 default: 164 default:
147 return 0; 165 return 0;
148 } 166 }
149} 167}
150 168
151int
152mapset_remove_attr(struct mapset *ms, struct attr *attr) 169int mapset_remove_attr(struct mapset *ms, struct attr *attr)
153{ 170{
171#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
172 dbg(0,"+#+:enter\n");
173#endif
154 switch (attr->type) { 174 switch (attr->type)
175 {
155 case attr_map: 176 case attr_map:
156 ms->maps=g_list_remove(ms->maps, attr->u.map); 177 ms->maps = g_list_remove(ms->maps, attr->u.map);
157 return 1; 178 return 1;
158 default: 179 default:
159 return 0; 180 return 0;
160 } 181 }
161} 182}
162 183
163int
164mapset_get_attr(struct mapset *ms, enum attr_type type, struct attr *attr, struct attr_iter *iter) 184int mapset_get_attr(struct mapset *ms, enum attr_type type, struct attr *attr, struct attr_iter *iter)
165{ 185{
186#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
187 dbg(0,"+#+:enter\n");
188#endif
166 GList *map; 189 GList *map;
167 map=ms->maps; 190 map = ms->maps;
168 attr->type=type; 191 attr->type = type;
169 switch (type) { 192 switch (type)
193 {
170 case attr_map: 194 case attr_map:
171 while (map) { 195 while (map)
196 {
172 if (!iter || iter->last == g_list_previous(map)) { 197 if (!iter || iter->last == g_list_previous(map))
198 {
173 attr->u.map=map->data; 199 attr->u.map = map->data;
174 if (iter) 200 if (iter)
175 iter->last=map; 201 iter->last = map;
176 return 1; 202 return 1;
203 }
204 map = g_list_next(map);
177 } 205 }
178 map=g_list_next(map);
179 }
180 break; 206 break;
181 default: 207 default:
182 break; 208 break;
183 } 209 }
184 return 0; 210 return 0;
185} 211}
186
187 212
188#if 0 213#if 0
189static void mapset_maps_free(struct mapset *ms) 214static void mapset_maps_free(struct mapset *ms)
190{ 215{
191 /* todo */ 216 /* todo */
200 * 225 *
201 * @param ms The mapset to be destroyed 226 * @param ms The mapset to be destroyed
202 */ 227 */
203void mapset_destroy(struct mapset *ms) 228void mapset_destroy(struct mapset *ms)
204{ 229{
230#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
231 dbg(0,"+#+:enter\n");
232#endif
205 GList *map; 233 GList *map;
206 map=ms->maps; 234 map = ms->maps;
207 while (map) { 235 while (map)
236 {
208 map_destroy(map->data); 237 map_destroy(map->data);
209 map=g_list_next(map); 238 map = g_list_next(map);
210 } 239 }
211 g_free(ms); 240 g_free(ms);
212} 241}
213 242
214/** 243/**
215 * @brief Handle for a mapset in use 244 * @brief Handle for a mapset in use
216 * 245 *
217 * This struct is used for a mapset that is in use. With this it is possible to iterate 246 * This struct is used for a mapset that is in use. With this it is possible to iterate
218 * all maps in a mapset. 247 * all maps in a mapset.
219 */ 248 */
220struct mapset_handle { 249struct mapset_handle
250{
221 GList *l; /**< Pointer to the current (next) map */ 251 GList *l; /**< Pointer to the current (next) map */
222}; 252};
223 253
224/** 254/**
225 * @brief Returns a new handle for a mapset 255 * @brief Returns a new handle for a mapset
226 * 256 *
231 * @return The new mapset handle 261 * @return The new mapset handle
232 */ 262 */
233struct mapset_handle * 263struct mapset_handle *
234mapset_open(struct mapset *ms) 264mapset_open(struct mapset *ms)
235{ 265{
266#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
267 dbg(0,"+#+:enter\n");
268#endif
236 struct mapset_handle *ret=NULL; 269 struct mapset_handle *ret = NULL;
237 if(ms) 270 if (ms)
238 { 271 {
239 ret=g_new(struct mapset_handle, 1); 272 ret=g_new(struct mapset_handle, 1);
240 ret->l=ms->maps; 273 ret->l = ms->maps;
241 } 274 }
242 275
243 return ret; 276 return ret;
244} 277}
245 278
253 * @param active Set to true to only get active maps (See description) 286 * @param active Set to true to only get active maps (See description)
254 * @return The next map 287 * @return The next map
255 */ 288 */
256struct map * mapset_next(struct mapset_handle *msh, int active) 289struct map * mapset_next(struct mapset_handle *msh, int active)
257{ 290{
291#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
292 dbg(0,"+#+:enter\n");
293#endif
258 struct map *ret; 294 struct map *ret;
259 struct attr active_attr; 295 struct attr active_attr;
260 296
261 for (;;) { 297 for (;;)
298 {
262 if (!msh || !msh->l) 299 if (!msh || !msh->l)
263 return NULL; 300 return NULL;
264 ret=msh->l->data; 301 ret = msh->l->data;
265 msh->l=g_list_next(msh->l); 302 msh->l = g_list_next(msh->l);
266 if (!active) 303 if (!active)
267 return ret; 304 return ret;
268 if (active == 2 && map_get_attr(ret, attr_route_active, &active_attr, NULL)) { 305 if (active == 2 && map_get_attr(ret, attr_route_active, &active_attr, NULL))
306 {
269 if (active_attr.u.num) 307 if (active_attr.u.num)
270 return ret; 308 return ret;
271 else 309 else
272 continue; 310 continue;
273 } 311 }
274 if (active == 3 && map_get_attr(ret, attr_search_active, &active_attr, NULL)) { 312 if (active == 3 && map_get_attr(ret, attr_search_active, &active_attr, NULL))
313 {
275 if (active_attr.u.num) 314 if (active_attr.u.num)
276 return ret; 315 return ret;
277 else 316 else
278 continue; 317 continue;
279 } 318 }
289 * 328 *
290 * @param ms The map 329 * @param ms The map
291 * @param map_name the map name used by the search 330 * @param map_name the map name used by the search
292 * @return The next map 331 * @return The next map
293 */ 332 */
294struct map * 333struct map *
295mapset_get_map_by_name(struct mapset *ms, char *map_name) 334mapset_get_map_by_name(struct mapset *ms, char *map_name)
296{ 335{
336#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
337 dbg(0,"+#+:enter\n");
338#endif
297 struct mapset_handle*msh; 339 struct mapset_handle*msh;
298 struct map*curr_map; 340 struct map*curr_map;
299 struct attr map_attr; 341 struct attr map_attr;
300 if( !ms || !map_name ) { 342 if (!ms || !map_name)
343 {
301 return NULL; 344 return NULL;
302 } 345 }
303 msh=mapset_open(ms); 346 msh = mapset_open(ms);
304 while ((curr_map=mapset_next(msh, 1))) { 347 while ((curr_map = mapset_next(msh, 1)))
348 {
305 //get map name 349 //get map name
306 if(map_get_attr(curr_map,attr_name, &map_attr,NULL)) { 350 if (map_get_attr(curr_map, attr_name, &map_attr, NULL))
351 {
307 if( ! strcmp(map_attr.u.str, map_name)) { 352 if (!strcmp(map_attr.u.str, map_name))
353 {
308 break; 354 break;
309 } 355 }
310 } 356 }
311 } 357 }
312 return curr_map; 358 return curr_map;
315/** 361/**
316 * @brief Closes a mapset handle after it is no longer used 362 * @brief Closes a mapset handle after it is no longer used
317 * 363 *
318 * @param msh Mapset handle to be closed 364 * @param msh Mapset handle to be closed
319 */ 365 */
320void
321mapset_close(struct mapset_handle *msh) 366void mapset_close(struct mapset_handle *msh)
322{ 367{
368#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
369 dbg(0,"+#+:enter\n");
370#endif
323 g_free(msh); 371 g_free(msh);
324} 372}
325 373
326/** 374/**
327 * @brief Holds information about a search in a mapset 375 * @brief Holds information about a search in a mapset
328 * 376 *
329 * This struct holds information about a search (e.g. for a street) in a mapset. 377 * This struct holds information about a search (e.g. for a street) in a mapset.
330 * 378 *
331 * @sa For a more detailed description see the documentation of mapset_search_new(). 379 * @sa For a more detailed description see the documentation of mapset_search_new().
332 */ 380 */
333struct mapset_search { 381struct mapset_search
382{
334 GList *map; /**< The list of maps to be searched within */ 383 GList *map; /**< The list of maps to be searched within */
335 struct map_search *ms; /**< A map search struct for the map currently active */ 384 struct map_search *ms; /**< A map search struct for the map currently active */
336 struct item *item; /**< "Superior" item. */ 385 struct item *item; /**< "Superior" item. */
337 struct attr *search_attr; /**< Attribute to be searched for. */ 386 struct attr *search_attr; /**< Attribute to be searched for. */
338 int partial; /**< Indicates if one would like to have partial matches */ 387 int partial; /**< Indicates if one would like to have partial matches */
339}; 388};
340 389
341/** 390/**
342 * @brief Starts a search on a mapset 391 * @brief Starts a search on a mapset
343 * 392 *
358 * @return A new mapset search struct for this search 407 * @return A new mapset search struct for this search
359 */ 408 */
360struct mapset_search * 409struct mapset_search *
361mapset_search_new(struct mapset *ms, struct item *item, struct attr *search_attr, int partial) 410mapset_search_new(struct mapset *ms, struct item *item, struct attr *search_attr, int partial)
362{ 411{
412#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
413 dbg(0,"+#+:enter\n");
414#endif
363 struct mapset_search *this; 415 struct mapset_search *this;
364 //dbg(0,"enter(%p,%p,%p,%d)\n", ms, item, search_attr, partial); 416 //dbg(0,"enter(%p,%p,%p,%d)\n", ms, item, search_attr, partial);
365 this=g_new0(struct mapset_search,1); 417 this=g_new0(struct mapset_search,1);
366 if(this != NULL && ms!=NULL ) 418 if (this != NULL && ms != NULL)
367 { 419 {
368 this->map=ms->maps; 420 this->map = ms->maps;
369 this->item=item; 421 this->item = item;
370 this->search_attr=search_attr; 422 this->search_attr = search_attr;
371 this->partial=partial; 423 this->partial = partial;
372 this->ms=map_search_new(this->map->data, item, search_attr, partial); 424 this->ms = map_search_new(this->map->data, item, search_attr, partial);
373 return this; 425 return this;
374 } 426 }
375 else 427 else
376 { 428 {
377 return NULL; 429 return NULL;
389 * @return The next found item or NULL if there are no more items found 441 * @return The next found item or NULL if there are no more items found
390 */ 442 */
391struct item * 443struct item *
392mapset_search_get_item(struct mapset_search *this_) 444mapset_search_get_item(struct mapset_search *this_)
393{ 445{
446#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
447 dbg(0,"+#+:enter\n");
448#endif
394 struct item *ret=NULL; 449 struct item *ret = NULL;
395 struct attr active_attr; 450 struct attr active_attr;
396 451
397 while ((this_) && (!this_->ms || !(ret=map_search_get_item(this_->ms)))) { /* The current map has no more items to be returned */ 452 while ((this_) && (!this_->ms || !(ret = map_search_get_item(this_->ms))))
453 { /* The current map has no more items to be returned */
398 if (this_->search_attr->type >= attr_country_all && this_->search_attr->type <= attr_country_name) 454 if (this_->search_attr->type >= attr_country_all && this_->search_attr->type <= attr_country_name)
399 break; 455 break;
400 for (;;) { 456 for (;;)
457 {
401 this_->map=g_list_next(this_->map); 458 this_->map = g_list_next(this_->map);
402 if (! this_->map) 459 if (!this_->map)
403 break; 460 break;
404 if (map_get_attr(this_->map->data, attr_search_active, &active_attr, NULL)) { 461 if (map_get_attr(this_->map->data, attr_search_active, &active_attr, NULL))
462 {
405 if (!active_attr.u.num) 463 if (!active_attr.u.num)
406 continue; 464 continue;
407 } 465 }
408 if (!map_get_attr(this_->map->data, attr_active, &active_attr, NULL)) 466 if (!map_get_attr(this_->map->data, attr_active, &active_attr, NULL))
409 break; 467 break;
410 if (active_attr.u.num) 468 if (active_attr.u.num)
411 break; 469 break;
412 } 470 }
413 if (! this_->map) 471 if (!this_->map)
414 break; 472 break;
415 map_search_destroy(this_->ms); 473 map_search_destroy(this_->ms);
416 this_->ms=map_search_new(this_->map->data, this_->item, this_->search_attr, this_->partial); 474 this_->ms = map_search_new(this_->map->data, this_->item, this_->search_attr, this_->partial);
417 } 475 }
418 return ret; 476 return ret;
419} 477}
420 478
421/** 479/**
422 * @brief Destroys a mapset search 480 * @brief Destroys a mapset search
423 * 481 *
424 * @param this The mapset search to be destroyed 482 * @param this The mapset search to be destroyed
425 */ 483 */
426void
427mapset_search_destroy(struct mapset_search *this_) 484void mapset_search_destroy(struct mapset_search *this_)
428{ 485{
486#ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
487 dbg(0,"+#+:enter\n");
488#endif
429 if (this_) { 489 if (this_)
490 {
430 map_search_destroy(this_->ms); 491 map_search_destroy(this_->ms);
431 g_free(this_); 492 g_free(this_);
432 } 493 }
433} 494}

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

   
Visit the ZANavi Wiki