Skip to content

Commit 856d99a

Browse files
committed
factorize duplicate code
1 parent ffb75fd commit 856d99a

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

source/time_tables/departure_boards.cpp

+14-12
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@ static bool is_terminus_for_all_stop_times(const std::vector<routing::datetime_s
6666
return !stop_times.empty();
6767
}
6868

69+
void update_display_information(bool& vj_found,
70+
const std::pair<unsigned int, const navitia::type::StopTime*>& dt_st,
71+
pbnavitia::PtDisplayInfo* pt_display_information,
72+
PbCreator& pb_creator) {
73+
if (!vj_found && dt_st.second != nullptr) {
74+
auto vj = dt_st.second->vehicle_journey;
75+
pt_display_information->set_trip_short_name(vj->name);
76+
pt_display_information->set_headsign(pb_creator.data->pt_data->headsign_handler.get_headsign(vj));
77+
vj_found = true;
78+
}
79+
}
80+
6981
static void fill_date_times(PbCreator& pb_creator,
7082
pbnavitia::StopSchedule* schedule,
7183
const std::pair<unsigned int, const navitia::type::StopTime*>& dt_st,
@@ -136,12 +148,7 @@ static void render(PbCreator& pb_creator,
136148

137149
// Now we fill the date_times
138150
for (auto dt_st : id_vec.second) {
139-
if (!vj_found && dt_st.second != nullptr) {
140-
auto vj = dt_st.second->vehicle_journey;
141-
pt_display_information->set_trip_short_name(vj->name);
142-
pt_display_information->set_headsign(pb_creator.data->pt_data->headsign_handler.get_headsign(vj));
143-
vj_found = true;
144-
}
151+
update_display_information(vj_found, dt_st, pt_display_information, pb_creator);
145152
fill_date_times(pb_creator, schedule, dt_st, calendar_id);
146153
}
147154

@@ -204,12 +211,7 @@ static void render(PbCreator& pb_creator,
204211

205212
// Now we fill the date_times
206213
for (auto dt_st : id_vec.second) {
207-
if (!vj_found && dt_st.second != nullptr) {
208-
auto vj = dt_st.second->vehicle_journey;
209-
pt_display_information->set_trip_short_name(vj->name);
210-
pt_display_information->set_headsign(pb_creator.data->pt_data->headsign_handler.get_headsign(vj));
211-
vj_found = true;
212-
}
214+
update_display_information(vj_found, dt_st, pt_display_information, pb_creator);
213215
fill_date_times(pb_creator, schedule, dt_st, calendar_id);
214216
}
215217

0 commit comments

Comments
 (0)