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 213 - (hide annotations) (download) (as text)
Thu Jul 2 16:33:31 2009 UTC (15 years, 8 months ago) by amb
File MIME type: text/x-csrc
File size: 9046 byte(s)
Removed unused header files, change assert statements, tidy some code.

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

Properties

Name Value
cvs:description Functions for ways.