From 6bb597e38df4192d528d54987106e4f9cf3b219e Mon Sep 17 00:00:00 2001 From: Sergey Magidovich Date: Mon, 16 Nov 2015 22:31:44 +0300 Subject: [PATCH] Code review. Move one-line functions to opening_hours.hpp. --- 3party/opening_hours/opening_hours.cpp | 890 +------------------------ 3party/opening_hours/opening_hours.hpp | 370 +++++----- 2 files changed, 187 insertions(+), 1073 deletions(-) diff --git a/3party/opening_hours/opening_hours.cpp b/3party/opening_hours/opening_hours.cpp index 13d4c2f1a8..49df936255 100644 --- a/3party/opening_hours/opening_hours.cpp +++ b/3party/opening_hours/opening_hours.cpp @@ -113,56 +113,12 @@ namespace osmoh { // HourMinutes ------------------------------------------------------------------------------------- -HourMinutes::HourMinutes(THours const duration) -{ - SetDuration(duration); -} - -HourMinutes::HourMinutes(TMinutes const duration) -{ - SetDuration(duration); -} - -bool HourMinutes::IsEmpty() const -{ - return m_empty; -} bool HourMinutes::IsExtended() const { return GetDuration() > 24_h; } -HourMinutes::THours HourMinutes::GetHours() const -{ - return m_hours; -} - -HourMinutes::TMinutes HourMinutes::GetMinutes() const -{ - return m_minutes; -} - -HourMinutes::TMinutes HourMinutes::GetDuration() const -{ - return GetMinutes() + GetHours(); -} - -HourMinutes::THours::rep HourMinutes::GetHoursCount() const -{ - return GetHours().count(); -} - -HourMinutes::TMinutes::rep HourMinutes::GetMinutesCount() const -{ - return GetMinutes().count(); -} - -HourMinutes::TMinutes::rep HourMinutes::GetDurationCount() const -{ - return GetDuration().count(); -} - void HourMinutes::SetHours(THours const hours) { m_empty = false; @@ -181,11 +137,6 @@ void HourMinutes::SetDuration(TMinutes const duration) SetMinutes(duration - GetHours()); } -void HourMinutes::AddDuration(TMinutes const duration) -{ - SetDuration(GetDuration() + duration); -} - HourMinutes operator-(HourMinutes const & hm) { HourMinutes result; @@ -204,46 +155,9 @@ std::ostream & operator<<(std::ostream & ost, HourMinutes const & hm) } // TimeEvent --------------------------------------------------------------------------------------- -TimeEvent::TimeEvent(Event const event): m_event(event) {} - -bool TimeEvent::IsEmpty() const -{ - return m_event == Event::None; -} - -bool TimeEvent::HasOffset() const -{ - return !m_offset.IsEmpty(); -} - -TimeEvent::Event TimeEvent::GetEvent() const -{ - return m_event; -} - -void TimeEvent::SetEvent(TimeEvent::Event const event) -{ - m_event = event; -} - -HourMinutes const & TimeEvent::GetOffset() const -{ - return m_offset; -} - -void TimeEvent::SetOffset(HourMinutes const & offset) -{ - m_offset = offset; -} - -void TimeEvent::AddDurationToOffset(HourMinutes::TMinutes const duration) -{ - m_offset.AddDuration(duration); -} - Time TimeEvent::GetEventTime() const { - return Time(HourMinutes(0_h + 0_min)); // TODO(mgsergio): get real time + return Time(HourMinutes(0_h + 0_min)); // TODO(mgsergio): get real time } std::ostream & operator<<(std::ostream & ost, TimeEvent::Event const event) @@ -286,31 +200,6 @@ std::ostream & operator<<(std::ostream & ost, TimeEvent const te) } // Time -------------------------------------------------------------------------------------------- -Time::Time(HourMinutes const & hm) -{ - SetHourMinutes(hm); -} - -Time::Time(TimeEvent const & te) -{ - SetEvent(te); -} - -Time::Type Time::GetType() const -{ - return m_type; -} - -Time::THours::rep Time::GetHoursCount() const -{ - return GetHours().count(); -} - -Time::TMinutes::rep Time::GetMinutesCount() const -{ - return GetMinutes().count(); -} - Time::THours Time::GetHours() const { if (IsEvent()) @@ -341,53 +230,18 @@ void Time::AddDuration(TMinutes const duration) } } -TimeEvent const & Time::GetEvent() const -{ - return m_event; -} - void Time::SetEvent(TimeEvent const & event) { m_type = Type::Event; m_event = event; } -HourMinutes const & Time::GetHourMinutes() const -{ - return m_hourMinutes; -} - -HourMinutes & Time::GetHourMinutes() -{ - return m_hourMinutes; -} - void Time::SetHourMinutes(HourMinutes const & hm) { m_type = Type::HourMinutes; m_hourMinutes = hm; } -bool Time::IsEmpty() const -{ - return GetType() == Type::None; -} - -bool Time::IsTime() const -{ - return IsHoursMinutes() || IsEvent(); -} - -bool Time::IsEvent() const -{ - return GetType() == Type::Event; -} - -bool Time::IsHoursMinutes() const -{ - return GetType() == Type::HourMinutes; -} - std::ostream & operator<<(std::ostream & ost, Time const & time) { if (time.IsEmpty()) @@ -404,7 +258,7 @@ std::ostream & operator<<(std::ostream & ost, Time const & time) return ost; } -// TimespanPrion ----------------------------------------------------------------------------------- +// TimespanPeriod ---------------------------------------------------------------------------------- TimespanPeriod::TimespanPeriod(HourMinutes const & hm): m_hourMinutes(hm), m_type(Type::HourMinutes) @@ -417,36 +271,6 @@ TimespanPeriod::TimespanPeriod(HourMinutes::TMinutes const minutes): { } -bool TimespanPeriod::IsEmpty() const -{ - return m_type == Type::None; -} - -bool TimespanPeriod::IsHoursMinutes() const -{ - return m_type == Type::HourMinutes; -} - -bool TimespanPeriod::IsMinutes() const -{ - return m_type == Type::Minutes; -} - -HourMinutes const & TimespanPeriod::GetHourMinutes() const -{ - return m_hourMinutes; -} - -HourMinutes::TMinutes TimespanPeriod::GetMinutes() const -{ - return m_minutes; -} - -HourMinutes::TMinutes::rep TimespanPeriod::GetMinutesCount() const -{ - return GetMinutes().count(); -} - std::ostream & operator<<(std::ostream & ost, TimespanPeriod const p) { if (p.IsEmpty()) @@ -459,36 +283,6 @@ std::ostream & operator<<(std::ostream & ost, TimespanPeriod const p) } // Timespan ---------------------------------------------------------------------------------------- -bool Timespan::IsEmpty() const -{ - return !HasStart() && !HasEnd(); -} - -bool Timespan::IsOpen() const -{ - return HasStart() && !HasEnd(); -} - -bool Timespan::HasStart() const -{ - return !GetStart().IsEmpty(); -} - -bool Timespan::HasEnd() const -{ - return !GetEnd().IsEmpty(); -} - -bool Timespan::HasPlus() const -{ - return m_plus; -} - -bool Timespan::HasPeriod() const -{ - return !m_period.IsEmpty(); -} - bool Timespan::HasExtendedHours() const { bool const canHaveExtendedHours = HasStart() && HasEnd() && @@ -508,58 +302,6 @@ bool Timespan::HasExtendedHours() const return endHM.GetDurationCount() != 0 && (endHM.GetDuration() < startHM.GetDuration()); } -Time const & Timespan::GetStart() const -{ - return m_start; -} - -Time const & Timespan::GetEnd() const -{ - return m_end; -} - -Time & Timespan::GetStart() -{ - return m_start; -} - -Time & Timespan::GetEnd() -{ - return m_end; -} - -TimespanPeriod const & Timespan::GetPeriod() const -{ - return m_period; -} - -void Timespan::SetStart(Time const & start) -{ - m_start = start; -} - -void Timespan::SetEnd(Time const & end) -{ - m_end = end; -} - -void Timespan::SetPeriod(TimespanPeriod const & period) -{ - m_period = period; -} - -void Timespan::SetPlus(bool const plus) -{ - m_plus = plus; -} - -bool Timespan::IsValid() const -{ - // TODO(mgsergio): implement validator. - // See https://trello.com/c/e4pbOhDC/24-opening-hours - return false; -} - std::ostream & operator<<(std::ostream & ost, Timespan const & span) { ost << span.GetStart(); @@ -581,41 +323,6 @@ std::ostream & operator<<(std::ostream & ost, osmoh::TTimespans const & timespan } // NthWeekdayOfTheMonthEntry ----------------------------------------------------------------------- -bool NthWeekdayOfTheMonthEntry::IsEmpty() const -{ - return !HasStart() && !HasEnd(); -} - -bool NthWeekdayOfTheMonthEntry::HasStart() const -{ - return GetStart() != NthDayOfTheMonth::None; -} - -bool NthWeekdayOfTheMonthEntry::HasEnd() const -{ - return GetEnd() != NthDayOfTheMonth::None; -} - -NthWeekdayOfTheMonthEntry::NthDayOfTheMonth NthWeekdayOfTheMonthEntry::GetStart() const -{ - return m_start; -} - -NthWeekdayOfTheMonthEntry::NthDayOfTheMonth NthWeekdayOfTheMonthEntry::GetEnd() const -{ - return m_end; -} - -void NthWeekdayOfTheMonthEntry::SetStart(NthDayOfTheMonth const s) -{ - m_start = s; -} - -void NthWeekdayOfTheMonthEntry::SetEnd(NthDayOfTheMonth const e) -{ - m_end = e; -} - std::ostream & operator<<(std::ostream & ost, NthWeekdayOfTheMonthEntry const entry) { if (entry.HasStart()) @@ -637,78 +344,6 @@ bool WeekdayRange::HasWday(Weekday const & wday) const return GetStart() <= wday && wday <= GetEnd(); } -bool WeekdayRange::HasSunday() const { return HasWday(Weekday::Sunday); } -bool WeekdayRange::HasMonday() const { return HasWday(Weekday::Monday); } -bool WeekdayRange::HasTuesday() const { return HasWday(Weekday::Tuesday); } -bool WeekdayRange::HasWednesday() const { return HasWday(Weekday::Wednesday); } -bool WeekdayRange::HasThursday() const { return HasWday(Weekday::Thursday); } -bool WeekdayRange::HasFriday() const { return HasWday(Weekday::Friday); } -bool WeekdayRange::HasSaturday() const { return HasWday(Weekday::Saturday); } - -bool WeekdayRange::HasStart() const -{ - return GetStart() != Weekday::None; -} - -bool WeekdayRange::HasEnd() const -{ - return GetEnd() != Weekday::None;; -} - -bool WeekdayRange::HasOffset() const -{ - return GetOffset() != 0; -} - -bool WeekdayRange::IsEmpty() const -{ - return GetStart() == Weekday::None && GetEnd() == Weekday::None; -} - -Weekday WeekdayRange::GetStart() const -{ - return m_start; -} - -Weekday WeekdayRange::GetEnd() const -{ - return m_end; -} - -void WeekdayRange::SetStart(Weekday const & wday) -{ - m_start = wday; -} - -void WeekdayRange::SetEnd(Weekday const & wday) -{ - m_end = wday; -} - -int32_t WeekdayRange::GetOffset() const -{ - return m_offset; -} - -void WeekdayRange::SetOffset(int32_t const offset) -{ - m_offset = offset; -} - -bool WeekdayRange::HasNth() const -{ - return !m_nths.empty(); -} - -WeekdayRange::TNths const & WeekdayRange::GetNths() const -{ - return m_nths; -} - -void WeekdayRange::AddNth(NthWeekdayOfTheMonthEntry const & entry) -{ - m_nths.push_back(entry); -} std::ostream & operator<<(std::ostream & ost, Weekday const wday) { @@ -768,26 +403,6 @@ std::ostream & operator<<(std::ostream & ost, TWeekdayRanges const & ranges) } // Holiday ----------------------------------------------------------------------------------------- -bool Holiday::IsPlural() const -{ - return m_plural; -} - -void Holiday::SetPlural(bool const plural) -{ - m_plural = plural; -} - -int32_t Holiday::GetOffset() const -{ - return m_offset; -} - -void Holiday::SetOffset(int32_t const offset) -{ - m_offset = offset; -} - std::ostream & operator<<(std::ostream & ost, Holiday const & holiday) { if (holiday.IsPlural()) @@ -809,50 +424,6 @@ std::ostream & operator<<(std::ostream & ost, THolidays const & holidays) } // Weekdays ---------------------------------------------------------------------------------------- -bool Weekdays::IsEmpty() const -{ - return GetWeekdayRanges().empty() && GetHolidays().empty(); -} - -bool Weekdays::HasWeekday() const -{ - return !GetWeekdayRanges().empty(); -} - -bool Weekdays::HasHolidays() const -{ - return !GetHolidays().empty(); -} - -TWeekdayRanges const & Weekdays::GetWeekdayRanges() const -{ - return m_weekdayRanges; -} - -THolidays const & Weekdays::GetHolidays() const -{ - return m_holidays; -} - -void Weekdays::SetWeekdayRanges(TWeekdayRanges const ranges) -{ - m_weekdayRanges = ranges; -} - -void Weekdays::SetHolidays(THolidays const & holidays) -{ - m_holidays = holidays; -} - -void Weekdays::AddWeekdayRange(WeekdayRange const range) -{ - m_weekdayRanges.push_back(range); -} - -void Weekdays::AddHoliday(Holiday const & holiday) -{ - m_holidays.push_back(holiday); -} std::ostream & operator<<(std::ostream & ost, Weekdays const & weekday) { @@ -864,51 +435,6 @@ std::ostream & operator<<(std::ostream & ost, Weekdays const & weekday) } // DateOffset -------------------------------------------------------------------------------------- -bool DateOffset::IsEmpty() const -{ - return !HasOffset() && !HasWDayOffset(); -} - -bool DateOffset::HasWDayOffset() const -{ - return m_wdayOffest != Weekday::None; -} - -bool DateOffset::HasOffset() const -{ - return m_offset != 0; -} - -bool DateOffset::IsWDayOffsetPositive() const -{ - return m_positive; -} - -Weekday DateOffset::GetWDayOffset() const -{ - return m_wdayOffest; -} - -int32_t DateOffset::GetOffset() const -{ - return m_offset; -} - -void DateOffset::SetWDayOffset(Weekday const wday) -{ - m_wdayOffest = wday; -} - -void DateOffset::SetOffset(int32_t const offset) -{ - m_offset = offset; -} - -void DateOffset::SetWDayOffsetPositive(bool const on) -{ - m_positive = on; -} - std::ostream & operator<<(std::ostream & ost, DateOffset const & offset) { if (offset.HasWDayOffset()) @@ -921,86 +447,6 @@ std::ostream & operator<<(std::ostream & ost, DateOffset const & offset) } // MonthDay ---------------------------------------------------------------------------------------- -bool MonthDay::IsEmpty() const -{ - return !HasYear() && !HasMonth() && !HasDayNum() && !IsVariable(); -} - -bool MonthDay::IsVariable() const -{ - return GetVariableDate() != VariableDate::None; -} - -bool MonthDay::HasYear() const -{ - return GetYear() != 0; -} - -bool MonthDay::HasMonth() const -{ - return GetMonth() != Month::None; -} - -bool MonthDay::HasDayNum() const -{ - return GetDayNum() != 0; -} - -bool MonthDay::HasOffset() const -{ - return !GetOffset().IsEmpty(); -} - -MonthDay::TYear MonthDay::GetYear() const -{ - return m_year; -} - -MonthDay::Month MonthDay::GetMonth() const -{ - return m_month; -} - -MonthDay::TDayNum MonthDay::GetDayNum() const -{ - return m_daynum; -} - -DateOffset const & MonthDay::GetOffset() const -{ - return m_offset; -} - -MonthDay::VariableDate MonthDay::GetVariableDate() const -{ - return m_variable_date; -} - -void MonthDay::SetYear(TYear const year) -{ - m_year = year; -} - -void MonthDay::SetMonth(Month const month) -{ - m_month = month; -} - -void MonthDay::SetDayNum(TDayNum const daynum) -{ - m_daynum = daynum; -} - -void MonthDay::SetOffset(DateOffset const & offset) -{ - m_offset = offset; -} - -void MonthDay::SetVariableDate(VariableDate const date) -{ - m_variable_date = date; -} - std::ostream & operator<<(std::ostream & ost, MonthDay::Month const month) { switch (month) @@ -1103,66 +549,6 @@ std::ostream & operator<<(std::ostream & ost, MonthDay const md) } // MonthdayRange ----------------------------------------------------------------------------------- -bool MonthdayRange::IsEmpty() const -{ - return !HasStart() && !HasEnd(); -} - -bool MonthdayRange::HasStart() const -{ - return !GetStart().IsEmpty(); -} - -bool MonthdayRange::HasEnd() const -{ - return !GetEnd().IsEmpty() || GetEnd().HasDayNum(); -} - -bool MonthdayRange::HasPeriod() const -{ - return m_period != 0; -} - -bool MonthdayRange::HasPlus() const -{ - return m_plus; -} - -MonthDay const & MonthdayRange::GetStart() const -{ - return m_start; -} - -MonthDay const & MonthdayRange::GetEnd() const -{ - return m_end; -} - -uint32_t MonthdayRange::GetPeriod() const -{ - return m_period; -} - -void MonthdayRange::SetStart(MonthDay const & start) -{ - m_start = start; -} - -void MonthdayRange::SetEnd(MonthDay const & end) -{ - m_end = end; -} - -void MonthdayRange::SetPeriod(uint32_t const period) -{ - m_period = period; -} - -void MonthdayRange::SetPlus(bool const plus) -{ - m_plus = plus; -} - std::ostream & operator<<(std::ostream & ost, MonthdayRange const & range) { if (range.HasStart()) @@ -1185,71 +571,6 @@ std::ostream & operator<<(std::ostream & ost, TMonthdayRanges const & ranges) } // YearRange --------------------------------------------------------------------------------------- -bool YearRange::IsEmpty() const -{ - return !HasStart() && !HasEnd(); -} - -bool YearRange::IsOpen() const -{ - return HasStart() && !HasEnd(); -} - -bool YearRange::HasStart() const -{ - return GetStart() != 0; -} - -bool YearRange::HasEnd() const -{ - return GetEnd() != 0; -} - -bool YearRange::HasPlus() const -{ - return m_plus; -} - -bool YearRange::HasPeriod() const -{ - return GetPeriod() != 0; -} - -YearRange::TYear YearRange::GetStart() const -{ - return m_start; -} - -YearRange::TYear YearRange::GetEnd() const -{ - return m_end; -} - -uint32_t YearRange::GetPeriod() const -{ - return m_period; -} - -void YearRange::SetStart(TYear const start) -{ - m_start = start; -} - -void YearRange::SetEnd(TYear const end) -{ - m_end = end; -} - -void YearRange::SetPlus(bool const plus) -{ - m_plus = plus; -} - -void YearRange::SetPeriod(uint32_t const period) -{ - m_period = period; -} - std::ostream & operator<<(std::ostream & ost, YearRange const range) { if (range.IsEmpty()) @@ -1277,61 +598,6 @@ std::ostream & operator<<(std::ostream & ost, TYearRanges const ranges) } // WeekRange --------------------------------------------------------------------------------------- -bool WeekRange::IsEmpty() const -{ - return !HasStart() && !HasEnd(); -} - -bool WeekRange::IsOpen() const -{ - return HasStart() && !HasEnd(); -} - -bool WeekRange::HasStart() const -{ - return GetStart() != 0; -} - -bool WeekRange::HasEnd() const -{ - return GetEnd() != 0; -} - -bool WeekRange::HasPeriod() const -{ - return GetPeriod() != 0; -} - -WeekRange::TWeek WeekRange::GetStart() const -{ - return m_start; -} - -WeekRange::TWeek WeekRange::GetEnd() const -{ - return m_end; -} - -uint32_t WeekRange::GetPeriod() const -{ - return m_period; -} - -void WeekRange::SetStart(TWeek const start) -{ - m_start = start; -} - -void WeekRange::SetEnd(TWeek const end) -{ - m_end = end; -} - -void WeekRange::SetPeriod(uint32_t const period) -{ - m_period = period; -} - std::ostream & operator<<(std::ostream & ost, WeekRange const range) { if (range.IsEmpty()) @@ -1356,158 +622,6 @@ std::ostream & operator<<(std::ostream & ost, TWeekRanges const ranges) } // RuleSequence ------------------------------------------------------------------------------------ -bool RuleSequence::IsEmpty() const -{ - return (!HasYears() && !HasMonths() && - !HasWeeks() && !HasWeekdays() && - !HasTimes()); -} - -bool RuleSequence::IsTwentyFourHours() const -{ - return m_twentyFourHours; -} - -bool RuleSequence::HasYears() const -{ - return !GetYears().empty(); -} - -bool RuleSequence::HasMonths() const -{ - return !GetMonths().empty(); -} - -bool RuleSequence::HasWeeks() const -{ - return !GetWeeks().empty(); -} - -bool RuleSequence::HasWeekdays() const -{ - return !GetWeekdays().IsEmpty(); -} - -bool RuleSequence::HasTimes() const -{ - return !GetTimes().empty(); -} - -bool RuleSequence::HasComment() const -{ - return !GetComment().empty(); -} - -bool RuleSequence::HasModifierComment() const -{ - return !GetModifierComment().empty(); -} - -bool RuleSequence::HasSeparatorForReadability() const -{ - return m_separatorForReadability; -} - -TYearRanges const & RuleSequence::GetYears() const -{ - return m_years; -} - -TMonthdayRanges const & RuleSequence::GetMonths() const -{ - return m_months; -} - -TWeekRanges const & RuleSequence::GetWeeks() const -{ - return m_weeks; -} - -Weekdays const & RuleSequence::GetWeekdays() const -{ - return m_weekdays; -} - -TTimespans const & RuleSequence::GetTimes() const -{ - return m_times; -} - -std::string const & RuleSequence::GetComment() const -{ - return m_comment; -} - -std::string const & RuleSequence::GetModifierComment() const -{ - return m_modifierComment; -} - -std::string const & RuleSequence::GetAnySeparator() const -{ - return m_anySeparator; -} - -RuleSequence::Modifier RuleSequence::GetModifier() const -{ - return m_modifier; -} - -void RuleSequence::SetTwentyFourHours(bool const on) -{ - m_twentyFourHours = on; -} - -void RuleSequence::SetYears(TYearRanges const & years) -{ - m_years = years; -} - -void RuleSequence::SetMonths(TMonthdayRanges const & months) -{ - m_months = months; -} - -void RuleSequence::SetWeeks(TWeekRanges const & weeks) -{ - m_weeks = weeks; -} - -void RuleSequence::SetWeekdays(Weekdays const & weekdays) -{ - m_weekdays = weekdays; -} - -void RuleSequence::SetTimes(TTimespans const & times) -{ - m_times = times; -} - -void RuleSequence::SetComment(std::string const & comment) -{ - m_comment = comment; -} - -void RuleSequence::SetModifierComment(std::string & comment) -{ - m_modifierComment = comment; -} - -void RuleSequence::SetAnySeparator(std::string const & separator) -{ - m_anySeparator = separator; -} - -void RuleSequence::SetSeparatorForReadability(bool const on) -{ - m_separatorForReadability = on; -} - -void RuleSequence::SetModifier(Modifier const modifier) -{ - m_modifier = modifier; -} - std::ostream & operator<<(std::ostream & ost, RuleSequence::Modifier const modifier) { switch (modifier) diff --git a/3party/opening_hours/opening_hours.hpp b/3party/opening_hours/opening_hours.hpp index 1e7504060d..4ff4ddb4a1 100644 --- a/3party/opening_hours/opening_hours.hpp +++ b/3party/opening_hours/opening_hours.hpp @@ -40,25 +40,25 @@ public: using TMinutes = std::chrono::minutes; HourMinutes() = default; - explicit HourMinutes(THours const duration); - explicit HourMinutes(TMinutes const duration); + explicit HourMinutes(THours const duration) { SetDuration(duration); } + explicit HourMinutes(TMinutes const duration) { SetDuration(duration); } - bool IsEmpty() const; + bool IsEmpty() const { return m_empty; } bool IsExtended() const; - THours GetHours() const; - TMinutes GetMinutes() const; - TMinutes GetDuration() const; + THours GetHours() const { return m_hours; } + TMinutes GetMinutes() const { return m_minutes; } + TMinutes GetDuration() const { return GetMinutes() + GetHours(); } - THours::rep GetHoursCount() const; - TMinutes::rep GetMinutesCount() const; - TMinutes::rep GetDurationCount() const; + THours::rep GetHoursCount() const { return GetHours().count(); } + TMinutes::rep GetMinutesCount() const { return GetMinutes().count(); } + TMinutes::rep GetDurationCount() const { return GetDuration().count(); } void SetHours(THours const hours); void SetMinutes(TMinutes const minutes); void SetDuration(TMinutes const duration); - void AddDuration(TMinutes const duration); + void AddDuration(TMinutes const duration) { SetDuration(GetDuration() + duration); } private: THours m_hours = THours::zero(); @@ -82,17 +82,17 @@ public: }; TimeEvent() = default; - TimeEvent(Event const event); + TimeEvent(Event const event): m_event(event) {} - bool IsEmpty() const; - bool HasOffset() const; + bool IsEmpty() const { return m_event == Event::None; } + bool HasOffset() const { return !m_offset.IsEmpty(); } - Event GetEvent() const; - void SetEvent(Event const event); + Event GetEvent() const { return m_event; } + void SetEvent(Event const event) { m_event = event; } - HourMinutes const & GetOffset() const; - void SetOffset(HourMinutes const & offset); - void AddDurationToOffset(HourMinutes::TMinutes const duration); + HourMinutes const & GetOffset() const { return m_offset; } + void SetOffset(HourMinutes const & offset) { m_offset = offset; } + void AddDurationToOffset(HourMinutes::TMinutes const duration) { m_offset.AddDuration(duration); } Time GetEventTime() const; @@ -117,31 +117,31 @@ class Time using TMinutes = HourMinutes::TMinutes; Time() = default; - Time(HourMinutes const & hm); - Time(TimeEvent const & te); + Time(HourMinutes const & hm) { SetHourMinutes(hm); } + Time(TimeEvent const & te) { SetEvent(te); } - Type GetType() const; + bool IsEmpty() const { return GetType() == Type::None; } + bool IsTime() const { return IsHoursMinutes() || IsEvent(); } + bool IsEvent() const { return GetType() == Type::Event; } + bool IsHoursMinutes() const { return GetType() == Type::HourMinutes; } - THours::rep GetHoursCount() const; - TMinutes::rep GetMinutesCount() const; + Type GetType() const { return m_type; } + + THours::rep GetHoursCount() const { return GetHours().count(); } + TMinutes::rep GetMinutesCount() const { return GetMinutes().count(); } THours GetHours() const; TMinutes GetMinutes() const; void AddDuration(TMinutes const duration); - TimeEvent const & GetEvent() const; + TimeEvent const & GetEvent() const { return m_event; } void SetEvent(TimeEvent const & event); - HourMinutes const & GetHourMinutes() const; - HourMinutes & GetHourMinutes(); + HourMinutes const & GetHourMinutes() const { return m_hourMinutes; } + HourMinutes & GetHourMinutes() { return m_hourMinutes; } void SetHourMinutes(HourMinutes const & hm); - bool IsEmpty() const; - bool IsTime() const; - bool IsEvent() const; - bool IsHoursMinutes() const; - private: HourMinutes m_hourMinutes; TimeEvent m_event; @@ -175,13 +175,13 @@ public: TimespanPeriod(HourMinutes const & hm); TimespanPeriod(HourMinutes::TMinutes const minutes); - bool IsEmpty() const; - bool IsHoursMinutes() const; - bool IsMinutes() const; + bool IsEmpty() const { return m_type == Type::None; } + bool IsHoursMinutes() const { return m_type == Type::HourMinutes; } + bool IsMinutes() const { return m_type == Type::Minutes; } - HourMinutes const & GetHourMinutes() const; - HourMinutes::TMinutes GetMinutes() const; - HourMinutes::TMinutes::rep GetMinutesCount() const; + HourMinutes const & GetHourMinutes() const { return m_hourMinutes; } + HourMinutes::TMinutes GetMinutes() const { return m_minutes; } + HourMinutes::TMinutes::rep GetMinutesCount() const { return GetMinutes().count(); } private: HourMinutes::TMinutes m_minutes; @@ -195,28 +195,26 @@ std::ostream & operator<<(std::ostream & ost, TimespanPeriod const p); class Timespan { public: - bool IsEmpty() const; - bool IsOpen() const; - bool HasStart() const; - bool HasEnd() const; - bool HasPlus() const; - bool HasPeriod() const; + bool IsEmpty() const { return !HasStart() && !HasEnd(); } + bool IsOpen() const { return HasStart() && !HasEnd(); } + bool HasStart() const { return !GetStart().IsEmpty(); } + bool HasEnd() const { return !GetEnd().IsEmpty(); } + bool HasPlus() const { return m_plus; } + bool HasPeriod() const { return !m_period.IsEmpty(); } bool HasExtendedHours() const; - Time const & GetStart() const; - Time const & GetEnd() const; + Time const & GetStart() const { return m_start; } + Time const & GetEnd() const { return m_end; } - Time & GetStart(); - Time & GetEnd(); + Time & GetStart() { return m_start; } + Time & GetEnd() { return m_end; } - TimespanPeriod const & GetPeriod() const; + TimespanPeriod const & GetPeriod() const { return m_period; } - void SetStart(Time const & start); - void SetEnd(Time const & end); - void SetPeriod(TimespanPeriod const & period); - void SetPlus(bool const plus); - - bool IsValid() const; + void SetStart(Time const & start) { m_start = start; } + void SetEnd(Time const & end) { m_end = end; } + void SetPeriod(TimespanPeriod const & period) { m_period = period; } + void SetPlus(bool const plus) { m_plus = plus; } private: Time m_start; @@ -243,15 +241,15 @@ public: Fifth }; - bool IsEmpty() const; - bool HasStart() const; - bool HasEnd() const; + bool IsEmpty() const { return !HasStart() && !HasEnd(); } + bool HasStart() const { return GetStart() != NthDayOfTheMonth::None; } + bool HasEnd() const { return GetEnd() != NthDayOfTheMonth::None; } - NthDayOfTheMonth GetStart() const; - NthDayOfTheMonth GetEnd() const; + NthDayOfTheMonth GetStart() const { return m_start; } + NthDayOfTheMonth GetEnd() const { return m_end; } - void SetStart(NthDayOfTheMonth const s); - void SetEnd(NthDayOfTheMonth const e); + void SetStart(NthDayOfTheMonth const s) { m_start = s; } + void SetEnd(NthDayOfTheMonth const e) { m_end = e; } private: NthDayOfTheMonth m_start = NthDayOfTheMonth::None; @@ -295,32 +293,33 @@ class WeekdayRange public: bool HasWday(Weekday const & wday) const; - bool HasSunday() const; - bool HasMonday() const; - bool HasTuesday() const; - bool HasWednesday() const; - bool HasThursday() const; - bool HasFriday() const; - bool HasSaturday() const; + bool HasSunday() const { return HasWday(Weekday::Sunday); } + bool HasMonday() const { return HasWday(Weekday::Monday); } + bool HasTuesday() const { return HasWday(Weekday::Tuesday); } + bool HasWednesday() const { return HasWday(Weekday::Wednesday); } + bool HasThursday() const { return HasWday(Weekday::Thursday); } + bool HasFriday() const { return HasWday(Weekday::Friday); } + bool HasSaturday() const { return HasWday(Weekday::Saturday); } - bool HasStart() const; - bool HasEnd() const; - bool HasOffset() const; - bool IsEmpty() const; + bool HasStart() const { return GetStart() != Weekday::None; } + bool HasEnd() const {return GetEnd() != Weekday::None; } + bool HasOffset() const { return GetOffset() != 0; } + bool IsEmpty() const { return GetStart() == Weekday::None && + GetEnd() == Weekday::None; } - Weekday GetStart() const; - Weekday GetEnd() const; + Weekday GetStart() const { return m_start; } + Weekday GetEnd() const { return m_end; } - void SetStart(Weekday const & wday); - void SetEnd(Weekday const & wday); + void SetStart(Weekday const & wday) { m_start = wday; } + void SetEnd(Weekday const & wday) { m_end = wday; } - int32_t GetOffset() const; - void SetOffset(int32_t const offset); + int32_t GetOffset() const { return m_offset; } + void SetOffset(int32_t const offset) { m_offset = offset; } - bool HasNth() const; - TNths const & GetNths() const; + bool HasNth() const { return !m_nths.empty(); } + TNths const & GetNths() const { return m_nths; } - void AddNth(NthWeekdayOfTheMonthEntry const & entry); + void AddNth(NthWeekdayOfTheMonthEntry const & entry) { m_nths.push_back(entry); } private: Weekday m_start = Weekday::None; @@ -337,11 +336,11 @@ std::ostream & operator<<(std::ostream & ost, TWeekdayRanges const & ranges); class Holiday { public: - bool IsPlural() const; - void SetPlural(bool const plural); + bool IsPlural() const { return m_plural; } + void SetPlural(bool const plural) { m_plural = plural; } - int32_t GetOffset() const; - void SetOffset(int32_t const offset); + int32_t GetOffset() const { return m_offset; } + void SetOffset(int32_t const offset) { m_offset = offset; } private: bool m_plural = false; @@ -357,18 +356,18 @@ std::ostream & operator<<(std::ostream & ost, THolidays const & holidys); class Weekdays { public: - bool IsEmpty() const; - bool HasWeekday() const; - bool HasHolidays() const; + bool IsEmpty() const { return GetWeekdayRanges().empty() && GetHolidays().empty(); } + bool HasWeekday() const { return !GetWeekdayRanges().empty(); } + bool HasHolidays() const { return !GetHolidays().empty(); } - TWeekdayRanges const & GetWeekdayRanges() const; - THolidays const & GetHolidays() const; + TWeekdayRanges const & GetWeekdayRanges() const { return m_weekdayRanges; } + THolidays const & GetHolidays() const { return m_holidays; } - void SetWeekdayRanges(TWeekdayRanges const ranges); - void SetHolidays(THolidays const & holidays); + void SetWeekdayRanges(TWeekdayRanges const ranges) { m_weekdayRanges = ranges; } + void SetHolidays(THolidays const & holidays) { m_holidays = holidays; } - void AddWeekdayRange(WeekdayRange const range); - void AddHoliday(Holiday const & holiday); + void AddWeekdayRange(WeekdayRange const range) { m_weekdayRanges.push_back(range); } + void AddHoliday(Holiday const & holiday) { m_holidays.push_back(holiday); } private: TWeekdayRanges m_weekdayRanges; @@ -380,18 +379,18 @@ std::ostream & operator<<(std::ostream & ost, Weekdays const & weekday); class DateOffset { public: - bool IsEmpty() const; - bool HasWDayOffset() const; - bool HasOffset() const; + bool IsEmpty() const { return !HasOffset() && !HasWDayOffset(); } + bool HasWDayOffset() const { return m_wdayOffest != Weekday::None; } + bool HasOffset() const { return m_offset != 0; } - bool IsWDayOffsetPositive() const; + bool IsWDayOffsetPositive() const { return m_positive; } - Weekday GetWDayOffset() const; - int32_t GetOffset() const; + Weekday GetWDayOffset() const { return m_wdayOffest; } + int32_t GetOffset() const { return m_offset; } - void SetWDayOffset(Weekday const wday); - void SetOffset(int32_t const offset); - void SetWDayOffsetPositive(bool const on); + void SetWDayOffset(Weekday const wday) { m_wdayOffest = wday; } + void SetOffset(int32_t const offset) { m_offset = offset; } + void SetWDayOffsetPositive(bool const on) { m_positive = on; } private: Weekday m_wdayOffest = Weekday::None; @@ -430,25 +429,25 @@ public: using TYear = uint16_t; using TDayNum = uint8_t; - bool IsEmpty() const; - bool IsVariable() const; + bool IsEmpty() const { return !HasYear() && !HasMonth() && !HasDayNum() && !IsVariable(); } + bool IsVariable() const { return GetVariableDate() != VariableDate::None; } - bool HasYear() const; - bool HasMonth() const; - bool HasDayNum() const; - bool HasOffset() const; + bool HasYear() const { return GetYear() != 0; } + bool HasMonth() const { return GetMonth() != Month::None; } + bool HasDayNum() const { return GetDayNum() != 0; } + bool HasOffset() const { return !GetOffset().IsEmpty(); } - TYear GetYear() const; - Month GetMonth() const; - TDayNum GetDayNum() const; - DateOffset const & GetOffset() const; - VariableDate GetVariableDate() const; + TYear GetYear() const { return m_year; } + Month GetMonth() const { return m_month; } + TDayNum GetDayNum() const { return m_daynum; } + DateOffset const & GetOffset() const { return m_offset; } + VariableDate GetVariableDate() const { return m_variable_date; } - void SetYear(TYear const year); - void SetMonth(Month const month); - void SetDayNum(TDayNum const daynum); - void SetOffset(DateOffset const & offset); - void SetVariableDate(VariableDate const date); + void SetYear(TYear const year) { m_year = year; } + void SetMonth(Month const month) { m_month = month; } + void SetDayNum(TDayNum const daynum) { m_daynum = daynum; } + void SetOffset(DateOffset const & offset) { m_offset = offset; } + void SetVariableDate(VariableDate const date) { m_variable_date = date; } private: TYear m_year = 0; @@ -479,20 +478,20 @@ std::ostream & operator<<(std::ostream & ost, MonthDay const md); class MonthdayRange { public: - bool IsEmpty() const; - bool HasStart() const; - bool HasEnd() const; - bool HasPeriod() const; - bool HasPlus() const; + bool IsEmpty() const { return !HasStart() && !HasEnd(); } + bool HasStart() const { return !GetStart().IsEmpty(); } + bool HasEnd() const { return !GetEnd().IsEmpty() || GetEnd().HasDayNum(); } + bool HasPeriod() const { return m_period != 0; } + bool HasPlus() const { return m_plus; } - MonthDay const & GetStart() const; - MonthDay const & GetEnd() const; - uint32_t GetPeriod() const; + MonthDay const & GetStart() const { return m_start; } + MonthDay const & GetEnd() const { return m_end; } + uint32_t GetPeriod() const { return m_period; } - void SetStart(MonthDay const & start); - void SetEnd(MonthDay const & end); - void SetPeriod(uint32_t const period); - void SetPlus(bool const plus); + void SetStart(MonthDay const & start) { m_start = start; } + void SetEnd(MonthDay const & end) { m_end = end; } + void SetPeriod(uint32_t const period) { m_period = period; } + void SetPlus(bool const plus) { m_plus = plus; } private: MonthDay m_start; @@ -511,21 +510,21 @@ class YearRange public: using TYear = uint16_t; - bool IsEmpty() const; - bool IsOpen() const; - bool HasStart() const; - bool HasEnd() const; - bool HasPlus() const; - bool HasPeriod() const; + bool IsEmpty() const { return !HasStart() && !HasEnd(); } + bool IsOpen() const { return HasStart() && !HasEnd(); } + bool HasStart() const { return GetStart() != 0; } + bool HasEnd() const { return GetEnd() != 0; } + bool HasPlus() const { return m_plus; } + bool HasPeriod() const { return GetPeriod() != 0; } - TYear GetStart() const; - TYear GetEnd() const; - uint32_t GetPeriod() const; + TYear GetStart() const { return m_start; } + TYear GetEnd() const { return m_end; } + uint32_t GetPeriod() const { return m_period; } - void SetStart(TYear const start); - void SetEnd(TYear const end); - void SetPlus(bool const plus); - void SetPeriod(uint32_t const period); + void SetStart(TYear const start) { m_start = start; } + void SetEnd(TYear const end) { m_end = end; } + void SetPlus(bool const plus) { m_plus = plus; } + void SetPeriod(uint32_t const period) { m_period = period; } private: TYear m_start = 0; @@ -544,19 +543,19 @@ class WeekRange public: using TWeek = uint8_t; - bool IsEmpty() const; - bool IsOpen() const; - bool HasStart() const; - bool HasEnd() const; - bool HasPeriod() const; + bool IsEmpty() const { return !HasStart() && !HasEnd(); } + bool IsOpen() const { return HasStart() && !HasEnd(); } + bool HasStart() const { return GetStart() != 0; } + bool HasEnd() const { return GetEnd() != 0; } + bool HasPeriod() const { return GetPeriod() != 0; } - TWeek GetStart() const; - TWeek GetEnd() const; - uint32_t GetPeriod() const; + TWeek GetStart() const { return m_start; } + TWeek GetEnd() const { return m_end; } + uint32_t GetPeriod() const { return m_period; } - void SetStart(TWeek const start); - void SetEnd(TWeek const end); - void SetPeriod(uint32_t const period); + void SetStart(TWeek const start) { m_start = start; } + void SetEnd(TWeek const end) { m_end = end; } + void SetPeriod(uint32_t const period) { m_period = period; } private: TWeek m_start = 0; @@ -581,44 +580,45 @@ public: Comment }; - bool IsEmpty() const; - bool IsTwentyFourHours() const; + bool IsEmpty() const { return !HasYears() && !HasMonths() && !HasWeeks() && + !HasWeekdays() && !HasTimes(); } + bool IsTwentyFourHours() const { return m_twentyFourHours; } - bool HasYears() const; - bool HasMonths() const; - bool HasWeeks() const; - bool HasWeekdays() const; - bool HasTimes() const; - bool HasComment() const; - bool HasModifierComment() const; - bool HasSeparatorForReadability() const; + bool HasYears() const { return !GetYears().empty(); } + bool HasMonths() const { return !GetMonths().empty(); } + bool HasWeeks() const { return !GetWeeks().empty(); } + bool HasWeekdays() const { return !GetWeekdays().IsEmpty(); } + bool HasTimes() const { return !GetTimes().empty(); } + bool HasComment() const { return !GetComment().empty(); } + bool HasModifierComment() const { return !GetModifierComment().empty(); } + bool HasSeparatorForReadability() const { return m_separatorForReadability; } - TYearRanges const & GetYears() const; - TMonthdayRanges const & GetMonths() const; - TWeekRanges const & GetWeeks() const; - Weekdays const & GetWeekdays() const; - TTimespans const & GetTimes() const; + TYearRanges const & GetYears() const { return m_years; } + TMonthdayRanges const & GetMonths() const { return m_months; } + TWeekRanges const & GetWeeks() const { return m_weeks; } + Weekdays const & GetWeekdays() const { return m_weekdays; } + TTimespans const & GetTimes() const { return m_times; } - std::string const & GetComment() const; - std::string const & GetModifierComment() const; - std::string const & GetAnySeparator() const; + std::string const & GetComment() const { return m_comment; } + std::string const & GetModifierComment() const { return m_modifierComment; } + std::string const & GetAnySeparator() const { return m_anySeparator; } - Modifier GetModifier() const; + Modifier GetModifier() const { return m_modifier; } - void SetTwentyFourHours(bool const on); - void SetYears(TYearRanges const & years); - void SetMonths(TMonthdayRanges const & months); - void SetWeeks(TWeekRanges const & weeks); + void SetTwentyFourHours(bool const on) { m_twentyFourHours = on; } + void SetYears(TYearRanges const & years) { m_years = years; } + void SetMonths(TMonthdayRanges const & months) { m_months = months; } + void SetWeeks(TWeekRanges const & weeks) { m_weeks = weeks; } - void SetWeekdays(Weekdays const & weekdays); - void SetTimes(TTimespans const & times); + void SetWeekdays(Weekdays const & weekdays) { m_weekdays = weekdays; } + void SetTimes(TTimespans const & times) { m_times = times; } - void SetComment(std::string const & comment); - void SetModifierComment(std::string & comment); - void SetAnySeparator(std::string const & separator); - void SetSeparatorForReadability(bool const on); + void SetComment(std::string const & comment) { m_comment = comment; } + void SetModifierComment(std::string & comment) { m_modifierComment = comment; } + void SetAnySeparator(std::string const & separator) { m_anySeparator = separator; } + void SetSeparatorForReadability(bool const on) { m_separatorForReadability = on; } - void SetModifier(Modifier const modifier); + void SetModifier(Modifier const modifier) { m_modifier = modifier; } private: bool m_twentyFourHours{false};