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 561 - (show annotations) (download) (as text)
Tue Dec 21 14:55:18 2010 UTC (14 years, 3 months ago) by amb
File MIME type: text/x-chdr
File size: 3282 byte(s)
Initial revision

1 /***************************************
2 $Header: /home/amb/CVS/routino/src/relations.h,v 1.1 2010-12-21 14:55:18 amb Exp $
3
4 A header file for the relations.
5
6 Part of the Routino routing software.
7 ******************/ /******************
8 This file Copyright 2008-2010 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 RELATIONS_H
26 #define RELATIONS_H /*+ To stop multiple inclusions. +*/
27
28 #include <stdint.h>
29
30 #include "types.h"
31
32 #include "files.h"
33 #include "profiles.h"
34
35
36 /* Data structures */
37
38
39 /*+ A structure containing a single relation. +*/
40 struct _TurnRelation
41 {
42 index_t from; /*+ The node that the path comes from. +*/
43 index_t via; /*+ The node that the path goes via. +*/
44 index_t to; /*+ The node that the path goes to. +*/
45
46 transports_t except; /*+ The types of transports that that this relation does not apply to. +*/
47 };
48
49
50 /*+ A structure containing the header from the file. +*/
51 typedef struct _RelationsFile
52 {
53 index_t trnumber; /*+ How many turn relations in total? +*/
54 }
55 RelationsFile;
56
57
58 /*+ A structure containing a set of relations (and pointers to mmap file). +*/
59 struct _Relations
60 {
61 RelationsFile file; /*+ The header data from the file. +*/
62
63 #if !SLIM
64
65 void *data; /*+ The memory mapped data. +*/
66
67 TurnRelation *turnrelations; /*+ An array of nodes. +*/
68
69 #else
70
71 int fd; /*+ The file descriptor for the file. +*/
72
73 off_t troffset; /*+ The offset of the turn relations in the file. +*/
74
75 TurnRelation cached; /*+ The cached relations. +*/
76
77 #endif
78 };
79
80
81 /* Functions */
82
83 Relations *LoadRelationList(const char *filename);
84
85
86 /* Macros and inline functions */
87
88 #if !SLIM
89
90 /*+ Return a Relation pointer given a set of relations and an index. +*/
91 #define LookupTurnRelation(xxx,yyy) (&(xxx)->turnrelations[yyy])
92
93 #else
94
95 static TurnRelation *LookupTurnRelation(Relations *relations,index_t index);
96
97
98 /*++++++++++++++++++++++++++++++++++++++
99 Find the Relation information for a particular relation.
100
101 TurnRelation *LookupTurnRelation Returns a pointer to the cached relation information.
102
103 Relations *relations The relations structure to use.
104
105 index_t index The index of the relation.
106 ++++++++++++++++++++++++++++++++++++++*/
107
108 static inline TurnRelation *LookupTurnRelation(Relations *relations,index_t index)
109 {
110 SeekFile(relations->fd,relations->troffset+(off_t)index*sizeof(TurnRelation));
111
112 ReadFile(relations->fd,&relations->cached,sizeof(TurnRelation));
113
114 return(&relations->cached);
115 }
116
117 #endif
118
119
120 #endif /* RELATIONS_H */