Routino SVN Repository Browser

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

ViewVC logotype

Contents of /trunk/src/ways.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1293 - (show annotations) (download) (as text)
Fri May 3 18:13:22 2013 UTC (11 years, 11 months ago) by amb
File MIME type: text/x-chdr
File size: 5102 byte(s)
Tidy up the code for the last check-in and use macros to allow replication of
the functions for each type.

1 /***************************************
2 A header file for the ways.
3
4 Part of the Routino routing software.
5 ******************/ /******************
6 This file Copyright 2008-2013 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
45 highway_t type; /*+ The highway type of the way. +*/
46
47 properties_t props; /*+ The properties of the way. +*/
48
49 speed_t speed; /*+ The defined maximum speed limit of the way. +*/
50
51 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 };
56
57
58 /*+ A structure containing the header from the file. +*/
59 typedef struct _WaysFile
60 {
61 index_t number; /*+ The number of ways. +*/
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[3]; /*+ Two cached nodes read from the file in slim mode. +*/
88
89 char *ncached[3]; /*+ The cached way name. +*/
90
91 WayCache *cache; /*+ A RAM cache of ways read from the file. +*/
92
93 #endif
94 };
95
96
97 /* Functions in ways.c */
98
99 Ways *LoadWayList(const char *filename);
100
101 int WaysCompare(Way *way1p,Way *way2p);
102
103
104 /* Macros and inline functions */
105
106 #if !SLIM
107
108 /*+ Return a Way* pointer given a set of ways and an index. +*/
109 #define LookupWay(xxx,yyy,zzz) (&(xxx)->ways[yyy])
110
111 /*+ 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
114 #else
115
116 static Way *LookupWay(Ways *ways,index_t index,int position);
117
118 static char *WayName(Ways *ways,Way *wayp);
119
120
121 /*++++++++++++++++++++++++++++++++++++++
122 Find the Way information for a particular way.
123
124 Way *LookupWay Returns a pointer to the cached way information.
125
126 Ways *ways The set of ways to use.
127
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 ways->cached[position-1]=*FetchCachedWay(ways->cache,index,ways->fd,sizeof(WaysFile));
136
137 return(&ways->cached[position-1]);
138 }
139
140
141 /*++++++++++++++++++++++++++++++++++++++
142 Find the name of a way.
143
144 char *WayName Returns a pointer to the name of the way.
145
146 Ways *ways The set of ways to use.
147
148 Way *wayp The Way pointer.
149 ++++++++++++++++++++++++++++++++++++++*/
150
151 static inline char *WayName(Ways *ways,Way *wayp)
152 {
153 int position=wayp-&ways->cached[-1];
154
155 int n=0;
156
157 SeekFile(ways->fd,ways->namesoffset+wayp->name);
158
159 if(!ways->ncached[position-1])
160 ways->ncached[position-1]=(char*)malloc(32);
161
162 while(1)
163 {
164 int i;
165 int m=ReadFile(ways->fd,ways->ncached[position-1]+n,32);
166
167 if(m<0)
168 break;
169
170 for(i=n;i<n+32;i++)
171 if(ways->ncached[position-1][i]==0)
172 goto exitloop;
173
174 n+=32;
175
176 ways->ncached[position-1]=(char*)realloc((void*)ways->ncached[position-1],n+32);
177 }
178
179 exitloop:
180
181 return(ways->ncached[position-1]);
182 }
183
184 #endif
185
186
187 #endif /* WAYS_H */

Properties

Name Value
cvs:description Header file for ways.