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 955 -
(show annotations)
(download)
(as text)
Sat Jan 28 14:40:54 2012 UTC (13 years, 2 months ago) by amb
File MIME type: text/x-chdr
File size: 4090 byte(s)
Sat Jan 28 14:40:54 2012 UTC (13 years, 2 months ago) by amb
File MIME type: text/x-chdr
File size: 4090 byte(s)
Simplify and standardise the included headers.
1 | /*************************************** |
2 | A header file for the relations. |
3 | |
4 | Part of the Routino routing software. |
5 | ******************/ /****************** |
6 | This file Copyright 2008-2012 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 | #include <sys/types.h> |
28 | |
29 | #include "types.h" |
30 | |
31 | #include "files.h" |
32 | #include "profiles.h" |
33 | |
34 | |
35 | /* Data structures */ |
36 | |
37 | |
38 | /*+ A structure containing a single relation. +*/ |
39 | struct _TurnRelation |
40 | { |
41 | index_t from; /*+ The segment that the path comes from. +*/ |
42 | index_t via; /*+ The node that the path goes via. +*/ |
43 | index_t to; /*+ The segment that the path goes to. +*/ |
44 | |
45 | transports_t except; /*+ The types of transports that that this relation does not apply to. +*/ |
46 | }; |
47 | |
48 | |
49 | /*+ A structure containing the header from the file. +*/ |
50 | typedef struct _RelationsFile |
51 | { |
52 | index_t trnumber; /*+ The number of turn relations in total. +*/ |
53 | } |
54 | RelationsFile; |
55 | |
56 | |
57 | /*+ A structure containing a set of relations (and pointers to mmap file). +*/ |
58 | struct _Relations |
59 | { |
60 | RelationsFile file; /*+ The header data from the file. +*/ |
61 | |
62 | #if !SLIM |
63 | |
64 | void *data; /*+ The memory mapped data. +*/ |
65 | |
66 | TurnRelation *turnrelations; /*+ An array of nodes. +*/ |
67 | |
68 | #else |
69 | |
70 | int fd; /*+ The file descriptor for the file. +*/ |
71 | |
72 | off_t troffset; /*+ The offset of the turn relations in the file. +*/ |
73 | |
74 | TurnRelation cached[2]; /*+ Two cached relations read from the file in slim mode. +*/ |
75 | index_t incache[2]; /*+ The indexes of the cached relations. +*/ |
76 | |
77 | #endif |
78 | |
79 | index_t via_start; /*+ The first via node in the file. +*/ |
80 | index_t via_end; /*+ The last via node in the file. +*/ |
81 | }; |
82 | |
83 | |
84 | /* Functions in relations.c */ |
85 | |
86 | Relations *LoadRelationList(const char *filename); |
87 | |
88 | index_t FindFirstTurnRelation1(Relations *relations,index_t via); |
89 | index_t FindNextTurnRelation1(Relations *relations,index_t current); |
90 | |
91 | index_t FindFirstTurnRelation2(Relations *relations,index_t via,index_t from); |
92 | index_t FindNextTurnRelation2(Relations *relations,index_t current); |
93 | |
94 | int IsTurnAllowed(Relations *relations,index_t index,index_t via,index_t from,index_t to,transports_t transport); |
95 | |
96 | |
97 | /* Macros and inline functions */ |
98 | |
99 | #if !SLIM |
100 | |
101 | /*+ Return a Relation pointer given a set of relations and an index. +*/ |
102 | #define LookupTurnRelation(xxx,yyy,ppp) (&(xxx)->turnrelations[yyy]) |
103 | |
104 | #else |
105 | |
106 | static TurnRelation *LookupTurnRelation(Relations *relations,index_t index,int position); |
107 | |
108 | |
109 | /*++++++++++++++++++++++++++++++++++++++ |
110 | Find the Relation information for a particular relation. |
111 | |
112 | TurnRelation *LookupTurnRelation Returns a pointer to the cached relation information. |
113 | |
114 | Relations *relations The set of relations to use. |
115 | |
116 | index_t index The index of the relation. |
117 | |
118 | int position The position in the cache to store this result. |
119 | ++++++++++++++++++++++++++++++++++++++*/ |
120 | |
121 | static inline TurnRelation *LookupTurnRelation(Relations *relations,index_t index,int position) |
122 | { |
123 | if(relations->incache[position-1]!=index) |
124 | { |
125 | SeekReadFile(relations->fd,&relations->cached[position-1],sizeof(TurnRelation),relations->troffset+(off_t)index*sizeof(TurnRelation)); |
126 | |
127 | relations->incache[position-1]=index; |
128 | } |
129 | |
130 | return(&relations->cached[position-1]); |
131 | } |
132 | |
133 | #endif |
134 | |
135 | |
136 | #endif /* RELATIONS_H */ |