Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Annotation of /trunk/src/ways.h
Parent Directory
|
Revision Log
Revision 887 -
(hide annotations)
(download)
(as text)
Mon Oct 31 19:09:40 2011 UTC (13 years, 5 months ago) by amb
File MIME type: text/x-chdr
File size: 5218 byte(s)
Mon Oct 31 19:09:40 2011 UTC (13 years, 5 months ago) by amb
File MIME type: text/x-chdr
File size: 5218 byte(s)
Use pread() and pwrite() functions instead of seek() followed by read() or write().
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 | 680 | This file Copyright 2008-2011 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 | 460 | #include "files.h" |
32 | amb | 21 | |
33 | amb | 460 | |
34 | amb | 21 | /* Data structures */ |
35 | |||
36 | |||
37 | amb | 298 | /*+ A structure containing a single way (members ordered to minimise overall size). +*/ |
38 | amb | 109 | struct _Way |
39 | amb | 87 | { |
40 | amb | 529 | index_t name; /*+ The offset of the name of the way in the names array. +*/ |
41 | amb | 87 | |
42 | amb | 529 | transports_t allow; /*+ The type of traffic allowed on the way. +*/ |
43 | amb | 296 | |
44 | amb | 529 | highway_t type; /*+ The highway type of the way. +*/ |
45 | amb | 109 | |
46 | amb | 530 | properties_t props; /*+ The properties of the way. +*/ |
47 | amb | 298 | |
48 | amb | 529 | speed_t speed; /*+ The defined maximum speed limit of the way. +*/ |
49 | amb | 135 | |
50 | amb | 529 | 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 | amb | 109 | }; |
55 | |||
56 | |||
57 | amb | 460 | /*+ A structure containing the header from the file. +*/ |
58 | typedef struct _WaysFile | ||
59 | amb | 21 | { |
60 | amb | 680 | index_t number; /*+ The number of ways stored. +*/ |
61 | index_t onumber; /*+ The number of ways originally. +*/ | ||
62 | amb | 87 | |
63 | amb | 529 | 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 | amb | 530 | properties_t props; /*+ 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 | void *data; /*+ The memory mapped data. +*/ | ||
78 | |||
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 | off_t namesoffset; /*+ The offset of the names within the file. +*/ | ||
86 | |||
87 | amb | 680 | Way cached[2]; /*+ Two cached nodes read from the file in slim mode. +*/ |
88 | amb | 564 | index_t incache[2]; /*+ The indexes of the cached ways. +*/ |
89 | amb | 460 | |
90 | char *ncached; /*+ The cached way name. +*/ | ||
91 | int nalloc; /*+ The amount of memory allocated for the way name. +*/ | ||
92 | |||
93 | #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 | 460 | int WaysCompare(Way *way1,Way *way2); |
102 | |||
103 | |||
104 | /* Macros and inline functions */ | ||
105 | |||
106 | #if !SLIM | ||
107 | |||
108 | amb | 109 | /*+ Return a Way* pointer given a set of ways and an index. +*/ |
109 | amb | 460 | #define LookupWay(xxx,yyy,zzz) (&(xxx)->ways[yyy]) |
110 | amb | 21 | |
111 | amb | 474 | /*+ Return the name of a way given the Way pointer and a set of ways. +*/ |
112 | #define WayName(xxx,yyy) (&(xxx)->names[(yyy)->name]) | ||
113 | amb | 21 | |
114 | amb | 460 | #else |
115 | amb | 411 | |
116 | amb | 460 | static Way *LookupWay(Ways *ways,index_t index,int position); |
117 | amb | 411 | |
118 | amb | 474 | static char *WayName(Ways *ways,Way *way); |
119 | amb | 21 | |
120 | |||
121 | amb | 460 | /*++++++++++++++++++++++++++++++++++++++ |
122 | Find the Way information for a particular way. | ||
123 | amb | 32 | |
124 | amb | 460 | Way *LookupWay Returns a pointer to the cached way information. |
125 | amb | 181 | |
126 | amb | 680 | Ways *ways The set of ways to use. |
127 | amb | 460 | |
128 | index_t index The index of the way. | ||
129 | |||
130 | int position The position in the cache to store the value. | ||
131 | ++++++++++++++++++++++++++++++++++++++*/ | ||
132 | |||
133 | static inline Way *LookupWay(Ways *ways,index_t index,int position) | ||
134 | { | ||
135 | amb | 564 | if(ways->incache[position-1]!=index) |
136 | { | ||
137 | amb | 887 | SeekReadFile(ways->fd,&ways->cached[position-1],sizeof(Way),sizeof(WaysFile)+(off_t)index*sizeof(Way)); |
138 | amb | 460 | |
139 | amb | 564 | ways->incache[position-1]=index; |
140 | } | ||
141 | |||
142 | return(&ways->cached[position-1]); | ||
143 | amb | 460 | } |
144 | |||
145 | |||
146 | /*++++++++++++++++++++++++++++++++++++++ | ||
147 | Find the name of a way. | ||
148 | |||
149 | amb | 474 | char *WayName Returns a pointer to the name of the way. |
150 | amb | 460 | |
151 | amb | 680 | Ways *ways The set of ways to use. |
152 | amb | 460 | |
153 | Way *way The Way pointer. | ||
154 | ++++++++++++++++++++++++++++++++++++++*/ | ||
155 | |||
156 | amb | 474 | static inline char *WayName(Ways *ways,Way *way) |
157 | amb | 460 | { |
158 | int n=0; | ||
159 | |||
160 | SeekFile(ways->fd,ways->namesoffset+way->name); | ||
161 | |||
162 | if(!ways->ncached) | ||
163 | ways->ncached=(char*)malloc(32); | ||
164 | |||
165 | while(1) | ||
166 | { | ||
167 | int i; | ||
168 | int m=ReadFile(ways->fd,ways->ncached+n,32); | ||
169 | |||
170 | if(m<0) | ||
171 | break; | ||
172 | |||
173 | for(i=n;i<n+32;i++) | ||
174 | if(ways->ncached[i]==0) | ||
175 | goto exitloop; | ||
176 | |||
177 | n+=32; | ||
178 | |||
179 | ways->ncached=(char*)realloc((void*)ways->ncached,n+32); | ||
180 | } | ||
181 | |||
182 | exitloop: | ||
183 | |||
184 | return(ways->ncached); | ||
185 | } | ||
186 | |||
187 | #endif | ||
188 | |||
189 | |||
190 | amb | 21 | #endif /* WAYS_H */ |
Properties
Name | Value |
---|---|
cvs:description | Header file for ways. |