Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Contents of /trunk/src/ways.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 214 - (show annotations) (download) (as text)
Thu Jul 2 17:49:16 2009 UTC (15 years, 8 months ago) by amb
File MIME type: text/x-csrc
File size: 9069 byte(s)
Fix some gcc pedantic warnings.

1 /***************************************
2 $Header: /home/amb/CVS/routino/src/ways.c,v 1.32 2009-07-02 17:49:16 amb Exp $
3
4 Way data type functions.
5
6 Part of the Routino routing software.
7 ******************/ /******************
8 This file Copyright 2008,2009 Andrew M. Bishop
9
10 This program is free software: you can redistribute it and/or modify
11 it under the terms of the GNU Affero General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Affero General Public License for more details.
19
20 You should have received a copy of the GNU Affero General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 ***************************************/
23
24
25 #include <sys/types.h>
26 #include <stdlib.h>
27 #include <string.h>
28
29 #include "functions.h"
30 #include "ways.h"
31
32
33 /*++++++++++++++++++++++++++++++++++++++
34 Load in a way list from a file.
35
36 Ways* LoadWayList Returns the way list.
37
38 const char *filename The name of the file to load.
39 ++++++++++++++++++++++++++++++++++++++*/
40
41 Ways *LoadWayList(const char *filename)
42 {
43 void *data;
44 Ways *ways;
45
46 ways=(Ways*)malloc(sizeof(Ways));
47
48 data=MapFile(filename);
49
50 if(!data)
51 return(NULL);
52
53 /* Copy the Ways structure from the loaded data */
54
55 *ways=*((Ways*)data);
56
57 /* Adjust the pointers in the Ways structure. */
58
59 ways->data =data;
60 ways->ways =(Way *)(data+(off_t)ways->ways);
61 ways->names=(char*)(data+(off_t)ways->names);
62
63 return(ways);
64 }
65
66
67 /*++++++++++++++++++++++++++++++++++++++
68 Decide on the type of a way given the "highway" parameter.
69
70 Highway HighwayType Returns the highway type of the way.
71
72 const char *highway The string containing the type of the way.
73 ++++++++++++++++++++++++++++++++++++++*/
74
75 Highway HighwayType(const char *highway)
76 {
77 switch(*highway)
78 {
79 case 'b':
80 if(!strcmp(highway,"byway")) return(Way_Track);
81 if(!strcmp(highway,"bridleway")) return(Way_Bridleway);
82 return(Way_Unknown);
83
84 case 'c':
85 if(!strcmp(highway,"cycleway")) return(Way_Cycleway);
86 return(Way_Unknown);
87
88 case 'f':
89 if(!strcmp(highway,"footway")) return(Way_Footway);
90 return(Way_Unknown);
91
92 case 'l':
93 if(!strcmp(highway,"living_street")) return(Way_Residential);
94 return(Way_Unknown);
95
96 case 'm':
97 if(!strncmp(highway,"motorway",8)) return(Way_Motorway);
98 if(!strcmp(highway,"minor")) return(Way_Unclassified);
99 return(Way_Unknown);
100
101 case 'p':
102 if(!strncmp(highway,"primary",7)) return(Way_Primary);
103 if(!strcmp(highway,"path")) return(Way_Path);
104 if(!strcmp(highway,"pedestrian")) return(Way_Footway);
105 return(Way_Unknown);
106
107 case 'r':
108 if(!strcmp(highway,"road")) return(Way_Unclassified);
109 if(!strcmp(highway,"residential")) return(Way_Residential);
110 return(Way_Unknown);
111
112 case 's':
113 if(!strncmp(highway,"secondary",9)) return(Way_Secondary);
114 if(!strcmp(highway,"service")) return(Way_Service);
115 if(!strcmp(highway,"services")) return(Way_Service);
116 if(!strcmp(highway,"steps")) return(Way_Footway);
117 return(Way_Unknown);
118
119 case 't':
120 if(!strncmp(highway,"trunk",5)) return(Way_Trunk);
121 if(!strcmp(highway,"tertiary")) return(Way_Tertiary);
122 if(!strcmp(highway,"track")) return(Way_Track);
123 return(Way_Unknown);
124
125 case 'u':
126 if(!strcmp(highway,"unclassified")) return(Way_Unclassified);
127 if(!strcmp(highway,"unsurfaced")) return(Way_Track);
128 if(!strcmp(highway,"unpaved")) return(Way_Track);
129 return(Way_Unknown);
130
131 case 'w':
132 if(!strcmp(highway,"walkway")) return(Way_Footway);
133 return(Way_Unknown);
134
135 default:
136 ;
137 }
138
139 return(Way_Unknown);
140 }
141
142
143 /*++++++++++++++++++++++++++++++++++++++
144 Decide on the allowed type of transport given the name of it.
145
146 Transport TransportType Returns the type of the transport.
147
148 const char *transport The string containing the method of transport.
149 ++++++++++++++++++++++++++++++++++++++*/
150
151 Transport TransportType(const char *transport)
152 {
153 switch(*transport)
154 {
155 case 'b':
156 if(!strcmp(transport,"bicycle"))
157 return(Transport_Bicycle);
158 break;
159
160 case 'f':
161 if(!strcmp(transport,"foot"))
162 return(Transport_Foot);
163 break;
164
165 case 'g':
166 if(!strcmp(transport,"goods"))
167 return(Transport_Goods);
168 break;
169
170 case 'h':
171 if(!strcmp(transport,"horse"))
172 return(Transport_Horse);
173 if(!strcmp(transport,"hgv"))
174 return(Transport_HGV);
175 break;
176
177 case 'm':
178 if(!strcmp(transport,"motorbike"))
179 return(Transport_Motorbike);
180 if(!strcmp(transport,"motorcar"))
181 return(Transport_Motorcar);
182 break;
183
184 case 'p':
185 if(!strcmp(transport,"psv"))
186 return(Transport_PSV);
187 break;
188
189 default:
190 return(Transport_None);
191 }
192
193 return(Transport_None);
194 }
195
196
197 /*++++++++++++++++++++++++++++++++++++++
198 A string containing the name of a type of highway.
199
200 const char *HighwayName Returns the name.
201
202 Highway highway The highway type.
203 ++++++++++++++++++++++++++++++++++++++*/
204
205 const char *HighwayName(Highway highway)
206 {
207 switch(highway)
208 {
209 case Way_Motorway:
210 return("motorway");
211 case Way_Trunk:
212 return("trunk");
213 case Way_Primary:
214 return("primary");
215 case Way_Secondary:
216 return("secondary");
217 case Way_Tertiary:
218 return("tertiary");
219 case Way_Unclassified:
220 return("unclassified");
221 case Way_Residential:
222 return("residential");
223 case Way_Service:
224 return("service");
225 case Way_Track:
226 return("track");
227 case Way_Path:
228 return("path");
229 case Way_Bridleway:
230 return("bridleway");
231 case Way_Cycleway:
232 return("cycleway");
233 case Way_Footway:
234 return("footway");
235
236 case Way_Unknown:
237 case Way_OneWay:
238 case Way_Roundabout:
239 return(NULL);
240 }
241
242 return(NULL);
243 }
244
245
246 /*++++++++++++++++++++++++++++++++++++++
247 A string containing the name of a type of transport.
248
249 const char *TransportName Returns the name.
250
251 Transport transport The transport type.
252 ++++++++++++++++++++++++++++++++++++++*/
253
254 const char *TransportName(Transport transport)
255 {
256 switch(transport)
257 {
258 case Transport_None:
259 return("NONE");
260
261 case Transport_Foot:
262 return("foot");
263 case Transport_Bicycle:
264 return("bicycle");
265 case Transport_Horse:
266 return("horse");
267 case Transport_Motorbike:
268 return("motorbike");
269 case Transport_Motorcar:
270 return("motorcar");
271 case Transport_Goods:
272 return("goods");
273 case Transport_HGV:
274 return("hgv");
275 case Transport_PSV:
276 return("psv");
277 }
278 return(NULL);
279 }
280
281
282 /*++++++++++++++++++++++++++++++++++++++
283 Returns a list of all the highway types.
284
285 const char *HighwayList Return a list of all the highway types.
286 ++++++++++++++++++++++++++++++++++++++*/
287
288 const char *HighwayList(void)
289 {
290 return " motorway = Motorway\n"
291 " trunk = Trunk\n"
292 " primary = Primary\n"
293 " secondary = Secondary\n"
294 " tertiary = Tertiary\n"
295 " unclassified = Unclassified\n"
296 " residential = Residential\n"
297 " service = Service\n"
298 " track = Track\n"
299 " path = Path\n"
300 " bridleway = Bridleway\n"
301 " cycleway = Cycleway\n"
302 " footway = Footway\n";
303 }
304
305
306 /*++++++++++++++++++++++++++++++++++++++
307 Returns a list of all the transport types.
308
309 const char *TransportList Return a list of all the transport types.
310 ++++++++++++++++++++++++++++++++++++++*/
311
312 const char *TransportList(void)
313 {
314 return " foot = Foot\n"
315 " bicycle = Bicycle\n"
316 " horse = Horse\n"
317 " motorbike = Motorbike\n"
318 " motorcar = Motorcar\n"
319 " goods = Goods (Small lorry, van)\n"
320 " hgv = HGV (Heavy Goods Vehicle - large lorry)\n"
321 " psv = PSV (Public Service Vehicle - bus, coach)\n";
322 }
323
324
325 /*++++++++++++++++++++++++++++++++++++++
326 Return 0 if the two ways are the same (in respect of their types and limits),
327 otherwise return positive or negative to allow sorting.
328
329 int WaysCompare Returns a comparison.
330
331 Way *way1 The first way.
332
333 Way *way2 The second way.
334 ++++++++++++++++++++++++++++++++++++++*/
335
336 int WaysCompare(Way *way1,Way *way2)
337 {
338 if(way1==way2)
339 return(0);
340
341 if(way1->type!=way2->type)
342 return((int)way1->type - (int)way2->type);
343
344 if(way1->allow!=way2->allow)
345 return((int)way1->allow - (int)way2->allow);
346
347 if(way1->speed!=way2->speed)
348 return((int)way1->speed - (int)way2->speed);
349
350 if(way1->weight!=way2->weight)
351 return((int)way1->weight - (int)way2->weight);
352
353 if(way1->height!=way2->height)
354 return((int)way1->height - (int)way2->height);
355
356 if(way1->width!=way2->width)
357 return((int)way1->width - (int)way2->width);
358
359 if(way1->length!=way2->length)
360 return((int)way1->length - (int)way2->length);
361
362 return(0);
363 }

Properties

Name Value
cvs:description Functions for ways.