aboutsummaryrefslogtreecommitdiffstats
path: root/lib/libtmi8/src/kv1_index.cpp
diff options
context:
space:
mode:
authorLibravatar Rutger Broekhoff2024-05-02 20:27:40 +0200
committerLibravatar Rutger Broekhoff2024-05-02 20:27:40 +0200
commit17a3ea880402338420699e03bcb24181e4ff3924 (patch)
treeda666ef91e0b60d20aa0b01529644c136fd1f4ab /lib/libtmi8/src/kv1_index.cpp
downloadoeuf-17a3ea880402338420699e03bcb24181e4ff3924.tar.gz
oeuf-17a3ea880402338420699e03bcb24181e4ff3924.zip
Initial commit
Based on dc4ba6a
Diffstat (limited to 'lib/libtmi8/src/kv1_index.cpp')
-rw-r--r--lib/libtmi8/src/kv1_index.cpp461
1 files changed, 461 insertions, 0 deletions
diff --git a/lib/libtmi8/src/kv1_index.cpp b/lib/libtmi8/src/kv1_index.cpp
new file mode 100644
index 0000000..23e9596
--- /dev/null
+++ b/lib/libtmi8/src/kv1_index.cpp
@@ -0,0 +1,461 @@
1// vim:set sw=2 ts=2 sts et:
2
3#include <tmi8/kv1_index.hpp>
4
5Kv1Index::Kv1Index(Kv1Records *records) : records(records) {
6 organizational_units.reserve(records->organizational_units.size());
7 for (size_t i = 0; i < records->organizational_units.size(); i++) {
8 auto *it = &records->organizational_units[i];
9 organizational_units[it->key] = it;
10 }
11 higher_organizational_units.reserve(records->higher_organizational_units.size());
12 for (size_t i = 0; i < records->higher_organizational_units.size(); i++) {
13 auto *it = &records->higher_organizational_units[i];
14 higher_organizational_units[it->key] = it;
15 }
16 user_stop_points.reserve(records->user_stop_points.size());
17 for (size_t i = 0; i < records->user_stop_points.size(); i++) {
18 auto *it = &records->user_stop_points[i];
19 user_stop_points[it->key] = it;
20 }
21 user_stop_areas.reserve(records->user_stop_areas.size());
22 for (size_t i = 0; i < records->user_stop_areas.size(); i++) {
23 auto *it = &records->user_stop_areas[i];
24 user_stop_areas[it->key] = it;
25 }
26 timing_links.reserve(records->timing_links.size());
27 for (size_t i = 0; i < records->timing_links.size(); i++) {
28 auto *it = &records->timing_links[i];
29 timing_links[it->key] = it;
30 }
31 links.reserve(records->links.size());
32 for (size_t i = 0; i < records->links.size(); i++) {
33 auto *it = &records->links[i];
34 links[it->key] = it;
35 }
36 lines.reserve(records->lines.size());
37 for (size_t i = 0; i < records->lines.size(); i++) {
38 auto *it = &records->lines[i];
39 lines[it->key] = it;
40 }
41 destinations.reserve(records->destinations.size());
42 for (size_t i = 0; i < records->destinations.size(); i++) {
43 auto *it = &records->destinations[i];
44 destinations[it->key] = it;
45 }
46 journey_patterns.reserve(records->journey_patterns.size());
47 for (size_t i = 0; i < records->journey_patterns.size(); i++) {
48 auto *it = &records->journey_patterns[i];
49 journey_patterns[it->key] = it;
50 }
51 concession_financer_relations.reserve(records->concession_financer_relations.size());
52 for (size_t i = 0; i < records->concession_financer_relations.size(); i++) {
53 auto *it = &records->concession_financer_relations[i];
54 concession_financer_relations[it->key] = it;
55 }
56 concession_areas.reserve(records->concession_areas.size());
57 for (size_t i = 0; i < records->concession_areas.size(); i++) {
58 auto *it = &records->concession_areas[i];
59 concession_areas[it->key] = it;
60 }
61 financers.reserve(records->financers.size());
62 for (size_t i = 0; i < records->financers.size(); i++) {
63 auto *it = &records->financers[i];
64 financers[it->key] = it;
65 }
66 journey_pattern_timing_links.reserve(records->journey_pattern_timing_links.size());
67 for (size_t i = 0; i < records->journey_pattern_timing_links.size(); i++) {
68 auto *it = &records->journey_pattern_timing_links[i];
69 journey_pattern_timing_links[it->key] = it;
70 }
71 points.reserve(records->points.size());
72 for (size_t i = 0; i < records->points.size(); i++) {
73 auto *it = &records->points[i];
74 points[it->key] = it;
75 }
76 point_on_links.reserve(records->point_on_links.size());
77 for (size_t i = 0; i < records->point_on_links.size(); i++) {
78 auto *it = &records->point_on_links[i];
79 point_on_links[it->key] = it;
80 }
81 icons.reserve(records->icons.size());
82 for (size_t i = 0; i < records->icons.size(); i++) {
83 auto *it = &records->icons[i];
84 icons[it->key] = it;
85 }
86 notices.reserve(records->notices.size());
87 for (size_t i = 0; i < records->notices.size(); i++) {
88 auto *it = &records->notices[i];
89 notices[it->key] = it;
90 }
91 time_demand_groups.reserve(records->time_demand_groups.size());
92 for (size_t i = 0; i < records->time_demand_groups.size(); i++) {
93 auto *it = &records->time_demand_groups[i];
94 time_demand_groups[it->key] = it;
95 }
96 time_demand_group_run_times.reserve(records->time_demand_group_run_times.size());
97 for (size_t i = 0; i < records->time_demand_group_run_times.size(); i++) {
98 auto *it = &records->time_demand_group_run_times[i];
99 time_demand_group_run_times[it->key] = it;
100 }
101 period_groups.reserve(records->period_groups.size());
102 for (size_t i = 0; i < records->period_groups.size(); i++) {
103 auto *it = &records->period_groups[i];
104 period_groups[it->key] = it;
105 }
106 specific_days.reserve(records->specific_days.size());
107 for (size_t i = 0; i < records->specific_days.size(); i++) {
108 auto *it = &records->specific_days[i];
109 specific_days[it->key] = it;
110 }
111 timetable_versions.reserve(records->timetable_versions.size());
112 for (size_t i = 0; i < records->timetable_versions.size(); i++) {
113 auto *it = &records->timetable_versions[i];
114 timetable_versions[it->key] = it;
115 }
116 public_journeys.reserve(records->public_journeys.size());
117 for (size_t i = 0; i < records->public_journeys.size(); i++) {
118 auto *it = &records->public_journeys[i];
119 public_journeys[it->key] = it;
120 }
121 period_group_validities.reserve(records->period_group_validities.size());
122 for (size_t i = 0; i < records->period_group_validities.size(); i++) {
123 auto *it = &records->period_group_validities[i];
124 period_group_validities[it->key] = it;
125 }
126 exceptional_operating_days.reserve(records->exceptional_operating_days.size());
127 for (size_t i = 0; i < records->exceptional_operating_days.size(); i++) {
128 auto *it = &records->exceptional_operating_days[i];
129 exceptional_operating_days[it->key] = it;
130 }
131 schedule_versions.reserve(records->schedule_versions.size());
132 for (size_t i = 0; i < records->schedule_versions.size(); i++) {
133 auto *it = &records->schedule_versions[i];
134 schedule_versions[it->key] = it;
135 }
136 public_journey_passing_times.reserve(records->public_journey_passing_times.size());
137 for (size_t i = 0; i < records->public_journey_passing_times.size(); i++) {
138 auto *it = &records->public_journey_passing_times[i];
139 public_journey_passing_times[it->key] = it;
140 }
141 operating_days.reserve(records->operating_days.size());
142 for (size_t i = 0; i < records->operating_days.size(); i++) {
143 auto *it = &records->operating_days[i];
144 operating_days[it->key] = it;
145 }
146}
147
148size_t Kv1Index::size() const {
149 return organizational_units.size()
150 + higher_organizational_units.size()
151 + user_stop_points.size()
152 + user_stop_areas.size()
153 + timing_links.size()
154 + links.size()
155 + lines.size()
156 + destinations.size()
157 + journey_patterns.size()
158 + concession_financer_relations.size()
159 + concession_areas.size()
160 + financers.size()
161 + journey_pattern_timing_links.size()
162 + points.size()
163 + point_on_links.size()
164 + icons.size()
165 + notices.size()
166 + time_demand_groups.size()
167 + time_demand_group_run_times.size()
168 + period_groups.size()
169 + specific_days.size()
170 + timetable_versions.size()
171 + public_journeys.size()
172 + period_group_validities.size()
173 + exceptional_operating_days.size()
174 + schedule_versions.size()
175 + public_journey_passing_times.size()
176 + operating_days.size();
177}
178
179void kv1LinkRecords(Kv1Index &index) {
180 for (auto &orunorun : index.records->higher_organizational_units) {
181 Kv1OrganizationalUnit::Key orun_parent_key(
182 orunorun.key.data_owner_code,
183 orunorun.key.organizational_unit_code_parent);
184 Kv1OrganizationalUnit::Key orun_child_key(
185 orunorun.key.data_owner_code,
186 orunorun.key.organizational_unit_code_child);
187 orunorun.p_organizational_unit_parent = index.organizational_units[orun_parent_key];
188 orunorun.p_organizational_unit_child = index.organizational_units[orun_child_key];
189 }
190 for (auto &usrstop : index.records->user_stop_points) {
191 Kv1Point::Key point_key(
192 usrstop.key.data_owner_code,
193 usrstop.key.user_stop_code);
194 usrstop.p_point = index.points[point_key];
195 if (!usrstop.user_stop_area_code.empty()) {
196 Kv1UserStopArea::Key usrstar_key(
197 usrstop.key.data_owner_code,
198 usrstop.user_stop_area_code);
199 usrstop.p_user_stop_area = index.user_stop_areas[usrstar_key];
200 }
201 }
202 for (auto &tili : index.records->timing_links) {
203 Kv1UserStopPoint::Key usrstop_begin_key(
204 tili.key.data_owner_code,
205 tili.key.user_stop_code_begin);
206 Kv1UserStopPoint::Key usrstop_end_key(
207 tili.key.data_owner_code,
208 tili.key.user_stop_code_end);
209 tili.p_user_stop_begin = index.user_stop_points[usrstop_begin_key];
210 tili.p_user_stop_end = index.user_stop_points[usrstop_end_key];
211 }
212 for (auto &link : index.records->links) {
213 Kv1UserStopPoint::Key usrstop_begin_key(
214 link.key.data_owner_code,
215 link.key.user_stop_code_begin);
216 Kv1UserStopPoint::Key usrstop_end_key(
217 link.key.data_owner_code,
218 link.key.user_stop_code_end);
219 link.p_user_stop_begin = index.user_stop_points[usrstop_begin_key];
220 link.p_user_stop_end = index.user_stop_points[usrstop_end_key];
221 }
222 for (auto &line : index.records->lines) {
223 if (!line.line_icon)
224 continue;
225 Kv1Icon::Key icon_key(
226 line.key.data_owner_code,
227 *line.line_icon);
228 line.p_line_icon = index.icons[icon_key];
229 }
230 for (auto &jopa : index.records->journey_patterns) {
231 Kv1Line::Key line_key(
232 jopa.key.data_owner_code,
233 jopa.key.line_planning_number);
234 jopa.p_line = index.lines[line_key];
235 }
236 for (auto &confinrel : index.records->concession_financer_relations) {
237 Kv1ConcessionArea::Key conarea_key(
238 confinrel.key.data_owner_code,
239 confinrel.concession_area_code);
240 confinrel.p_concession_area = index.concession_areas[conarea_key];
241 if (!confinrel.financer_code.empty()) {
242 Kv1Financer::Key financer_key(
243 confinrel.key.data_owner_code,
244 confinrel.financer_code);
245 confinrel.p_financer = index.financers[financer_key];
246 }
247 }
248 for (auto &jopatili : index.records->journey_pattern_timing_links) {
249 Kv1Line::Key line_key(
250 jopatili.key.data_owner_code,
251 jopatili.key.line_planning_number);
252 Kv1JourneyPattern::Key jopa_key(
253 jopatili.key.data_owner_code,
254 jopatili.key.line_planning_number,
255 jopatili.key.journey_pattern_code);
256 Kv1UserStopPoint::Key usrstop_begin_key(
257 jopatili.key.data_owner_code,
258 jopatili.user_stop_code_begin);
259 Kv1UserStopPoint::Key usrstop_end_key(
260 jopatili.key.data_owner_code,
261 jopatili.user_stop_code_end);
262 Kv1ConcessionFinancerRelation::Key confinrel_key(
263 jopatili.key.data_owner_code,
264 jopatili.con_fin_rel_code);
265 Kv1Destination::Key dest_key(
266 jopatili.key.data_owner_code,
267 jopatili.dest_code);
268 jopatili.p_line = index.lines[line_key];
269 jopatili.p_journey_pattern = index.journey_patterns[jopa_key];
270 jopatili.p_user_stop_begin = index.user_stop_points[usrstop_begin_key];
271 jopatili.p_user_stop_end = index.user_stop_points[usrstop_end_key];
272 jopatili.p_con_fin_rel = index.concession_financer_relations[confinrel_key];
273 jopatili.p_dest = index.destinations[dest_key];
274 if (jopatili.line_dest_icon) {
275 Kv1Icon::Key icon_key{
276 jopatili.key.data_owner_code,
277 *jopatili.line_dest_icon,
278 };
279 jopatili.p_line_dest_icon = index.icons[icon_key];
280 }
281 }
282 for (auto &pool : index.records->point_on_links) {
283 Kv1UserStopPoint::Key usrstop_begin_key(
284 pool.key.data_owner_code,
285 pool.key.user_stop_code_begin);
286 Kv1UserStopPoint::Key usrstop_end_key(
287 pool.key.data_owner_code,
288 pool.key.user_stop_code_end);
289 Kv1Point::Key point_key(
290 pool.key.point_data_owner_code,
291 pool.key.point_code);
292 pool.p_user_stop_begin = index.user_stop_points[usrstop_begin_key];
293 pool.p_user_stop_end = index.user_stop_points[usrstop_end_key];
294 pool.p_point = index.points[point_key];
295 }
296 for (auto &ntcassgnm : index.records->notice_assignments) {
297 Kv1Notice::Key notice_key(
298 ntcassgnm.data_owner_code,
299 ntcassgnm.notice_code);
300 ntcassgnm.p_notice = index.notices[notice_key];
301 }
302 for (auto &timdemgrp : index.records->time_demand_groups) {
303 Kv1Line::Key line_key(
304 timdemgrp.key.data_owner_code,
305 timdemgrp.key.line_planning_number);
306 Kv1JourneyPattern::Key jopa_key(
307 timdemgrp.key.data_owner_code,
308 timdemgrp.key.line_planning_number,
309 timdemgrp.key.journey_pattern_code);
310 timdemgrp.p_line = index.lines[line_key];
311 timdemgrp.p_journey_pattern = index.journey_patterns[jopa_key];
312 }
313 for (auto &timdemrnt : index.records->time_demand_group_run_times) {
314 Kv1Line::Key line_key(
315 timdemrnt.key.data_owner_code,
316 timdemrnt.key.line_planning_number);
317 Kv1JourneyPattern::Key jopa_key(
318 timdemrnt.key.data_owner_code,
319 timdemrnt.key.line_planning_number,
320 timdemrnt.key.journey_pattern_code);
321 Kv1TimeDemandGroup::Key timdemgrp_key(
322 timdemrnt.key.data_owner_code,
323 timdemrnt.key.line_planning_number,
324 timdemrnt.key.journey_pattern_code,
325 timdemrnt.key.time_demand_group_code);
326 Kv1UserStopPoint::Key usrstop_begin_key(
327 timdemrnt.key.data_owner_code,
328 timdemrnt.user_stop_code_begin);
329 Kv1UserStopPoint::Key usrstop_end_key(
330 timdemrnt.key.data_owner_code,
331 timdemrnt.user_stop_code_end);
332 Kv1JourneyPatternTimingLink::Key jopatili_key(
333 timdemrnt.key.data_owner_code,
334 timdemrnt.key.line_planning_number,
335 timdemrnt.key.journey_pattern_code,
336 timdemrnt.key.timing_link_order);
337 timdemrnt.p_line = index.lines[line_key];
338 timdemrnt.p_user_stop_end = index.user_stop_points[usrstop_end_key];
339 timdemrnt.p_user_stop_begin = index.user_stop_points[usrstop_begin_key];
340 timdemrnt.p_journey_pattern = index.journey_patterns[jopa_key];
341 timdemrnt.p_time_demand_group = index.time_demand_groups[timdemgrp_key];
342 timdemrnt.p_journey_pattern_timing_link = index.journey_pattern_timing_links[jopatili_key];
343 }
344 for (auto &tive : index.records->timetable_versions) {
345 Kv1OrganizationalUnit::Key orun_key(
346 tive.key.data_owner_code,
347 tive.key.organizational_unit_code);
348 Kv1PeriodGroup::Key pegr_key(
349 tive.key.data_owner_code,
350 tive.key.period_group_code);
351 Kv1SpecificDay::Key specday_key(
352 tive.key.data_owner_code,
353 tive.key.specific_day_code);
354 tive.p_organizational_unit = index.organizational_units[orun_key];
355 tive.p_period_group = index.period_groups[pegr_key];
356 tive.p_specific_day = index.specific_days[specday_key];
357 }
358 for (auto &pujo : index.records->public_journeys) {
359 Kv1TimetableVersion::Key tive_key(
360 pujo.key.data_owner_code,
361 pujo.key.organizational_unit_code,
362 pujo.key.timetable_version_code,
363 pujo.key.period_group_code,
364 pujo.key.specific_day_code);
365 Kv1OrganizationalUnit::Key orun_key(
366 pujo.key.data_owner_code,
367 pujo.key.organizational_unit_code);
368 Kv1PeriodGroup::Key pegr_key(
369 pujo.key.data_owner_code,
370 pujo.key.period_group_code);
371 Kv1SpecificDay::Key specday_key(
372 pujo.key.data_owner_code,
373 pujo.key.specific_day_code);
374 Kv1Line::Key line_key(
375 pujo.key.data_owner_code,
376 pujo.key.line_planning_number);
377 Kv1TimeDemandGroup::Key timdemgrp_key(
378 pujo.key.data_owner_code,
379 pujo.key.line_planning_number,
380 pujo.journey_pattern_code,
381 pujo.time_demand_group_code);
382 Kv1JourneyPattern::Key jopa_key(
383 pujo.key.data_owner_code,
384 pujo.key.line_planning_number,
385 pujo.journey_pattern_code);
386 pujo.p_timetable_version = index.timetable_versions[tive_key];
387 pujo.p_organizational_unit = index.organizational_units[orun_key];
388 pujo.p_period_group = index.period_groups[pegr_key];
389 pujo.p_specific_day = index.specific_days[specday_key];
390 pujo.p_line = index.lines[line_key];
391 pujo.p_time_demand_group = index.time_demand_groups[timdemgrp_key];
392 pujo.p_journey_pattern = index.journey_patterns[jopa_key];
393 }
394 for (auto &pegrval : index.records->period_group_validities) {
395 Kv1OrganizationalUnit::Key orun_key(
396 pegrval.key.data_owner_code,
397 pegrval.key.organizational_unit_code);
398 Kv1PeriodGroup::Key pegr_key(
399 pegrval.key.data_owner_code,
400 pegrval.key.period_group_code);
401 pegrval.p_organizational_unit = index.organizational_units[orun_key];
402 pegrval.p_period_group = index.period_groups[pegr_key];
403 }
404 for (auto &excopday : index.records->exceptional_operating_days) {
405 Kv1OrganizationalUnit::Key orun_key(
406 excopday.key.data_owner_code,
407 excopday.key.organizational_unit_code);
408 Kv1SpecificDay::Key specday_key(
409 excopday.key.data_owner_code,
410 excopday.specific_day_code);
411 Kv1PeriodGroup::Key pegr_key(
412 excopday.key.data_owner_code,
413 excopday.period_group_code);
414 excopday.p_organizational_unit = index.organizational_units[orun_key];
415 excopday.p_specific_day = index.specific_days[specday_key];
416 excopday.p_period_group = index.period_groups[pegr_key];
417 }
418 for (auto &schedvers : index.records->schedule_versions) {
419 Kv1OrganizationalUnit::Key orun_key(
420 schedvers.key.data_owner_code,
421 schedvers.key.organizational_unit_code);
422 schedvers.p_organizational_unit = index.organizational_units[orun_key];
423 }
424 for (auto &pujopass : index.records->public_journey_passing_times) {
425 Kv1OrganizationalUnit::Key orun_key(
426 pujopass.key.data_owner_code,
427 pujopass.key.organizational_unit_code);
428 Kv1ScheduleVersion::Key schedvers_key(
429 pujopass.key.data_owner_code,
430 pujopass.key.organizational_unit_code,
431 pujopass.key.schedule_code,
432 pujopass.key.schedule_type_code);
433 Kv1Line::Key line_key(
434 pujopass.key.data_owner_code,
435 pujopass.key.line_planning_number);
436 Kv1JourneyPattern::Key jopa_key(
437 pujopass.key.data_owner_code,
438 pujopass.key.line_planning_number,
439 pujopass.journey_pattern_code);
440 Kv1UserStopPoint::Key usrstop_key(
441 pujopass.key.data_owner_code,
442 pujopass.user_stop_code);
443 pujopass.p_organizational_unit = index.organizational_units[orun_key];
444 pujopass.p_schedule_version = index.schedule_versions[schedvers_key];
445 pujopass.p_line = index.lines[line_key];
446 pujopass.p_journey_pattern = index.journey_patterns[jopa_key];
447 pujopass.p_user_stop = index.user_stop_points[usrstop_key];
448 }
449 for (auto &operday : index.records->operating_days) {
450 Kv1OrganizationalUnit::Key orun_key(
451 operday.key.data_owner_code,
452 operday.key.organizational_unit_code);
453 Kv1ScheduleVersion::Key schedvers_key(
454 operday.key.data_owner_code,
455 operday.key.organizational_unit_code,
456 operday.key.schedule_code,
457 operday.key.schedule_type_code);
458 operday.p_organizational_unit = index.organizational_units[orun_key];
459 operday.p_schedule_version = index.schedule_versions[schedvers_key];
460 }
461}