diff options
author | tegzed <tegzed@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2011-03-19 22:22:12 +0000 |
---|---|---|
committer | tegzed <tegzed@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2011-03-19 22:22:12 +0000 |
commit | 8b9d704e01ac33d16972ad6ab71d8d6b350fa12e (patch) | |
tree | 85963d1a3566c89c05e8aea0d3fdfea17374887d | |
parent | 444e54ef8c640ecaf29becacc67d4abf3e259451 (diff) | |
download | navit-8b9d704e01ac33d16972ad6ab71d8d6b350fa12e.tar.gz |
Add:core: - Added reference counting map destruction mechanism
- Added item creation function to the map interface
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@4370 ffa7fe5e-494d-0410-b361-a75ebd5db220
-rw-r--r-- | navit/map.c | 46 | ||||
-rw-r--r-- | navit/map.h | 2 | ||||
-rw-r--r-- | navit/mapset.c | 35 | ||||
-rw-r--r-- | navit/mapset.h | 1 | ||||
-rw-r--r-- | navit/route.c | 4 |
5 files changed, 82 insertions, 6 deletions
diff --git a/navit/map.c b/navit/map.c index a991bdf40..d8ca5e363 100644 --- a/navit/map.c +++ b/navit/map.c @@ -61,6 +61,7 @@ struct map { struct map_priv *priv; /**< Private data of the map, only known to the map plugin */ struct attr **attrs; /**< Attributes of this map */ struct callback_list *attr_cbl; /**< List of callbacks that are called when attributes change */ + int refcount; }; /** @@ -112,9 +113,19 @@ map_new(struct attr *parent, struct attr **attrs) map_destroy(m); m=NULL; } + else { + m->refcount = 0; + } return m; } +void +map_ref(struct map* m) +{ + m->refcount++; +} + + /** * @brief Gets an attribute from a map * @@ -247,6 +258,16 @@ map_set_projection(struct map *this_, enum projection pro) this_->meth.pro=pro; } +void +map_destroy_do(struct map *m) +{ + if (m->priv) + m->meth.map_destroy(m->priv); + attr_list_free(m->attrs); + callback_list_destroy(m->attr_cbl); + g_free(m); +} + /** * @brief Destroys an opened map * @@ -255,11 +276,12 @@ map_set_projection(struct map *this_, enum projection pro) void map_destroy(struct map *m) { - if (m->priv) - m->meth.map_destroy(m->priv); - attr_list_free(m->attrs); - callback_list_destroy(m->attr_cbl); - g_free(m); + if(0<m->refcount) { + m->refcount--; + } + if(0 == m->refcount) { + map_destroy_do(m); + } } /** @@ -672,3 +694,17 @@ map_dump(struct map *map) { map_dump_filedesc(map, stdout); } + +struct item * +map_rect_create_item(struct map_rect *mr, enum item_type type_) +{ + if(mr && mr->priv && mr->m) { + return mr->m->meth.map_rect_create_item(mr->priv, type_) ; + } + else { + return NULL; + } +} + + + diff --git a/navit/map.h b/navit/map.h index a1b8f1dcf..c64a016b7 100644 --- a/navit/map.h +++ b/navit/map.h @@ -235,6 +235,7 @@ struct map_search; struct map_selection; struct pcoord; struct map *map_new(struct attr *parent, struct attr **attrs); +void map_ref(struct map* m); int map_get_attr(struct map *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter); int map_set_attr(struct map *this_, struct attr *attr); void map_add_callback(struct map *this_, struct callback *cb); @@ -248,6 +249,7 @@ void map_destroy(struct map *m); struct map_rect *map_rect_new(struct map *m, struct map_selection *sel); struct item *map_rect_get_item(struct map_rect *mr); struct item *map_rect_get_item_byid(struct map_rect *mr, int id_hi, int id_lo); +struct item *map_rect_create_item(struct map_rect *mr, enum item_type type_); void map_rect_destroy(struct map_rect *mr); struct map_search *map_search_new(struct map *m, struct item *item, struct attr *search_attr, int partial); struct item *map_search_get_item(struct map_search *this_); diff --git a/navit/mapset.c b/navit/mapset.c index 9c6c6a1be..bc0dd09bc 100644 --- a/navit/mapset.c +++ b/navit/mapset.c @@ -87,6 +87,7 @@ mapset_add_attr(struct mapset *ms, struct attr *attr) switch (attr->type) { case attr_map: ms->maps=g_list_append(ms->maps, attr->u.map); + map_ref(attr->u.map); return 1; default: return 0; @@ -147,6 +148,12 @@ static void mapset_maps_free(struct mapset *ms) */ void mapset_destroy(struct mapset *ms) { + GList *map; + map=ms->maps; + while (map) { + map_destroy(map->data); + map=g_list_next(map); + } g_free(ms); } @@ -224,6 +231,34 @@ struct map * mapset_next(struct mapset_handle *msh, int active) } /** + * @brief Gets a map from the mapset by name + * + * @param ms The map + * @param map_name the map name used by the search + * @return The next map + */ +struct map * +mapset_get_map_by_name(struct mapset *ms, char*map_name) +{ + struct mapset_handle*msh; + struct map*curr_map; + struct attr map_attr; + if( !ms || !map_name ) { + return NULL; + } + msh=mapset_open(ms); + while ((curr_map=mapset_next(msh, 1))) { + //get map name + if(map_get_attr(curr_map,attr_name, &map_attr,NULL)) { + if( ! strcmp(map_attr.u.str, map_name)) { + break; + } + } + } + return curr_map; +} + +/** * @brief Closes a mapset handle after it is no longer used * * @param msh Mapset handle to be closed diff --git a/navit/mapset.h b/navit/mapset.h index a705a263c..54011bb3b 100644 --- a/navit/mapset.h +++ b/navit/mapset.h @@ -40,6 +40,7 @@ int mapset_add_attr(struct mapset *ms, struct attr *attr); int mapset_remove_attr(struct mapset *ms, struct attr *attr); int mapset_get_attr(struct mapset *ms, enum attr_type type, struct attr *attr, struct attr_iter *iter); void mapset_destroy(struct mapset *ms); +struct map *mapset_get_map_by_name(struct mapset *ms, char*map_name); struct mapset_handle *mapset_open(struct mapset *ms); struct map *mapset_next(struct mapset_handle *msh, int active); void mapset_close(struct mapset_handle *msh); diff --git a/navit/route.c b/navit/route.c index b0cf3a8df..21a205dff 100644 --- a/navit/route.c +++ b/navit/route.c @@ -3432,8 +3432,10 @@ route_get_map_helper(struct route *this_, struct map **map, char *type, char *de attrs[3]=&a_description; attrs[4]=NULL; - if (! *map) + if (! *map) { *map=map_new(NULL, attrs); + map_ref(*map); + } return *map; } |