Routino SVN Repository Browser

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

ViewVC logotype

Contents of /trunk/src/ways.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 213 - (show 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 /***************************************
2 $Header: /home/amb/CVS/routino/src/ways.c,v 1.31 2009-07-02 16:33:31 amb Exp $
3
4 Way data type functions.
5
6 Part of the Routino routing software.
7 ******************/ /******************
8 This file Copyright 2008,2009 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 <stdlib.h>
26 #include <string.h>
27
28 #include "functions.h"
29 #include "ways.h"
30
31
32 /*++++++++++++++++++++++++++++++++++++++
33 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 void *data;
43 Ways *ways;
44
45 ways=(Ways*)malloc(sizeof(Ways));
46
47 data=MapFile(filename);
48
49 if(!data)
50 return(NULL);
51
52 /* 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 }
64
65
66 /*++++++++++++++++++++++++++++++++++++++
67 Decide on the type of a way given the "highway" parameter.
68
69 Highway HighwayType Returns the highway type of the way.
70
71 const char *highway The string containing the type of the way.
72 ++++++++++++++++++++++++++++++++++++++*/
73
74 Highway HighwayType(const char *highway)
75 {
76 switch(*highway)
77 {
78 case 'b':
79 if(!strcmp(highway,"byway")) return(Way_Track);
80 if(!strcmp(highway,"bridleway")) return(Way_Bridleway);
81 return(Way_Unknown);
82
83 case 'c':
84 if(!strcmp(highway,"cycleway")) return(Way_Cycleway);
85 return(Way_Unknown);
86
87 case 'f':
88 if(!strcmp(highway,"footway")) return(Way_Footway);
89 return(Way_Unknown);
90
91 case 'l':
92 if(!strcmp(highway,"living_street")) return(Way_Residential);
93 return(Way_Unknown);
94
95 case 'm':
96 if(!strncmp(highway,"motorway",8)) return(Way_Motorway);
97 if(!strcmp(highway,"minor")) return(Way_Unclassified);
98 return(Way_Unknown);
99
100 case 'p':
101 if(!strncmp(highway,"primary",7)) return(Way_Primary);
102 if(!strcmp(highway,"path")) return(Way_Path);
103 if(!strcmp(highway,"pedestrian")) return(Way_Footway);
104 return(Way_Unknown);
105
106 case 'r':
107 if(!strcmp(highway,"road")) return(Way_Unclassified);
108 if(!strcmp(highway,"residential")) return(Way_Residential);
109 return(Way_Unknown);
110
111 case 's':
112 if(!strncmp(highway,"secondary",9)) return(Way_Secondary);
113 if(!strcmp(highway,"service")) return(Way_Service);
114 if(!strcmp(highway,"services")) return(Way_Service);
115 if(!strcmp(highway,"steps")) return(Way_Footway);
116 return(Way_Unknown);
117
118 case 't':
119 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 return(Way_Unknown);
123
124 case 'u':
125 if(!strcmp(highway,"unclassified")) return(Way_Unclassified);
126 if(!strcmp(highway,"unsurfaced")) return(Way_Track);
127 if(!strcmp(highway,"unpaved")) return(Way_Track);
128 return(Way_Unknown);
129
130 case 'w':
131 if(!strcmp(highway,"walkway")) return(Way_Footway);
132 return(Way_Unknown);
133
134 default:
135 ;
136 }
137
138 return(Way_Unknown);
139 }
140
141
142 /*++++++++++++++++++++++++++++++++++++++
143 Decide on the allowed type of transport given the name of it.
144
145 Transport TransportType Returns the type of the transport.
146
147 const char *transport The string containing the method of transport.
148 ++++++++++++++++++++++++++++++++++++++*/
149
150 Transport TransportType(const char *transport)
151 {
152 switch(*transport)
153 {
154 case 'b':
155 if(!strcmp(transport,"bicycle"))
156 return(Transport_Bicycle);
157 break;
158
159 case 'f':
160 if(!strcmp(transport,"foot"))
161 return(Transport_Foot);
162 break;
163
164 case 'g':
165 if(!strcmp(transport,"goods"))
166 return(Transport_Goods);
167 break;
168
169 case 'h':
170 if(!strcmp(transport,"horse"))
171 return(Transport_Horse);
172 if(!strcmp(transport,"hgv"))
173 return(Transport_HGV);
174 break;
175
176 case 'm':
177 if(!strcmp(transport,"motorbike"))
178 return(Transport_Motorbike);
179 if(!strcmp(transport,"motorcar"))
180 return(Transport_Motorcar);
181 break;
182
183 case 'p':
184 if(!strcmp(transport,"psv"))
185 return(Transport_PSV);
186 break;
187
188 default:
189 return(Transport_None);
190 }
191
192 return(Transport_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_Path:
227 return("path");
228 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 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 return " motorway = Motorway\n"
290 " trunk = Trunk\n"
291 " primary = Primary\n"
292 " secondary = Secondary\n"
293 " tertiary = Tertiary\n"
294 " unclassified = Unclassified\n"
295 " residential = Residential\n"
296 " service = Service\n"
297 " track = Track\n"
298 " path = Path\n"
299 " bridleway = Bridleway\n"
300 " cycleway = Cycleway\n"
301 " footway = Footway\n";
302 }
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 return " foot = Foot\n"
314 " bicycle = Bicycle\n"
315 " horse = Horse\n"
316 " motorbike = Motorbike\n"
317 " 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 }
322
323
324 /*++++++++++++++++++++++++++++++++++++++
325 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
328 int WaysCompare Returns a comparison.
329
330 Way *way1 The first way.
331
332 Way *way2 The second way.
333 ++++++++++++++++++++++++++++++++++++++*/
334
335 int WaysCompare(Way *way1,Way *way2)
336 {
337 if(way1==way2)
338 return(0);
339
340 if(way1->type!=way2->type)
341 return((int)way1->type - (int)way2->type);
342
343 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 return(0);
362 }

Properties

Name Value
cvs:description Functions for ways.