From 7516753825500f90ac2de6f18c256d5abec1ff33 Mon Sep 17 00:00:00 2001 From: Khlopkova Olga Date: Fri, 5 Feb 2021 17:59:44 +0300 Subject: [PATCH] Fixes for StopLocationType & FareTransfers::Unlimited --- just_gtfs.h | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/just_gtfs.h b/just_gtfs.h index 4077c02..9fc160c 100644 --- a/just_gtfs.h +++ b/just_gtfs.h @@ -888,7 +888,7 @@ struct Stop Text stop_code; Text stop_desc; Text stop_url; - StopLocationType location_type = StopLocationType::GenericNode; + StopLocationType location_type = StopLocationType::StopOrPlatform; Text stop_timezone; Text wheelchair_boarding; Id level_id; @@ -999,6 +999,14 @@ struct FareAttributesItem size_t transfer_duration = 0; // Length of time in seconds before a transfer expires }; +inline bool operator==(const FareAttributesItem & lhs, const FareAttributesItem & rhs) +{ + return std::tie(lhs.fare_id, lhs.price, lhs.currency_type, lhs.payment_method, lhs.transfers, + lhs.agency_id, lhs.transfer_duration) == + std::tie(rhs.fare_id, rhs.price, rhs.currency_type, rhs.payment_method, rhs.transfers, + rhs.agency_id, rhs.transfer_duration); +} + // Optional dataset file struct FareRule { @@ -1840,7 +1848,7 @@ inline Result Feed::add_fare_attributes(const ParsedCsvRow & row) item.currency_type = row.at("currency_type"); set_field(item.payment_method, row, "payment_method", false); - set_field(item.transfers, row, "transfers", false); + set_field(item.transfers, row, "transfers"); // Conditionally optional: item.agency_id = get_value_or_default(row, "agency_id"); @@ -2778,9 +2786,12 @@ inline void Feed::write_fare_attributes(std::ofstream & out) const for (const auto & attribute : fare_attributes) { std::vector fields{ - wrap(attribute.fare_id), wrap(attribute.price), attribute.currency_type, - wrap(attribute.payment_method), wrap(attribute.transfers), wrap(attribute.agency_id), - wrap(attribute.transfer_duration)}; + wrap(attribute.fare_id), wrap(attribute.price), attribute.currency_type, + wrap(attribute.payment_method), + // Here we handle GTFS specification corner case: "The fact that this field can be left + // empty is an exception to the requirement that a Required field must not be empty.": + attribute.transfers == FareTransfers::Unlimited ? "" : wrap(attribute.transfers), + wrap(attribute.agency_id), wrap(attribute.transfer_duration)}; write_joined(out, std::move(fields)); } }