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/relations.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 681 - (show annotations) (download) (as text)
Sun Apr 24 18:01:24 2011 UTC (13 years, 10 months ago) by amb
File MIME type: text/x-chdr
File size: 4093 byte(s)
Make the comments more consistent.

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 segment that the path comes from. +*/
41 index_t via; /*+ The node that the path goes via. +*/
42 index_t to; /*+ The segment 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; /*+ The number of 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]; /*+ Two cached relations read from the file in slim mode. +*/
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
82
83 /* Functions in relations.c */
84
85 Relations *LoadRelationList(const char *filename);
86
87 index_t FindFirstTurnRelation1(Relations *relations,index_t via);
88 index_t FindNextTurnRelation1(Relations *relations,index_t current);
89
90 index_t FindFirstTurnRelation2(Relations *relations,index_t via,index_t from);
91 index_t FindNextTurnRelation2(Relations *relations,index_t current);
92
93 int IsTurnAllowed(Relations *relations,index_t index,index_t via,index_t from,index_t to,transports_t transport);
94
95
96 /* Macros and inline functions */
97
98 #if !SLIM
99
100 /*+ Return a Relation pointer given a set of relations and an index. +*/
101 #define LookupTurnRelation(xxx,yyy,ppp) (&(xxx)->turnrelations[yyy])
102
103 #else
104
105 static TurnRelation *LookupTurnRelation(Relations *relations,index_t index,int position);
106
107
108 /*++++++++++++++++++++++++++++++++++++++
109 Find the Relation information for a particular relation.
110
111 TurnRelation *LookupTurnRelation Returns a pointer to the cached relation information.
112
113 Relations *relations The set of relations to use.
114
115 index_t index The index of the relation.
116
117 int position The position in the cache to store this result.
118 ++++++++++++++++++++++++++++++++++++++*/
119
120 static inline TurnRelation *LookupTurnRelation(Relations *relations,index_t index,int position)
121 {
122 if(relations->incache[position-1]!=index)
123 {
124 SeekFile(relations->fd,relations->troffset+(off_t)index*sizeof(TurnRelation));
125
126 ReadFile(relations->fd,&relations->cached[position-1],sizeof(TurnRelation));
127
128 relations->incache[position-1]=index;
129 }
130
131 return(&relations->cached[position-1]);
132 }
133
134 #endif
135
136
137 #endif /* RELATIONS_H */