Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Annotation of /trunk/src/relations.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 680 - (hide annotations) (download) (as text)
Sun Apr 24 15:14:53 2011 UTC (13 years, 11 months ago) by amb
File MIME type: text/x-chdr
File size: 4096 byte(s)
Update comments throughout the source code.

1 amb 561 /***************************************
2     A header file for the relations.
3    
4     Part of the Routino routing software.
5     ******************/ /******************
6 amb 596 This file Copyright 2008-2011 Andrew M. Bishop
7 amb 561
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 amb 599 index_t from; /*+ The segment that the path comes from. +*/
41 amb 561 index_t via; /*+ The node that the path goes via. +*/
42 amb 599 index_t to; /*+ The segment that the path goes to. +*/
43 amb 561
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 amb 680 index_t trnumber; /*+ The number of turn relations in total. +*/
52 amb 561 }
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 amb 680 TurnRelation cached[2]; /*+ Two cached relations read from the file in slim mode. +*/
74 amb 563 index_t incache[2]; /*+ The indexes of the cached relations. +*/
75 amb 561
76     #endif
77 amb 563
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 amb 561 };
81    
82    
83 amb 680 /* Functions in relations.c */
84 amb 561
85     Relations *LoadRelationList(const char *filename);
86    
87 amb 562 index_t FindFirstTurnRelation1(Relations *relations,index_t via);
88     index_t FindNextTurnRelation1(Relations *relations,index_t current);
89 amb 561
90 amb 562 index_t FindFirstTurnRelation2(Relations *relations,index_t via,index_t from);
91     index_t FindNextTurnRelation2(Relations *relations,index_t current);
92    
93 amb 596 int IsTurnAllowed(Relations *relations,index_t index,index_t via,index_t from,index_t to,transports_t transport);
94 amb 562
95 amb 596
96 amb 561 /* Macros and inline functions */
97    
98     #if !SLIM
99    
100     /*+ Return a Relation pointer given a set of relations and an index. +*/
101 amb 562 #define LookupTurnRelation(xxx,yyy,ppp) (&(xxx)->turnrelations[yyy])
102 amb 561
103     #else
104    
105 amb 562 static TurnRelation *LookupTurnRelation(Relations *relations,index_t index,int position);
106 amb 561
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 relations structure to use.
114    
115     index_t index The index of the relation.
116 amb 562
117     int position The position in the cache to store this result.
118 amb 561 ++++++++++++++++++++++++++++++++++++++*/
119    
120 amb 562 static inline TurnRelation *LookupTurnRelation(Relations *relations,index_t index,int position)
121 amb 561 {
122 amb 562 if(relations->incache[position-1]!=index)
123     {
124     SeekFile(relations->fd,relations->troffset+(off_t)index*sizeof(TurnRelation));
125 amb 561
126 amb 562 ReadFile(relations->fd,&relations->cached[position-1],sizeof(TurnRelation));
127 amb 561
128 amb 562 relations->incache[position-1]=index;
129     }
130    
131     return(&relations->cached[position-1]);
132 amb 561 }
133    
134     #endif
135    
136    
137     #endif /* RELATIONS_H */