Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Contents of /trunk/src/relations.h
Parent Directory
|
Revision Log
Revision 596 -
(show annotations)
(download)
(as text)
Sun Jan 9 15:12:32 2011 UTC (14 years, 2 months ago) by amb
File MIME type: text/x-chdr
File size: 4184 byte(s)
Sun Jan 9 15:12:32 2011 UTC (14 years, 2 months ago) by amb
File MIME type: text/x-chdr
File size: 4184 byte(s)
Check turn relations when finding a route.
1 | /*************************************** |
2 | A header file for the relations. |
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 RELATIONS_H |
24 | #define RELATIONS_H /*+ To stop multiple inclusions. +*/ |
25 | |
26 | #include <stdint.h> |
27 | |
28 | #include "types.h" |
29 | |
30 | #include "files.h" |
31 | #include "profiles.h" |
32 | |
33 | |
34 | /* Data structures */ |
35 | |
36 | |
37 | /*+ A structure containing a single relation. +*/ |
38 | struct _TurnRelation |
39 | { |
40 | index_t from; /*+ The node that the path comes from. +*/ |
41 | index_t via; /*+ The node that the path goes via. +*/ |
42 | index_t to; /*+ The node that the path goes to. +*/ |
43 | |
44 | transports_t except; /*+ The types of transports that that this relation does not apply to. +*/ |
45 | }; |
46 | |
47 | |
48 | /*+ A structure containing the header from the file. +*/ |
49 | typedef struct _RelationsFile |
50 | { |
51 | index_t trnumber; /*+ How many turn relations in total? +*/ |
52 | } |
53 | RelationsFile; |
54 | |
55 | |
56 | /*+ A structure containing a set of relations (and pointers to mmap file). +*/ |
57 | struct _Relations |
58 | { |
59 | RelationsFile file; /*+ The header data from the file. +*/ |
60 | |
61 | #if !SLIM |
62 | |
63 | void *data; /*+ The memory mapped data. +*/ |
64 | |
65 | TurnRelation *turnrelations; /*+ An array of nodes. +*/ |
66 | |
67 | #else |
68 | |
69 | int fd; /*+ The file descriptor for the file. +*/ |
70 | |
71 | off_t troffset; /*+ The offset of the turn relations in the file. +*/ |
72 | |
73 | TurnRelation cached[2]; /*+ The cached relations. +*/ |
74 | index_t incache[2]; /*+ The indexes of the cached relations. +*/ |
75 | |
76 | #endif |
77 | |
78 | index_t via_start; /*+ The first via node in the file. +*/ |
79 | index_t via_end; /*+ The last via node in the file. +*/ |
80 | |
81 | index_t from_start; /*+ The first from node in the file. +*/ |
82 | index_t from_end; /*+ The last from node in the file. +*/ |
83 | }; |
84 | |
85 | |
86 | /* Functions */ |
87 | |
88 | Relations *LoadRelationList(const char *filename); |
89 | |
90 | index_t FindFirstTurnRelation1(Relations *relations,index_t via); |
91 | index_t FindNextTurnRelation1(Relations *relations,index_t current); |
92 | |
93 | index_t FindFirstTurnRelation2(Relations *relations,index_t via,index_t from); |
94 | index_t FindNextTurnRelation2(Relations *relations,index_t current); |
95 | |
96 | int IsTurnAllowed(Relations *relations,index_t index,index_t via,index_t from,index_t to,transports_t transport); |
97 | |
98 | |
99 | /* Macros and inline functions */ |
100 | |
101 | #if !SLIM |
102 | |
103 | /*+ Return a Relation pointer given a set of relations and an index. +*/ |
104 | #define LookupTurnRelation(xxx,yyy,ppp) (&(xxx)->turnrelations[yyy]) |
105 | |
106 | #else |
107 | |
108 | static TurnRelation *LookupTurnRelation(Relations *relations,index_t index,int position); |
109 | |
110 | |
111 | /*++++++++++++++++++++++++++++++++++++++ |
112 | Find the Relation information for a particular relation. |
113 | |
114 | TurnRelation *LookupTurnRelation Returns a pointer to the cached relation information. |
115 | |
116 | Relations *relations The relations structure to use. |
117 | |
118 | index_t index The index of the relation. |
119 | |
120 | int position The position in the cache to store this result. |
121 | ++++++++++++++++++++++++++++++++++++++*/ |
122 | |
123 | static inline TurnRelation *LookupTurnRelation(Relations *relations,index_t index,int position) |
124 | { |
125 | if(relations->incache[position-1]!=index) |
126 | { |
127 | SeekFile(relations->fd,relations->troffset+(off_t)index*sizeof(TurnRelation)); |
128 | |
129 | ReadFile(relations->fd,&relations->cached[position-1],sizeof(TurnRelation)); |
130 | |
131 | relations->incache[position-1]=index; |
132 | } |
133 | |
134 | return(&relations->cached[position-1]); |
135 | } |
136 | |
137 | #endif |
138 | |
139 | |
140 | #endif /* RELATIONS_H */ |