Skip to content

Commit

Permalink
factorize duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
datanel committed Oct 11, 2024
1 parent ffb75fd commit 856d99a
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions source/time_tables/departure_boards.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ static bool is_terminus_for_all_stop_times(const std::vector<routing::datetime_s
return !stop_times.empty();
}

void update_display_information(bool& vj_found,
const std::pair<unsigned int, const navitia::type::StopTime*>& dt_st,
pbnavitia::PtDisplayInfo* pt_display_information,
PbCreator& pb_creator) {
if (!vj_found && dt_st.second != nullptr) {
auto vj = dt_st.second->vehicle_journey;
pt_display_information->set_trip_short_name(vj->name);
pt_display_information->set_headsign(pb_creator.data->pt_data->headsign_handler.get_headsign(vj));
vj_found = true;
}
}

static void fill_date_times(PbCreator& pb_creator,
pbnavitia::StopSchedule* schedule,
const std::pair<unsigned int, const navitia::type::StopTime*>& dt_st,
Expand Down Expand Up @@ -136,12 +148,7 @@ static void render(PbCreator& pb_creator,

// Now we fill the date_times
for (auto dt_st : id_vec.second) {
if (!vj_found && dt_st.second != nullptr) {
auto vj = dt_st.second->vehicle_journey;
pt_display_information->set_trip_short_name(vj->name);
pt_display_information->set_headsign(pb_creator.data->pt_data->headsign_handler.get_headsign(vj));
vj_found = true;
}
update_display_information(vj_found, dt_st, pt_display_information, pb_creator);
fill_date_times(pb_creator, schedule, dt_st, calendar_id);
}

Expand Down Expand Up @@ -204,12 +211,7 @@ static void render(PbCreator& pb_creator,

// Now we fill the date_times
for (auto dt_st : id_vec.second) {
if (!vj_found && dt_st.second != nullptr) {
auto vj = dt_st.second->vehicle_journey;
pt_display_information->set_trip_short_name(vj->name);
pt_display_information->set_headsign(pb_creator.data->pt_data->headsign_handler.get_headsign(vj));
vj_found = true;
}
update_display_information(vj_found, dt_st, pt_display_information, pb_creator);
fill_date_times(pb_creator, schedule, dt_st, calendar_id);
}

Expand Down

0 comments on commit 856d99a

Please sign in to comment.