forked from bliksemlabs/rrrr
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tdata.h
207 lines (152 loc) · 7 KB
/
tdata.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/* Copyright 2013 Bliksem Labs. See the LICENSE file at the top-level directory of this distribution and at https://github.com/bliksemlabs/rrrr/. */
/* tdata.h */
#ifndef _TDATA_H
#define _TDATA_H
#include "geometry.h"
#include "util.h"
#include "radixtree.h"
#include "gtfs-realtime.pb-c.h"
#include <stddef.h>
typedef uint32_t calendar_t;
typedef struct stop stop_t;
struct stop {
uint32_t stop_routes_offset;
uint32_t transfers_offset;
};
/* An individual Route in the RAPTOR sense: A group of VehicleJourneys all having the same JourneyPattern. */
typedef struct route route_t;
struct route {
uint32_t route_stops_offset;
uint32_t trip_ids_offset;
uint32_t headsign_offset;
uint16_t n_stops;
uint16_t n_trips;
uint16_t attributes;
uint16_t agency_index;
uint16_t shortname_index;
uint16_t productcategory_index;
rtime_t min_time;
rtime_t max_time;
};
/* An individual VehicleJourney, a materialized instance of a time demand type. */
typedef struct trip trip_t;
struct trip {
uint32_t stop_times_offset; // The offset of the first stoptime of the time demand type used by this trip
rtime_t begin_time; // The absolute start time since at the departure of the first stop
int16_t realtime_delay; // This is signed to indicate early or late. All zeros upon creation (but serves as padding).
};
typedef struct stoptime stoptime_t;
struct stoptime {
rtime_t arrival;
rtime_t departure;
};
typedef enum stop_attribute {
sa_wheelchair_boarding = 1, // wheelchair accessible
sa_visual_accessible = 2, // accessible for blind people
sa_shelter = 4, // roof against rain
sa_bikeshed = 8, // you can put your bike somewhere
sa_bicyclerent = 16, // you can rent a bicycle
sa_parking = 32 // carparking is available
} stop_attribute_t;
typedef enum routestop_attribute {
rsa_waitingpoint = 1, // at this stop the vehicle waits if its early
rsa_boarding = 2, // a passenger can enter the vehicle at this stop
rsa_alighting = 4 // a passenger can leave the vehicle at this stop
} routestop_attribute_t;
// treat entirely as read-only?
typedef struct tdata tdata_t;
struct tdata {
void *base;
size_t size;
// required data
uint64_t calendar_start_time; // midnight of the first day in the 32-day calendar in seconds since the epoch, DST ignorant
calendar_t dst_active;
uint32_t n_stops;
uint32_t n_routes;
uint32_t n_trips;
stop_t *stops;
uint8_t *stop_attributes;
route_t *routes;
uint32_t *route_stops;
uint8_t *route_stop_attributes;
stoptime_t *stop_times;
trip_t *trips;
uint32_t *stop_routes;
uint32_t *transfer_target_stops;
uint8_t *transfer_dist_meters;
// optional data -- NULL pointer means it is not available
latlon_t *stop_coords;
uint32_t platformcode_width;
char *platformcodes;
char *stop_names;
uint32_t *stop_nameidx;
uint32_t agency_id_width;
char *agency_ids;
uint32_t agency_name_width;
char *agency_names;
uint32_t agency_url_width;
char *agency_urls;
char *headsigns;
uint32_t route_shortname_width;
char *route_shortnames;
uint32_t productcategory_width;
char *productcategories;
calendar_t *trip_active;
calendar_t *route_active;
uint8_t *trip_attributes;
uint32_t route_id_width;
char *route_ids;
uint32_t stop_id_width;
char *stop_ids;
uint32_t trip_id_width;
char *trip_ids;
TransitRealtime__FeedMessage *alerts;
};
void tdata_load(char* filename, tdata_t*);
void tdata_close(tdata_t*);
void tdata_dump(tdata_t*);
uint32_t *tdata_stops_for_route(tdata_t *, uint32_t route);
uint8_t *tdata_stop_attributes_for_route(tdata_t *, uint32_t route);
/* TODO: return number of items and store pointer to beginning, to allow restricted pointers */
uint32_t tdata_routes_for_stop(tdata_t*, uint32_t stop, uint32_t **routes_ret);
stoptime_t *tdata_stoptimes_for_route(tdata_t*, uint32_t route_index);
void tdata_dump_route(tdata_t*, uint32_t route_index, uint32_t trip_index);
char *tdata_route_id_for_index(tdata_t*, uint32_t route_index);
char *tdata_stop_id_for_index(tdata_t*, uint32_t stop_index);
uint8_t *tdata_stop_attributes_for_index(tdata_t*, uint32_t stop_index);
char *tdata_trip_id_for_index(tdata_t*, uint32_t trip_index);
char *tdata_trip_id_for_route_trip_index(tdata_t *td, uint32_t route_index, uint32_t trip_index);
char *tdata_agency_id_for_index(tdata_t *td, uint32_t agency_index);
char *tdata_agency_name_for_index(tdata_t *td, uint32_t agency_index);
char *tdata_agency_url_for_index(tdata_t *td, uint32_t agency_index);
char *tdata_headsign_for_offset(tdata_t *td, uint32_t headsign_offset);
char *tdata_route_shortname_for_index(tdata_t *td, uint32_t route_shortname_index);
char *tdata_productcategory_for_index(tdata_t *td, uint32_t productcategory_index);
char *tdata_stop_name_for_index(tdata_t*, uint32_t stop_index);
char *tdata_platformcode_for_index(tdata_t*, uint32_t stop_index);
uint32_t tdata_stopidx_by_stop_name(tdata_t*, char* stop_name, uint32_t start_index);
uint32_t tdata_stopidx_by_stop_id(tdata_t*, char* stop_id, uint32_t start_index);
uint32_t tdata_routeidx_by_route_id(tdata_t*, char* route_id, uint32_t start_index);
char *tdata_trip_ids_for_route(tdata_t*, uint32_t route_index);
uint8_t *tdata_trip_attributes_for_route(tdata_t*, uint32_t route_index);
calendar_t *tdata_trip_masks_for_route(tdata_t*, uint32_t route_index);
char *tdata_headsign_for_route(tdata_t*, uint32_t route_index);
char *tdata_shortname_for_route(tdata_t*, uint32_t route_index);
char *tdata_productcategory_for_route(tdata_t*, uint32_t route_index);
char *tdata_agency_id_for_route(tdata_t*, uint32_t route_index);
char *tdata_agency_name_for_route(tdata_t*, uint32_t route_index);
char *tdata_agency_url_for_route(tdata_t*, uint32_t route_index);
/* Returns a pointer to the first stoptime for the trip (VehicleJourney). These are generally TimeDemandTypes that must
be shifted in time to get the true scheduled arrival and departure times. */
stoptime_t *tdata_timedemand_type(tdata_t*, uint32_t route_index, uint32_t trip_index);
/* Get a pointer to the array of trip structs for this route. */
trip_t *tdata_trips_for_route(tdata_t *td, uint32_t route_index);
void tdata_apply_gtfsrt (tdata_t *tdata, RadixTree *tripid_index, uint8_t *buf, size_t len);
void tdata_apply_gtfsrt_file (tdata_t *tdata, RadixTree *tripid_index, char *filename);
void tdata_clear_gtfsrt (tdata_t *tdata);
void tdata_apply_gtfsrt_alerts (tdata_t *tdata, RadixTree *routeid_index, RadixTree *stopid_index, RadixTree *tripid_index, uint8_t *buf, size_t len);
void tdata_apply_gtfsrt_alerts_file (tdata_t *tdata, RadixTree *routeid_index, RadixTree *stopid_index, RadixTree *tripid_index, char *filename);
void tdata_clear_gtfsrt_alerts (tdata_t *tdata);
/* The signed delay of the specified trip in seconds. */
float tdata_delay_min (tdata_t *td, uint32_t route_index, uint32_t trip_index);
#endif // _TDATA_H