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 528 -
(show annotations)
(download)
(as text)
Sat Nov 27 11:27:44 2010 UTC (14 years, 3 months ago) by amb
File MIME type: text/x-chdr
File size: 5259 byte(s)
Sat Nov 27 11:27:44 2010 UTC (14 years, 3 months ago) by amb
File MIME type: text/x-chdr
File size: 5259 byte(s)
Change the waytype_t type into highway_t.
1 | /*************************************** |
2 | $Header: /home/amb/CVS/routino/src/ways.h,v 1.44 2010-11-27 11:27:44 amb Exp $ |
3 | |
4 | A header file for the ways. |
5 | |
6 | Part of the Routino routing software. |
7 | ******************/ /****************** |
8 | This file Copyright 2008-2010 Andrew M. Bishop |
9 | |
10 | 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 | ***************************************/ |
23 | |
24 | |
25 | #ifndef WAYS_H |
26 | #define WAYS_H /*+ To stop multiple inclusions. +*/ |
27 | |
28 | #include <stdint.h> |
29 | #include <stdlib.h> |
30 | |
31 | #include "types.h" |
32 | |
33 | #include "files.h" |
34 | |
35 | |
36 | /* Data structures */ |
37 | |
38 | |
39 | /*+ A structure containing a single way (members ordered to minimise overall size). +*/ |
40 | struct _Way |
41 | { |
42 | index_t name; /*+ The offset of the name of the way in the names array. +*/ |
43 | |
44 | allow_t allow; /*+ The type of traffic allowed on the way. +*/ |
45 | |
46 | highway_t type; /*+ The highway type of the way. +*/ |
47 | |
48 | wayprop_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; /*+ How many ways are stored? +*/ |
63 | index_t onumber; /*+ How many ways were there originally? +*/ |
64 | |
65 | highways_t highways; /*+ The types of highways that were seen when parsing. +*/ |
66 | allow_t allow; /*+ The types of traffic that were seen when parsing. +*/ |
67 | wayprop_t props; /*+ The properties that were seen when parsing. +*/ |
68 | } |
69 | WaysFile; |
70 | |
71 | |
72 | /*+ A structure containing a set of ways (and pointers to mmap file). +*/ |
73 | struct _Ways |
74 | { |
75 | WaysFile file; /*+ The header data from the file. +*/ |
76 | |
77 | #if !SLIM |
78 | |
79 | void *data; /*+ The memory mapped data. +*/ |
80 | |
81 | Way *ways; /*+ An array of ways. +*/ |
82 | char *names; /*+ An array of characters containing the names. +*/ |
83 | |
84 | #else |
85 | |
86 | int fd; /*+ The file descriptor for the file. +*/ |
87 | off_t namesoffset; /*+ The offset of the names within the file. +*/ |
88 | |
89 | Way wcached[2]; /*+ The cached ways. +*/ |
90 | |
91 | char *ncached; /*+ The cached way name. +*/ |
92 | index_t nincache; /*+ The index of the cached way name. +*/ |
93 | int nalloc; /*+ The amount of memory allocated for the way name. +*/ |
94 | |
95 | #endif |
96 | }; |
97 | |
98 | |
99 | /* Functions */ |
100 | |
101 | Ways *LoadWayList(const char *filename); |
102 | |
103 | int WaysCompare(Way *way1,Way *way2); |
104 | |
105 | |
106 | /* Macros and inline functions */ |
107 | |
108 | #if !SLIM |
109 | |
110 | /*+ Return a Way* pointer given a set of ways and an index. +*/ |
111 | #define LookupWay(xxx,yyy,zzz) (&(xxx)->ways[yyy]) |
112 | |
113 | /*+ 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 | |
116 | #else |
117 | |
118 | static Way *LookupWay(Ways *ways,index_t index,int position); |
119 | |
120 | static char *WayName(Ways *ways,Way *way); |
121 | |
122 | |
123 | /*++++++++++++++++++++++++++++++++++++++ |
124 | Find the Way information for a particular way. |
125 | |
126 | Way *LookupWay Returns a pointer to the cached way information. |
127 | |
128 | Ways *ways The ways structure to use. |
129 | |
130 | index_t index The index of the way. |
131 | |
132 | int position The position in the cache to store the value. |
133 | ++++++++++++++++++++++++++++++++++++++*/ |
134 | |
135 | static inline Way *LookupWay(Ways *ways,index_t index,int position) |
136 | { |
137 | SeekFile(ways->fd,sizeof(WaysFile)+(off_t)index*sizeof(Way)); |
138 | |
139 | ReadFile(ways->fd,&ways->wcached[position-1],sizeof(Way)); |
140 | |
141 | return(&ways->wcached[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 ways structure to use. |
151 | |
152 | Way *way The Way pointer. |
153 | ++++++++++++++++++++++++++++++++++++++*/ |
154 | |
155 | static inline char *WayName(Ways *ways,Way *way) |
156 | { |
157 | int n=0; |
158 | |
159 | if(way->name==ways->nincache) |
160 | return(ways->ncached); |
161 | |
162 | SeekFile(ways->fd,ways->namesoffset+way->name); |
163 | |
164 | if(!ways->ncached) |
165 | ways->ncached=(char*)malloc(32); |
166 | |
167 | while(1) |
168 | { |
169 | int i; |
170 | int m=ReadFile(ways->fd,ways->ncached+n,32); |
171 | |
172 | if(m<0) |
173 | break; |
174 | |
175 | for(i=n;i<n+32;i++) |
176 | if(ways->ncached[i]==0) |
177 | goto exitloop; |
178 | |
179 | n+=32; |
180 | |
181 | ways->ncached=(char*)realloc((void*)ways->ncached,n+32); |
182 | } |
183 | |
184 | exitloop: |
185 | |
186 | return(ways->ncached); |
187 | } |
188 | |
189 | #endif |
190 | |
191 | |
192 | #endif /* WAYS_H */ |
Properties
Name | Value |
---|---|
cvs:description | Header file for ways. |