Routino SVN Repository Browser

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

ViewVC logotype

Contents of /branches/destination-access/src/ways.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1867 - (show annotations) (download) (as text)
Sat Mar 5 14:34:32 2016 UTC (9 years ago) by amb
File MIME type: text/x-chdr
File size: 5459 byte(s)
Update for version 3.1 release.

1 /***************************************
2 A header file for the ways.
3
4 Part of the Routino routing software.
5 ******************/ /******************
6 This file Copyright 2008-2016 Andrew M. Bishop
7
8 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 ***************************************/
21
22
23 #ifndef WAYS_H
24 #define WAYS_H /*+ To stop multiple inclusions. +*/
25
26 #include <stdint.h>
27 #include <stdlib.h>
28
29 #include "types.h"
30
31 #include "cache.h"
32 #include "files.h"
33
34
35 /* Data structures */
36
37
38 /*+ A structure containing a single way (members ordered to minimise overall size). +*/
39 struct _Way
40 {
41 index_t name; /*+ The offset of the name of the way in the names array. +*/
42
43 transports_t allow; /*+ The type of traffic allowed on the way. +*/
44 transports_t destination; /*+ The type of traffic allowed on the way - only for access to waypoints. +*/
45
46 highway_t type; /*+ The highway type of the way. +*/
47
48 properties_t props; /*+ The properties of the way. +*/
49
50 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 };
57
58
59 /*+ A structure containing the header from the file. +*/
60 typedef struct _WaysFile
61 {
62 index_t number; /*+ The number of ways. +*/
63
64 highways_t highways; /*+ The types of highways that were seen when parsing. +*/
65 transports_t allow; /*+ The types of traffic that were seen when parsing. +*/
66 properties_t props; /*+ The properties that were seen when parsing. +*/
67 }
68 WaysFile;
69
70
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 char *data; /*+ The memory mapped data. +*/
79
80 Way *ways; /*+ An array of ways. +*/
81 char *names; /*+ An array of characters containing the names. +*/
82
83 #else
84
85 int fd; /*+ The file descriptor for the file. +*/
86 offset_t namesoffset; /*+ The offset of the names within the file. +*/
87
88 Way cached[3]; /*+ Two cached nodes read from the file in slim mode. +*/
89
90 char *ncached[3]; /*+ The cached way name. +*/
91
92 WayCache *cache; /*+ A RAM cache of ways read from the file. +*/
93
94 #endif
95 };
96
97
98 /* Functions in ways.c */
99
100 Ways *LoadWayList(const char *filename);
101
102 void DestroyWayList(Ways *ways);
103
104 int WaysCompare(Way *way1p,Way *way2p);
105
106
107 /* Macros and inline functions */
108
109 #if !SLIM
110
111 /*+ Return a Way* pointer given a set of ways and an index. +*/
112 #define LookupWay(xxx,yyy,zzz) (&(xxx)->ways[yyy])
113
114 /*+ Return the name of a way given the Way pointer and a set of ways. +*/
115 #define WayName(xxx,yyy) (&(xxx)->names[(yyy)->name])
116
117 #else
118
119 static inline Way *LookupWay(Ways *ways,index_t index,int position);
120
121 static inline char *WayName(Ways *ways,Way *wayp);
122
123 CACHE_NEWCACHE_PROTO(Way)
124 CACHE_DELETECACHE_PROTO(Way)
125 CACHE_FETCHCACHE_PROTO(Way)
126 CACHE_INVALIDATECACHE_PROTO(Way)
127
128 /* Data type */
129
130 CACHE_STRUCTURE(Way)
131
132 /* Inline functions */
133
134 CACHE_NEWCACHE(Way)
135 CACHE_DELETECACHE(Way)
136 CACHE_FETCHCACHE(Way)
137 CACHE_INVALIDATECACHE(Way)
138
139
140 /*++++++++++++++++++++++++++++++++++++++
141 Find the Way information for a particular way.
142
143 Way *LookupWay Returns a pointer to the cached way information.
144
145 Ways *ways The set of ways to use.
146
147 index_t index The index of the way.
148
149 int position The position in the cache to store the value.
150 ++++++++++++++++++++++++++++++++++++++*/
151
152 static inline Way *LookupWay(Ways *ways,index_t index,int position)
153 {
154 ways->cached[position-1]=*FetchCachedWay(ways->cache,index,ways->fd,sizeof(WaysFile));
155
156 return(&ways->cached[position-1]);
157 }
158
159
160 /*++++++++++++++++++++++++++++++++++++++
161 Find the name of a way.
162
163 char *WayName Returns a pointer to the name of the way.
164
165 Ways *ways The set of ways to use.
166
167 Way *wayp The Way pointer.
168 ++++++++++++++++++++++++++++++++++++++*/
169
170 static inline char *WayName(Ways *ways,Way *wayp)
171 {
172 int position=(int)(wayp-ways->cached);
173 int n=0;
174
175 if(!ways->ncached[position])
176 ways->ncached[position]=(char*)malloc(64);
177
178 while(!SlimFetch(ways->fd,ways->ncached[position]+n,64,ways->namesoffset+wayp->name+n))
179 {
180 int i;
181
182 for(i=n;i<n+64;i++)
183 if(ways->ncached[position][i]==0)
184 goto exitloop;
185
186 n+=64;
187
188 ways->ncached[position]=(char*)realloc((void*)ways->ncached[position],n+64);
189 }
190
191 exitloop:
192
193 return(ways->ncached[position]);
194 }
195
196 #endif
197
198
199 #endif /* WAYS_H */

Properties

Name Value
cvs:description Header file for ways.