Diff of /trunk/src/osm.c

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

revision 54 by harbaum, Fri Feb 6 12:06:30 2009 UTC revision 75 by harbaum, Thu Feb 12 19:58:20 2009 UTC
# Line 21  Line 21 
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>
# Line 579  void osm_members_free(member_t *member) Line 578  void osm_members_free(member_t *member)
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  }  }
# Line 2155  item_id_t osm_new_node_id(osm_t *osm) { Line 2157  item_id_t osm_new_node_id(osm_t *osm) {
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    
# Line 2191  void osm_node_attach(osm_t *osm, node_t Line 2215  void osm_node_attach(osm_t *osm, node_t
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    
# Line 2467  void osm_way_remove_from_relation(osm_t Line 2500  void osm_way_remove_from_relation(osm_t
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    
# Line 2530  void osm_way_delete(osm_t *osm, icon_t * Line 2592  void osm_way_delete(osm_t *osm, icon_t *
2592    }    }
2593  }  }
2594    
2595    void osm_relation_delete(osm_t *osm, relation_t *relation,
2596                             gboolean permanently) {
2597    
2598      /* new relations aren't stored on the server and are just */
2599      /* deleted permanently */
2600      if(relation->flags & OSM_FLAG_NEW) {
2601        printf("About to delete NEW relation #%ld -> force permanent delete\n",
2602               relation->id);
2603        permanently = TRUE;
2604      }
2605    
2606      /* the deletion of a relation doesn't affect the members as they */
2607      /* don't have any reference to the relation they are part of */
2608    
2609      if(!permanently) {
2610        printf("mark relation #%ld as deleted\n", relation->id);
2611        relation->flags |= OSM_FLAG_DELETED;
2612      } else {
2613        printf("permanently delete relation #%ld\n", relation->id);
2614    
2615        /* remove it from the chain */
2616        relation_t **crelation = &osm->relation;
2617        int found = 0;
2618    
2619        while(*crelation) {
2620          if(*crelation == relation) {
2621            found++;
2622            *crelation = (*crelation)->next;
2623    
2624            osm_relation_free(relation);
2625          } else
2626            crelation = &((*crelation)->next);
2627        }
2628        g_assert(found == 1);
2629      }
2630    }
2631    
2632  void osm_way_revert(way_t *way) {  void osm_way_revert(way_t *way) {
2633    node_chain_t *new = NULL;    node_chain_t *new = NULL;
2634    
# Line 2627  char *osm_type_string(type_t type) { Line 2726  char *osm_type_string(type_t type) {
2726    return NULL;    return NULL;
2727  }  }
2728    
2729    char *osm_object_string(type_t type, void *object) {
2730      char *type_str = osm_type_string(type);
2731    
2732      if(!object)
2733        return g_strdup_printf("%s #<invalid>", type_str);
2734    
2735      switch(type) {
2736      case ILLEGAL:
2737        return g_strdup_printf("%s #<unspec>", type_str);
2738        break;
2739      case NODE:
2740        return g_strdup_printf("%s #%ld", type_str, ((node_t*)object)->id);
2741        break;
2742      case WAY:
2743        return g_strdup_printf("%s #%ld", type_str, ((way_t*)object)->id);
2744        break;
2745      case RELATION:
2746        return g_strdup_printf("%s #%ld", type_str, ((relation_t*)object)->id);
2747        break;
2748      case NODE_ID:
2749      case WAY_ID:
2750      case RELATION_ID:
2751        return g_strdup_printf("%s #%ld", type_str, *((item_id_t*)object));
2752        break;
2753      }
2754      return NULL;
2755    }
2756    
2757  // vim:et:ts=8:sw=2:sts=2:ai  // vim:et:ts=8:sw=2:sts=2:ai

Legend:
Removed from v.54  
changed lines
  Added in v.75