Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Annotation of /trunk/src/relations.h
Parent Directory
|
Revision Log
Revision 562 -
(hide annotations)
(download)
(as text)
Tue Dec 21 17:01:46 2010 UTC (14 years, 3 months ago) by amb
File MIME type: text/x-chdr
File size: 3864 byte(s)
Tue Dec 21 17:01:46 2010 UTC (14 years, 3 months ago) by amb
File MIME type: text/x-chdr
File size: 3864 byte(s)
Add functions to search for turn relations that match a particular node.
1 | amb | 561 | /*************************************** |
2 | amb | 562 | $Header: /home/amb/CVS/routino/src/relations.h,v 1.2 2010-12-21 17:01:46 amb Exp $ |
3 | amb | 561 | |
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 | amb | 562 | TurnRelation cached[3]; /*+ The cached relations. +*/ |
76 | index_t incache[3]; /*+ The indexes of the cached relations. +*/ | ||
77 | amb | 561 | |
78 | #endif | ||
79 | }; | ||
80 | |||
81 | |||
82 | /* Functions */ | ||
83 | |||
84 | Relations *LoadRelationList(const char *filename); | ||
85 | |||
86 | amb | 562 | index_t FindFirstTurnRelation1(Relations *relations,index_t via); |
87 | index_t FindNextTurnRelation1(Relations *relations,index_t current); | ||
88 | amb | 561 | |
89 | amb | 562 | index_t FindFirstTurnRelation2(Relations *relations,index_t via,index_t from); |
90 | index_t FindNextTurnRelation2(Relations *relations,index_t current); | ||
91 | |||
92 | |||
93 | amb | 561 | /* Macros and inline functions */ |
94 | |||
95 | #if !SLIM | ||
96 | |||
97 | /*+ Return a Relation pointer given a set of relations and an index. +*/ | ||
98 | amb | 562 | #define LookupTurnRelation(xxx,yyy,ppp) (&(xxx)->turnrelations[yyy]) |
99 | amb | 561 | |
100 | #else | ||
101 | |||
102 | amb | 562 | static TurnRelation *LookupTurnRelation(Relations *relations,index_t index,int position); |
103 | amb | 561 | |
104 | |||
105 | /*++++++++++++++++++++++++++++++++++++++ | ||
106 | Find the Relation information for a particular relation. | ||
107 | |||
108 | TurnRelation *LookupTurnRelation Returns a pointer to the cached relation information. | ||
109 | |||
110 | Relations *relations The relations structure to use. | ||
111 | |||
112 | index_t index The index of the relation. | ||
113 | amb | 562 | |
114 | int position The position in the cache to store this result. | ||
115 | amb | 561 | ++++++++++++++++++++++++++++++++++++++*/ |
116 | |||
117 | amb | 562 | static inline TurnRelation *LookupTurnRelation(Relations *relations,index_t index,int position) |
118 | amb | 561 | { |
119 | amb | 562 | if(relations->incache[position-1]!=index) |
120 | { | ||
121 | SeekFile(relations->fd,relations->troffset+(off_t)index*sizeof(TurnRelation)); | ||
122 | amb | 561 | |
123 | amb | 562 | ReadFile(relations->fd,&relations->cached[position-1],sizeof(TurnRelation)); |
124 | amb | 561 | |
125 | amb | 562 | relations->incache[position-1]=index; |
126 | } | ||
127 | |||
128 | return(&relations->cached[position-1]); | ||
129 | amb | 561 | } |
130 | |||
131 | #endif | ||
132 | |||
133 | |||
134 | #endif /* RELATIONS_H */ |