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.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 464 - (hide annotations) (download) (as text)
Sat Jul 31 14:06:56 2010 UTC (14 years, 8 months ago) by amb
File MIME type: text/x-chdr
File size: 5910 byte(s)
Ensure that seeking within a file uses a 64-bit offset.

1 amb 21 /***************************************
2 amb 464 $Header: /home/amb/CVS/routino/src/ways.h,v 1.39 2010-07-31 14:06:56 amb Exp $
3 amb 21
4     A header file for the ways.
5 amb 151
6     Part of the Routino routing software.
7 amb 21 ******************/ /******************
8 amb 365 This file Copyright 2008-2010 Andrew M. Bishop
9 amb 21
10 amb 151 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 21 ***************************************/
23    
24    
25     #ifndef WAYS_H
26     #define WAYS_H /*+ To stop multiple inclusions. +*/
27    
28     #include <stdint.h>
29 amb 460 #include <stdlib.h>
30 amb 21
31 amb 109 #include "types.h"
32 amb 21
33 amb 460 #include "files.h"
34 amb 21
35 amb 460
36 amb 21 /* Data structures */
37    
38    
39 amb 298 /*+ A structure containing a single way (members ordered to minimise overall size). +*/
40 amb 109 struct _Way
41 amb 87 {
42 amb 109 index_t name; /*+ The offset of the name of the way in the names array. +*/
43 amb 87
44 amb 296 wayallow_t allow; /*+ The type of traffic allowed on the way. +*/
45    
46 amb 298 waytype_t type; /*+ The highway type of the way. +*/
47 amb 109
48 amb 298 wayprop_t props; /*+ The properties of the way. +*/
49    
50 amb 135 speed_t speed; /*+ The defined maximum speed limit of the way. +*/
51    
52     weight_t weight; /*+ The defined maximum weight of traffic on the way. +*/
53     height_t height; /*+ The defined maximum height of traffic on the way. +*/
54     width_t width; /*+ The defined maximum width of traffic on the way. +*/
55     length_t length; /*+ The defined maximum length of traffic on the way. +*/
56 amb 109 };
57    
58    
59 amb 460 /*+ A structure containing the header from the file. +*/
60     typedef struct _WaysFile
61 amb 21 {
62 amb 307 uint32_t number; /*+ How many ways are stored? +*/
63     uint32_t onumber; /*+ How many ways were there originally? +*/
64 amb 87
65 amb 398 wayallow_t allow; /*+ The types of traffic that were seen when parsing. +*/
66     wayprop_t props; /*+ The properties that were seen when parsing. +*/
67 amb 460 }
68     WaysFile;
69 amb 87
70 amb 460
71     /*+ A structure containing a set of ways (and pointers to mmap file). +*/
72     struct _Ways
73     {
74     WaysFile file; /*+ The header data from the file. +*/
75    
76     #if !SLIM
77    
78     void *data; /*+ The memory mapped data. +*/
79    
80 amb 307 Way *ways; /*+ An array of ways. +*/
81     char *names; /*+ An array of characters containing the names. +*/
82    
83 amb 460 #else
84    
85     int fd; /*+ The file descriptor for the file. +*/
86     off_t namesoffset; /*+ The offset of the names within the file. +*/
87    
88     Way wcached[2]; /*+ The cached ways. +*/
89    
90     char *ncached; /*+ The cached way name. +*/
91     index_t nincache; /*+ The index of the cached way name. +*/
92     int nalloc; /*+ The amount of memory allocated for the way name. +*/
93    
94     #endif
95 amb 109 };
96 amb 21
97    
98 amb 460 /* Functions */
99 amb 21
100 amb 460 Ways *LoadWayList(const char *filename);
101 amb 21
102 amb 460 int WaysCompare(Way *way1,Way *way2);
103    
104    
105     /* Macros and inline functions */
106    
107     /*+ Return the name of a way if it has one or the name of the highway type otherwise. +*/
108     #define WayNameHighway(xxx,yyy) (WayNamed(xxx,yyy)?WayNameRaw(xxx,yyy):HighwayName(HIGHWAY(yyy->type)))
109    
110     #if !SLIM
111    
112 amb 109 /*+ Return a Way* pointer given a set of ways and an index. +*/
113 amb 460 #define LookupWay(xxx,yyy,zzz) (&(xxx)->ways[yyy])
114 amb 21
115 amb 411 /*+ Return the raw name of a way given the Way pointer and a set of ways. +*/
116     #define WayNameRaw(xxx,yyy) (&(xxx)->names[(yyy)->name])
117 amb 21
118 amb 411 /*+ Decide if a way has a name or not. +*/
119     #define WayNamed(xxx,yyy) ((xxx)->names[(yyy)->name])
120 amb 21
121 amb 460 #else
122 amb 411
123 amb 460 static Way *LookupWay(Ways *ways,index_t index,int position);
124 amb 411
125 amb 460 static char *WayNameRaw(Ways *ways,Way *way);
126 amb 21
127 amb 460 static int WayNamed(Ways *ways,Way *way);
128 amb 21
129    
130 amb 460 /*++++++++++++++++++++++++++++++++++++++
131     Find the Way information for a particular way.
132 amb 32
133 amb 460 Way *LookupWay Returns a pointer to the cached way information.
134 amb 181
135 amb 460 Ways *ways The ways structure to use.
136    
137     index_t index The index of the way.
138    
139     int position The position in the cache to store the value.
140     ++++++++++++++++++++++++++++++++++++++*/
141    
142     static inline Way *LookupWay(Ways *ways,index_t index,int position)
143     {
144 amb 464 SeekFile(ways->fd,sizeof(WaysFile)+(off_t)index*sizeof(Way));
145 amb 460
146     ReadFile(ways->fd,&ways->wcached[position-1],sizeof(Way));
147    
148     return(&ways->wcached[position-1]);
149     }
150    
151    
152     /*++++++++++++++++++++++++++++++++++++++
153     Find the name of a way.
154    
155     char *WayNameRaw Returns a pointer to the name of the way.
156    
157     Ways *ways The ways structure to use.
158    
159     Way *way The Way pointer.
160     ++++++++++++++++++++++++++++++++++++++*/
161    
162     static inline char *WayNameRaw(Ways *ways,Way *way)
163     {
164     int n=0;
165    
166     if(way->name==ways->nincache)
167     return(ways->ncached);
168    
169     SeekFile(ways->fd,ways->namesoffset+way->name);
170    
171     if(!ways->ncached)
172     ways->ncached=(char*)malloc(32);
173    
174     while(1)
175     {
176     int i;
177     int m=ReadFile(ways->fd,ways->ncached+n,32);
178    
179     if(m<0)
180     break;
181    
182     for(i=n;i<n+32;i++)
183     if(ways->ncached[i]==0)
184     goto exitloop;
185    
186     n+=32;
187    
188     ways->ncached=(char*)realloc((void*)ways->ncached,n+32);
189     }
190    
191     exitloop:
192    
193     return(ways->ncached);
194     }
195    
196    
197     /*++++++++++++++++++++++++++++++++++++++
198     Check if a way has a name.
199    
200     int WayNamed Returns a pointer to the name of the way.
201    
202     Ways *ways The ways structure to use.
203    
204     Way *way The Way pointer.
205     ++++++++++++++++++++++++++++++++++++++*/
206    
207     static inline int WayNamed(Ways *ways,Way *way)
208     {
209     if(way->name!=ways->nincache)
210     WayNameRaw(ways,way);
211    
212     return(ways->ncached[0]);
213     }
214    
215     #endif
216    
217    
218 amb 21 #endif /* WAYS_H */

Properties

Name Value
cvs:description Header file for ways.