summaryrefslogtreecommitdiff
path: root/navit/mapset.c
blob: e3606815709a46df558fb52d57ee089dd00823a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/**
 * Navit, a modular navigation system.
 * Copyright (C) 2005-2008 Navit Team
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA.
 */

#include <string.h>
#include <glib.h>
#include <glib/gprintf.h>
#include "debug.h"
#include "item.h"
#include "mapset.h"
#include "projection.h"
#include "map.h"

struct mapset {
	GList *maps;
};

struct mapset *mapset_new(void)
{
	struct mapset *ms;

	ms=g_new0(struct mapset, 1);

	return ms;
}

void mapset_add(struct mapset *ms, struct map *m)
{
	ms->maps=g_list_append(ms->maps, m);
}

#if 0
static void mapset_maps_free(struct mapset *ms)
{
	/* todo */
}
#endif

void mapset_destroy(struct mapset *ms)
{
	g_free(ms);
}

struct mapset_handle {
	GList *l;
};

struct mapset_handle *
mapset_open(struct mapset *ms)
{
	struct mapset_handle *ret;

	ret=g_new(struct mapset_handle, 1);
	ret->l=ms->maps;

	return ret;
}

struct map * mapset_next(struct mapset_handle *msh, int active)
{
	struct map *ret;
	struct attr active_attr;

	for (;;) {
		if (!msh->l)
			return NULL;
		ret=msh->l->data;
		msh->l=g_list_next(msh->l);
		if (!active)
			return ret;			
		if (!map_get_attr(ret, attr_active, &active_attr, NULL))
			return ret;
		if (active_attr.u.num)
			return ret;
	}
}

void 
mapset_close(struct mapset_handle *msh)
{
	g_free(msh);
}

struct mapset_search {
	GList *map;
	struct map_search *ms;
	struct item *item;
	struct attr *search_attr;
	int partial;
};

struct mapset_search *
mapset_search_new(struct mapset *ms, struct item *item, struct attr *search_attr, int partial)
{
	struct mapset_search *this;
	dbg(1,"enter(%p,%p,%p,%d)\n", ms, item, search_attr, partial);
	this=g_new0(struct mapset_search,1);
	this->map=ms->maps;
	this->item=item;
	this->search_attr=search_attr;
	this->partial=partial;
	this->ms=map_search_new(this->map->data, item, search_attr, partial);
	return this;
}

struct item *
mapset_search_get_item(struct mapset_search *this)
{
	struct item *ret=NULL;
	struct attr active_attr;

	while (!this->ms || !(ret=map_search_get_item(this->ms))) {
		if (this->search_attr->type >= attr_country_all && this->search_attr->type <= attr_country_name)
			break;
		for (;;) {
			this->map=g_list_next(this->map);
			if (! this->map)
				break;
			if (!map_get_attr(this->map, attr_active, &active_attr, NULL))
				break;
			if (active_attr.u.num)
				break;
		}
		if (! this->map)
			break;
		map_search_destroy(this->ms);
		this->ms=map_search_new(this->map->data, this->item, this->search_attr, this->partial);
	}
	return ret;
}

void
mapset_search_destroy(struct mapset_search *this)
{
	if (this) {
		map_search_destroy(this->ms);
		g_free(this);
	}
}