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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 887 - (show annotations) (download) (as text)
Mon Oct 31 19:09:40 2011 UTC (13 years, 5 months ago) by amb
File MIME type: text/x-chdr
File size: 4128 byte(s)
Use pread() and pwrite() functions instead of seek() followed by read() or
write().

1 /***************************************
2 A header file for the extended Ways structure.
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 WAYSX_H
24 #define WAYSX_H /*+ To stop multiple inclusions. +*/
25
26 #include <stdint.h>
27
28 #include "types.h"
29
30 #include "typesx.h"
31 #include "ways.h"
32
33 #include "files.h"
34
35
36 /* Data structures */
37
38
39 /*+ An extended structure containing a single way. +*/
40 struct _WayX
41 {
42 way_t id; /*+ The way identifier; the OSM value. +*/
43
44 index_t prop; /*+ The index of the properties of the way in the compacted list. +*/
45
46 Way way; /*+ The real Way data. +*/
47 };
48
49
50 /*+ A structure containing a set of ways (memory format). +*/
51 struct _WaysX
52 {
53 char *filename; /*+ The name of the temporary file (for the WaysX). +*/
54 int fd; /*+ The file descriptor of the temporary file (for the WaysX). +*/
55
56 index_t number; /*+ The number of extended ways still being considered. +*/
57
58 #if !SLIM
59
60 WayX *data; /*+ The extended ways data (when mapped into memory). +*/
61
62 #else
63
64 WayX cached[2]; /*+ Two cached ways read from the file in slim mode. +*/
65
66 #endif
67
68 index_t cnumber; /*+ The number of entries after compacting. +*/
69
70 way_t *idata; /*+ The extended way IDs (sorted by ID). +*/
71
72 char *nfilename; /*+ The name of the temporary file (for the names). +*/
73 int nfd; /*+ The file descriptor of the temporary file (for the names). +*/
74
75 uint32_t nlength; /*+ The length of the string of name entries. +*/
76 };
77
78
79 /* Functions in waysx.c */
80
81
82 WaysX *NewWayList(int append);
83 void FreeWayList(WaysX *waysx,int keep);
84
85 void SaveWayList(WaysX *waysx,const char *filename);
86
87 index_t IndexWayX(WaysX *waysx,way_t id);
88
89 void AppendWay(WaysX *waysx,way_t id,Way *way,const char *name);
90
91 void SortWayList(WaysX *waysx);
92
93 void CompactWayList(WaysX *waysx);
94
95
96 /* Macros / inline functions */
97
98 #if !SLIM
99
100 #define LookupWayX(waysx,index,position) &(waysx)->data[index]
101
102 #define PutBackWayX(waysx,index,position) /* nop */
103
104 #else
105
106 static WayX *LookupWayX(WaysX *waysx,index_t index,int position);
107
108 static void PutBackWayX(WaysX *waysx,index_t index,int position);
109
110
111 /*++++++++++++++++++++++++++++++++++++++
112 Lookup a particular extended way with the specified id from the file on disk.
113
114 WayX *LookupWayX Returns a pointer to a cached copy of the extended way.
115
116 WaysX *waysx The set of ways to use.
117
118 index_t index The way index to look for.
119
120 int position The position in the cache to use.
121 ++++++++++++++++++++++++++++++++++++++*/
122
123 static inline WayX *LookupWayX(WaysX *waysx,index_t index,int position)
124 {
125 SeekReadFile(waysx->fd,&waysx->cached[position-1],sizeof(WayX),(off_t)index*sizeof(WayX));
126
127 return(&waysx->cached[position-1]);
128 }
129
130
131 /*++++++++++++++++++++++++++++++++++++++
132 Put back an extended way's data into the file on disk.
133
134 WaysX *waysx The set of ways to use.
135
136 index_t index The way index to put back.
137
138 int position The position in the cache to use.
139 ++++++++++++++++++++++++++++++++++++++*/
140
141 static inline void PutBackWayX(WaysX *waysx,index_t index,int position)
142 {
143 SeekWriteFile(waysx->fd,&waysx->cached[position-1],sizeof(WayX),(off_t)index*sizeof(WayX));
144 }
145
146 #endif /* SLIM */
147
148
149 #endif /* WAYSX_H */

Properties

Name Value
cvs:description Extended ways header.