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