Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Contents of /trunk/src/ways.h
Parent Directory
|
Revision Log
Revision 921 -
(show annotations)
(download)
(as text)
Sat Nov 26 15:09:51 2011 UTC (13 years, 3 months ago) by amb
File MIME type: text/x-chdr
File size: 5251 byte(s)
Sat Nov 26 15:09:51 2011 UTC (13 years, 3 months ago) by amb
File MIME type: text/x-chdr
File size: 5251 byte(s)
Allow space to cache one name for each cached way (in slim mode).
1 | /*************************************** |
2 | A header file for the ways. |
3 | |
4 | Part of the Routino routing software. |
5 | ******************/ /****************** |
6 | This file Copyright 2008-2011 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 "files.h" |
32 | |
33 | |
34 | /* Data structures */ |
35 | |
36 | |
37 | /*+ A structure containing a single way (members ordered to minimise overall size). +*/ |
38 | struct _Way |
39 | { |
40 | index_t name; /*+ The offset of the name of the way in the names array. +*/ |
41 | |
42 | transports_t allow; /*+ The type of traffic allowed on the way. +*/ |
43 | |
44 | highway_t type; /*+ The highway type of the way. +*/ |
45 | |
46 | properties_t props; /*+ The properties of the way. +*/ |
47 | |
48 | speed_t speed; /*+ The defined maximum speed limit of the way. +*/ |
49 | |
50 | weight_t weight; /*+ The defined maximum weight of traffic on the way. +*/ |
51 | height_t height; /*+ The defined maximum height of traffic on the way. +*/ |
52 | width_t width; /*+ The defined maximum width of traffic on the way. +*/ |
53 | length_t length; /*+ The defined maximum length of traffic on the way. +*/ |
54 | }; |
55 | |
56 | |
57 | /*+ A structure containing the header from the file. +*/ |
58 | typedef struct _WaysFile |
59 | { |
60 | index_t number; /*+ The number of ways stored. +*/ |
61 | index_t onumber; /*+ The number of ways originally. +*/ |
62 | |
63 | highways_t highways; /*+ The types of highways that were seen when parsing. +*/ |
64 | transports_t allow; /*+ The types of traffic that were seen when parsing. +*/ |
65 | properties_t props; /*+ The properties that were seen when parsing. +*/ |
66 | } |
67 | WaysFile; |
68 | |
69 | |
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 | void *data; /*+ The memory mapped data. +*/ |
78 | |
79 | Way *ways; /*+ An array of ways. +*/ |
80 | char *names; /*+ An array of characters containing the names. +*/ |
81 | |
82 | #else |
83 | |
84 | int fd; /*+ The file descriptor for the file. +*/ |
85 | off_t namesoffset; /*+ The offset of the names within the file. +*/ |
86 | |
87 | Way cached[2]; /*+ Two cached nodes read from the file in slim mode. +*/ |
88 | index_t incache[2]; /*+ The indexes of the cached ways. +*/ |
89 | |
90 | char *ncached[2]; /*+ The cached way name. +*/ |
91 | |
92 | #endif |
93 | }; |
94 | |
95 | |
96 | /* Functions in ways.c */ |
97 | |
98 | Ways *LoadWayList(const char *filename); |
99 | |
100 | int WaysCompare(Way *way1,Way *way2); |
101 | |
102 | |
103 | /* Macros and inline functions */ |
104 | |
105 | #if !SLIM |
106 | |
107 | /*+ Return a Way* pointer given a set of ways and an index. +*/ |
108 | #define LookupWay(xxx,yyy,zzz) (&(xxx)->ways[yyy]) |
109 | |
110 | /*+ Return the name of a way given the Way pointer and a set of ways. +*/ |
111 | #define WayName(xxx,yyy) (&(xxx)->names[(yyy)->name]) |
112 | |
113 | #else |
114 | |
115 | static Way *LookupWay(Ways *ways,index_t index,int position); |
116 | |
117 | static char *WayName(Ways *ways,Way *way); |
118 | |
119 | |
120 | /*++++++++++++++++++++++++++++++++++++++ |
121 | Find the Way information for a particular way. |
122 | |
123 | Way *LookupWay Returns a pointer to the cached way information. |
124 | |
125 | Ways *ways The set of ways to use. |
126 | |
127 | index_t index The index of the way. |
128 | |
129 | int position The position in the cache to store the value. |
130 | ++++++++++++++++++++++++++++++++++++++*/ |
131 | |
132 | static inline Way *LookupWay(Ways *ways,index_t index,int position) |
133 | { |
134 | if(ways->incache[position-1]!=index) |
135 | { |
136 | SeekReadFile(ways->fd,&ways->cached[position-1],sizeof(Way),sizeof(WaysFile)+(off_t)index*sizeof(Way)); |
137 | |
138 | ways->incache[position-1]=index; |
139 | } |
140 | |
141 | return(&ways->cached[position-1]); |
142 | } |
143 | |
144 | |
145 | /*++++++++++++++++++++++++++++++++++++++ |
146 | Find the name of a way. |
147 | |
148 | char *WayName Returns a pointer to the name of the way. |
149 | |
150 | Ways *ways The set of ways to use. |
151 | |
152 | Way *way The Way pointer. |
153 | ++++++++++++++++++++++++++++++++++++++*/ |
154 | |
155 | static inline char *WayName(Ways *ways,Way *way) |
156 | { |
157 | int position=way-&ways->cached[-1]; |
158 | |
159 | int n=0; |
160 | |
161 | SeekFile(ways->fd,ways->namesoffset+way->name); |
162 | |
163 | if(!ways->ncached[position-1]) |
164 | ways->ncached[position-1]=(char*)malloc(32); |
165 | |
166 | while(1) |
167 | { |
168 | int i; |
169 | int m=ReadFile(ways->fd,ways->ncached[position-1]+n,32); |
170 | |
171 | if(m<0) |
172 | break; |
173 | |
174 | for(i=n;i<n+32;i++) |
175 | if(ways->ncached[position-1][i]==0) |
176 | goto exitloop; |
177 | |
178 | n+=32; |
179 | |
180 | ways->ncached[position-1]=(char*)realloc((void*)ways->ncached[position-1],n+32); |
181 | } |
182 | |
183 | exitloop: |
184 | |
185 | return(ways->ncached[position-1]); |
186 | } |
187 | |
188 | #endif |
189 | |
190 | |
191 | #endif /* WAYS_H */ |
Properties
Name | Value |
---|---|
cvs:description | Header file for ways. |