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/types.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1989 - (show annotations) (download) (as text)
Wed Apr 17 17:54:45 2019 UTC (5 years, 11 months ago) by amb
File MIME type: text/x-csrc
File size: 13696 byte(s)
Rename some structure members and function names to reflect more
clearly their meaning (mostly change "allow" to "transport").  No
changes to file formats or API.

1 /***************************************
2 Functions for handling the data types.
3
4 Part of the Routino routing software.
5 ******************/ /******************
6 This file Copyright 2008-2015, 2019 Andrew M. Bishop
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Affero General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Affero General Public License for more details.
17
18 You should have received a copy of the GNU Affero General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ***************************************/
21
22
23 #include <string.h>
24
25 #include "types.h"
26
27
28 /*++++++++++++++++++++++++++++++++++++++
29 Decide on the type of a way given the "highway" parameter.
30
31 Highway HighwayType Returns the highway type of the way.
32
33 const char *highway The string containing the type of the way.
34 ++++++++++++++++++++++++++++++++++++++*/
35
36 Highway HighwayType(const char *highway)
37 {
38 switch(*highway)
39 {
40 case 'c':
41 if(!strcmp(highway,"cycleway")) return(Highway_Cycleway);
42 break;
43
44 case 'f':
45 if(!strcmp(highway,"ferry")) return(Highway_Ferry);
46 break;
47
48 case 'm':
49 if(!strcmp(highway,"motorway")) return(Highway_Motorway);
50 break;
51
52 case 'p':
53 if(!strcmp(highway,"primary")) return(Highway_Primary);
54 if(!strcmp(highway,"path")) return(Highway_Path);
55 break;
56
57 case 'r':
58 if(!strcmp(highway,"residential")) return(Highway_Residential);
59 break;
60
61 case 's':
62 if(!strcmp(highway,"secondary")) return(Highway_Secondary);
63 if(!strcmp(highway,"service")) return(Highway_Service);
64 if(!strcmp(highway,"steps")) return(Highway_Steps);
65 break;
66
67 case 't':
68 if(!strcmp(highway,"trunk")) return(Highway_Trunk);
69 if(!strcmp(highway,"tertiary")) return(Highway_Tertiary);
70 if(!strcmp(highway,"track")) return(Highway_Track);
71 break;
72
73 case 'u':
74 if(!strcmp(highway,"unclassified")) return(Highway_Unclassified);
75 break;
76
77 default:
78 ;
79 }
80
81 return(Highway_None);
82 }
83
84
85 /*++++++++++++++++++++++++++++++++++++++
86 Decide on the type of transport given the name of it.
87
88 Transport TransportType Returns the type of the transport.
89
90 const char *transport The string containing the method of transport.
91 ++++++++++++++++++++++++++++++++++++++*/
92
93 Transport TransportType(const char *transport)
94 {
95 switch(*transport)
96 {
97 case 'b':
98 if(!strcmp(transport,"bicycle"))
99 return(Transport_Bicycle);
100 break;
101
102 case 'f':
103 if(!strcmp(transport,"foot"))
104 return(Transport_Foot);
105 break;
106
107 case 'g':
108 if(!strcmp(transport,"goods"))
109 return(Transport_Goods);
110 break;
111
112 case 'h':
113 if(!strcmp(transport,"horse"))
114 return(Transport_Horse);
115 if(!strcmp(transport,"hgv"))
116 return(Transport_HGV);
117 break;
118
119 case 'm':
120 if(!strcmp(transport,"moped"))
121 return(Transport_Moped);
122 if(!strcmp(transport,"motorcycle"))
123 return(Transport_Motorcycle);
124 if(!strcmp(transport,"motorcar"))
125 return(Transport_Motorcar);
126 break;
127
128 case 'p':
129 if(!strcmp(transport,"psv"))
130 return(Transport_PSV);
131 break;
132
133 case 'w':
134 if(!strcmp(transport,"wheelchair"))
135 return(Transport_Wheelchair);
136 break;
137
138 default:
139 return(Transport_None);
140 }
141
142 return(Transport_None);
143 }
144
145
146 /*++++++++++++++++++++++++++++++++++++++
147 Decide on the type of property given the name of it.
148
149 Property PropertyType Returns the type of the property.
150
151 const char *property The string containing the method of property.
152 ++++++++++++++++++++++++++++++++++++++*/
153
154 Property PropertyType(const char *property)
155 {
156 switch(*property)
157 {
158 case 'b':
159 if(!strcmp(property,"bicycleroute"))
160 return(Property_BicycleRoute);
161
162 if(!strcmp(property,"bridge"))
163 return(Property_Bridge);
164 break;
165
166 case 'f':
167 if(!strcmp(property,"footroute"))
168 return(Property_FootRoute);
169 break;
170
171 case 'm':
172 if(!strcmp(property,"multilane"))
173 return(Property_Multilane);
174 break;
175
176 case 'p':
177 if(!strcmp(property,"paved"))
178 return(Property_Paved);
179 break;
180
181 case 't':
182 if(!strcmp(property,"tunnel"))
183 return(Property_Tunnel);
184 break;
185
186 default:
187 return(Property_None);
188 }
189
190 return(Property_None);
191 }
192
193
194 /*++++++++++++++++++++++++++++++++++++++
195 A string containing the name of a type of highway.
196
197 const char *HighwayName Returns the name.
198
199 Highway highway The highway type.
200 ++++++++++++++++++++++++++++++++++++++*/
201
202 const char *HighwayName(Highway highway)
203 {
204 switch(highway)
205 {
206 case Highway_None:
207 return("NONE");
208
209 case Highway_Motorway:
210 return("motorway");
211 case Highway_Trunk:
212 return("trunk");
213 case Highway_Primary:
214 return("primary");
215 case Highway_Secondary:
216 return("secondary");
217 case Highway_Tertiary:
218 return("tertiary");
219 case Highway_Unclassified:
220 return("unclassified");
221 case Highway_Residential:
222 return("residential");
223 case Highway_Service:
224 return("service");
225 case Highway_Track:
226 return("track");
227 case Highway_Cycleway:
228 return("cycleway");
229 case Highway_Path:
230 return("path");
231 case Highway_Steps:
232 return("steps");
233 case Highway_Ferry:
234 return("ferry");
235
236 case Highway_Count:
237 ;
238
239 case Highway_CycleBothWays:
240 ;
241 case Highway_OneWay:
242 ;
243 case Highway_Roundabout:
244 ;
245 case Highway_Area:
246 ;
247 }
248
249 return(NULL);
250 }
251
252
253 /*++++++++++++++++++++++++++++++++++++++
254 A string containing the name of a type of transport.
255
256 const char *TransportName Returns the name.
257
258 Transport transport The transport type.
259 ++++++++++++++++++++++++++++++++++++++*/
260
261 const char *TransportName(Transport transport)
262 {
263 switch(transport)
264 {
265 case Transport_None:
266 return("NONE");
267
268 case Transport_Foot:
269 return("foot");
270 case Transport_Horse:
271 return("horse");
272 case Transport_Wheelchair:
273 return("wheelchair");
274 case Transport_Bicycle:
275 return("bicycle");
276 case Transport_Moped:
277 return("moped");
278 case Transport_Motorcycle:
279 return("motorcycle");
280 case Transport_Motorcar:
281 return("motorcar");
282 case Transport_Goods:
283 return("goods");
284 case Transport_HGV:
285 return("hgv");
286 case Transport_PSV:
287 return("psv");
288
289 case Transport_Count:
290 ;
291 }
292
293 return(NULL);
294 }
295
296
297 /*++++++++++++++++++++++++++++++++++++++
298 A string containing the name of a highway property.
299
300 const char *PropertyName Returns the name.
301
302 Property property The property type.
303 ++++++++++++++++++++++++++++++++++++++*/
304
305 const char *PropertyName(Property property)
306 {
307 switch(property)
308 {
309 case Property_None:
310 return("NONE");
311
312 case Property_Paved:
313 return("paved");
314
315 case Property_Multilane:
316 return("multilane");
317
318 case Property_Bridge:
319 return("bridge");
320
321 case Property_Tunnel:
322 return("tunnel");
323
324 case Property_FootRoute:
325 return("footroute");
326
327 case Property_BicycleRoute:
328 return("bicycleroute");
329
330 case Property_Count:
331 ;
332 }
333
334 return(NULL);
335 }
336
337
338 /*++++++++++++++++++++++++++++++++++++++
339 A string containing the names of highways.
340
341 const char *HighwaysNameList Returns the list of names.
342
343 highways_t highways The highways type.
344 ++++++++++++++++++++++++++++++++++++++*/
345
346 const char *HighwaysNameList(highways_t highways)
347 {
348 static char string[256]; /* static allocation of return value (set each call) */
349
350 string[0]=0;
351
352 if(highways & Highways_Motorway)
353 strcat(string,"motorway");
354
355 if(highways & Highways_Trunk)
356 {
357 if(*string) strcat(string,", ");
358 strcat(string,"trunk");
359 }
360
361 if(highways & Highways_Primary)
362 {
363 if(*string) strcat(string,", ");
364 strcat(string,"primary");
365 }
366
367 if(highways & Highways_Tertiary)
368 {
369 if(*string) strcat(string,", ");
370 strcat(string,"tertiary");
371 }
372
373 if(highways & Highways_Unclassified)
374 {
375 if(*string) strcat(string,", ");
376 strcat(string,"unclassified");
377 }
378
379 if(highways & Highways_Residential)
380 {
381 if(*string) strcat(string,", ");
382 strcat(string,"residential");
383 }
384
385 if(highways & Highways_Service)
386 {
387 if(*string) strcat(string,", ");
388 strcat(string,"service");
389 }
390
391 if(highways & Highways_Track)
392 {
393 if(*string) strcat(string,", ");
394 strcat(string,"track");
395 }
396
397 if(highways & Highways_Cycleway)
398 {
399 if(*string) strcat(string,", ");
400 strcat(string,"cycleway");
401 }
402
403 if(highways & Highways_Path)
404 {
405 if(*string) strcat(string,", ");
406 strcat(string,"path");
407 }
408
409 if(highways & Highways_Steps)
410 {
411 if(*string) strcat(string,", ");
412 strcat(string,"steps");
413 }
414
415 if(highways & Highways_Ferry)
416 {
417 if(*string) strcat(string,", ");
418 strcat(string,"ferry");
419 }
420
421 return(string);
422 }
423
424
425 /*++++++++++++++++++++++++++++++++++++++
426 A string containing the names of transports.
427
428 const char *TransportsNameList Returns the list of names.
429
430 transports_t transports The transports type.
431 ++++++++++++++++++++++++++++++++++++++*/
432
433 const char *TransportsNameList(transports_t transports)
434 {
435 static char string[256]; /* static allocation of return value (set each call) */
436
437 string[0]=0;
438
439 if(transports & Transports_Foot)
440 strcat(string,"foot");
441
442 if(transports & Transports_Horse)
443 {
444 if(*string) strcat(string,", ");
445 strcat(string,"horse");
446 }
447
448 if(transports & Transports_Wheelchair)
449 {
450 if(*string) strcat(string,", ");
451 strcat(string,"wheelchair");
452 }
453
454 if(transports & Transports_Bicycle)
455 {
456 if(*string) strcat(string,", ");
457 strcat(string,"bicycle");
458 }
459
460 if(transports & Transports_Moped)
461 {
462 if(*string) strcat(string,", ");
463 strcat(string,"moped");
464 }
465
466 if(transports & Transports_Motorcycle)
467 {
468 if(*string) strcat(string,", ");
469 strcat(string,"motorcycle");
470 }
471
472 if(transports & Transports_Motorcar)
473 {
474 if(*string) strcat(string,", ");
475 strcat(string,"motorcar");
476 }
477
478 if(transports & Transports_Goods)
479 {
480 if(*string) strcat(string,", ");
481 strcat(string,"goods");
482 }
483
484 if(transports & Transports_HGV)
485 {
486 if(*string) strcat(string,", ");
487 strcat(string,"hgv");
488 }
489
490 if(transports & Transports_PSV)
491 {
492 if(*string) strcat(string,", ");
493 strcat(string,"psv");
494 }
495
496 return(string);
497 }
498
499
500 /*++++++++++++++++++++++++++++++++++++++
501 A string containing the names of the properties of a way.
502
503 const char *PropertiesNameList Returns the list of names.
504
505 properties_t properties The properties of the way.
506 ++++++++++++++++++++++++++++++++++++++*/
507
508 const char *PropertiesNameList(properties_t properties)
509 {
510 static char string[256]; /* static allocation of return value (set each call) */
511
512 string[0]=0;
513
514 if(properties & Properties_Paved)
515 {
516 if(*string) strcat(string,", ");
517 strcat(string,"paved");
518 }
519
520 if(properties & Properties_Multilane)
521 {
522 if(*string) strcat(string,", ");
523 strcat(string,"multilane");
524 }
525
526 if(properties & Properties_Bridge)
527 {
528 if(*string) strcat(string,", ");
529 strcat(string,"bridge");
530 }
531
532 if(properties & Properties_Tunnel)
533 {
534 if(*string) strcat(string,", ");
535 strcat(string,"tunnel");
536 }
537
538 if(properties & Properties_FootRoute)
539 {
540 if(*string) strcat(string,", ");
541 strcat(string,"footroute");
542 }
543
544 if(properties & Properties_BicycleRoute)
545 {
546 if(*string) strcat(string,", ");
547 strcat(string,"bicycleroute");
548 }
549
550 return(string);
551 }
552
553
554 /*++++++++++++++++++++++++++++++++++++++
555 Returns a list of all the highway types.
556
557 const char *HighwayList Return a list of all the highway types.
558 ++++++++++++++++++++++++++++++++++++++*/
559
560 const char *HighwayList(void)
561 {
562 return " motorway = Motorway\n"
563 " trunk = Trunk\n"
564 " primary = Primary\n"
565 " secondary = Secondary\n"
566 " tertiary = Tertiary\n"
567 " unclassified = Unclassified\n"
568 " residential = Residential\n"
569 " service = Service\n"
570 " track = Track\n"
571 " cycleway = Cycleway\n"
572 " path = Path\n"
573 " steps = Steps\n"
574 " ferry = Ferry\n"
575 ;
576 }
577
578
579 /*++++++++++++++++++++++++++++++++++++++
580 Returns a list of all the transport types.
581
582 const char *TransportList Return a list of all the transport types.
583 ++++++++++++++++++++++++++++++++++++++*/
584
585 const char *TransportList(void)
586 {
587 return " foot = Foot\n"
588 " bicycle = Bicycle\n"
589 " wheelchair = Wheelchair\n"
590 " horse = Horse\n"
591 " moped = Moped (Small motorcycle, limited speed)\n"
592 " motorcycle = Motorcycle\n"
593 " motorcar = Motorcar\n"
594 " goods = Goods (Small lorry, van)\n"
595 " hgv = HGV (Heavy Goods Vehicle - large lorry)\n"
596 " psv = PSV (Public Service Vehicle - bus, coach)\n"
597 ;
598 }
599
600
601 /*++++++++++++++++++++++++++++++++++++++
602 Returns a list of all the property types.
603
604 const char *PropertyList Return a list of all the highway proprties.
605 ++++++++++++++++++++++++++++++++++++++*/
606
607 const char *PropertyList(void)
608 {
609 return " paved = Paved (suitable for normal wheels)\n"
610 " multilane = Multiple lanes\n"
611 " bridge = Bridge\n"
612 " tunnel = Tunnel\n"
613 " footroute = A route marked for foot travel\n"
614 " bicycleroute = A route marked for bicycle travel\n"
615 ;
616 }

Properties

Name Value
cvs:description Move the type checking/printing functions from way.c to type.c.