diff --git a/editor/opening_hours_ui.cpp b/editor/opening_hours_ui.cpp index ac194a725a..34215f7eaf 100644 --- a/editor/opening_hours_ui.cpp +++ b/editor/opening_hours_ui.cpp @@ -281,7 +281,7 @@ osmoh::Timespan TimeTable::GetPredefinedExcludeTime() const TimeTableSet::TimeTableSet() { - push_back(TimeTable::GetPredefinedTimeTable()); + m_table.push_back(TimeTable::GetPredefinedTimeTable()); } TOpeningDays TimeTableSet::GetUnhandledDays() const @@ -317,59 +317,60 @@ TimeTable TimeTableSet::GetComplementTimeTable() const bool TimeTableSet::Append(TimeTable const & tt) { auto copy = *this; - copy.push_back(tt); + copy.m_table.push_back(tt); - if (!TimeTableSet::UpdateByIndex(copy, copy.size() - 1)) + if (!TimeTableSet::UpdateByIndex(copy, copy.Size() - 1)) return false; - swap(copy); + m_table.swap(copy.m_table); return true; } bool TimeTableSet::Remove(size_t const index) { - if (index == 0 || index >= size()) + if (index == 0 || index >= Size()) return false; - erase(begin() + index); + m_table.erase(m_table.begin() + index); return true; } bool TimeTableSet::Replace(TimeTable const & tt, size_t const index) { - if (index >= size()) + if (index >= Size()) return false; auto copy = *this; - copy[index] = tt; + copy.m_table[index] = tt; if (!TimeTableSet::UpdateByIndex(copy, index)) return false; - swap(copy); + m_table.swap(copy.m_table); return true; } bool TimeTableSet::UpdateByIndex(TimeTableSet & ttSet, size_t const index) { - if (index >= ttSet.size() || !ttSet[index].IsValid()) + auto const & updated = ttSet.m_table[index]; + + if (index >= ttSet.Size() || !updated.IsValid()) return false; - auto const & updated = ttSet[index]; - - for (auto i = 0; i < ttSet.size(); ++i) + for (auto i = 0; i < ttSet.Size(); ++i) { if (i == index) continue; + auto && tt = ttSet.m_table[i]; // Remove all days of updated timetable from all other timetables. TOpeningDays days; - set_difference(std::begin(ttSet[i].GetOpeningDays()), std::end(ttSet[i].GetOpeningDays()), + set_difference(std::begin(tt.GetOpeningDays()), std::end(tt.GetOpeningDays()), std::begin(updated.GetOpeningDays()), std::end(updated.GetOpeningDays()), inserter(days, std::end(days))); - if (!ttSet[i].SetOpeningDays(days)) + if (!tt.SetOpeningDays(days)) return false; } diff --git a/editor/opening_hours_ui.hpp b/editor/opening_hours_ui.hpp index f0bbc39816..c80e254006 100644 --- a/editor/opening_hours_ui.hpp +++ b/editor/opening_hours_ui.hpp @@ -68,35 +68,36 @@ private: class TimeTableSet; using TTimeTableProxy = TimeTableProxyBase; -class TimeTableSet : vector +class TimeTableSet { -public: - using TBase = vector; - using TBase::TBase; + using TTimeTableSetImpl = vector; +public: TimeTableSet(); TOpeningDays GetUnhandledDays() const; TimeTable GetComplementTimeTable() const; - TTimeTableProxy Get(size_t const index) { return TTimeTableProxy(*this, index, (*this)[index]); } + TTimeTableProxy Get(size_t const index) { return TTimeTableProxy(*this, index, m_table[index]); } TTimeTableProxy Front() { return Get(0); } TTimeTableProxy Back() { return Get(Size() - 1); } - size_t Size() const { return size(); } - bool Empty() const { return empty(); } + size_t Size() const { return m_table.size(); } + bool Empty() const { return m_table.empty(); } bool Append(TimeTable const & tt); bool Remove(size_t const index); bool Replace(TimeTable const & tt, size_t const index); - TBase::const_iterator begin() const { return TBase::begin(); } - TBase::const_iterator end() const { return TBase::end(); } + TTimeTableSetImpl::const_iterator begin() const { return m_table.begin(); } + TTimeTableSetImpl::const_iterator end() const { return m_table.end(); } private: static bool UpdateByIndex(TimeTableSet & ttSet, size_t const index); + + TTimeTableSetImpl m_table; }; } // namespace ui } // namespace editor