Merge with modular_map
[navit-package] / src / mapset.c
1 #include <glib.h>
2 #include <glib/gprintf.h>
3 #include "debug.h"
4 #include "attr.h"
5 #include "mapset.h"
6 #include "map.h"
7
8 struct mapset {
9         GList *maps;
10 };
11
12 struct mapset *mapset_new(void)
13 {
14         struct mapset *ms;
15
16         ms=g_new0(struct mapset, 1);
17
18         return ms;
19 }
20
21 void mapset_add(struct mapset *ms, struct map *m)
22 {
23         ms->maps=g_list_append(ms->maps, m);
24 }
25
26 #if 0
27 static void mapset_maps_free(struct mapset *ms)
28 {
29         /* todo */
30 }
31 #endif
32
33 void mapset_destroy(struct mapset *ms)
34 {
35         g_free(ms);
36 }
37
38 struct mapset_handle {
39         GList *l;
40 };
41
42 struct mapset_handle *
43 mapset_open(struct mapset *ms)
44 {
45         struct mapset_handle *ret;
46
47         ret=g_new(struct mapset_handle, 1);
48         ret->l=ms->maps;
49
50         return ret;
51 }
52
53 struct map * mapset_next(struct mapset_handle *msh, int active)
54 {
55         struct map *ret;
56
57         for (;;) {
58                 if (!msh->l)
59                         return NULL;
60                 ret=msh->l->data;
61                 msh->l=g_list_next(msh->l);
62                 if (!active || map_get_active(ret))
63                         return ret;
64         }
65 }
66
67 void 
68 mapset_close(struct mapset_handle *msh)
69 {
70         g_free(msh);
71 }
72
73 struct mapset_search {
74         GList *map;
75         struct map_search *ms;
76         struct item *item;
77         struct attr *search_attr;
78         int partial;
79 };
80
81 struct mapset_search *
82 mapset_search_new(struct mapset *ms, struct item *item, struct attr *search_attr, int partial)
83 {
84         struct mapset_search *this;
85         dbg(1,"enter(%p,%p,%p,%d)\n", ms, item, search_attr, partial);
86         this=g_new0(struct mapset_search,1);
87         this->map=ms->maps;
88         this->item=item;
89         this->search_attr=search_attr;
90         this->partial=partial;
91         this->ms=map_search_new(this->map->data, item, search_attr, partial);
92         return this;
93 }
94
95 struct item *
96 mapset_search_get_item(struct mapset_search *this)
97 {
98         struct item *ret;
99         while (!(ret=map_search_get_item(this->ms))) {
100                 if (this->search_attr->type >= attr_country_all && this->search_attr->type <= attr_country_name)
101                         break;
102                 this->map=g_list_next(this->map);
103                 if (! this->map)
104                         break;
105                 map_search_destroy(this->ms);
106                 this->ms=map_search_new(this->map->data, this->item, this->search_attr, this->partial);
107         }
108         return ret;
109 }
110
111 void
112 mapset_search_destroy(struct mapset_search *this)
113 {
114         map_search_destroy(this->ms);
115         g_free(this);
116 }