21 |
/* this is in fact selected depending on the plattform in the Makefile */ |
/* this is in fact selected depending on the plattform in the Makefile */ |
22 |
// #define OSM_DOM_PARSER |
// #define OSM_DOM_PARSER |
23 |
// #define OSM_STREAM_PARSER |
// #define OSM_STREAM_PARSER |
|
// #define OSM_QND_XML_PARSER |
|
24 |
|
|
25 |
#include <stdio.h> |
#include <stdio.h> |
26 |
#include <stdlib.h> |
#include <stdlib.h> |
578 |
} |
} |
579 |
} |
} |
580 |
|
|
581 |
|
void osm_relation_free(relation_t *relation) { |
582 |
|
osm_tags_free(relation->tag); |
583 |
|
osm_members_free(relation->member); |
584 |
|
|
585 |
|
g_free(relation); |
586 |
|
} |
587 |
|
|
588 |
static void osm_relations_free(relation_t *relation) { |
static void osm_relations_free(relation_t *relation) { |
589 |
while(relation) { |
while(relation) { |
590 |
relation_t *next = relation->next; |
relation_t *next = relation->next; |
591 |
|
osm_relation_free(relation); |
|
osm_tags_free(relation->tag); |
|
|
osm_members_free(relation->member); |
|
|
|
|
|
g_free(relation); |
|
592 |
relation = next; |
relation = next; |
593 |
} |
} |
594 |
} |
} |
2157 |
return 0; |
return 0; |
2158 |
} |
} |
2159 |
|
|
2160 |
|
item_id_t osm_new_relation_id(osm_t *osm) { |
2161 |
|
item_id_t id = -1; |
2162 |
|
|
2163 |
|
while(TRUE) { |
2164 |
|
gboolean found = FALSE; |
2165 |
|
relation_t *relation = osm->relation; |
2166 |
|
while(relation) { |
2167 |
|
if(relation->id == id) |
2168 |
|
found = TRUE; |
2169 |
|
|
2170 |
|
relation = relation->next; |
2171 |
|
} |
2172 |
|
|
2173 |
|
/* no such id so far -> use it */ |
2174 |
|
if(!found) return id; |
2175 |
|
|
2176 |
|
id--; |
2177 |
|
} |
2178 |
|
g_assert(0); |
2179 |
|
return 0; |
2180 |
|
} |
2181 |
|
|
2182 |
node_t *osm_node_new(osm_t *osm, gint x, gint y) { |
node_t *osm_node_new(osm_t *osm, gint x, gint y) { |
2183 |
printf("Creating new node\n"); |
printf("Creating new node\n"); |
2184 |
|
|
2215 |
*lnode = node; |
*lnode = node; |
2216 |
} |
} |
2217 |
|
|
2218 |
|
void osm_node_restore(osm_t *osm, node_t *node) { |
2219 |
|
printf("Restoring node\n"); |
2220 |
|
|
2221 |
|
/* attach to end of node list */ |
2222 |
|
node_t **lnode = &osm->node; |
2223 |
|
while(*lnode) lnode = &(*lnode)->next; |
2224 |
|
*lnode = node; |
2225 |
|
} |
2226 |
|
|
2227 |
way_t *osm_way_new(void) { |
way_t *osm_way_new(void) { |
2228 |
printf("Creating new way\n"); |
printf("Creating new way\n"); |
2229 |
|
|
2500 |
} |
} |
2501 |
} |
} |
2502 |
|
|
2503 |
|
relation_t *osm_relation_new(void) { |
2504 |
|
printf("Creating new relation\n"); |
2505 |
|
|
2506 |
|
relation_t *relation = g_new0(relation_t, 1); |
2507 |
|
relation->visible = TRUE; |
2508 |
|
relation->flags = OSM_FLAG_NEW; |
2509 |
|
relation->time = time(NULL); |
2510 |
|
|
2511 |
|
/* add created_by tag */ |
2512 |
|
relation->tag = g_new0(tag_t, 1); |
2513 |
|
relation->tag->key = g_strdup("created_by"); |
2514 |
|
relation->tag->value = g_strdup(PACKAGE " v" VERSION); |
2515 |
|
|
2516 |
|
return relation; |
2517 |
|
} |
2518 |
|
|
2519 |
|
void osm_relation_attach(osm_t *osm, relation_t *relation) { |
2520 |
|
printf("Attaching relation\n"); |
2521 |
|
|
2522 |
|
relation->id = osm_new_relation_id(osm); |
2523 |
|
relation->flags = OSM_FLAG_NEW; |
2524 |
|
|
2525 |
|
/* attach to end of relation list */ |
2526 |
|
relation_t **lrelation = &osm->relation; |
2527 |
|
while(*lrelation) lrelation = &(*lrelation)->next; |
2528 |
|
*lrelation = relation; |
2529 |
|
} |
2530 |
|
|
2531 |
|
|
2532 |
void osm_way_delete(osm_t *osm, icon_t **icon, |
void osm_way_delete(osm_t *osm, icon_t **icon, |
2533 |
way_t *way, gboolean permanently) { |
way_t *way, gboolean permanently) { |
2534 |
|
|
2667 |
|
|
2668 |
return new_tags; |
return new_tags; |
2669 |
} |
} |
2670 |
|
|
2671 |
|
/* return plain text of type */ |
2672 |
|
char *osm_type_string(type_t type) { |
2673 |
|
const struct { type_t type; char *name; } types[] = { |
2674 |
|
{ ILLEGAL, "illegal" }, |
2675 |
|
{ NODE, "node" }, |
2676 |
|
{ WAY, "way" }, |
2677 |
|
{ RELATION, "relation" }, |
2678 |
|
{ NODE_ID, "node id" }, |
2679 |
|
{ WAY_ID, "way id" }, |
2680 |
|
{ RELATION_ID, "relation id" }, |
2681 |
|
{ 0, NULL } |
2682 |
|
}; |
2683 |
|
|
2684 |
|
int i; |
2685 |
|
for(i=0;types[i].name;i++) |
2686 |
|
if(type == types[i].type) |
2687 |
|
return types[i].name; |
2688 |
|
|
2689 |
|
return NULL; |
2690 |
|
} |
2691 |
|
|
2692 |
|
char *osm_object_string(type_t type, void *object) { |
2693 |
|
char *type_str = osm_type_string(type); |
2694 |
|
|
2695 |
|
if(!object) |
2696 |
|
return g_strdup_printf("%s #<invalid>", type_str); |
2697 |
|
|
2698 |
|
switch(type) { |
2699 |
|
case ILLEGAL: |
2700 |
|
return g_strdup_printf("%s #<unspec>", type_str); |
2701 |
|
break; |
2702 |
|
case NODE: |
2703 |
|
return g_strdup_printf("%s #%ld", type_str, ((node_t*)object)->id); |
2704 |
|
break; |
2705 |
|
case WAY: |
2706 |
|
return g_strdup_printf("%s #%ld", type_str, ((way_t*)object)->id); |
2707 |
|
break; |
2708 |
|
case RELATION: |
2709 |
|
return g_strdup_printf("%s #%ld", type_str, ((relation_t*)object)->id); |
2710 |
|
break; |
2711 |
|
case NODE_ID: |
2712 |
|
case WAY_ID: |
2713 |
|
case RELATION_ID: |
2714 |
|
return g_strdup_printf("%s #%ld", type_str, *((item_id_t*)object)); |
2715 |
|
break; |
2716 |
|
} |
2717 |
|
return NULL; |
2718 |
|
} |
2719 |
|
|
2720 |
// vim:et:ts=8:sw=2:sts=2:ai |
// vim:et:ts=8:sw=2:sts=2:ai |