Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Annotation of /trunk/src/ways.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 296 - (hide annotations) (download) (as text)
Tue Oct 27 17:31:44 2009 UTC (15 years, 4 months ago) by amb
File MIME type: text/x-csrc
File size: 9082 byte(s)
Added Moped to the list of transports (and incidentally increased the transport
data type to 16 bits and re-ordered the Way data-type in response).

1 amb 7 /***************************************
2 amb 296 $Header: /home/amb/CVS/routino/src/ways.c,v 1.35 2009-10-27 17:31:44 amb Exp $
3 amb 7
4     Way data type functions.
5 amb 157
6     Part of the Routino routing software.
7 amb 7 ******************/ /******************
8 amb 157 This file Copyright 2008,2009 Andrew M. Bishop
9 amb 7
10 amb 157 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 amb 7 ***************************************/
23    
24    
25 amb 214 #include <sys/types.h>
26 amb 7 #include <stdlib.h>
27     #include <string.h>
28    
29     #include "functions.h"
30 amb 20 #include "ways.h"
31 amb 7
32    
33     /*++++++++++++++++++++++++++++++++++++++
34 amb 20 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 amb 87 void *data;
44     Ways *ways;
45    
46     ways=(Ways*)malloc(sizeof(Ways));
47    
48     data=MapFile(filename);
49    
50 amb 100 if(!data)
51     return(NULL);
52    
53 amb 87 /* 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 amb 20 }
65    
66    
67     /*++++++++++++++++++++++++++++++++++++++
68 amb 30 Decide on the type of a way given the "highway" parameter.
69    
70 amb 74 Highway HighwayType Returns the highway type of the way.
71 amb 30
72 amb 74 const char *highway The string containing the type of the way.
73 amb 30 ++++++++++++++++++++++++++++++++++++++*/
74    
75 amb 74 Highway HighwayType(const char *highway)
76 amb 30 {
77 amb 74 switch(*highway)
78 amb 30 {
79     case 'b':
80 amb 74 if(!strcmp(highway,"byway")) return(Way_Track);
81 amb 293 if(!strcmp(highway,"bridleway")) return(Way_Path);
82 amb 30 return(Way_Unknown);
83    
84     case 'c':
85 amb 74 if(!strcmp(highway,"cycleway")) return(Way_Cycleway);
86 amb 30 return(Way_Unknown);
87    
88     case 'f':
89 amb 293 if(!strcmp(highway,"footway")) return(Way_Path);
90 amb 30 return(Way_Unknown);
91    
92 amb 135 case 'l':
93     if(!strcmp(highway,"living_street")) return(Way_Residential);
94     return(Way_Unknown);
95    
96 amb 30 case 'm':
97 amb 74 if(!strncmp(highway,"motorway",8)) return(Way_Motorway);
98 amb 85 if(!strcmp(highway,"minor")) return(Way_Unclassified);
99 amb 30 return(Way_Unknown);
100    
101     case 'p':
102 amb 74 if(!strncmp(highway,"primary",7)) return(Way_Primary);
103 amb 148 if(!strcmp(highway,"path")) return(Way_Path);
104 amb 293 if(!strcmp(highway,"pedestrian")) return(Way_Path);
105 amb 30 return(Way_Unknown);
106    
107     case 'r':
108 amb 85 if(!strcmp(highway,"road")) return(Way_Unclassified);
109 amb 74 if(!strcmp(highway,"residential")) return(Way_Residential);
110 amb 30 return(Way_Unknown);
111    
112     case 's':
113 amb 74 if(!strncmp(highway,"secondary",9)) return(Way_Secondary);
114     if(!strcmp(highway,"service")) return(Way_Service);
115 amb 135 if(!strcmp(highway,"services")) return(Way_Service);
116 amb 293 if(!strcmp(highway,"steps")) return(Way_Path);
117 amb 30 return(Way_Unknown);
118    
119     case 't':
120 amb 74 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 amb 30 return(Way_Unknown);
124    
125     case 'u':
126 amb 85 if(!strcmp(highway,"unclassified")) return(Way_Unclassified);
127 amb 74 if(!strcmp(highway,"unsurfaced")) return(Way_Track);
128     if(!strcmp(highway,"unpaved")) return(Way_Track);
129 amb 30 return(Way_Unknown);
130    
131     case 'w':
132 amb 293 if(!strcmp(highway,"walkway")) return(Way_Path);
133 amb 30 return(Way_Unknown);
134    
135     default:
136     ;
137     }
138    
139     return(Way_Unknown);
140     }
141 amb 54
142    
143     /*++++++++++++++++++++++++++++++++++++++
144     Decide on the allowed type of transport given the name of it.
145    
146 amb 74 Transport TransportType Returns the type of the transport.
147 amb 54
148     const char *transport The string containing the method of transport.
149     ++++++++++++++++++++++++++++++++++++++*/
150    
151 amb 74 Transport TransportType(const char *transport)
152 amb 54 {
153     switch(*transport)
154     {
155     case 'b':
156     if(!strcmp(transport,"bicycle"))
157 amb 74 return(Transport_Bicycle);
158 amb 54 break;
159    
160     case 'f':
161     if(!strcmp(transport,"foot"))
162 amb 74 return(Transport_Foot);
163 amb 54 break;
164    
165     case 'g':
166     if(!strcmp(transport,"goods"))
167 amb 74 return(Transport_Goods);
168 amb 54 break;
169    
170     case 'h':
171     if(!strcmp(transport,"horse"))
172 amb 74 return(Transport_Horse);
173 amb 54 if(!strcmp(transport,"hgv"))
174 amb 74 return(Transport_HGV);
175 amb 54 break;
176    
177     case 'm':
178 amb 296 if(!strcmp(transport,"moped"))
179     return(Transport_Moped);
180 amb 54 if(!strcmp(transport,"motorbike"))
181 amb 74 return(Transport_Motorbike);
182 amb 54 if(!strcmp(transport,"motorcar"))
183 amb 74 return(Transport_Motorcar);
184 amb 54 break;
185    
186     case 'p':
187     if(!strcmp(transport,"psv"))
188 amb 74 return(Transport_PSV);
189 amb 54 break;
190    
191     default:
192 amb 74 return(Transport_None);
193 amb 54 }
194    
195 amb 74 return(Transport_None);
196 amb 54 }
197 amb 63
198    
199     /*++++++++++++++++++++++++++++++++++++++
200 amb 82 A string containing the name of a type of highway.
201    
202     const char *HighwayName Returns the name.
203    
204     Highway highway The highway type.
205     ++++++++++++++++++++++++++++++++++++++*/
206    
207     const char *HighwayName(Highway highway)
208     {
209     switch(highway)
210     {
211     case Way_Motorway:
212     return("motorway");
213     case Way_Trunk:
214     return("trunk");
215     case Way_Primary:
216     return("primary");
217     case Way_Secondary:
218     return("secondary");
219     case Way_Tertiary:
220     return("tertiary");
221 amb 85 case Way_Unclassified:
222     return("unclassified");
223 amb 82 case Way_Residential:
224     return("residential");
225     case Way_Service:
226     return("service");
227     case Way_Track:
228     return("track");
229 amb 293 case Way_Cycleway:
230     return("cycleway");
231 amb 148 case Way_Path:
232     return("path");
233 amb 82
234     case Way_Unknown:
235     case Way_OneWay:
236     case Way_Roundabout:
237     return(NULL);
238     }
239    
240     return(NULL);
241     }
242    
243    
244     /*++++++++++++++++++++++++++++++++++++++
245     A string containing the name of a type of transport.
246    
247     const char *TransportName Returns the name.
248    
249     Transport transport The transport type.
250     ++++++++++++++++++++++++++++++++++++++*/
251    
252     const char *TransportName(Transport transport)
253     {
254     switch(transport)
255     {
256     case Transport_None:
257     return("NONE");
258    
259     case Transport_Foot:
260     return("foot");
261 amb 294 case Transport_Horse:
262     return("horse");
263 amb 82 case Transport_Bicycle:
264     return("bicycle");
265 amb 296 case Transport_Moped:
266     return("moped");
267 amb 82 case Transport_Motorbike:
268     return("motorbike");
269     case Transport_Motorcar:
270     return("motorcar");
271     case Transport_Goods:
272     return("goods");
273     case Transport_HGV:
274     return("hgv");
275     case Transport_PSV:
276     return("psv");
277     }
278     return(NULL);
279     }
280    
281    
282     /*++++++++++++++++++++++++++++++++++++++
283 amb 75 Returns a list of all the highway types.
284    
285     const char *HighwayList Return a list of all the highway types.
286     ++++++++++++++++++++++++++++++++++++++*/
287    
288     const char *HighwayList(void)
289     {
290 amb 87 return " motorway = Motorway\n"
291     " trunk = Trunk\n"
292     " primary = Primary\n"
293     " secondary = Secondary\n"
294     " tertiary = Tertiary\n"
295 amb 75 " unclassified = Unclassified\n"
296 amb 87 " residential = Residential\n"
297     " service = Service\n"
298     " track = Track\n"
299 amb 293 " cycleway = Cycleway\n"
300 amb 148 " path = Path\n"
301 amb 293 ;
302 amb 75 }
303    
304    
305     /*++++++++++++++++++++++++++++++++++++++
306     Returns a list of all the transport types.
307    
308     const char *TransportList Return a list of all the transport types.
309     ++++++++++++++++++++++++++++++++++++++*/
310    
311     const char *TransportList(void)
312     {
313 amb 87 return " foot = Foot\n"
314     " bicycle = Bicycle\n"
315     " horse = Horse\n"
316 amb 296 " moped = Moped (Small motorbike, limited speed)\n"
317 amb 75 " motorbike = Motorbike\n"
318 amb 87 " motorcar = Motorcar\n"
319     " goods = Goods (Small lorry, van)\n"
320     " hgv = HGV (Heavy Goods Vehicle - large lorry)\n"
321 amb 293 " psv = PSV (Public Service Vehicle - bus, coach)\n"
322     ;
323 amb 75 }
324 amb 181
325    
326     /*++++++++++++++++++++++++++++++++++++++
327 amb 201 Return 0 if the two ways are the same (in respect of their types and limits),
328     otherwise return positive or negative to allow sorting.
329 amb 181
330 amb 201 int WaysCompare Returns a comparison.
331 amb 181
332     Way *way1 The first way.
333    
334     Way *way2 The second way.
335     ++++++++++++++++++++++++++++++++++++++*/
336    
337 amb 201 int WaysCompare(Way *way1,Way *way2)
338 amb 181 {
339     if(way1==way2)
340 amb 201 return(0);
341 amb 181
342 amb 201 if(way1->type!=way2->type)
343     return((int)way1->type - (int)way2->type);
344 amb 181
345 amb 201 if(way1->allow!=way2->allow)
346     return((int)way1->allow - (int)way2->allow);
347    
348     if(way1->speed!=way2->speed)
349     return((int)way1->speed - (int)way2->speed);
350    
351     if(way1->weight!=way2->weight)
352     return((int)way1->weight - (int)way2->weight);
353    
354     if(way1->height!=way2->height)
355     return((int)way1->height - (int)way2->height);
356    
357     if(way1->width!=way2->width)
358     return((int)way1->width - (int)way2->width);
359    
360     if(way1->length!=way2->length)
361     return((int)way1->length - (int)way2->length);
362    
363 amb 181 return(0);
364     }

Properties

Name Value
cvs:description Functions for ways.