diff --git a/include/nigiri/rt/frun.h b/include/nigiri/rt/frun.h index 8bbedf29..f97aab58 100644 --- a/include/nigiri/rt/frun.h +++ b/include/nigiri/rt/frun.h @@ -19,81 +19,82 @@ struct timetable; namespace nigiri::rt { -// Full run. Same as `run` data structure, extended with timetable and -// rt_timetable to be able to look up additional info. -struct frun : public run { - struct run_stop { - stop get_stop() const noexcept; - stop get_scheduled_stop() const noexcept; - location get_location() const noexcept; - geo::latlng pos() const noexcept; - location_idx_t get_location_idx() const noexcept; - location_idx_t get_scheduled_location_idx() const noexcept; - std::string_view name() const noexcept; - std::string_view track() const noexcept; - std::string_view id() const noexcept; - - provider const& get_provider(event_type = event_type::kDep) const noexcept; - trip_idx_t get_trip_idx(event_type = event_type::kDep) const noexcept; - std::string_view trip_display_name( - event_type = event_type::kDep) const noexcept; - - unixtime_t scheduled_time(event_type) const noexcept; - unixtime_t time(event_type) const noexcept; - duration_t delay(event_type) const noexcept; - - std::string_view line(event_type = event_type::kDep) const noexcept; - std::string_view scheduled_line( - event_type = event_type::kDep) const noexcept; - std::string_view direction(event_type = event_type::kDep) const noexcept; - - clasz get_clasz(event_type = event_type::kDep) const noexcept; - clasz get_scheduled_clasz(event_type = event_type::kDep) const noexcept; - - bool bikes_allowed(event_type = event_type::kDep) const noexcept; - - route_color get_route_color(event_type = event_type::kDep) const noexcept; - - bool in_allowed() const noexcept; - bool out_allowed() const noexcept; - bool in_allowed_wheelchair() const noexcept; - bool out_allowed_wheelchair() const noexcept; - bool is_canceled() const noexcept; - - bool in_allowed(bool const is_wheelchair) const noexcept; - bool out_allowed(bool const is_wheelchair) const noexcept; - - template - bool can_start(bool const is_wheelchair) const { - if constexpr (SearchDir == direction::kForward) { - return is_wheelchair ? in_allowed_wheelchair() : in_allowed(); - } else { - return is_wheelchair ? out_allowed_wheelchair() : out_allowed(); - } - } +struct frun; + +struct run_stop { + stop get_stop() const noexcept; + stop get_scheduled_stop() const noexcept; + location get_location() const noexcept; + geo::latlng pos() const noexcept; + location_idx_t get_location_idx() const noexcept; + location_idx_t get_scheduled_location_idx() const noexcept; + std::string_view name() const noexcept; + std::string_view track() const noexcept; + std::string_view id() const noexcept; + + provider const& get_provider(event_type = event_type::kDep) const noexcept; + trip_idx_t get_trip_idx(event_type = event_type::kDep) const noexcept; + std::string_view trip_display_name( + event_type = event_type::kDep) const noexcept; + + unixtime_t scheduled_time(event_type) const noexcept; + unixtime_t time(event_type) const noexcept; + duration_t delay(event_type) const noexcept; + + std::string_view line(event_type = event_type::kDep) const noexcept; + std::string_view scheduled_line(event_type = event_type::kDep) const noexcept; + std::string_view direction(event_type = event_type::kDep) const noexcept; + + clasz get_clasz(event_type = event_type::kDep) const noexcept; + clasz get_scheduled_clasz(event_type = event_type::kDep) const noexcept; + + bool bikes_allowed(event_type = event_type::kDep) const noexcept; - template - bool can_finish(bool const is_wheelchair) const { - if constexpr (SearchDir == direction::kForward) { - return is_wheelchair ? out_allowed_wheelchair() : out_allowed(); - } else { - return is_wheelchair ? in_allowed_wheelchair() : in_allowed(); - } + route_color get_route_color(event_type = event_type::kDep) const noexcept; + + bool in_allowed() const noexcept; + bool out_allowed() const noexcept; + bool in_allowed_wheelchair() const noexcept; + bool out_allowed_wheelchair() const noexcept; + bool is_canceled() const noexcept; + + bool in_allowed(bool const is_wheelchair) const noexcept; + bool out_allowed(bool const is_wheelchair) const noexcept; + + template + bool can_start(bool const is_wheelchair) const { + if constexpr (SearchDir == direction::kForward) { + return is_wheelchair ? in_allowed_wheelchair() : in_allowed(); + } else { + return is_wheelchair ? out_allowed_wheelchair() : out_allowed(); } + } + + template + bool can_finish(bool const is_wheelchair) const { + if constexpr (SearchDir == direction::kForward) { + return is_wheelchair ? out_allowed_wheelchair() : out_allowed(); + } else { + return is_wheelchair ? in_allowed_wheelchair() : in_allowed(); + } + } - stop_idx_t section_idx(event_type) const noexcept; + stop_idx_t section_idx(event_type) const noexcept; - timetable const& tt() const noexcept; - rt_timetable const* rtt() const noexcept; + timetable const& tt() const noexcept; + rt_timetable const* rtt() const noexcept; - void print(std::ostream&, bool first = false, bool last = false) const; - bool operator==(run_stop const&) const = default; - friend std::ostream& operator<<(std::ostream&, run_stop const&); + void print(std::ostream&, bool first = false, bool last = false) const; + bool operator==(run_stop const&) const = default; + friend std::ostream& operator<<(std::ostream&, run_stop const&); - frun const* fr_{nullptr}; - stop_idx_t stop_idx_{0U}; - }; + frun const* fr_{nullptr}; + stop_idx_t stop_idx_{0U}; +}; +// Full run. Same as `run` data structure, extended with timetable and +// rt_timetable to be able to look up additional info. +struct frun : public run { struct iterator { using difference_type = stop_idx_t; using value_type = run_stop; diff --git a/src/rt/frun.cc b/src/rt/frun.cc index 95be09cc..60c07de4 100644 --- a/src/rt/frun.cc +++ b/src/rt/frun.cc @@ -13,7 +13,7 @@ namespace nigiri::rt { -stop frun::run_stop::get_stop() const noexcept { +stop run_stop::get_stop() const noexcept { assert(fr_->size() > stop_idx_); return stop{ (fr_->is_rt() && rtt() != nullptr) @@ -22,7 +22,7 @@ stop frun::run_stop::get_stop() const noexcept { [stop_idx_]}; } -stop frun::run_stop::get_scheduled_stop() const noexcept { +stop run_stop::get_scheduled_stop() const noexcept { assert(fr_->size() > stop_idx_); return fr_->is_scheduled() ? tt().route_location_seq_[tt().transport_route_[fr_->t_.t_idx_]] @@ -30,7 +30,7 @@ stop frun::run_stop::get_scheduled_stop() const noexcept { : rtt()->rt_transport_location_seq_[fr_->rt_][stop_idx_]; } -std::string_view frun::run_stop::name() const noexcept { +std::string_view run_stop::name() const noexcept { auto const l = get_location_idx(); auto const type = tt().locations_.types_.at(l); auto const p = @@ -40,7 +40,7 @@ std::string_view frun::run_stop::name() const noexcept { return tt().locations_.names_.at(p).view(); } -std::string_view frun::run_stop::id() const noexcept { +std::string_view run_stop::id() const noexcept { auto const l = get_location_idx(); auto const type = tt().locations_.types_.at(l); return tt() @@ -51,7 +51,7 @@ std::string_view frun::run_stop::id() const noexcept { .view(); } -std::string_view frun::run_stop::track() const noexcept { +std::string_view run_stop::track() const noexcept { auto const l = get_location_idx(); return (tt().locations_.types_.at(l) == location_type::kTrack || tt().locations_.types_.at(l) == location_type::kGeneratedTrack) @@ -59,48 +59,46 @@ std::string_view frun::run_stop::track() const noexcept { : ""; } -location frun::run_stop::get_location() const noexcept { +location run_stop::get_location() const noexcept { assert(fr_->size() > stop_idx_); return location{*fr_->tt_, get_stop().location_idx()}; } -geo::latlng frun::run_stop::pos() const noexcept { +geo::latlng run_stop::pos() const noexcept { assert(fr_->size() > stop_idx_); return fr_->tt_->locations_.coordinates_[get_stop().location_idx()]; } -location_idx_t frun::run_stop::get_location_idx() const noexcept { +location_idx_t run_stop::get_location_idx() const noexcept { assert(fr_->size() > stop_idx_); return get_stop().location_idx(); } -location_idx_t frun::run_stop::get_scheduled_location_idx() const noexcept { +location_idx_t run_stop::get_scheduled_location_idx() const noexcept { assert(fr_->size() > stop_idx_); return get_scheduled_stop().location_idx(); } -unixtime_t frun::run_stop::scheduled_time( - event_type const ev_type) const noexcept { +unixtime_t run_stop::scheduled_time(event_type const ev_type) const noexcept { assert(fr_->size() > stop_idx_); return fr_->is_scheduled() ? tt().event_time(fr_->t_, stop_idx_, ev_type) : rtt()->unix_event_time(fr_->rt_, stop_idx_, ev_type); } -unixtime_t frun::run_stop::time(event_type const ev_type) const noexcept { +unixtime_t run_stop::time(event_type const ev_type) const noexcept { assert(fr_->size() > stop_idx_); return (fr_->is_rt() && rtt() != nullptr) ? rtt()->unix_event_time(fr_->rt_, stop_idx_, ev_type) : tt().event_time(fr_->t_, stop_idx_, ev_type); } -duration_t frun::run_stop::delay(event_type const ev_type) const noexcept { +duration_t run_stop::delay(event_type const ev_type) const noexcept { assert(fr_->size() > stop_idx_); return time(ev_type) - scheduled_time(ev_type); } -trip_idx_t frun::run_stop::get_trip_idx( - event_type const ev_type) const noexcept { +trip_idx_t run_stop::get_trip_idx(event_type const ev_type) const noexcept { auto const sections = tt().transport_to_trip_section_.at(fr_->t_.t_idx_); return tt() .merged_trips_[sections.at(sections.size() == 1U ? 0U @@ -108,18 +106,17 @@ trip_idx_t frun::run_stop::get_trip_idx( .at(0); } -std::string_view frun::run_stop::trip_display_name( +std::string_view run_stop::trip_display_name( event_type const ev_type) const noexcept { return tt().trip_display_names_[get_trip_idx(ev_type)].view(); } -stop_idx_t frun::run_stop::section_idx( - event_type const ev_type) const noexcept { +stop_idx_t run_stop::section_idx(event_type const ev_type) const noexcept { return static_cast(ev_type == event_type::kDep ? stop_idx_ : stop_idx_ - 1); } -std::string_view frun::run_stop::line(event_type const ev_type) const noexcept { +std::string_view run_stop::line(event_type const ev_type) const noexcept { if (fr_->is_rt() && rtt() != nullptr) { auto const rt_line = rtt()->rt_transport_line_.at(fr_->rt_); return rt_line.empty() ? scheduled_line(ev_type) : rt_line.view(); @@ -128,7 +125,7 @@ std::string_view frun::run_stop::line(event_type const ev_type) const noexcept { } } -provider const& frun::run_stop::get_provider( +provider const& run_stop::get_provider( event_type const ev_type) const noexcept { auto const provider_sections = tt().transport_section_providers_.at(fr_->t_.t_idx_); @@ -137,8 +134,7 @@ provider const& frun::run_stop::get_provider( return tt().providers_.at(provider_idx); } -std::string_view frun::run_stop::direction( - event_type const ev_type) const noexcept { +std::string_view run_stop::direction(event_type const ev_type) const noexcept { if (!fr_->is_scheduled()) { return ""; } @@ -165,7 +161,7 @@ std::string_view frun::run_stop::direction( return direction; } -std::string_view frun::run_stop::scheduled_line( +std::string_view run_stop::scheduled_line( event_type const ev_type) const noexcept { if (!fr_->is_scheduled()) { return ""; @@ -182,7 +178,7 @@ std::string_view frun::run_stop::scheduled_line( } } -clasz frun::run_stop::get_clasz(event_type const ev_type) const noexcept { +clasz run_stop::get_clasz(event_type const ev_type) const noexcept { if (fr_->is_rt() && rtt() != nullptr) { auto const clasz_sections = rtt()->rt_transport_section_clasz_.at(fr_->rt_); return clasz_sections.at( @@ -195,8 +191,7 @@ clasz frun::run_stop::get_clasz(event_type const ev_type) const noexcept { } } -clasz frun::run_stop::get_scheduled_clasz( - event_type const ev_type) const noexcept { +clasz run_stop::get_scheduled_clasz(event_type const ev_type) const noexcept { if (!fr_->is_scheduled()) { return clasz(); } @@ -206,7 +201,7 @@ clasz frun::run_stop::get_scheduled_clasz( : section_idx(ev_type)); } -bool frun::run_stop::bikes_allowed(event_type const ev_type) const noexcept { +bool run_stop::bikes_allowed(event_type const ev_type) const noexcept { if (fr_->is_rt() && rtt() != nullptr) { auto const bikes_allowed_seq = rtt()->rt_bikes_allowed_per_section_.at(fr_->rt_); @@ -220,43 +215,39 @@ bool frun::run_stop::bikes_allowed(event_type const ev_type) const noexcept { } } -route_color frun::run_stop::get_route_color(event_type ev_type) const noexcept { +route_color run_stop::get_route_color(event_type ev_type) const noexcept { auto const color_sections = tt().transport_section_route_colors_.at(fr_->t_.t_idx_); return color_sections.at(color_sections.size() == 1U ? 0U : section_idx(ev_type)); } -bool frun::run_stop::is_canceled() const noexcept { +bool run_stop::is_canceled() const noexcept { return get_stop().is_cancelled(); } -bool frun::run_stop::in_allowed() const noexcept { - return get_stop().in_allowed(); -} +bool run_stop::in_allowed() const noexcept { return get_stop().in_allowed(); } -bool frun::run_stop::out_allowed() const noexcept { - return get_stop().out_allowed(); -} +bool run_stop::out_allowed() const noexcept { return get_stop().out_allowed(); } -bool frun::run_stop::in_allowed_wheelchair() const noexcept { +bool run_stop::in_allowed_wheelchair() const noexcept { return get_stop().in_allowed_wheelchair(); } -bool frun::run_stop::out_allowed_wheelchair() const noexcept { +bool run_stop::out_allowed_wheelchair() const noexcept { return get_stop().out_allowed_wheelchair(); } -bool frun::run_stop::in_allowed(bool const wheelchair) const noexcept { +bool run_stop::in_allowed(bool const wheelchair) const noexcept { return wheelchair ? in_allowed_wheelchair() : in_allowed(); } -bool frun::run_stop::out_allowed(bool const wheelchair) const noexcept { +bool run_stop::out_allowed(bool const wheelchair) const noexcept { return wheelchair ? out_allowed_wheelchair() : out_allowed(); } -timetable const& frun::run_stop::tt() const noexcept { return *fr_->tt_; } -rt_timetable const* frun::run_stop::rtt() const noexcept { return fr_->rtt_; } +timetable const& run_stop::tt() const noexcept { return *fr_->tt_; } +rt_timetable const* run_stop::rtt() const noexcept { return fr_->rtt_; } frun::iterator& frun::iterator::operator++() noexcept { do { @@ -294,7 +285,7 @@ bool frun::iterator::operator!=(iterator o) const noexcept { return !(*this == o); } -frun::run_stop frun::iterator::operator*() const noexcept { return rs_; } +run_stop frun::iterator::operator*() const noexcept { return rs_; } frun::frun(timetable const& tt, rt_timetable const* rtt, run r) : run{r}, tt_{&tt}, rtt_{rtt} { @@ -377,7 +368,7 @@ stop_idx_t frun::size() const noexcept { : tt_->route_location_seq_[tt_->transport_route_[t_.t_idx_]].size()); } -frun::run_stop frun::operator[](stop_idx_t const i) const noexcept { +run_stop frun::operator[](stop_idx_t const i) const noexcept { return run_stop{this, static_cast(stop_range_.from_ + i)}; } @@ -491,9 +482,9 @@ trip_idx_t frun::trip_idx() const { throw utl::fail("trip idx only for scheduled trip"); } -void frun::run_stop::print(std::ostream& out, - bool const first, - bool const last) const { +void run_stop::print(std::ostream& out, + bool const first, + bool const last) const { auto const& tz = tt().locations_.timezones_.at( get_transport_stop_tz(*fr_->tt_, fr_->t_.t_idx_, get_location().l_)); @@ -566,7 +557,7 @@ void frun::run_stop::print(std::ostream& out, } } -std::ostream& operator<<(std::ostream& out, frun::run_stop const& stp) { +std::ostream& operator<<(std::ostream& out, run_stop const& stp) { stp.print(out); return out; } diff --git a/src/rt/vdv/vdv_update.cc b/src/rt/vdv/vdv_update.cc index 20640d78..ea883f6a 100644 --- a/src/rt/vdv/vdv_update.cc +++ b/src/rt/vdv/vdv_update.cc @@ -322,7 +322,7 @@ std::optional updater::find_run(std::string_view vdv_run_id, } void update_event(rt_timetable& rtt, - frun::run_stop const& rs, + run_stop const& rs, event_type const et, unixtime_t const new_time, std::optional* delay_propagation = nullptr) {