Imported Upstream version 1.5.1
[routino] / src / types.c
1 /***************************************
2  $Header: /home/amb/routino/src/RCS/types.c,v 1.6 2010/09/17 17:43:41 amb Exp $
3
4  Functions for handling the data types.
5
6  Part of the Routino routing software.
7  ******************/ /******************
8  This file Copyright 2008-2010 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 <string.h>
26
27 #include "types.h"
28
29
30 /*++++++++++++++++++++++++++++++++++++++
31   Decide on the type of a way given the "highway" parameter.
32
33   Highway HighwayType Returns the highway type of the way.
34
35   const char *highway The string containing the type of the way.
36   ++++++++++++++++++++++++++++++++++++++*/
37
38 Highway HighwayType(const char *highway)
39 {
40  switch(*highway)
41    {
42    case 'c':
43     if(!strcmp(highway,"cycleway")) return(Way_Cycleway);
44     return(Way_Count);
45
46    case 'f':
47     if(!strcmp(highway,"ferry")) return(Way_Ferry);
48     return(Way_Count);
49
50    case 'm':
51     if(!strcmp(highway,"motorway")) return(Way_Motorway);
52     return(Way_Count);
53
54    case 'p':
55     if(!strcmp(highway,"primary")) return(Way_Primary);
56     if(!strcmp(highway,"path")) return(Way_Path);
57     return(Way_Count);
58
59    case 'r':
60     if(!strcmp(highway,"residential")) return(Way_Residential);
61     return(Way_Count);
62
63    case 's':
64     if(!strcmp(highway,"secondary")) return(Way_Secondary);
65     if(!strcmp(highway,"service")) return(Way_Service);
66     if(!strcmp(highway,"steps")) return(Way_Steps);
67     return(Way_Count);
68
69    case 't':
70     if(!strcmp(highway,"trunk")) return(Way_Trunk);
71     if(!strcmp(highway,"tertiary")) return(Way_Tertiary);
72     if(!strcmp(highway,"track")) return(Way_Track);
73     return(Way_Count);
74
75    case 'u':
76     if(!strcmp(highway,"unclassified")) return(Way_Unclassified);
77     return(Way_Count);
78
79    default:
80     ;
81    }
82
83  return(Way_Count);
84 }
85
86
87 /*++++++++++++++++++++++++++++++++++++++
88   Decide on the type of transport given the name of it.
89
90   Transport TransportType Returns the type of the transport.
91
92   const char *transport The string containing the method of transport.
93   ++++++++++++++++++++++++++++++++++++++*/
94
95 Transport TransportType(const char *transport)
96 {
97  switch(*transport)
98    {
99    case 'b':
100     if(!strcmp(transport,"bicycle"))
101        return(Transport_Bicycle);
102     break;
103
104    case 'f':
105     if(!strcmp(transport,"foot"))
106        return(Transport_Foot);
107     break;
108
109    case 'g':
110     if(!strcmp(transport,"goods"))
111        return(Transport_Goods);
112     break;
113
114    case 'h':
115     if(!strcmp(transport,"horse"))
116        return(Transport_Horse);
117     if(!strcmp(transport,"hgv"))
118        return(Transport_HGV);
119     break;
120
121    case 'm':
122     if(!strcmp(transport,"moped"))
123        return(Transport_Moped);
124     if(!strcmp(transport,"motorbike"))
125        return(Transport_Motorbike);
126     if(!strcmp(transport,"motorcar"))
127        return(Transport_Motorcar);
128     break;
129
130    case 'p':
131     if(!strcmp(transport,"psv"))
132        return(Transport_PSV);
133     break;
134
135    case 'w':
136     if(!strcmp(transport,"wheelchair"))
137        return(Transport_Wheelchair);
138     break;
139
140    default:
141     return(Transport_None);
142    }
143
144  return(Transport_None);
145 }
146
147
148 /*++++++++++++++++++++++++++++++++++++++
149   Decide on the type of property given the name of it.
150
151   Property PropertyType Returns the type of the property.
152
153   const char *property The string containing the method of property.
154   ++++++++++++++++++++++++++++++++++++++*/
155
156 Property PropertyType(const char *property)
157 {
158  switch(*property)
159    {
160    case 'b':
161     if(!strcmp(property,"bicycleroute"))
162        return(Property_BicycleRoute);
163
164     if(!strcmp(property,"bridge"))
165        return(Property_Bridge);
166     break;
167
168    case 'f':
169     if(!strcmp(property,"footroute"))
170        return(Property_FootRoute);
171     break;
172
173    case 'm':
174     if(!strcmp(property,"multilane"))
175        return(Property_Multilane);
176     break;
177
178    case 'p':
179     if(!strcmp(property,"paved"))
180        return(Property_Paved);
181     break;
182
183    case 't':
184     if(!strcmp(property,"tunnel"))
185        return(Property_Tunnel);
186     break;
187
188    default:
189     return(Property_None);
190    }
191
192  return(Property_None);
193 }
194
195
196 /*++++++++++++++++++++++++++++++++++++++
197   A string containing the name of a type of highway.
198
199   const char *HighwayName Returns the name.
200
201   Highway highway The highway type.
202   ++++++++++++++++++++++++++++++++++++++*/
203
204 const char *HighwayName(Highway highway)
205 {
206  switch(highway)
207    {
208    case Way_Motorway:
209     return("motorway");
210    case Way_Trunk:
211     return("trunk");
212    case Way_Primary:
213     return("primary");
214    case Way_Secondary:
215     return("secondary");
216    case Way_Tertiary:
217     return("tertiary");
218    case Way_Unclassified:
219     return("unclassified");
220    case Way_Residential:
221     return("residential");
222    case Way_Service:
223     return("service");
224    case Way_Track:
225     return("track");
226    case Way_Cycleway:
227     return("cycleway");
228    case Way_Path:
229     return("path");
230    case Way_Steps:
231     return("steps");
232    case Way_Ferry:
233     return("ferry");
234
235    case Way_Count:
236     ;
237
238    case Way_OneWay:
239    case Way_Roundabout:
240     ;
241    }
242
243  return(NULL);
244 }
245
246
247 /*++++++++++++++++++++++++++++++++++++++
248   A string containing the name of a type of transport.
249
250   const char *TransportName Returns the name.
251
252   Transport transport The transport type.
253   ++++++++++++++++++++++++++++++++++++++*/
254
255 const char *TransportName(Transport transport)
256 {
257  switch(transport)
258    {
259    case Transport_None:
260     return("NONE");
261
262    case Transport_Foot:
263     return("foot");
264    case Transport_Horse:
265     return("horse");
266    case Transport_Wheelchair:
267     return("wheelchair");
268    case Transport_Bicycle:
269     return("bicycle");
270    case Transport_Moped:
271     return("moped");
272    case Transport_Motorbike:
273     return("motorbike");
274    case Transport_Motorcar:
275     return("motorcar");
276    case Transport_Goods:
277     return("goods");
278    case Transport_HGV:
279     return("hgv");
280    case Transport_PSV:
281     return("psv");
282
283    case Transport_Count:
284     ;
285   }
286
287  return(NULL);
288 }
289
290
291 /*++++++++++++++++++++++++++++++++++++++
292   A string containing the name of a highway property.
293
294   const char *PropertyName Returns the name.
295
296   Property property The property type.
297   ++++++++++++++++++++++++++++++++++++++*/
298
299 const char *PropertyName(Property property)
300 {
301  switch(property)
302    {
303    case Property_None:
304     return("NONE");
305
306    case Property_Paved:
307     return("paved");
308
309    case Property_Multilane:
310     return("multilane");
311
312    case Property_Bridge:
313     return("bridge");
314
315    case Property_Tunnel:
316     return("tunnel");
317
318    case Property_FootRoute:
319     return("footroute");
320
321    case Property_BicycleRoute:
322     return("bicycleroute");
323
324    case Property_Count:
325     ;
326   }
327
328  return(NULL);
329 }
330
331
332 /*++++++++++++++++++++++++++++++++++++++
333   A string containing the names of allowed transports on a way.
334
335   const char *AllowedNameList Returns the list of names.
336
337   allow_t allowed The allowed type.
338   ++++++++++++++++++++++++++++++++++++++*/
339
340 const char *AllowedNameList(allow_t allowed)
341 {
342  static char string[256];
343
344  string[0]=0;
345
346  if(allowed & Allow_Foot)
347     strcat(string,"foot");
348
349  if(allowed & Allow_Horse)
350    {
351     if(*string) strcat(string,", ");
352     strcat(string,"horse");
353    }
354
355  if(allowed & Allow_Wheelchair)
356    {
357     if(*string) strcat(string,", ");
358     strcat(string,"wheelchair");
359    }
360
361  if(allowed & Allow_Bicycle)
362    {
363     if(*string) strcat(string,", ");
364     strcat(string,"bicycle");
365    }
366
367  if(allowed & Allow_Moped)
368    {
369     if(*string) strcat(string,", ");
370     strcat(string,"moped");
371    }
372
373  if(allowed & Allow_Motorbike)
374    {
375     if(*string) strcat(string,", ");
376     strcat(string,"motorbike");
377    }
378
379  if(allowed & Allow_Motorcar)
380    {
381     if(*string) strcat(string,", ");
382     strcat(string,"motorcar");
383    }
384
385  if(allowed & Allow_Goods)
386    {
387     if(*string) strcat(string,", ");
388     strcat(string,"goods");
389    }
390
391  if(allowed & Allow_HGV)
392    {
393     if(*string) strcat(string,", ");
394     strcat(string,"hgv");
395    }
396
397  if(allowed & Allow_PSV)
398    {
399     if(*string) strcat(string,", ");
400     strcat(string,"psv");
401    }
402
403  return(string);
404 }
405
406
407 /*++++++++++++++++++++++++++++++++++++++
408   A string containing the names of the properties of a way.
409
410   const char *PropertiesNameList Returns the list of names.
411
412   wayprop_t properties The properties of the way.
413   ++++++++++++++++++++++++++++++++++++++*/
414
415 const char *PropertiesNameList(wayprop_t properties)
416 {
417  static char string[256];
418
419  string[0]=0;
420
421  if(properties & Properties_Paved)
422    {
423     if(*string) strcat(string,", ");
424     strcat(string,"paved");
425    }
426
427  if(properties & Properties_Multilane)
428    {
429     if(*string) strcat(string,", ");
430     strcat(string,"multilane");
431    }
432
433  if(properties & Properties_Bridge)
434    {
435     if(*string) strcat(string,", ");
436     strcat(string,"bridge");
437    }
438
439  if(properties & Properties_Tunnel)
440    {
441     if(*string) strcat(string,", ");
442     strcat(string,"tunnel");
443    }
444
445  if(properties & Properties_FootRoute)
446    {
447     if(*string) strcat(string,", ");
448     strcat(string,"footroute");
449    }
450
451  if(properties & Properties_BicycleRoute)
452    {
453     if(*string) strcat(string,", ");
454     strcat(string,"bicycleroute");
455    }
456
457  return(string);
458 }
459
460
461 /*++++++++++++++++++++++++++++++++++++++
462   Returns a list of all the highway types.
463
464   const char *HighwayList Return a list of all the highway types.
465   ++++++++++++++++++++++++++++++++++++++*/
466
467 const char *HighwayList(void)
468 {
469  return "    motorway     = Motorway\n"
470         "    trunk        = Trunk\n"
471         "    primary      = Primary\n"
472         "    secondary    = Secondary\n"
473         "    tertiary     = Tertiary\n"
474         "    unclassified = Unclassified\n"
475         "    residential  = Residential\n"
476         "    service      = Service\n"
477         "    track        = Track\n"
478         "    cycleway     = Cycleway\n"
479         "    path         = Path\n"
480         "    steps        = Steps\n"
481         "    ferry        = Ferry\n"
482         ;
483 }
484
485
486 /*++++++++++++++++++++++++++++++++++++++
487   Returns a list of all the transport types.
488
489   const char *TransportList Return a list of all the transport types.
490   ++++++++++++++++++++++++++++++++++++++*/
491
492 const char *TransportList(void)
493 {
494  return "    foot       = Foot\n"
495         "    bicycle    = Bicycle\n"
496         "    wheelchair = Wheelchair\n"
497         "    horse      = Horse\n"
498         "    moped      = Moped     (Small motorbike, limited speed)\n"
499         "    motorbike  = Motorbike\n"
500         "    motorcar   = Motorcar\n"
501         "    goods      = Goods     (Small lorry, van)\n"
502         "    hgv        = HGV       (Heavy Goods Vehicle - large lorry)\n"
503         "    psv        = PSV       (Public Service Vehicle - bus, coach)\n"
504         ;
505 }
506
507
508 /*++++++++++++++++++++++++++++++++++++++
509   Returns a list of all the property types.
510
511   const char *PropertyList Return a list of all the highway proprties.
512   ++++++++++++++++++++++++++++++++++++++*/
513
514 const char *PropertyList(void)
515 {
516  return "    paved        = Paved (suitable for normal wheels)\n"
517         "    multilane    = Multiple lanes\n"
518         "    bridge       = Bridge\n"
519         "    tunnel       = Tunnel\n"
520         "    footroute    = A route marked for foot travel\n"
521         "    bicycleroute = A route marked for bicycle travel\n"
522         ;
523 }