2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
22 * @brief Contains code used for loading more than one map
24 * The code in this file introduces "mapsets", which are collections of several maps.
25 * This enables navit to operate on more than one map at once. See map.c / map.h to learn
26 * how maps are handled.
31 #include <glib/gprintf.h>
35 #include "projection.h"
41 * This structure holds a complete mapset
44 GList *maps; /**< Linked list of all the maps in the mapset */
48 * @brief Creates a new, empty mapset
50 * @return The new mapset
52 struct mapset *mapset_new(struct attr *parent, struct attr **attrs)
56 ms=g_new0(struct mapset, 1);
63 * @brief Adds a map to a mapset
65 * @param ms The mapset to add the map to
66 * @param m The map to be added
69 mapset_add_attr(struct mapset *ms, struct attr *attr)
73 ms->maps=g_list_append(ms->maps, attr->u.map);
81 static void mapset_maps_free(struct mapset *ms)
88 * @brief Destroys a mapset.
90 * This destroys a mapset. Please note that it does not touch the contained maps
93 * @param ms The mapset to be destroyed
95 void mapset_destroy(struct mapset *ms)
101 * @brief Handle for a mapset in use
103 * This struct is used for a mapset that is in use. With this it is possible to iterate
104 * all maps in a mapset.
106 struct mapset_handle {
107 GList *l; /**< Pointer to the current (next) map */
111 * @brief Returns a new handle for a mapset
113 * This returns a new handle for an existing mapset. The new handle points to the first
116 * @param ms The mapset to get a handle of
117 * @return The new mapset handle
119 struct mapset_handle *
120 mapset_open(struct mapset *ms)
122 struct mapset_handle *ret=NULL;
125 ret=g_new(struct mapset_handle, 1);
133 * @brief Gets the next map from a mapset handle
135 * If you set active to true, this function will not return any maps that
136 * have the attr_active attribute associated with them and set to false.
138 * @param msh The mapset handle to get the next map of
139 * @param active Set to true to only get active maps (See description)
140 * @return The next map
142 struct map * mapset_next(struct mapset_handle *msh, int active)
145 struct attr active_attr;
151 msh->l=g_list_next(msh->l);
154 if (!map_get_attr(ret, attr_active, &active_attr, NULL))
156 if (active_attr.u.num)
162 * @brief Closes a mapset handle after it is no longer used
164 * @param msh Mapset handle to be closed
167 mapset_close(struct mapset_handle *msh)
173 * @brief Holds information about a search in a mapset
175 * This struct holds information about a search (e.g. for a street) in a mapset.
177 * @sa For a more detailed description see the documentation of mapset_search_new().
179 struct mapset_search {
180 GList *map; /**< The list of maps to be searched within */
181 struct map_search *ms; /**< A map search struct for the map currently active */
182 struct item *item; /**< "Superior" item. */
183 struct attr *search_attr; /**< Attribute to be searched for. */
184 int partial; /**< Indicates if one would like to have partial matches */
188 * @brief Starts a search on a mapset
190 * This function starts a search on a mapset. What attributes one can search for depends on the
191 * map plugin. See the description of map_search_new() in map.c for details.
193 * If you enable partial matches bear in mind that the search matches only the begin of the
194 * strings - a search for a street named "street" would match to "streetfoo", but not to
195 * "somestreet". Search is case insensitive.
197 * The item passed to this function specifies a "superior item" to "search within" - e.g. a town
198 * in which we want to search for a street, or a country in which to search for a town.
200 * @param ms The mapset that should be searched
201 * @param item Specifies a superior item to "search within" (see description)
202 * @param search_attr Attribute specifying what to search for. See description.
203 * @param partial Set this to true to also have partial matches. See description.
204 * @return A new mapset search struct for this search
206 struct mapset_search *
207 mapset_search_new(struct mapset *ms, struct item *item, struct attr *search_attr, int partial)
209 struct mapset_search *this;
210 dbg(1,"enter(%p,%p,%p,%d)\n", ms, item, search_attr, partial);
211 this=g_new0(struct mapset_search,1);
212 if(this != NULL && ms!=NULL )
216 this->search_attr=search_attr;
217 this->partial=partial;
218 this->ms=map_search_new(this->map->data, item, search_attr, partial);
228 * @brief Returns the next found item from a mapset search
230 * This function returns the next item from a mapset search or NULL if there are no more items found.
231 * It automatically iterates through all the maps in the mapset. Please note that maps which have the
232 * attr_active attribute associated with them and set to false are not searched.
234 * @param this The mapset search to return an item from
235 * @return The next found item or NULL if there are no more items found
238 mapset_search_get_item(struct mapset_search *this)
240 struct item *ret=NULL;
241 struct attr active_attr;
243 while ((this) && (!this->ms || !(ret=map_search_get_item(this->ms)))) { /* The current map has no more items to be returned */
244 if (this->search_attr->type >= attr_country_all && this->search_attr->type <= attr_country_name)
247 this->map=g_list_next(this->map);
250 if (!map_get_attr(this->map->data, attr_active, &active_attr, NULL))
252 if (active_attr.u.num)
257 map_search_destroy(this->ms);
258 this->ms=map_search_new(this->map->data, this->item, this->search_attr, this->partial);
264 * @brief Destroys a mapset search
266 * @param this The mapset search to be destroyed
269 mapset_search_destroy(struct mapset_search *this)
272 map_search_destroy(this->ms);