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 1989 - (hide annotations) (download) (as text)
Wed Apr 17 17:54:45 2019 UTC (5 years, 11 months ago) by amb
File MIME type: text/x-chdr
File size: 5354 byte(s)
Rename some structure members and function names to reflect more
clearly their meaning (mostly change "allow" to "transport").  No
changes to file formats or API.

1 amb 21 /***************************************
2     A header file for the ways.
3 amb 151
4     Part of the Routino routing software.
5 amb 21 ******************/ /******************
6 amb 1989 This file Copyright 2008-2016, 2019 Andrew M. Bishop
7 amb 21
8 amb 151 This program is free software: you can redistribute it and/or modify
9     it under the terms of the GNU Affero General Public License as published by
10     the Free Software Foundation, either version 3 of the License, or
11     (at your option) any later version.
12    
13     This program is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16     GNU Affero General Public License for more details.
17    
18     You should have received a copy of the GNU Affero General Public License
19     along with this program. If not, see <http://www.gnu.org/licenses/>.
20 amb 21 ***************************************/
21    
22    
23     #ifndef WAYS_H
24     #define WAYS_H /*+ To stop multiple inclusions. +*/
25    
26     #include <stdint.h>
27 amb 460 #include <stdlib.h>
28 amb 21
29 amb 109 #include "types.h"
30 amb 21
31 amb 1292 #include "cache.h"
32 amb 460 #include "files.h"
33 amb 21
34 amb 460
35 amb 21 /* Data structures */
36    
37    
38 amb 298 /*+ A structure containing a single way (members ordered to minimise overall size). +*/
39 amb 109 struct _Way
40 amb 87 {
41 amb 529 index_t name; /*+ The offset of the name of the way in the names array. +*/
42 amb 87
43 amb 529 transports_t allow; /*+ The type of traffic allowed on the way. +*/
44 amb 296
45 amb 529 highway_t type; /*+ The highway type of the way. +*/
46 amb 109
47 amb 530 properties_t props; /*+ The properties of the way. +*/
48 amb 298
49 amb 529 speed_t speed; /*+ The defined maximum speed limit of the way. +*/
50 amb 135
51 amb 529 weight_t weight; /*+ The defined maximum weight of traffic on the way. +*/
52     height_t height; /*+ The defined maximum height of traffic on the way. +*/
53     width_t width; /*+ The defined maximum width of traffic on the way. +*/
54     length_t length; /*+ The defined maximum length of traffic on the way. +*/
55 amb 109 };
56    
57    
58 amb 460 /*+ A structure containing the header from the file. +*/
59     typedef struct _WaysFile
60 amb 21 {
61 amb 1103 index_t number; /*+ The number of ways. +*/
62 amb 87
63 amb 529 highways_t highways; /*+ The types of highways that were seen when parsing. +*/
64 amb 1989 transports_t transports; /*+ The types of traffic that were seen when parsing. +*/
65     properties_t properties; /*+ The properties that were seen when parsing. +*/
66 amb 460 }
67     WaysFile;
68 amb 87
69 amb 460
70     /*+ A structure containing a set of ways (and pointers to mmap file). +*/
71     struct _Ways
72     {
73     WaysFile file; /*+ The header data from the file. +*/
74    
75     #if !SLIM
76    
77 amb 1652 char *data; /*+ The memory mapped data. +*/
78 amb 460
79 amb 307 Way *ways; /*+ An array of ways. +*/
80     char *names; /*+ An array of characters containing the names. +*/
81    
82 amb 460 #else
83    
84     int fd; /*+ The file descriptor for the file. +*/
85 amb 1741 offset_t namesoffset; /*+ The offset of the names within the file. +*/
86 amb 460
87 amb 924 Way cached[3]; /*+ Two cached nodes read from the file in slim mode. +*/
88 amb 460
89 amb 924 char *ncached[3]; /*+ The cached way name. +*/
90 amb 460
91 amb 1292 WayCache *cache; /*+ A RAM cache of ways read from the file. +*/
92    
93 amb 460 #endif
94 amb 109 };
95 amb 21
96    
97 amb 680 /* Functions in ways.c */
98 amb 21
99 amb 460 Ways *LoadWayList(const char *filename);
100 amb 21
101 amb 1312 void DestroyWayList(Ways *ways);
102    
103 amb 1078 int WaysCompare(Way *way1p,Way *way2p);
104 amb 460
105    
106     /* Macros and inline functions */
107    
108     #if !SLIM
109    
110 amb 109 /*+ Return a Way* pointer given a set of ways and an index. +*/
111 amb 460 #define LookupWay(xxx,yyy,zzz) (&(xxx)->ways[yyy])
112 amb 21
113 amb 474 /*+ Return the name of a way given the Way pointer and a set of ways. +*/
114     #define WayName(xxx,yyy) (&(xxx)->names[(yyy)->name])
115 amb 21
116 amb 460 #else
117 amb 411
118 amb 1296 static inline Way *LookupWay(Ways *ways,index_t index,int position);
119 amb 411
120 amb 1296 static inline char *WayName(Ways *ways,Way *wayp);
121 amb 21
122 amb 1296 CACHE_NEWCACHE_PROTO(Way)
123     CACHE_DELETECACHE_PROTO(Way)
124     CACHE_FETCHCACHE_PROTO(Way)
125     CACHE_INVALIDATECACHE_PROTO(Way)
126 amb 21
127 amb 1739 /* Data type */
128 amb 1296
129 amb 1739 CACHE_STRUCTURE(Way)
130    
131 amb 1296 /* Inline functions */
132    
133     CACHE_NEWCACHE(Way)
134     CACHE_DELETECACHE(Way)
135     CACHE_FETCHCACHE(Way)
136     CACHE_INVALIDATECACHE(Way)
137    
138    
139 amb 460 /*++++++++++++++++++++++++++++++++++++++
140     Find the Way information for a particular way.
141 amb 32
142 amb 460 Way *LookupWay Returns a pointer to the cached way information.
143 amb 181
144 amb 680 Ways *ways The set of ways to use.
145 amb 460
146     index_t index The index of the way.
147    
148     int position The position in the cache to store the value.
149     ++++++++++++++++++++++++++++++++++++++*/
150    
151     static inline Way *LookupWay(Ways *ways,index_t index,int position)
152     {
153 amb 1293 ways->cached[position-1]=*FetchCachedWay(ways->cache,index,ways->fd,sizeof(WaysFile));
154 amb 460
155 amb 564 return(&ways->cached[position-1]);
156 amb 460 }
157    
158    
159     /*++++++++++++++++++++++++++++++++++++++
160     Find the name of a way.
161    
162 amb 474 char *WayName Returns a pointer to the name of the way.
163 amb 460
164 amb 680 Ways *ways The set of ways to use.
165 amb 460
166 amb 1078 Way *wayp The Way pointer.
167 amb 460 ++++++++++++++++++++++++++++++++++++++*/
168    
169 amb 1078 static inline char *WayName(Ways *ways,Way *wayp)
170 amb 460 {
171 amb 1863 int position=(int)(wayp-ways->cached);
172 amb 460 int n=0;
173    
174 amb 1863 if(!ways->ncached[position])
175     ways->ncached[position]=(char*)malloc(64);
176 amb 460
177 amb 1863 while(!SlimFetch(ways->fd,ways->ncached[position]+n,64,ways->namesoffset+wayp->name+n))
178 amb 460 {
179     int i;
180    
181 amb 1416 for(i=n;i<n+64;i++)
182 amb 1863 if(ways->ncached[position][i]==0)
183 amb 1419 goto exitloop;
184 amb 460
185 amb 1416 n+=64;
186 amb 460
187 amb 1863 ways->ncached[position]=(char*)realloc((void*)ways->ncached[position],n+64);
188 amb 460 }
189    
190 amb 1419 exitloop:
191    
192 amb 1863 return(ways->ncached[position]);
193 amb 460 }
194    
195     #endif
196    
197    
198 amb 21 #endif /* WAYS_H */

Properties

Name Value
cvs:description Header file for ways.