Diff of /trunk/src/osm.h

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

src/osm.h revision 1 by harbaum, Tue Dec 9 20:06:06 2008 UTC trunk/src/osm.h revision 191 by harbaum, Tue Jul 7 07:36:27 2009 UTC
# Line 27  Line 27 
27  #define OSM_FLAG_NEW      (1<<2)  #define OSM_FLAG_NEW      (1<<2)
28  #define OSM_FLAG_HIDDEN   (1<<3)  #define OSM_FLAG_HIDDEN   (1<<3)
29    
30  typedef gulong item_id_t;  /* item_id_t needs to be signed as osm2go uses negative ids for items */
31    /* not yet registered with the main osm database */
32    #if 1
33    /* currently 31 bit is still sufficient since there are less than */
34    /* 2 billion nodes or changesets */
35    typedef gint32 item_id_t;
36    #define G_TYPE_ITEM_ID_T G_TYPE_INT
37    #define ITEM_ID_FORMAT  "%" G_GINT32_FORMAT
38    #else
39    /* the future may require us to switch to 64 bits */
40    typedef gint64 item_id_t;
41    #define G_TYPE_ITEM_ID_T G_TYPE_INT64
42    #define ITEM_ID_FORMAT  "%" G_GINT64_FORMAT
43    #endif
44    
45  #define ID_ILLEGAL  ((item_id_t)0)  #define ID_ILLEGAL  ((item_id_t)0)
46    
# Line 53  typedef struct tag_s { Line 66  typedef struct tag_s {
66    
67  typedef struct node_s {  typedef struct node_s {
68    item_id_t id;    item_id_t id;
69      item_id_t version;
70    pos_t pos;    pos_t pos;
71    lpos_t lpos;    lpos_t lpos;
72    user_t *user;    user_t *user;
# Line 82  typedef struct node_chain { Line 96  typedef struct node_chain {
96    
97  typedef struct way_s {  typedef struct way_s {
98    item_id_t id;    item_id_t id;
99      item_id_t version;
100      item_id_t changeset;
101    user_t *user;    user_t *user;
102    gboolean visible;    gboolean visible;
103    time_t time;    time_t time;
# Line 95  typedef struct way_s { Line 111  typedef struct way_s {
111      gulong color;      gulong color;
112      gint width;      gint width;
113      float zoom_max;      float zoom_max;
114        gboolean dashed;
115        guint dash_length;
116    
117      union {      union {
118        struct {        struct {
# Line 121  typedef struct way_chain { Line 139  typedef struct way_chain {
139    
140  typedef struct relation_s {  typedef struct relation_s {
141    item_id_t id;    item_id_t id;
142      item_id_t version;
143      item_id_t changeset;
144    user_t *user;    user_t *user;
145    gboolean visible;    gboolean visible;
146    time_t time;    time_t time;
# Line 136  typedef struct relation_chain_s { Line 156  typedef struct relation_chain_s {
156    struct relation_chain_s *next;    struct relation_chain_s *next;
157  } relation_chain_t;  } relation_chain_t;
158    
159    /* two of these hash tables are used, one for nodes and one for ways */
160    /* currently relations aren't used often enough to justify the use */
161    /* of a hash table */
162    
163    /* the current hash table uses 16 bits. each table thus is */
164    /* 256 kbytes (2^16 * sizeof(void*)) in size */
165    #define ID2HASH(a) ((unsigned short)(a) ^ (unsigned short)((a)>>16))
166    typedef struct hash_item_s {
167      union {
168        node_t *node;
169        way_t *way;
170        relation_t *relation;
171      } data;
172    
173      struct hash_item_s *next;
174    } hash_item_t;
175    
176    typedef struct {
177      hash_item_t *hash[65536];
178    } hash_table_t;
179    
180  typedef enum {  typedef enum {
181    ILLEGAL=0, NODE, WAY, RELATION, NODE_ID, WAY_ID, RELATION_ID    ILLEGAL=0, NODE, WAY, RELATION, NODE_ID, WAY_ID, RELATION_ID
182  } type_t;  } type_t;
183    
184  typedef struct member_s {  typedef struct {
185    type_t type;    type_t type;
   char   *role;  
   
186    union {    union {
187      node_t *node;      node_t *node;
188      way_t *way;      way_t *way;
189      relation_t *relation;      relation_t *relation;
190      item_id_t id;      item_id_t id;
191        void *ptr;
192    };    };
193    } object_t;
194    
195    typedef struct member_s {
196      object_t object;
197      char   *role;
198    struct member_s *next;    struct member_s *next;
199  } member_t;  } member_t;
200    
201  typedef struct osm_s {  typedef struct osm_s {
202    bounds_t *bounds;   // original bounds as they appear in the file    bounds_t *bounds;   // original bounds as they appear in the file
203    user_t *user;    user_t *user;
204    
205    node_t *node;    node_t *node;
206      hash_table_t *node_hash;
207    
208    way_t  *way;    way_t  *way;
209      hash_table_t *way_hash;
210    
211      // hashing relations doesn't yet make much sense as relations are quite rare
212    relation_t  *relation;    relation_t  *relation;
213    
214  } osm_t;  } osm_t;
215    
216  #include <libxml/parser.h>  #include <libxml/parser.h>
217  #include <libxml/tree.h>  #include <libxml/tree.h>
218    
219  osm_t *osm_parse(char *filename);  osm_t *osm_parse(char *path, char *filename);
220  gboolean osm_sanity_check(GtkWidget *parent, osm_t *osm);  gboolean osm_sanity_check(GtkWidget *parent, osm_t *osm);
221  tag_t *osm_parse_osm_tag(osm_t *osm, xmlDocPtr doc, xmlNode *a_node);  tag_t *osm_parse_osm_tag(osm_t *osm, xmlDocPtr doc, xmlNode *a_node);
222  node_chain_t *osm_parse_osm_way_nd(osm_t *osm, xmlDocPtr doc, xmlNode *a_node);  node_chain_t *osm_parse_osm_way_nd(osm_t *osm, xmlDocPtr doc, xmlNode *a_node);
# Line 201  gboolean osm_is_creator_tag(tag_t *tag); Line 252  gboolean osm_is_creator_tag(tag_t *tag);
252  gboolean osm_tag_key_and_value_present(tag_t *haystack, tag_t *tag);  gboolean osm_tag_key_and_value_present(tag_t *haystack, tag_t *tag);
253  gboolean osm_tag_key_other_value_present(tag_t *haystack, tag_t *tag);  gboolean osm_tag_key_other_value_present(tag_t *haystack, tag_t *tag);
254    
255  char *osm_generate_xml_node(osm_t *osm, node_t *node);  char *osm_generate_xml_changeset(osm_t *osm, char *comment);
256  char *osm_generate_xml_way(osm_t *osm, way_t *way);  char *osm_generate_xml_node(osm_t *osm, item_id_t changeset, node_t *node);
257  char *osm_generate_xml_relation(osm_t *osm, relation_t *relation);  char *osm_generate_xml_way(osm_t *osm, item_id_t changeset, way_t *way);
258    char *osm_generate_xml_relation(osm_t *osm, item_id_t changeset,
259                                    relation_t *relation);
260    
261  node_t *osm_get_node_by_id(osm_t *osm, item_id_t id);  node_t *osm_get_node_by_id(osm_t *osm, item_id_t id);
262  way_t *osm_get_way_by_id(osm_t *osm, item_id_t id);  way_t *osm_get_way_by_id(osm_t *osm, item_id_t id);
# Line 212  relation_t *osm_get_relation_by_id(osm_t Line 265  relation_t *osm_get_relation_by_id(osm_t
265  guint osm_way_number_of_nodes(way_t *way);  guint osm_way_number_of_nodes(way_t *way);
266  relation_chain_t *osm_node_to_relation(osm_t *osm, node_t *node);  relation_chain_t *osm_node_to_relation(osm_t *osm, node_t *node);
267  relation_chain_t *osm_way_to_relation(osm_t *osm, way_t *way);  relation_chain_t *osm_way_to_relation(osm_t *osm, way_t *way);
268    relation_chain_t *osm_relation_to_relation(osm_t *osm, relation_t *relation);
269    relation_chain_t *osm_object_to_relation(osm_t *osm, object_t *object);
270    void osm_relation_chain_free(relation_chain_t *relation_chain);
271  way_chain_t *osm_node_to_way(osm_t *osm, node_t *node);  way_chain_t *osm_node_to_way(osm_t *osm, node_t *node);
272    
273  /* ----------- edit functions ----------- */  /* ----------- edit functions ----------- */
274  node_t *osm_node_new(osm_t *osm, gint x, gint y);  node_t *osm_node_new(osm_t *osm, gint x, gint y);
275  void osm_node_attach(osm_t *osm, node_t *node);  void osm_node_attach(osm_t *osm, node_t *node);
276    void osm_node_restore(osm_t *osm, node_t *node);
277  way_chain_t *osm_node_delete(osm_t *osm, struct icon_s **icon, node_t *node,  way_chain_t *osm_node_delete(osm_t *osm, struct icon_s **icon, node_t *node,
278                               gboolean permanently, gboolean affect_ways);                               gboolean permanently, gboolean affect_ways);
279  void osm_way_delete(osm_t *osm, struct icon_s **icon, way_t *way,  void osm_way_delete(osm_t *osm, struct icon_s **icon, way_t *way,
# Line 229  gboolean osm_position_within_bounds(osm_ Line 286  gboolean osm_position_within_bounds(osm_
286  item_id_t osm_new_way_id(osm_t *osm);  item_id_t osm_new_way_id(osm_t *osm);
287  gboolean osm_way_ends_with_node(way_t *way, node_t *node);  gboolean osm_way_ends_with_node(way_t *way, node_t *node);
288    
289  void osm_way_revert(way_t *way);  void osm_way_reverse(way_t *way);
290    guint osm_way_reverse_direction_sensitive_tags(way_t *way);
291    guint osm_way_reverse_direction_sensitive_roles(osm_t *osm, way_t *way);
292    
293  void osm_node_remove_from_relation(osm_t *osm, node_t *node);  void osm_node_remove_from_relation(osm_t *osm, node_t *node);
294  void osm_way_remove_from_relation(osm_t *osm, way_t *way);  void osm_way_remove_from_relation(osm_t *osm, way_t *way);
# Line 240  void osm_way_rotate(way_t *way, gint off Line 299  void osm_way_rotate(way_t *way, gint off
299    
300  tag_t *osm_tags_copy(tag_t *tag, gboolean update_creator);  tag_t *osm_tags_copy(tag_t *tag, gboolean update_creator);
301    
302    relation_t *osm_relation_new(void);
303    void osm_relation_free(relation_t *relation);
304    void osm_relation_attach(osm_t *osm, relation_t *relation);
305    void osm_relation_delete(osm_t *osm, relation_t *relation,
306                             gboolean permanently);
307    gint osm_relation_members_num(relation_t *relation);
308    
309    char *osm_object_type_string(object_t *object);
310    char *osm_object_id_string(object_t *object);
311    char *osm_object_string(object_t *object);
312    tag_t *osm_object_get_tags(object_t *object);
313    void osm_object_set_flags(object_t *map_item, int set, int clr);
314    
315  #endif /* OSM_H */  #endif /* OSM_H */
316    
317    // vim:et:ts=8:sw=2:sts=2:ai

Legend:
Removed from v.1  
changed lines
  Added in v.191