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 300 - (show annotations) (download) (as text)
Tue Nov 3 18:44:30 2009 UTC (15 years, 4 months ago) by amb
File MIME type: text/x-csrc
File size: 12080 byte(s)
Rename Way_Unknown to Way_Count to make more sense and match the properties.

1 /***************************************
2 $Header: /home/amb/CVS/routino/src/ways.c,v 1.37 2009-11-03 18:44:30 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_Path);
82 return(Way_Count);
83
84 case 'c':
85 if(!strcmp(highway,"cycleway")) return(Way_Cycleway);
86 return(Way_Count);
87
88 case 'f':
89 if(!strcmp(highway,"footway")) return(Way_Path);
90 return(Way_Count);
91
92 case 'l':
93 if(!strcmp(highway,"living_street")) return(Way_Residential);
94 return(Way_Count);
95
96 case 'm':
97 if(!strncmp(highway,"motorway",8)) return(Way_Motorway);
98 if(!strcmp(highway,"minor")) return(Way_Unclassified);
99 return(Way_Count);
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_Path);
105 return(Way_Count);
106
107 case 'r':
108 if(!strcmp(highway,"road")) return(Way_Unclassified);
109 if(!strcmp(highway,"residential")) return(Way_Residential);
110 return(Way_Count);
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_Path);
117 return(Way_Count);
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_Count);
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_Count);
130
131 case 'w':
132 if(!strcmp(highway,"walkway")) return(Way_Path);
133 return(Way_Count);
134
135 default:
136 ;
137 }
138
139 return(Way_Count);
140 }
141
142
143 /*++++++++++++++++++++++++++++++++++++++
144 Decide on the 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,"moped"))
179 return(Transport_Moped);
180 if(!strcmp(transport,"motorbike"))
181 return(Transport_Motorbike);
182 if(!strcmp(transport,"motorcar"))
183 return(Transport_Motorcar);
184 break;
185
186 case 'p':
187 if(!strcmp(transport,"psv"))
188 return(Transport_PSV);
189 break;
190
191 default:
192 return(Transport_None);
193 }
194
195 return(Transport_None);
196 }
197
198
199 /*++++++++++++++++++++++++++++++++++++++
200 Decide on the type of property given the name of it.
201
202 Property PropertyType Returns the type of the property.
203
204 const char *property The string containing the method of property.
205 ++++++++++++++++++++++++++++++++++++++*/
206
207 Property PropertyType(const char *property)
208 {
209 switch(*property)
210 {
211 case 'p':
212 if(!strcmp(property,"paved"))
213 return(Property_Paved);
214 break;
215
216 default:
217 return(Property_None);
218 }
219
220 return(Property_None);
221 }
222
223
224 /*++++++++++++++++++++++++++++++++++++++
225 A string containing the name of a type of highway.
226
227 const char *HighwayName Returns the name.
228
229 Highway highway The highway type.
230 ++++++++++++++++++++++++++++++++++++++*/
231
232 const char *HighwayName(Highway highway)
233 {
234 switch(highway)
235 {
236 case Way_Motorway:
237 return("motorway");
238 case Way_Trunk:
239 return("trunk");
240 case Way_Primary:
241 return("primary");
242 case Way_Secondary:
243 return("secondary");
244 case Way_Tertiary:
245 return("tertiary");
246 case Way_Unclassified:
247 return("unclassified");
248 case Way_Residential:
249 return("residential");
250 case Way_Service:
251 return("service");
252 case Way_Track:
253 return("track");
254 case Way_Cycleway:
255 return("cycleway");
256 case Way_Path:
257 return("path");
258
259 case Way_Count:
260 ;
261
262 case Way_OneWay:
263 case Way_Roundabout:
264 ;
265 }
266
267 return(NULL);
268 }
269
270
271 /*++++++++++++++++++++++++++++++++++++++
272 A string containing the name of a type of transport.
273
274 const char *TransportName Returns the name.
275
276 Transport transport The transport type.
277 ++++++++++++++++++++++++++++++++++++++*/
278
279 const char *TransportName(Transport transport)
280 {
281 switch(transport)
282 {
283 case Transport_None:
284 return("NONE");
285
286 case Transport_Foot:
287 return("foot");
288 case Transport_Horse:
289 return("horse");
290 case Transport_Bicycle:
291 return("bicycle");
292 case Transport_Moped:
293 return("moped");
294 case Transport_Motorbike:
295 return("motorbike");
296 case Transport_Motorcar:
297 return("motorcar");
298 case Transport_Goods:
299 return("goods");
300 case Transport_HGV:
301 return("hgv");
302 case Transport_PSV:
303 return("psv");
304 }
305
306 return(NULL);
307 }
308
309
310 /*++++++++++++++++++++++++++++++++++++++
311 A string containing the name of a highway property.
312
313 const char *PropertyName Returns the name.
314
315 Property property The property type.
316 ++++++++++++++++++++++++++++++++++++++*/
317
318 const char *PropertyName(Property property)
319 {
320 switch(property)
321 {
322 case Property_None:
323 return("NONE");
324
325 case Property_Paved:
326 return("paved");
327
328 case Property_Count:
329 ;
330 }
331
332 return(NULL);
333 }
334
335
336 /*++++++++++++++++++++++++++++++++++++++
337 A string containing the names of allowed transports on a way.
338
339 const char *AllowedNameList Returns the list of names.
340
341 wayallow_t allowed The allowed type.
342 ++++++++++++++++++++++++++++++++++++++*/
343
344 const char *AllowedNameList(wayallow_t allowed)
345 {
346 static char string[256];
347
348 string[0]=0;
349
350 if(allowed & Allow_Foot)
351 strcat(string,"foot");
352
353 if(allowed & Allow_Horse)
354 {
355 if(*string) strcat(string,", ");
356 strcat(string,"horse");
357 }
358
359 if(allowed & Allow_Bicycle)
360 {
361 if(*string) strcat(string,", ");
362 strcat(string,"bicycle");
363 }
364
365 if(allowed & Allow_Moped)
366 {
367 if(*string) strcat(string,", ");
368 strcat(string,"moped");
369 }
370
371 if(allowed & Allow_Motorbike)
372 {
373 if(*string) strcat(string,", ");
374 strcat(string,"motorbike");
375 }
376
377 if(allowed & Allow_Motorcar)
378 {
379 if(*string) strcat(string,", ");
380 strcat(string,"motorcar");
381 }
382
383 if(allowed & Allow_Goods)
384 {
385 if(*string) strcat(string,", ");
386 strcat(string,"goods");
387 }
388
389 if(allowed & Allow_HGV)
390 {
391 if(*string) strcat(string,", ");
392 strcat(string,"hgv");
393 }
394
395 if(allowed & Allow_PSV)
396 {
397 if(*string) strcat(string,", ");
398 strcat(string,"psv");
399 }
400
401 return(string);
402 }
403
404
405 /*++++++++++++++++++++++++++++++++++++++
406 A string containing the names of the properties of a way.
407
408 const char *PropertiesNameList Returns the list of names.
409
410 wayprop_t properties The properties of the way.
411 ++++++++++++++++++++++++++++++++++++++*/
412
413 const char *PropertiesNameList(wayprop_t properties)
414 {
415 static char string[256];
416
417 string[0]=0;
418
419 if(properties & Properties_Paved)
420 {
421 if(*string) strcat(string,", ");
422 strcat(string,"paved");
423 }
424
425 return(string);
426 }
427
428
429 /*++++++++++++++++++++++++++++++++++++++
430 Returns a list of all the highway types.
431
432 const char *HighwayList Return a list of all the highway types.
433 ++++++++++++++++++++++++++++++++++++++*/
434
435 const char *HighwayList(void)
436 {
437 return " motorway = Motorway\n"
438 " trunk = Trunk\n"
439 " primary = Primary\n"
440 " secondary = Secondary\n"
441 " tertiary = Tertiary\n"
442 " unclassified = Unclassified\n"
443 " residential = Residential\n"
444 " service = Service\n"
445 " track = Track\n"
446 " cycleway = Cycleway\n"
447 " path = Path\n"
448 ;
449 }
450
451
452 /*++++++++++++++++++++++++++++++++++++++
453 Returns a list of all the transport types.
454
455 const char *TransportList Return a list of all the transport types.
456 ++++++++++++++++++++++++++++++++++++++*/
457
458 const char *TransportList(void)
459 {
460 return " foot = Foot\n"
461 " bicycle = Bicycle\n"
462 " horse = Horse\n"
463 " moped = Moped (Small motorbike, limited speed)\n"
464 " motorbike = Motorbike\n"
465 " motorcar = Motorcar\n"
466 " goods = Goods (Small lorry, van)\n"
467 " hgv = HGV (Heavy Goods Vehicle - large lorry)\n"
468 " psv = PSV (Public Service Vehicle - bus, coach)\n"
469 ;
470 }
471
472
473 /*++++++++++++++++++++++++++++++++++++++
474 Returns a list of all the property types.
475
476 const char *PropertyList Return a list of all the highway proprties.
477 ++++++++++++++++++++++++++++++++++++++*/
478
479 const char *PropertyList(void)
480 {
481 return " paved = Paved\n"
482 ;
483 }
484
485
486 /*++++++++++++++++++++++++++++++++++++++
487 Return 0 if the two ways are the same (in respect of their types and limits),
488 otherwise return positive or negative to allow sorting.
489
490 int WaysCompare Returns a comparison.
491
492 Way *way1 The first way.
493
494 Way *way2 The second way.
495 ++++++++++++++++++++++++++++++++++++++*/
496
497 int WaysCompare(Way *way1,Way *way2)
498 {
499 if(way1==way2)
500 return(0);
501
502 if(way1->type!=way2->type)
503 return((int)way1->type - (int)way2->type);
504
505 if(way1->allow!=way2->allow)
506 return((int)way1->allow - (int)way2->allow);
507
508 if(way1->props!=way2->props)
509 return((int)way1->props - (int)way2->props);
510
511 if(way1->speed!=way2->speed)
512 return((int)way1->speed - (int)way2->speed);
513
514 if(way1->weight!=way2->weight)
515 return((int)way1->weight - (int)way2->weight);
516
517 if(way1->height!=way2->height)
518 return((int)way1->height - (int)way2->height);
519
520 if(way1->width!=way2->width)
521 return((int)way1->width - (int)way2->width);
522
523 if(way1->length!=way2->length)
524 return((int)way1->length - (int)way2->length);
525
526 return(0);
527 }

Properties

Name Value
cvs:description Functions for ways.