Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Annotation of /trunk/src/types.c
Parent Directory
|
Revision Log
Revision 364 -
(hide annotations)
(download)
(as text)
Mon Apr 12 16:41:47 2010 UTC (14 years, 11 months ago) by amb
File MIME type: text/x-csrc
File size: 11644 byte(s)
Mon Apr 12 16:41:47 2010 UTC (14 years, 11 months ago) by amb
File MIME type: text/x-csrc
File size: 11644 byte(s)
Initial revision
1 | amb | 364 | /*************************************** |
2 | $Header: /home/amb/CVS/routino/src/types.c,v 1.1 2010-04-12 16:41:47 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 'b': | ||
43 | if(!strcmp(highway,"byway")) return(Way_Track); | ||
44 | if(!strcmp(highway,"bridleway")) return(Way_Path); | ||
45 | return(Way_Count); | ||
46 | |||
47 | case 'c': | ||
48 | if(!strcmp(highway,"cycleway")) return(Way_Cycleway); | ||
49 | return(Way_Count); | ||
50 | |||
51 | case 'f': | ||
52 | if(!strcmp(highway,"footway")) return(Way_Path); | ||
53 | return(Way_Count); | ||
54 | |||
55 | case 'l': | ||
56 | if(!strcmp(highway,"living_street")) return(Way_Residential); | ||
57 | return(Way_Count); | ||
58 | |||
59 | case 'm': | ||
60 | if(!strncmp(highway,"motorway",8)) return(Way_Motorway); | ||
61 | if(!strcmp(highway,"minor")) return(Way_Unclassified); | ||
62 | return(Way_Count); | ||
63 | |||
64 | case 'p': | ||
65 | if(!strncmp(highway,"primary",7)) return(Way_Primary); | ||
66 | if(!strcmp(highway,"path")) return(Way_Path); | ||
67 | if(!strcmp(highway,"pedestrian")) return(Way_Path); | ||
68 | return(Way_Count); | ||
69 | |||
70 | case 'r': | ||
71 | if(!strcmp(highway,"road")) return(Way_Unclassified); | ||
72 | if(!strcmp(highway,"residential")) return(Way_Residential); | ||
73 | return(Way_Count); | ||
74 | |||
75 | case 's': | ||
76 | if(!strncmp(highway,"secondary",9)) return(Way_Secondary); | ||
77 | if(!strcmp(highway,"service")) return(Way_Service); | ||
78 | if(!strcmp(highway,"services")) return(Way_Service); | ||
79 | if(!strcmp(highway,"steps")) return(Way_Steps); | ||
80 | return(Way_Count); | ||
81 | |||
82 | case 't': | ||
83 | if(!strncmp(highway,"trunk",5)) return(Way_Trunk); | ||
84 | if(!strcmp(highway,"tertiary")) return(Way_Tertiary); | ||
85 | if(!strcmp(highway,"track")) return(Way_Track); | ||
86 | return(Way_Count); | ||
87 | |||
88 | case 'u': | ||
89 | if(!strcmp(highway,"unclassified")) return(Way_Unclassified); | ||
90 | if(!strcmp(highway,"unsurfaced")) return(Way_Track); | ||
91 | if(!strcmp(highway,"unpaved")) return(Way_Track); | ||
92 | return(Way_Count); | ||
93 | |||
94 | case 'w': | ||
95 | if(!strcmp(highway,"walkway")) return(Way_Path); | ||
96 | return(Way_Count); | ||
97 | |||
98 | default: | ||
99 | ; | ||
100 | } | ||
101 | |||
102 | return(Way_Count); | ||
103 | } | ||
104 | |||
105 | |||
106 | /*++++++++++++++++++++++++++++++++++++++ | ||
107 | Decide on the type of transport given the name of it. | ||
108 | |||
109 | Transport TransportType Returns the type of the transport. | ||
110 | |||
111 | const char *transport The string containing the method of transport. | ||
112 | ++++++++++++++++++++++++++++++++++++++*/ | ||
113 | |||
114 | Transport TransportType(const char *transport) | ||
115 | { | ||
116 | switch(*transport) | ||
117 | { | ||
118 | case 'b': | ||
119 | if(!strcmp(transport,"bicycle")) | ||
120 | return(Transport_Bicycle); | ||
121 | break; | ||
122 | |||
123 | case 'f': | ||
124 | if(!strcmp(transport,"foot")) | ||
125 | return(Transport_Foot); | ||
126 | break; | ||
127 | |||
128 | case 'g': | ||
129 | if(!strcmp(transport,"goods")) | ||
130 | return(Transport_Goods); | ||
131 | break; | ||
132 | |||
133 | case 'h': | ||
134 | if(!strcmp(transport,"horse")) | ||
135 | return(Transport_Horse); | ||
136 | if(!strcmp(transport,"hgv")) | ||
137 | return(Transport_HGV); | ||
138 | break; | ||
139 | |||
140 | case 'm': | ||
141 | if(!strcmp(transport,"moped")) | ||
142 | return(Transport_Moped); | ||
143 | if(!strcmp(transport,"motorbike")) | ||
144 | return(Transport_Motorbike); | ||
145 | if(!strcmp(transport,"motorcar")) | ||
146 | return(Transport_Motorcar); | ||
147 | break; | ||
148 | |||
149 | case 'p': | ||
150 | if(!strcmp(transport,"psv")) | ||
151 | return(Transport_PSV); | ||
152 | break; | ||
153 | |||
154 | case 'w': | ||
155 | if(!strcmp(transport,"wheelchair")) | ||
156 | return(Transport_Wheelchair); | ||
157 | break; | ||
158 | |||
159 | default: | ||
160 | return(Transport_None); | ||
161 | } | ||
162 | |||
163 | return(Transport_None); | ||
164 | } | ||
165 | |||
166 | |||
167 | /*++++++++++++++++++++++++++++++++++++++ | ||
168 | Decide on the type of property given the name of it. | ||
169 | |||
170 | Property PropertyType Returns the type of the property. | ||
171 | |||
172 | const char *property The string containing the method of property. | ||
173 | ++++++++++++++++++++++++++++++++++++++*/ | ||
174 | |||
175 | Property PropertyType(const char *property) | ||
176 | { | ||
177 | switch(*property) | ||
178 | { | ||
179 | case 'b': | ||
180 | if(!strcmp(property,"bridge")) | ||
181 | return(Property_Bridge); | ||
182 | break; | ||
183 | |||
184 | case 'm': | ||
185 | if(!strcmp(property,"multilane")) | ||
186 | return(Property_Multilane); | ||
187 | break; | ||
188 | |||
189 | case 'p': | ||
190 | if(!strcmp(property,"paved")) | ||
191 | return(Property_Paved); | ||
192 | break; | ||
193 | |||
194 | case 't': | ||
195 | if(!strcmp(property,"tunnel")) | ||
196 | return(Property_Tunnel); | ||
197 | break; | ||
198 | |||
199 | default: | ||
200 | return(Property_None); | ||
201 | } | ||
202 | |||
203 | return(Property_None); | ||
204 | } | ||
205 | |||
206 | |||
207 | /*++++++++++++++++++++++++++++++++++++++ | ||
208 | A string containing the name of a type of highway. | ||
209 | |||
210 | const char *HighwayName Returns the name. | ||
211 | |||
212 | Highway highway The highway type. | ||
213 | ++++++++++++++++++++++++++++++++++++++*/ | ||
214 | |||
215 | const char *HighwayName(Highway highway) | ||
216 | { | ||
217 | switch(highway) | ||
218 | { | ||
219 | case Way_Motorway: | ||
220 | return("motorway"); | ||
221 | case Way_Trunk: | ||
222 | return("trunk"); | ||
223 | case Way_Primary: | ||
224 | return("primary"); | ||
225 | case Way_Secondary: | ||
226 | return("secondary"); | ||
227 | case Way_Tertiary: | ||
228 | return("tertiary"); | ||
229 | case Way_Unclassified: | ||
230 | return("unclassified"); | ||
231 | case Way_Residential: | ||
232 | return("residential"); | ||
233 | case Way_Service: | ||
234 | return("service"); | ||
235 | case Way_Track: | ||
236 | return("track"); | ||
237 | case Way_Cycleway: | ||
238 | return("cycleway"); | ||
239 | case Way_Path: | ||
240 | return("path"); | ||
241 | case Way_Steps: | ||
242 | return("steps"); | ||
243 | |||
244 | case Way_Count: | ||
245 | ; | ||
246 | |||
247 | case Way_OneWay: | ||
248 | case Way_Roundabout: | ||
249 | ; | ||
250 | } | ||
251 | |||
252 | return(NULL); | ||
253 | } | ||
254 | |||
255 | |||
256 | /*++++++++++++++++++++++++++++++++++++++ | ||
257 | A string containing the name of a type of transport. | ||
258 | |||
259 | const char *TransportName Returns the name. | ||
260 | |||
261 | Transport transport The transport type. | ||
262 | ++++++++++++++++++++++++++++++++++++++*/ | ||
263 | |||
264 | const char *TransportName(Transport transport) | ||
265 | { | ||
266 | switch(transport) | ||
267 | { | ||
268 | case Transport_None: | ||
269 | return("NONE"); | ||
270 | |||
271 | case Transport_Foot: | ||
272 | return("foot"); | ||
273 | case Transport_Horse: | ||
274 | return("horse"); | ||
275 | case Transport_Wheelchair: | ||
276 | return("wheelchair"); | ||
277 | case Transport_Bicycle: | ||
278 | return("bicycle"); | ||
279 | case Transport_Moped: | ||
280 | return("moped"); | ||
281 | case Transport_Motorbike: | ||
282 | return("motorbike"); | ||
283 | case Transport_Motorcar: | ||
284 | return("motorcar"); | ||
285 | case Transport_Goods: | ||
286 | return("goods"); | ||
287 | case Transport_HGV: | ||
288 | return("hgv"); | ||
289 | case Transport_PSV: | ||
290 | return("psv"); | ||
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_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 | wayallow_t allowed The allowed type. | ||
338 | ++++++++++++++++++++++++++++++++++++++*/ | ||
339 | |||
340 | const char *AllowedNameList(wayallow_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 | return(string); | ||
446 | } | ||
447 | |||
448 | |||
449 | /*++++++++++++++++++++++++++++++++++++++ | ||
450 | Returns a list of all the highway types. | ||
451 | |||
452 | const char *HighwayList Return a list of all the highway types. | ||
453 | ++++++++++++++++++++++++++++++++++++++*/ | ||
454 | |||
455 | const char *HighwayList(void) | ||
456 | { | ||
457 | return " motorway = Motorway\n" | ||
458 | " trunk = Trunk\n" | ||
459 | " primary = Primary\n" | ||
460 | " secondary = Secondary\n" | ||
461 | " tertiary = Tertiary\n" | ||
462 | " unclassified = Unclassified\n" | ||
463 | " residential = Residential\n" | ||
464 | " service = Service\n" | ||
465 | " track = Track\n" | ||
466 | " cycleway = Cycleway\n" | ||
467 | " path = Path\n" | ||
468 | " steps = Steps\n" | ||
469 | ; | ||
470 | } | ||
471 | |||
472 | |||
473 | /*++++++++++++++++++++++++++++++++++++++ | ||
474 | Returns a list of all the transport types. | ||
475 | |||
476 | const char *TransportList Return a list of all the transport types. | ||
477 | ++++++++++++++++++++++++++++++++++++++*/ | ||
478 | |||
479 | const char *TransportList(void) | ||
480 | { | ||
481 | return " foot = Foot\n" | ||
482 | " bicycle = Bicycle\n" | ||
483 | " wheelchair = Wheelchair\n" | ||
484 | " horse = Horse\n" | ||
485 | " moped = Moped (Small motorbike, limited speed)\n" | ||
486 | " motorbike = Motorbike\n" | ||
487 | " motorcar = Motorcar\n" | ||
488 | " goods = Goods (Small lorry, van)\n" | ||
489 | " hgv = HGV (Heavy Goods Vehicle - large lorry)\n" | ||
490 | " psv = PSV (Public Service Vehicle - bus, coach)\n" | ||
491 | ; | ||
492 | } | ||
493 | |||
494 | |||
495 | /*++++++++++++++++++++++++++++++++++++++ | ||
496 | Returns a list of all the property types. | ||
497 | |||
498 | const char *PropertyList Return a list of all the highway proprties. | ||
499 | ++++++++++++++++++++++++++++++++++++++*/ | ||
500 | |||
501 | const char *PropertyList(void) | ||
502 | { | ||
503 | return " paved = Paved (suitable for normal wheels)\n" | ||
504 | " multilane = Multiple lanes\n" | ||
505 | " bridge = Bridge\n" | ||
506 | " Tunnel = Tunnel\n" | ||
507 | ; | ||
508 | } |
Properties
Name | Value |
---|---|
cvs:description | Move the type checking/printing functions from way.c to type.c. |