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 1741 - (hide annotations) (download) (as text)
Sat Jul 11 14:25:16 2015 UTC (9 years, 8 months ago) by amb
File MIME type: text/x-chdr
File size: 4431 byte(s)
Merge change from MS-Windows branch (offset_t).

1 amb 561 /***************************************
2     A header file for the relations.
3    
4     Part of the Routino routing software.
5     ******************/ /******************
6 amb 1652 This file Copyright 2008-2015 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 amb 955 #include <sys/types.h>
28 amb 561
29     #include "types.h"
30    
31 amb 1292 #include "cache.h"
32 amb 561 #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 amb 599 index_t from; /*+ The segment that the path comes from. +*/
43 amb 561 index_t via; /*+ The node that the path goes via. +*/
44 amb 599 index_t to; /*+ The segment that the path goes to. +*/
45 amb 561
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 amb 680 index_t trnumber; /*+ The number of turn relations in total. +*/
54 amb 561 }
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 amb 1652 char *data; /*+ The memory mapped data. +*/
66 amb 561
67     TurnRelation *turnrelations; /*+ An array of nodes. +*/
68    
69     #else
70    
71     int fd; /*+ The file descriptor for the file. +*/
72    
73 amb 1741 offset_t troffset; /*+ The offset of the turn relations in the file. +*/
74 amb 561
75 amb 680 TurnRelation cached[2]; /*+ Two cached relations read from the file in slim mode. +*/
76 amb 561
77 amb 1292 TurnRelationCache *cache; /*+ A RAM cache of turn relations read from the file. +*/
78    
79 amb 561 #endif
80 amb 563
81     index_t via_start; /*+ The first via node in the file. +*/
82     index_t via_end; /*+ The last via node in the file. +*/
83 amb 561 };
84    
85    
86 amb 680 /* Functions in relations.c */
87 amb 561
88     Relations *LoadRelationList(const char *filename);
89    
90 amb 1312 void DestroyRelationList(Relations *relations);
91    
92 amb 562 index_t FindFirstTurnRelation1(Relations *relations,index_t via);
93     index_t FindNextTurnRelation1(Relations *relations,index_t current);
94 amb 561
95 amb 562 index_t FindFirstTurnRelation2(Relations *relations,index_t via,index_t from);
96     index_t FindNextTurnRelation2(Relations *relations,index_t current);
97    
98 amb 596 int IsTurnAllowed(Relations *relations,index_t index,index_t via,index_t from,index_t to,transports_t transport);
99 amb 562
100 amb 596
101 amb 561 /* Macros and inline functions */
102    
103     #if !SLIM
104    
105     /*+ Return a Relation pointer given a set of relations and an index. +*/
106 amb 562 #define LookupTurnRelation(xxx,yyy,ppp) (&(xxx)->turnrelations[yyy])
107 amb 561
108     #else
109    
110 amb 1296 /* Prototypes */
111 amb 561
112 amb 1296 static inline TurnRelation *LookupTurnRelation(Relations *relations,index_t index,int position);
113 amb 561
114 amb 1296 CACHE_NEWCACHE_PROTO(TurnRelation)
115     CACHE_DELETECACHE_PROTO(TurnRelation)
116     CACHE_FETCHCACHE_PROTO(TurnRelation)
117     CACHE_INVALIDATECACHE_PROTO(TurnRelation)
118    
119 amb 1739 /* Data type */
120 amb 1296
121 amb 1739 CACHE_STRUCTURE(TurnRelation)
122    
123 amb 1296 /* Inline functions */
124    
125     CACHE_NEWCACHE(TurnRelation)
126     CACHE_DELETECACHE(TurnRelation)
127     CACHE_FETCHCACHE(TurnRelation)
128     CACHE_INVALIDATECACHE(TurnRelation)
129    
130    
131 amb 561 /*++++++++++++++++++++++++++++++++++++++
132     Find the Relation information for a particular relation.
133    
134     TurnRelation *LookupTurnRelation Returns a pointer to the cached relation information.
135    
136 amb 681 Relations *relations The set of relations to use.
137 amb 561
138     index_t index The index of the relation.
139 amb 562
140     int position The position in the cache to store this result.
141 amb 561 ++++++++++++++++++++++++++++++++++++++*/
142    
143 amb 562 static inline TurnRelation *LookupTurnRelation(Relations *relations,index_t index,int position)
144 amb 561 {
145 amb 1293 relations->cached[position-1]=*FetchCachedTurnRelation(relations->cache,index,relations->fd,relations->troffset);
146 amb 561
147 amb 562 return(&relations->cached[position-1]);
148 amb 561 }
149    
150     #endif
151    
152    
153     #endif /* RELATIONS_H */