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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 84 - (show annotations) (download) (as text)
Sun Jan 25 12:09:15 2009 UTC (16 years, 1 month ago) by amb
File MIME type: text/x-chdr
File size: 4553 byte(s)
Change the segment->way so that it contains the index of the way, not the id.

1 /***************************************
2 $Header: /home/amb/CVS/routino/src/ways.h,v 1.15 2009-01-25 12:09:15 amb Exp $
3
4 A header file for the ways.
5 ******************/ /******************
6 Written by Andrew M. Bishop
7
8 This file Copyright 2009 Andrew M. Bishop
9 It may be distributed under the GNU Public License, version 2, or
10 any higher version. See section COPYING of the GNU Public license
11 for conditions under which this file may be redistributed.
12 ***************************************/
13
14
15 #ifndef WAYS_H
16 #define WAYS_H /*+ To stop multiple inclusions. +*/
17
18 #include <stdint.h>
19
20
21 /* Constants */
22
23
24 /*+ The number of bins for ways - expect ~1,000,000 ways and use 4*sqrt(N) bins. +*/
25 #define NBINS_WAYS 4096
26
27 /*+ The array size increment for ways - expect ~1,000,000 ways. +*/
28 #define INCREMENT_WAYS 256*1024
29
30
31 /* Simple Types */
32
33
34 /*+ A way identifier. +*/
35 typedef uint32_t way_t;
36
37 /*+ The speed limit of the way. +*/
38 typedef uint8_t speed_t;
39
40 /*+ The type of a way. +*/
41 typedef uint8_t waytype_t;
42
43 /*+ The different types of a way. +*/
44 typedef enum _Highway
45 {
46 Way_Motorway = 1,
47 Way_Trunk = 2,
48 Way_Primary = 3,
49 Way_Secondary = 4,
50 Way_Tertiary = 5,
51 Way_Unclassfied= 6,
52 Way_Residential= 7,
53 Way_Service = 8,
54 Way_Track = 9,
55 Way_Bridleway =10,
56 Way_Cycleway =11,
57 Way_Footway =12,
58
59 Way_Unknown =13,
60
61 Way_OneWay =16,
62 Way_Roundabout =32
63 }
64 Highway;
65
66 #define HIGHWAY(xx) ((xx)&0x0f)
67
68
69 /*+ The type of a method of transport. +*/
70 typedef uint8_t transport_t;
71
72 /*+ The different methods of transport. +*/
73 typedef enum _Transport
74 {
75 Transport_None = 0,
76
77 Transport_Foot = 1,
78 Transport_Bicycle = 2,
79 Transport_Horse = 3,
80 Transport_Motorbike = 4,
81 Transport_Motorcar = 5,
82 Transport_Goods = 6,
83 Transport_HGV = 7,
84 Transport_PSV = 8
85 }
86 Transport;
87
88
89 /*+ The allowed traffic on a way. +*/
90 typedef uint8_t wayallow_t;
91
92 /*+ The different allowed traffic on a way. +*/
93 typedef enum _Allowed
94 {
95 Allow_Foot =1<<(Transport_Foot -1),
96 Allow_Bicycle =1<<(Transport_Bicycle -1),
97 Allow_Horse =1<<(Transport_Horse -1),
98 Allow_Motorbike =1<<(Transport_Motorbike-1),
99 Allow_Motorcar =1<<(Transport_Motorcar -1),
100 Allow_Goods =1<<(Transport_Goods -1),
101 Allow_HGV =1<<(Transport_HGV -1),
102 Allow_PSV =1<<(Transport_PSV -1),
103
104 Allow_ALL =255
105 }
106 Allowed;
107
108
109 /* Data structures */
110
111
112 /*+ A structure containing a single way. +*/
113 typedef struct _Way
114 {
115 way_t id; /*+ The way identifier. +*/
116 uint32_t name; /*+ An offset of the name of the way in the ways array. +*/
117 speed_t limit; /*+ The defined speed limit on the way. +*/
118 waytype_t type; /*+ The type of the way. +*/
119 wayallow_t allow; /*+ The type of traffic allowed on the way. +*/
120 }
121 Way;
122
123 /*+ A structure containing a set of ways (mmap format). +*/
124 typedef struct _Ways
125 {
126 uint32_t offset[NBINS_WAYS]; /*+ An offset to the first entry in each bin. +*/
127 uint32_t number; /*+ How many entries are used in total? +*/
128 Way ways[1]; /*+ An array of ways whose size is not limited to 1
129 (i.e. may overflow the end of this structure). +*/
130 }
131 Ways;
132
133 /*+ A structure containing a set of ways (memory format). +*/
134 typedef struct _WaysMem
135 {
136 uint32_t alloced; /*+ How many entries are allocated? +*/
137 uint32_t number; /*+ How many entries are used? +*/
138 uint32_t number_str; /*+ How many name entries are used? +*/
139 uint32_t sorted; /*+ Is the data sorted and therefore searchable? +*/
140
141 Ways *ways; /*+ The real data that will be memory mapped later. +*/
142 char **names; /*+ An array of names. +*/
143 }
144 WaysMem;
145
146
147 /* Functions */
148
149
150 WaysMem *NewWayList(void);
151
152 Ways *LoadWayList(const char *filename);
153 Ways *SaveWayList(WaysMem *ways,const char *filename);
154
155 Way *FindWay(Ways *ways,way_t id);
156
157 Way *AppendWay(WaysMem *ways,way_t id,const char *name);
158
159 void SortWayList(WaysMem *ways);
160
161 Highway HighwayType(const char *highway);
162 Transport TransportType(const char *transport);
163
164 const char *HighwayName(Highway highway);
165 const char *TransportName(Transport transport);
166
167 const char *HighwayList(void);
168 const char *TransportList(void);
169
170 #define LookupWay(xxx,yyy) (&(xxx)->ways[yyy])
171
172 #define IndexWay(xxx,yyy) ((yyy)-&(xxx)->ways[0])
173
174 #define WayName(xxx,yyy) ((char*)&(xxx)->ways[(yyy)->name])
175
176
177 #endif /* WAYS_H */

Properties

Name Value
cvs:description Header file for ways.