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/segments.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, 10 months ago) by amb
File MIME type: text/x-chdr
File size: 7422 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 $Header: /home/amb/CVS/routino/src/segments.h,v 1.38 2010-12-21 17:18:41 amb Exp $
3
4 A header file for the segments.
5
6 Part of the Routino routing software.
7 ******************/ /******************
8 This file Copyright 2008-2013 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 SEGMENTS_H
26 #define SEGMENTS_H /*+ To stop multiple inclusions. +*/
27
28 #include <stdint.h>
29
30 #include "types.h"
31
32 #include "cache.h"
33 #include "files.h"
34 #include "profiles.h"
35
36
37 /* Data structures */
38
39
40 /*+ A structure containing a single segment. +*/
41 struct _Segment
42 {
43 index_t node1; /*+ The index of the starting node. +*/
44 index_t node2; /*+ The index of the finishing node. +*/
45
46 index_t next2; /*+ The index of the next segment sharing node2. +*/
47
48 index_t way; /*+ The index of the way associated with the segment. +*/
49
50 distance_t distance; /*+ The distance between the nodes. +*/
51 };
52
53
54 /*+ A structure containing the header from the file. +*/
55 typedef struct _SegmentsFile
56 {
57 index_t number; /*+ The number of segments in total. +*/
58 index_t snumber; /*+ The number of super-segments. +*/
59 index_t nnumber; /*+ The number of normal segments. +*/
60 }
61 SegmentsFile;
62
63
64 /*+ A structure containing a set of segments (and pointers to mmap file). +*/
65 struct _Segments
66 {
67 SegmentsFile file; /*+ The header data from the file. +*/
68
69 #if !SLIM
70
71 void *data; /*+ The memory mapped data. +*/
72
73 Segment *segments; /*+ An array of segments. +*/
74
75 #else
76
77 int fd; /*+ The file descriptor for the file. +*/
78
79 Segment cached[3]; /*+ Three cached segments read from the file in slim mode. +*/
80 index_t incache[3]; /*+ The indexes of the cached segments. +*/
81
82 SegmentCache *cache; /*+ A RAM cache of segments read from the file. +*/
83
84 #endif
85 };
86
87
88 /* Functions in segments.c */
89
90 Segments *LoadSegmentList(const char *filename);
91
92 index_t FindClosestSegmentHeading(Nodes *nodes,Segments *segments,Ways *ways,index_t node1,double heading,Profile *profile);
93
94 distance_t Distance(double lat1,double lon1,double lat2,double lon2);
95
96 duration_t Duration(Segment *segmentp,Way *wayp,Profile *profile);
97
98 double TurnAngle(Nodes *nodes,Segment *segment1p,Segment *segment2p,index_t node);
99 double BearingAngle(Nodes *nodes,Segment *segmentp,index_t node);
100
101
102 static inline Segment *NextSegment(Segments *segments,Segment *segmentp,index_t node);
103
104
105 /* Macros and inline functions */
106
107 /*+ Return true if this is a normal segment. +*/
108 #define IsNormalSegment(xxx) (((xxx)->distance)&SEGMENT_NORMAL)
109
110 /*+ Return true if this is a super-segment. +*/
111 #define IsSuperSegment(xxx) (((xxx)->distance)&SEGMENT_SUPER)
112
113 /*+ Return true if the segment is oneway. +*/
114 #define IsOneway(xxx) ((xxx)->distance&(ONEWAY_2TO1|ONEWAY_1TO2))
115
116 /*+ Return true if the segment is oneway towards the specified node. +*/
117 #define IsOnewayTo(xxx,yyy) ((xxx)->node1==(yyy)?((xxx)->distance&ONEWAY_2TO1):((xxx)->distance&ONEWAY_1TO2))
118
119 /*+ Return true if the segment is oneway from the specified node. +*/
120 #define IsOnewayFrom(xxx,yyy) ((xxx)->node2==(yyy)?((xxx)->distance&ONEWAY_2TO1):((xxx)->distance&ONEWAY_1TO2))
121
122 /*+ Return the other node in the segment that is not the specified node. +*/
123 #define OtherNode(xxx,yyy) ((xxx)->node1==(yyy)?(xxx)->node2:(xxx)->node1)
124
125 #if !SLIM
126
127 /*+ Return a segment pointer given a set of segments and an index. +*/
128 #define LookupSegment(xxx,yyy,ppp) (&(xxx)->segments[yyy])
129
130 /*+ Return a segment index given a set of segments and a pointer. +*/
131 #define IndexSegment(xxx,yyy) (index_t)((yyy)-&(xxx)->segments[0])
132
133
134 /*++++++++++++++++++++++++++++++++++++++
135 Find the next segment with a particular starting node.
136
137 Segment *NextSegment Returns a pointer to the next segment.
138
139 Segments *segments The set of segments to use.
140
141 Segment *segmentp The current segment.
142
143 index_t node The wanted node.
144 ++++++++++++++++++++++++++++++++++++++*/
145
146 static inline Segment *NextSegment(Segments *segments,Segment *segmentp,index_t node)
147 {
148 if(segmentp->node1==node)
149 {
150 segmentp++;
151
152 if(IndexSegment(segments,segmentp)>=segments->file.number || segmentp->node1!=node)
153 return(NULL);
154 else
155 return(segmentp);
156 }
157 else
158 {
159 if(segmentp->next2==NO_SEGMENT)
160 return(NULL);
161 else
162 return(LookupSegment(segments,segmentp->next2,1));
163 }
164 }
165
166 #else
167
168 static Segment *LookupSegment(Segments *segments,index_t index,int position);
169
170 static index_t IndexSegment(Segments *segments,Segment *segmentp);
171
172
173 /*++++++++++++++++++++++++++++++++++++++
174 Find the Segment information for a particular segment.
175
176 Segment *LookupSegment Returns a pointer to the cached segment information.
177
178 Segments *segments The set of segments to use.
179
180 index_t index The index of the segment.
181
182 int position The position in the cache to store the value.
183 ++++++++++++++++++++++++++++++++++++++*/
184
185 static inline Segment *LookupSegment(Segments *segments,index_t index,int position)
186 {
187 segments->cached[position-1]=*FetchCachedSegment(segments->cache,index,segments->fd,sizeof(SegmentsFile));
188
189 segments->incache[position-1]=index;
190
191 return(&segments->cached[position-1]);
192 }
193
194
195 /*++++++++++++++++++++++++++++++++++++++
196 Find the segment index for a particular segment pointer.
197
198 index_t IndexSegment Returns the index of the segment in the list.
199
200 Segments *segments The set of segments to use.
201
202 Segment *segmentp The segment whose index is to be found.
203 ++++++++++++++++++++++++++++++++++++++*/
204
205 static inline index_t IndexSegment(Segments *segments,Segment *segmentp)
206 {
207 int position1=segmentp-&segments->cached[0];
208
209 return(segments->incache[position1]);
210 }
211
212
213 /*++++++++++++++++++++++++++++++++++++++
214 Find the next segment with a particular starting node.
215
216 Segment *NextSegment Returns a pointer to the next segment.
217
218 Segments *segments The set of segments to use.
219
220 Segment *segmentp The current segment.
221
222 index_t node The wanted node.
223 ++++++++++++++++++++++++++++++++++++++*/
224
225 static inline Segment *NextSegment(Segments *segments,Segment *segmentp,index_t node)
226 {
227 int position=segmentp-&segments->cached[-1];
228
229 if(segmentp->node1==node)
230 {
231 index_t index=IndexSegment(segments,segmentp);
232
233 index++;
234
235 if(index>=segments->file.number)
236 return(NULL);
237
238 segmentp=LookupSegment(segments,index,position);
239
240 if(segmentp->node1!=node)
241 return(NULL);
242 else
243 return(segmentp);
244 }
245 else
246 {
247 if(segmentp->next2==NO_SEGMENT)
248 return(NULL);
249 else
250 return(LookupSegment(segments,segmentp->next2,position));
251 }
252 }
253
254 #endif
255
256
257 #endif /* SEGMENTS_H */

Properties

Name Value
cvs:description Header file for segments.