From 971a6385a1dcfd39078e028108151d497ebc70f8 Mon Sep 17 00:00:00 2001 From: Sergey Magidovich Date: Wed, 4 Nov 2015 21:32:55 +0300 Subject: [PATCH] Code review: rename files; fix comments; remove redundant \ns; wchar_t -> char (the last one); add `using osmoh::XXX' in opening_hours_parsers.hpp to improve readability; fix variable and function names. --- .../{osm_time_range.cpp => opening_hours.cpp} | 58 ++--- .../{osm_time_range.hpp => opening_hours.hpp} | 45 ++-- 3party/opening_hours/opening_hours.pro | 18 +- .../opening_hours_integration_tests.cpp | 2 +- .../opening_hours_integration_tests.pro | 6 +- ..._parsers.hpp => opening_hours_parsers.hpp} | 224 +++++++++--------- ...pp => opening_hours_parsers_terminals.hpp} | 4 +- ...opening_hours_supported_features_tests.cpp | 2 +- ...opening_hours_supported_features_tests.pro | 6 +- ...ange_tests.cpp => opening_hours_tests.cpp} | 18 +- .../opening_hours_tests.pro | 8 +- .../{parse.cpp => parse_opening_hours.cpp} | 4 +- .../{parse.hpp => parse_opening_hours.hpp} | 2 +- 3party/opening_hours/rules_evaluation.cpp | 7 +- 3party/opening_hours/rules_evaluation.hpp | 7 +- .../rules_evaluation_private.hpp | 2 +- map/osm_opening_hours.hpp | 2 +- search/intermediate_result.cpp | 2 +- 18 files changed, 199 insertions(+), 218 deletions(-) rename 3party/opening_hours/{osm_time_range.cpp => opening_hours.cpp} (94%) rename 3party/opening_hours/{osm_time_range.hpp => opening_hours.hpp} (94%) rename 3party/opening_hours/{osm_parsers.hpp => opening_hours_parsers.hpp} (56%) rename 3party/opening_hours/{osm_parsers_terminals.hpp => opening_hours_parsers_terminals.hpp} (99%) rename 3party/opening_hours/opening_hours_tests/{osm_time_range_tests.cpp => opening_hours_tests.cpp} (98%) rename 3party/opening_hours/{parse.cpp => parse_opening_hours.cpp} (96%) rename 3party/opening_hours/{parse.hpp => parse_opening_hours.hpp} (92%) diff --git a/3party/opening_hours/osm_time_range.cpp b/3party/opening_hours/opening_hours.cpp similarity index 94% rename from 3party/opening_hours/osm_time_range.cpp rename to 3party/opening_hours/opening_hours.cpp index c4f4004f36..dc02707301 100644 --- a/3party/opening_hours/osm_time_range.cpp +++ b/3party/opening_hours/opening_hours.cpp @@ -22,7 +22,7 @@ THE SOFTWARE. */ -#include "osm_time_range.hpp" +#include "opening_hours.hpp" #include #include @@ -366,42 +366,42 @@ std::ostream & operator<<(std::ostream & ost, osmoh::TTimespans const & timespan } -bool NthEntry::IsEmpty() const +bool NthWeekdayOfTheMonthEntry::IsEmpty() const { return !HasStart() && !HasEnd(); } -bool NthEntry::HasStart() const +bool NthWeekdayOfTheMonthEntry::HasStart() const { - return GetStart() != Nth::None; + return GetStart() != NthDayOfTheMonth::None; } -bool NthEntry::HasEnd() const +bool NthWeekdayOfTheMonthEntry::HasEnd() const { - return GetEnd() != Nth::None; + return GetEnd() != NthDayOfTheMonth::None; } -NthEntry::Nth NthEntry::GetStart() const +NthWeekdayOfTheMonthEntry::NthDayOfTheMonth NthWeekdayOfTheMonthEntry::GetStart() const { return m_start; } -NthEntry::Nth NthEntry::GetEnd() const +NthWeekdayOfTheMonthEntry::NthDayOfTheMonth NthWeekdayOfTheMonthEntry::GetEnd() const { return m_end; } -void NthEntry::SetStart(Nth const s) +void NthWeekdayOfTheMonthEntry::SetStart(NthDayOfTheMonth const s) { m_start = s; } -void NthEntry::SetEnd(Nth const e) +void NthWeekdayOfTheMonthEntry::SetEnd(NthDayOfTheMonth const e) { m_end = e; } -std::ostream & operator<<(std::ostream & ost, NthEntry const entry) +std::ostream & operator<<(std::ostream & ost, NthWeekdayOfTheMonthEntry const entry) { if (entry.HasStart()) ost << static_cast(entry.GetStart()); @@ -496,7 +496,7 @@ WeekdayRange::TNths const & WeekdayRange::GetNths() const return m_nths; } -void WeekdayRange::AddNth(NthEntry const & entry) +void WeekdayRange::AddNth(NthWeekdayOfTheMonthEntry const & entry) { m_nths.push_back(entry); } @@ -1143,9 +1143,9 @@ bool RuleSequence::IsEmpty() const !HasTimes()); } -bool RuleSequence::Is24Per7() const +bool RuleSequence::IsTwentyFourHours() const { - return m_24_per_7; + return m_twentyFourHours; } bool RuleSequence::HasYears() const @@ -1185,7 +1185,7 @@ bool RuleSequence::HasModifierComment() const bool RuleSequence::HasSeparatorForReadability() const { - return m_separator_for_readablility; + return m_separatorForReadability; } TYearRanges const & RuleSequence::GetYears() const @@ -1220,12 +1220,12 @@ std::string const & RuleSequence::GetComment() const std::string const & RuleSequence::GetModifierComment() const { - return m_modifier_comment; + return m_modifierComment; } std::string const & RuleSequence::GetAnySeparator() const { - return m_any_separator; + return m_anySeparator; } RuleSequence::Modifier RuleSequence::GetModifier() const @@ -1233,9 +1233,9 @@ RuleSequence::Modifier RuleSequence::GetModifier() const return m_modifier; } -void RuleSequence::Set24Per7(bool const on) +void RuleSequence::SetTwentyFourHours(bool const on) { - m_24_per_7 = on; + m_twentyFourHours = on; } void RuleSequence::SetYears(TYearRanges const & years) @@ -1270,17 +1270,17 @@ void RuleSequence::SetComment(std::string const & comment) void RuleSequence::SetModifierComment(std::string & comment) { - m_modifier_comment = comment; + m_modifierComment = comment; } void RuleSequence::SetAnySeparator(std::string const & separator) { - m_any_separator = separator; + m_anySeparator = separator; } void RuleSequence::SetSeparatorForReadability(bool const on) { - m_separator_for_readablility = on; + m_separatorForReadability = on; } void RuleSequence::SetModifier(Modifier const modifier) @@ -1288,18 +1288,6 @@ void RuleSequence::SetModifier(Modifier const modifier) m_modifier = modifier; } -// uint32_t RuleSequence::id{}; -// void RuleSequence::dump() const -// { -// std::cout << "My id: " << my_id << '\n' -// << "Years " << GetYears().size() << '\n' -// << "Months " << GetMonths().size() << '\n' -// << "Weeks " << GetWeeks().size() << '\n' -// << "Holidays " << GetWeekdays().GetHolidays().size() << '\n' -// << "Weekdays " << GetWeekdays().GetWeekdayRanges().size() << '\n' -// << "Times " << GetTimes().size() << std::endl; -// } - std::ostream & operator<<(std::ostream & ost, RuleSequence::Modifier const modifier) { switch (modifier) @@ -1329,7 +1317,7 @@ std::ostream & operator<<(std::ostream & ost, RuleSequence const & s) space = true; }; - if (s.Is24Per7()) + if (s.IsTwentyFourHours()) { putSpace(); ost << "24/7"; diff --git a/3party/opening_hours/osm_time_range.hpp b/3party/opening_hours/opening_hours.hpp similarity index 94% rename from 3party/opening_hours/osm_time_range.hpp rename to 3party/opening_hours/opening_hours.hpp index 058ede1825..164953c0e0 100644 --- a/3party/opening_hours/osm_time_range.hpp +++ b/3party/opening_hours/opening_hours.hpp @@ -57,7 +57,6 @@ public: using THours = std::chrono::hours; using TMinutes = std::chrono::minutes; - Time() = default; Time(Time const &) = default; Time(THours const hours); @@ -91,7 +90,6 @@ public: private: Time GetEventTime() const; - Event m_event{Event::NotEvent}; TMinutes m_duration{TMinutes::zero()}; TStateRep m_state{State::IsNotTime}; @@ -149,10 +147,10 @@ using TTimespans = std::vector; std::ostream & operator<<(std::ostream & ost, Timespan const & span); std::ostream & operator<<(std::ostream & ost, osmoh::TTimespans const & timespans); -class NthEntry +class NthWeekdayOfTheMonthEntry { public: - enum class Nth + enum class NthDayOfTheMonth { None, First, @@ -162,23 +160,22 @@ public: Fifth }; - bool IsEmpty() const; bool HasStart() const; bool HasEnd() const; - Nth GetStart() const; - Nth GetEnd() const; + NthDayOfTheMonth GetStart() const; + NthDayOfTheMonth GetEnd() const; - void SetStart(Nth const s); - void SetEnd(Nth const e); + void SetStart(NthDayOfTheMonth const s); + void SetEnd(NthDayOfTheMonth const e); private: - Nth m_start{}; - Nth m_end{}; + NthDayOfTheMonth m_start{}; + NthDayOfTheMonth m_end{}; }; -std::ostream & operator<<(std::ostream & ost, NthEntry const entry); +std::ostream & operator<<(std::ostream & ost, NthWeekdayOfTheMonthEntry const entry); enum class Weekday { @@ -210,7 +207,7 @@ std::ostream & operator<<(std::ostream & ost, Weekday const wday); class WeekdayRange { - using TNths = std::vector; + using TNths = std::vector; public: bool HasWday(Weekday const & wday) const; @@ -241,7 +238,7 @@ public: bool HasNth() const; TNths const & GetNths() const; - void AddNth(NthEntry const & entry); + void AddNth(NthWeekdayOfTheMonthEntry const & entry); private: Weekday m_start{}; @@ -274,7 +271,7 @@ using THolidays = std::vector; std::ostream & operator<<(std::ostream & ost, Holiday const & holiday); std::ostream & operator<<(std::ostream & ost, THolidays const & holidys); -/// Correspond to weekday_selector in osm opening hours +// Correspond to weekday_selector in osm opening hours. class Weekdays { public: @@ -351,7 +348,6 @@ public: using TYear = uint16_t; using TDayNum = uint8_t; - bool IsEmpty() const; bool IsVariable() const; @@ -428,13 +424,11 @@ using TMonthdayRanges = std::vector; std::ostream & operator<<(std::ostream & ost, MonthdayRange const & range); std::ostream & operator<<(std::ostream & ost, TMonthdayRanges const & ranges); - class YearRange { public: using TYear = uint16_t; - bool IsEmpty() const; bool IsOpen() const; bool HasStart() const; @@ -468,7 +462,6 @@ class WeekRange public: using TWeek = uint8_t; - bool IsEmpty() const; bool IsOpen() const; bool HasStart() const; @@ -506,9 +499,8 @@ public: Comment }; - bool IsEmpty() const; - bool Is24Per7() const; + bool IsTwentyFourHours() const; bool HasYears() const; bool HasMonths() const; @@ -531,7 +523,7 @@ public: Modifier GetModifier() const; - void Set24Per7(bool const on); + void SetTwentyFourHours(bool const on); void SetYears(TYearRanges const & years); void SetMonths(TMonthdayRanges const & months); void SetWeeks(TWeekRanges const & weeks); @@ -549,8 +541,7 @@ public: private: void dump() const; -private: - bool m_24_per_7{false}; + bool m_twentyFourHours{false}; TYearRanges m_years; TMonthdayRanges m_months; @@ -560,11 +551,11 @@ private: TTimespans m_times; std::string m_comment; - std::string m_any_separator{";"}; - bool m_separator_for_readablility{false}; + std::string m_anySeparator{";"}; + bool m_separatorForReadability{false}; Modifier m_modifier{Modifier::DefaultOpen}; - std::string m_modifier_comment; + std::string m_modifierComment; }; using TRuleSequences = std::vector; diff --git a/3party/opening_hours/opening_hours.pro b/3party/opening_hours/opening_hours.pro index a4b3efd71c..aa2b5c01fd 100644 --- a/3party/opening_hours/opening_hours.pro +++ b/3party/opening_hours/opening_hours.pro @@ -13,13 +13,13 @@ ROOT_DIR = ../.. include($$ROOT_DIR/common.pri) -HEADERS += osm_time_range.hpp \ - osm_parsers.hpp \ - osm_parsers_terminals.hpp \ - parse.hpp \ - rules_evalustion.hpp \ - rules_evalustion_private.hpp \ +HEADERS += rules_evaluation.hpp \ + rules_evaluation_private.hpp \ + opening_hours_parsers.hpp \ + opening_hours_parsers_terminals.hpp \ + opening_hours.hpp \ + parse_opening_hours.hpp -SOURCES += osm_time_range.cpp \ - parse.cpp \ - rules_evaluation.cpp \ +SOURCES += rules_evaluation.cpp \ + opening_hours.cpp \ + parse_opening_hours.cpp diff --git a/3party/opening_hours/opening_hours_integration_tests/opening_hours_integration_tests.cpp b/3party/opening_hours/opening_hours_integration_tests/opening_hours_integration_tests.cpp index 8638a587eb..3b363e0c2d 100644 --- a/3party/opening_hours/opening_hours_integration_tests/opening_hours_integration_tests.cpp +++ b/3party/opening_hours/opening_hours_integration_tests/opening_hours_integration_tests.cpp @@ -1,4 +1,4 @@ -#include "parse.hpp" +#include "parse_opening_hours.hpp" #include "rules_evaluation.hpp" #define BOOST_TEST_MODULE OpeningHoursIntegration diff --git a/3party/opening_hours/opening_hours_integration_tests/opening_hours_integration_tests.pro b/3party/opening_hours/opening_hours_integration_tests/opening_hours_integration_tests.pro index 945646f27e..d292b6c136 100644 --- a/3party/opening_hours/opening_hours_integration_tests/opening_hours_integration_tests.pro +++ b/3party/opening_hours/opening_hours_integration_tests/opening_hours_integration_tests.pro @@ -11,9 +11,9 @@ include($$ROOT_DIR/common.pri) OPENING_HOURS_INCLUDE = $$ROOT_DIR/3party/opening_hours INCLUDEPATH += $$OPENING_HOURS_INCLUDE -HEADERS += $$OPENING_HOURS_INCLUDE/osm_time_range.hpp \ - $$OPENING_HOURS_INCLUDE/parse.hpp \ +HEADERS += $$OPENING_HOURS_INCLUDE/opening_hours.hpp \ + $$OPENING_HOURS_INCLUDE/parse_opening_hours.hpp \ $$OPENING_HOURS_INCLUDE/rules_evaluation.hpp \ - $$OPENING_HOURS_INCLUDE/rules_evaluation_private.hpp \ + $$OPENING_HOURS_INCLUDE/rules_evaluation_private.hpp SOURCES += opening_hours_integration_tests.cpp diff --git a/3party/opening_hours/osm_parsers.hpp b/3party/opening_hours/opening_hours_parsers.hpp similarity index 56% rename from 3party/opening_hours/osm_parsers.hpp rename to 3party/opening_hours/opening_hours_parsers.hpp index 44f06a846a..53378afd43 100644 --- a/3party/opening_hours/osm_parsers.hpp +++ b/3party/opening_hours/opening_hours_parsers.hpp @@ -1,6 +1,6 @@ #pragma once -#include "osm_time_range.hpp" +#include "opening_hours.hpp" // #define BOOST_SPIRIT_DEBUG #define BOOST_SPIRIT_USE_PHOENIX_V3 @@ -23,7 +23,7 @@ #include #endif -#include "osm_parsers_terminals.hpp" +#include "opening_hours_parsers_terminals.hpp" namespace osmoh { @@ -66,18 +66,18 @@ public: using qi::_2; using qi::_3; using qi::_val; + using osmoh::YearRange; static const qi::int_parser year = {}; - year_range = (year >> dash >> year >> '/' >> uint_) - [bind(&osmoh::YearRange::SetStart, _val, _1), - bind(&osmoh::YearRange::SetEnd, _val, _2), - bind(&osmoh::YearRange::SetPeriod, _val, _3)] - | (year >> dash >> year) [bind(&osmoh::YearRange::SetStart, _val, _1), - bind(&osmoh::YearRange::SetEnd, _val, _2)] - | (year >> lit('+')) [bind(&osmoh::YearRange::SetStart, _val, _1), - bind(&osmoh::YearRange::SetPlus, _val, true)] - | year [bind(&osmoh::YearRange::SetStart, _val, _1)] + year_range = (year >> dash >> year >> '/' >> uint_) [bind(&YearRange::SetStart, _val, _1), + bind(&YearRange::SetEnd, _val, _2), + bind(&YearRange::SetPeriod, _val, _3)] + | (year >> dash >> year) [bind(&YearRange::SetStart, _val, _1), + bind(&YearRange::SetEnd, _val, _2)] + | (year >> lit('+')) [bind(&YearRange::SetStart, _val, _1), + bind(&YearRange::SetPlus, _val, true)] + | year [bind(&YearRange::SetStart, _val, _1)] ; main %= (year_range % ','); @@ -100,14 +100,14 @@ public: using qi::_2; using qi::_3; using qi::_val; + using osmoh::WeekRange; - week = (weeknum >> dash >> weeknum >> '/' >> uint_) - [bind(&osmoh::WeekRange::SetStart, _val, _1), - bind(&osmoh::WeekRange::SetEnd, _val, _2), - bind(&osmoh::WeekRange::SetPeriod, _val, _3)] - | (weeknum >> dash >> weeknum) [bind(&osmoh::WeekRange::SetStart, _val, _1), - bind(&osmoh::WeekRange::SetEnd, _val, _2)] - | weeknum [bind(&osmoh::WeekRange::SetStart, _val, _1)] + week = (weeknum >> dash >> weeknum >> '/' >> uint_) [bind(&WeekRange::SetStart, _val, _1), + bind(&WeekRange::SetEnd, _val, _2), + bind(&WeekRange::SetPeriod, _val, _3)] + | (weeknum >> dash >> weeknum) [bind(&WeekRange::SetStart, _val, _1), + bind(&WeekRange::SetEnd, _val, _2)] + | weeknum [bind(&WeekRange::SetStart, _val, _1)] ; main %= charset::no_case[lit("week")] >> (week % ','); @@ -144,6 +144,9 @@ public: using qi::lit; using qi::double_; using qi::lexeme; + using osmoh::DateOffset; + using osmoh::MonthDay; + using osmoh::MonthdayRange; static const qi::int_parser year = {}; @@ -152,60 +155,60 @@ public: date_offset = ((lit('+')[_a = true] | lit('-')[_a = false]) >> charset::no_case[wdays] >> day_offset) - [bind(&osmoh::DateOffset::SetWDayOffset, _val, _1), - bind(&osmoh::DateOffset::SetOffset, _val, _2), - bind(&osmoh::DateOffset::SetWDayOffsetPositive, _val, _a)] + [bind(&DateOffset::SetWDayOffset, _val, _1), + bind(&DateOffset::SetOffset, _val, _2), + bind(&DateOffset::SetWDayOffsetPositive, _val, _a)] | ((lit('+')[_a = true] | lit('-') [_a = false]) >> charset::no_case[wdays]) - [bind(&osmoh::DateOffset::SetWDayOffset, _val, _1), - bind(&osmoh::DateOffset::SetWDayOffsetPositive, _val, _a)] - | day_offset [bind(&osmoh::DateOffset::SetOffset, _val, _1)] + [bind(&DateOffset::SetWDayOffset, _val, _1), + bind(&DateOffset::SetWDayOffsetPositive, _val, _a)] + | day_offset [bind(&DateOffset::SetOffset, _val, _1)] ; - date_left = (year >> charset::no_case[month]) [bind(&osmoh::MonthDay::SetYear, _val, _1), - bind(&osmoh::MonthDay::SetMonth, _val, _2)] + date_left = (year >> charset::no_case[month]) [bind(&MonthDay::SetYear, _val, _1), + bind(&MonthDay::SetMonth, _val, _2)] - | charset::no_case[month] [bind(&osmoh::MonthDay::SetMonth, _val, _1)] + | charset::no_case[month] [bind(&MonthDay::SetMonth, _val, _1)] ; - date_right = charset::no_case[month] [bind(&osmoh::MonthDay::SetMonth, _val, _1)] + date_right = charset::no_case[month] [bind(&MonthDay::SetMonth, _val, _1)] ; date_from = (date_left >> (daynum >> !(lit(':') >> qi::digit))) - [_val = _1, bind(&osmoh::MonthDay::SetDayNum, _val, _2)] - | (year >> charset::no_case[lit("easter")]) [bind(&osmoh::MonthDay::SetYear, _val, _1), - bind(&osmoh::MonthDay::SetVariableDate, _val, + [_val = _1, bind(&MonthDay::SetDayNum, _val, _2)] + | (year >> charset::no_case[lit("easter")]) [bind(&MonthDay::SetYear, _val, _1), + bind(&MonthDay::SetVariableDate, _val, MonthDay::VariableDate::Easter)] - | charset::no_case[lit("easter")] [bind(&osmoh::MonthDay::SetVariableDate, _val, + | charset::no_case[lit("easter")] [bind(&MonthDay::SetVariableDate, _val, MonthDay::VariableDate::Easter)] ; date_to = date_from [_val = _1] - | (daynum >> !(lit(':') >> qi::digit)) [bind(&osmoh::MonthDay::SetDayNum, _val, _1)] + | (daynum >> !(lit(':') >> qi::digit)) [bind(&MonthDay::SetDayNum, _val, _1)] ; date_from_with_offset = (date_from >> date_offset) - [_val = _1, bind(&osmoh::MonthDay::SetOffset, _val, _2)] + [_val = _1, bind(&MonthDay::SetOffset, _val, _2)] | date_from [_val = _1] ; date_to_with_offset = (date_to >> date_offset) - [_val = _1, bind(&osmoh::MonthDay::SetOffset, _val, _2)] + [_val = _1, bind(&MonthDay::SetOffset, _val, _2)] | date_to [_val = _1] ; monthday_range = (date_from_with_offset >> dash >> date_to_with_offset) - [bind(&osmoh::MonthdayRange::SetStart, _val, _1), - bind(&osmoh::MonthdayRange::SetEnd, _val, _2)] - | (date_from_with_offset >> '+') [bind(&osmoh::MonthdayRange::SetStart, _val, _1), - bind(&osmoh::MonthdayRange::SetPlus, _val, true)] + [bind(&MonthdayRange::SetStart, _val, _1), + bind(&MonthdayRange::SetEnd, _val, _2)] + | (date_from_with_offset >> '+') [bind(&MonthdayRange::SetStart, _val, _1), + bind(&MonthdayRange::SetPlus, _val, true)] | (date_left >> dash >> date_right >> '/' >> uint_) - [bind(&osmoh::MonthdayRange::SetStart, _val, _1), - bind(&osmoh::MonthdayRange::SetEnd, _val, _2), - bind(&osmoh::MonthdayRange::SetPeriod, _val, _3)] - | (date_left >> lit("-") >> date_right) [bind(&osmoh::MonthdayRange::SetStart, _val, _1), - bind(&osmoh::MonthdayRange::SetEnd, _val, _2)] - | date_from [bind(&osmoh::MonthdayRange::SetStart, _val, _1)] - | date_left [bind(&osmoh::MonthdayRange::SetStart, _val, _1)] + [bind(&MonthdayRange::SetStart, _val, _1), + bind(&MonthdayRange::SetEnd, _val, _2), + bind(&MonthdayRange::SetPeriod, _val, _3)] + | (date_left >> lit("-") >> date_right) [bind(&MonthdayRange::SetStart, _val, _1), + bind(&MonthdayRange::SetEnd, _val, _2)] + | date_from [bind(&MonthdayRange::SetStart, _val, _1)] + | date_left [bind(&MonthdayRange::SetStart, _val, _1)] ; main %= (monthday_range % ','); @@ -227,8 +230,8 @@ template class weekday_selector : public qi::grammar { protected: - qi::rule nth; - qi::rule nth_entry; + qi::rule nth; + qi::rule nth_entry; qi::rule> day_offset; qi::rule weekday_range; qi::rule weekday_sequence; @@ -246,17 +249,21 @@ public: using qi::lit; using qi::ushort_; using boost::phoenix::bind; + using osmoh::NthWeekdayOfTheMonthEntry; + using osmoh::Holiday; + using osmoh::WeekdayRange; + using osmoh::Weekdays; - nth = ushort_(1)[_val = osmoh::NthEntry::Nth::First] - | ushort_(2) [_val = osmoh::NthEntry::Nth::Second] - | ushort_(3) [_val = osmoh::NthEntry::Nth::Third] - | ushort_(4) [_val = osmoh::NthEntry::Nth::Fourth] - | ushort_(5) [_val = osmoh::NthEntry::Nth::Fifth]; + nth = ushort_(1)[_val = NthWeekdayOfTheMonthEntry::NthDayOfTheMonth::First] + | ushort_(2) [_val = NthWeekdayOfTheMonthEntry::NthDayOfTheMonth::Second] + | ushort_(3) [_val = NthWeekdayOfTheMonthEntry::NthDayOfTheMonth::Third] + | ushort_(4) [_val = NthWeekdayOfTheMonthEntry::NthDayOfTheMonth::Fourth] + | ushort_(5) [_val = NthWeekdayOfTheMonthEntry::NthDayOfTheMonth::Fifth]; - nth_entry = (nth >> dash >> nth) [bind(&osmoh::NthEntry::SetStart, _val, _1), - bind(&osmoh::NthEntry::SetEnd, _val, _2)] - | (lit('-') >> nth) [bind(&osmoh::NthEntry::SetEnd, _val, _1)] - | nth [bind(&osmoh::NthEntry::SetStart, _val, _1)] + nth_entry = (nth >> dash >> nth) [bind(&NthWeekdayOfTheMonthEntry::SetStart, _val, _1), + bind(&NthWeekdayOfTheMonthEntry::SetEnd, _val, _2)] + | (lit('-') >> nth) [bind(&NthWeekdayOfTheMonthEntry::SetEnd, _val, _1)] + | nth [bind(&NthWeekdayOfTheMonthEntry::SetStart, _val, _1)] ; day_offset = @@ -265,30 +272,30 @@ public: charset::no_case[(lit("days") | lit("day"))] ) ; - holiday = (charset::no_case[lit("SH")] [bind(&osmoh::Holiday::SetPlural, _val, false)] - >> -day_offset [bind(&osmoh::Holiday::SetOffset, _val, _1)]) - | charset::no_case[lit("PH")] [bind(&osmoh::Holiday::SetPlural, _val, true)] + holiday = (charset::no_case[lit("SH")] [bind(&Holiday::SetPlural, _val, false)] + >> -day_offset [bind(&Holiday::SetOffset, _val, _1)]) + | charset::no_case[lit("PH")] [bind(&Holiday::SetPlural, _val, true)] ; holiday_sequence %= (holiday % ','); weekday_range = - ( charset::no_case[wdays] [bind(&osmoh::WeekdayRange::SetStart, _val, _1)] >> - '[' >> (nth_entry [bind(&osmoh::WeekdayRange::AddNth, _val, _1)]) % ',') >> ']' >> - -(day_offset [bind(&osmoh::WeekdayRange::SetOffset, _val, _1)]) - | charset::no_case[(wdays >> dash >> wdays)] [bind(&osmoh::WeekdayRange::SetStart, _val, _1), - bind(&osmoh::WeekdayRange::SetEnd, _val, _2)] - | charset::no_case[wdays] [bind(&osmoh::WeekdayRange::SetStart, _val, _1)] + ( charset::no_case[wdays] [bind(&WeekdayRange::SetStart, _val, _1)] >> + '[' >> (nth_entry [bind(&WeekdayRange::AddNth, _val, _1)]) % ',') >> ']' >> + -(day_offset [bind(&WeekdayRange::SetOffset, _val, _1)]) + | charset::no_case[(wdays >> dash >> wdays)] [bind(&WeekdayRange::SetStart, _val, _1), + bind(&WeekdayRange::SetEnd, _val, _2)] + | charset::no_case[wdays] [bind(&WeekdayRange::SetStart, _val, _1)] ; weekday_sequence %= (weekday_range % ',') >> !qi::no_skip[charset::alpha] ; main = (holiday_sequence >> -lit(',') >> weekday_sequence) - [bind(&osmoh::Weekdays::SetHolidays, _val, _1), - bind(&osmoh::Weekdays::SetWeekdayRanges, _val, _2)] - | holiday_sequence [bind(&osmoh::Weekdays::SetHolidays, _val, _1)] - | weekday_sequence [bind(&osmoh::Weekdays::SetWeekdayRanges, _val, _1)] + [bind(&Weekdays::SetHolidays, _val, _1), + bind(&Weekdays::SetWeekdayRanges, _val, _2)] + | holiday_sequence [bind(&Weekdays::SetHolidays, _val, _1)] + | weekday_sequence [bind(&Weekdays::SetWeekdayRanges, _val, _1)] ; BOOST_SPIRIT_DEBUG_NODE(main); @@ -324,25 +331,27 @@ public: using charset::char_; using boost::phoenix::bind; using boost::phoenix::construct; + using osmoh::Time; + using osmoh::Timespan; hour_minutes = - (hours >> lit(':') >> minutes) [bind(&osmoh::Time::SetHours, _val, _1), + (hours >> lit(':') >> minutes) [bind(&Time::SetHours, _val, _1), _val = _val + _2] ; extended_hour_minutes = - (exthours >> lit(':') >> minutes)[bind(&osmoh::Time::SetHours, _val, _1), + (exthours >> lit(':') >> minutes)[bind(&Time::SetHours, _val, _1), _val = _val + _2] ; - variable_time = eps [phx::bind(&osmoh::Time::SetHours, _val, 0_h)] >> + variable_time = eps [phx::bind(&Time::SetHours, _val, 0_h)] >> (lit('(') - >> charset::no_case[event][bind(&osmoh::Time::SetEvent, _val, _1)] + >> charset::no_case[event][bind(&Time::SetEvent, _val, _1)] >> ( (lit('+') >> hour_minutes) [_val = _val + _1] | (lit('-') >> hour_minutes) [_val = _val - _1] ) >> lit(')') ) - | charset::no_case[event][bind(&osmoh::Time::SetEvent, _val, _1)] + | charset::no_case[event][bind(&Time::SetEvent, _val, _1)] ; extended_time %= extended_hour_minutes | variable_time; @@ -351,29 +360,29 @@ public: timespan = (time >> dash >> extended_time >> '/' >> hour_minutes) - [bind(&osmoh::Timespan::SetStart, _val, _1), - bind(&osmoh::Timespan::SetEnd, _val, _2), - bind(&osmoh::Timespan::SetPeriod, _val, _3)] + [bind(&Timespan::SetStart, _val, _1), + bind(&Timespan::SetEnd, _val, _2), + bind(&Timespan::SetPeriod, _val, _3)] | (time >> dash >> extended_time >> '/' >> minutes) - [bind(&osmoh::Timespan::SetStart, _val, _1), - bind(&osmoh::Timespan::SetEnd, _val, _2), - bind(&osmoh::Timespan::SetPeriod, _val, _3)] + [bind(&Timespan::SetStart, _val, _1), + bind(&Timespan::SetEnd, _val, _2), + bind(&Timespan::SetPeriod, _val, _3)] | (time >> dash >> extended_time >> '+') - [bind(&osmoh::Timespan::SetStart, _val, _1), - bind(&osmoh::Timespan::SetEnd, _val, _2), - bind(&osmoh::Timespan::SetPlus, _val, true)] + [bind(&Timespan::SetStart, _val, _1), + bind(&Timespan::SetEnd, _val, _2), + bind(&Timespan::SetPlus, _val, true)] | (time >> dash >> extended_time) - [bind(&osmoh::Timespan::SetStart, _val, _1), - bind(&osmoh::Timespan::SetEnd, _val, _2)] + [bind(&Timespan::SetStart, _val, _1), + bind(&Timespan::SetEnd, _val, _2)] | (time >> '+') - [bind(&osmoh::Timespan::SetStart, _val, _1), - bind(&osmoh::Timespan::SetPlus, _val, true)] + [bind(&Timespan::SetStart, _val, _1), + bind(&Timespan::SetPlus, _val, true)] - | time[bind(&osmoh::Timespan::SetStart, _val, _1)] + | time[bind(&Timespan::SetStart, _val, _1)] ; main %= timespan % ','; @@ -422,8 +431,9 @@ public: using phx::back; using phx::push_back; using phx::construct; + using osmoh::RuleSequence; - using Modifier = osmoh::RuleSequence::Modifier; + using Modifier = RuleSequence::Modifier; comment %= '"' >> +(char_ - '"') >> '"' ; @@ -434,37 +444,37 @@ public: ; wide_range_selectors = - ( -(year_selector [bind(&osmoh::RuleSequence::SetYears, _r1, _1)]) >> - -(month_selector [bind(&osmoh::RuleSequence::SetMonths, _r1, _1)]) >> - -(week_selector [bind(&osmoh::RuleSequence::SetWeeks, _r1, _1)]) >> - -(lit(':') [bind(&osmoh::RuleSequence::SetSeparatorForReadability, _r1, true)])) - | (comment >> ':') [bind(&osmoh::RuleSequence::SetComment, _r1, _1)] + ( -(year_selector [bind(&RuleSequence::SetYears, _r1, _1)]) >> + -(month_selector [bind(&RuleSequence::SetMonths, _r1, _1)]) >> + -(week_selector [bind(&RuleSequence::SetWeeks, _r1, _1)]) >> + -(lit(':') [bind(&RuleSequence::SetSeparatorForReadability, _r1, true)])) + | (comment >> ':') [bind(&RuleSequence::SetComment, _r1, _1)] ; small_range_selectors = - ( -(weekday_selector [bind(&osmoh::RuleSequence::SetWeekdays, _r1, _1)]) >> - -(time_selector [bind(&osmoh::RuleSequence::SetTimes, _r1, _1)])) + ( -(weekday_selector [bind(&RuleSequence::SetWeekdays, _r1, _1)]) >> + -(time_selector [bind(&RuleSequence::SetTimes, _r1, _1)])) ; rule_modifier = (charset::no_case[lit("open")] - [bind(&osmoh::RuleSequence::SetModifier, _r1, Modifier::Open)] >> - -(comment [bind(&osmoh::RuleSequence::SetModifierComment, _r1, _1)])) + [bind(&RuleSequence::SetModifier, _r1, Modifier::Open)] >> + -(comment [bind(&RuleSequence::SetModifierComment, _r1, _1)])) | ((charset::no_case[lit("closed") | lit("off")]) - [bind(&osmoh::RuleSequence::SetModifier, _r1, Modifier::Closed)] >> - -(comment [bind(&osmoh::RuleSequence::SetModifierComment, _r1, _1)])) + [bind(&RuleSequence::SetModifier, _r1, Modifier::Closed)] >> + -(comment [bind(&RuleSequence::SetModifierComment, _r1, _1)])) | (charset::no_case[lit("unknown")] - [bind(&osmoh::RuleSequence::SetModifier, _r1, Modifier::Unknown)] >> - -(comment [bind(&osmoh::RuleSequence::SetModifierComment, _r1, _1)])) + [bind(&RuleSequence::SetModifier, _r1, Modifier::Unknown)] >> + -(comment [bind(&RuleSequence::SetModifierComment, _r1, _1)])) - | comment [bind(&osmoh::RuleSequence::SetModifier, _r1, Modifier::Comment), - bind(&osmoh::RuleSequence::SetModifierComment, _r1, _1)] + | comment [bind(&RuleSequence::SetModifier, _r1, Modifier::Comment), + bind(&RuleSequence::SetModifierComment, _r1, _1)] ; rule_sequence = - ( lit("24/7") [bind(&osmoh::RuleSequence::Set24Per7, _val, true)] + ( lit("24/7") [bind(&RuleSequence::SetTwentyFourHours, _val, true)] | ( -wide_range_selectors(_val) >> -small_range_selectors(_val) )) >> -rule_modifier(_val) @@ -472,7 +482,7 @@ public: main = ( -(lit("opening_hours") >> lit('=')) >> (rule_sequence [push_back(_val, _1)] % - (separator [phx::bind(&osmoh::RuleSequence::SetAnySeparator, back(_val), _1)]))) + (separator [phx::bind(&RuleSequence::SetAnySeparator, back(_val), _1)]))) ; BOOST_SPIRIT_DEBUG_NODE(main); diff --git a/3party/opening_hours/osm_parsers_terminals.hpp b/3party/opening_hours/opening_hours_parsers_terminals.hpp similarity index 99% rename from 3party/opening_hours/osm_parsers_terminals.hpp rename to 3party/opening_hours/opening_hours_parsers_terminals.hpp index 6f1f8f17a2..490fc8d1e9 100644 --- a/3party/opening_hours/osm_parsers_terminals.hpp +++ b/3party/opening_hours/opening_hours_parsers_terminals.hpp @@ -5,12 +5,12 @@ namespace parsing { namespace qi = boost::spirit::qi; -struct dash_ : public qi::symbols +struct dash_ : public qi::symbols { dash_() { add - (L"-") + ("-") /* not standard */ // (L"–")(L"—")(L"-")(L"~")(L"~")(L"〜")(L"to")(L"às")(L"ás")(L"as")(L"a")(L"ate")(L"bis") ; diff --git a/3party/opening_hours/opening_hours_supported_features_tests/opening_hours_supported_features_tests.cpp b/3party/opening_hours/opening_hours_supported_features_tests/opening_hours_supported_features_tests.cpp index 287554a7d0..40b1e4c471 100644 --- a/3party/opening_hours/opening_hours_supported_features_tests/opening_hours_supported_features_tests.cpp +++ b/3party/opening_hours/opening_hours_supported_features_tests/opening_hours_supported_features_tests.cpp @@ -1,4 +1,4 @@ -#include "parse.hpp" +#include "parse_opening_hours.hpp" #include "rules_evaluation.hpp" #define BOOST_TEST_MODULE OpeningHoursSupportedFeatures diff --git a/3party/opening_hours/opening_hours_supported_features_tests/opening_hours_supported_features_tests.pro b/3party/opening_hours/opening_hours_supported_features_tests/opening_hours_supported_features_tests.pro index 405f9fe154..3de8098096 100644 --- a/3party/opening_hours/opening_hours_supported_features_tests/opening_hours_supported_features_tests.pro +++ b/3party/opening_hours/opening_hours_supported_features_tests/opening_hours_supported_features_tests.pro @@ -11,9 +11,9 @@ include($$ROOT_DIR/common.pri) OPENING_HOURS_INCLUDE = $$ROOT_DIR/3party/opening_hours INCLUDEPATH += $$OPENING_HOURS_INCLUDE -HEADERS += $$OPENING_HOURS_INCLUDE/osm_time_range.hpp \ - $$OPENING_HOURS_INCLUDE/parse.hpp \ +HEADERS += $$OPENING_HOURS_INCLUDE/opening_hours.hpp \ + $$OPENING_HOURS_INCLUDE/parse_opening_hours.hpp \ $$OPENING_HOURS_INCLUDE/rules_evaluation.hpp \ - $$OPENING_HOURS_INCLUDE/rules_evaluation_private.hpp \ + $$OPENING_HOURS_INCLUDE/rules_evaluation_private.hpp SOURCES += opening_hours_supported_features_tests.cpp diff --git a/3party/opening_hours/opening_hours_tests/osm_time_range_tests.cpp b/3party/opening_hours/opening_hours_tests/opening_hours_tests.cpp similarity index 98% rename from 3party/opening_hours/opening_hours_tests/osm_time_range_tests.cpp rename to 3party/opening_hours/opening_hours_tests/opening_hours_tests.cpp index eeb1d0612a..be3652569e 100644 --- a/3party/opening_hours/opening_hours_tests/osm_time_range_tests.cpp +++ b/3party/opening_hours/opening_hours_tests/opening_hours_tests.cpp @@ -22,8 +22,7 @@ THE SOFTWARE. */ -#include "osm_time_range.hpp" -#include "parse.hpp" +#include "parse_opening_hours.hpp" #include "rules_evaluation.hpp" #include "rules_evaluation_private.hpp" @@ -70,7 +69,6 @@ bool Test(std::string const & str, Parser const & p, bool full_match = true) template std::string ParseAndUnparse(std::string const & str) { - ParseResult parseResult; if (!osmoh::Parse(str, parseResult)) return ":CAN'T PARSE:"; @@ -278,30 +276,30 @@ BOOST_AUTO_TEST_CASE(OpeningHours_TestTimespan) } } -BOOST_AUTO_TEST_CASE(OpeningHours_TestNthEntry) +BOOST_AUTO_TEST_CASE(OpeningHours_TestNthWeekdayOfTheMonthEntry) { using namespace osmoh; { - NthEntry entry; + NthWeekdayOfTheMonthEntry entry; BOOST_CHECK(entry.IsEmpty()); BOOST_CHECK(!entry.HasStart()); BOOST_CHECK(!entry.HasEnd()); BOOST_CHECK_EQUAL(ToString(entry), ""); - entry.SetStart(NthEntry::Nth::Third); + entry.SetStart(NthWeekdayOfTheMonthEntry::NthDayOfTheMonth::Third); BOOST_CHECK(!entry.IsEmpty()); BOOST_CHECK(entry.HasStart()); BOOST_CHECK(!entry.HasEnd()); BOOST_CHECK_EQUAL(ToString(entry), "3"); - entry.SetEnd(NthEntry::Nth::Fifth); + entry.SetEnd(NthWeekdayOfTheMonthEntry::NthDayOfTheMonth::Fifth); BOOST_CHECK(!entry.IsEmpty()); BOOST_CHECK(entry.HasStart()); BOOST_CHECK(entry.HasEnd()); BOOST_CHECK_EQUAL(ToString(entry), "3-5"); - entry.SetStart(NthEntry::Nth::None); + entry.SetStart(NthWeekdayOfTheMonthEntry::NthDayOfTheMonth::None); BOOST_CHECK(!entry.IsEmpty()); BOOST_CHECK(!entry.HasStart()); BOOST_CHECK(entry.HasEnd()); @@ -347,8 +345,8 @@ BOOST_AUTO_TEST_CASE(OpeningHours_TestWeekdayRange) WeekdayRange range; BOOST_CHECK(!range.HasNth()); - NthEntry entry; - entry.SetStart(NthEntry::NthEntry::Nth::First); + NthWeekdayOfTheMonthEntry entry; + entry.SetStart(NthWeekdayOfTheMonthEntry::NthDayOfTheMonth::First); range.AddNth(entry); BOOST_CHECK(range.HasNth()); } diff --git a/3party/opening_hours/opening_hours_tests/opening_hours_tests.pro b/3party/opening_hours/opening_hours_tests/opening_hours_tests.pro index 367e92bcaf..2c708b55ca 100644 --- a/3party/opening_hours/opening_hours_tests/opening_hours_tests.pro +++ b/3party/opening_hours/opening_hours_tests/opening_hours_tests.pro @@ -11,9 +11,9 @@ include($$ROOT_DIR/common.pri) OPENING_HOURS_INCLUDE = $$ROOT_DIR/3party/opening_hours INCLUDEPATH += $$OPENING_HOURS_INCLUDE -HEADERS += $$OPENING_HOURS_INCLUDE/osm_time_range.hpp \ - $$OPENING_HOURS_INCLUDE/parse.hpp \ +HEADERS += $$OPENING_HOURS_INCLUDE/opening_hours.hpp \ + $$OPENING_HOURS_INCLUDE/parse_opening_hours.hpp \ $$OPENING_HOURS_INCLUDE/rules_evaluation.hpp \ - $$OPENING_HOURS_INCLUDE/rules_evaluation_private.hpp \ + $$OPENING_HOURS_INCLUDE/rules_evaluation_private.hpp -SOURCES += osm_time_range_tests.cpp +SOURCES += opening_hours_tests.cpp diff --git a/3party/opening_hours/parse.cpp b/3party/opening_hours/parse_opening_hours.cpp similarity index 96% rename from 3party/opening_hours/parse.cpp rename to 3party/opening_hours/parse_opening_hours.cpp index 789044a892..ed51efcece 100644 --- a/3party/opening_hours/parse.cpp +++ b/3party/opening_hours/parse_opening_hours.cpp @@ -1,5 +1,5 @@ -#include "parse.hpp" -#include "osm_parsers.hpp" +#include "parse_opening_hours.hpp" +#include "opening_hours_parsers.hpp" namespace { diff --git a/3party/opening_hours/parse.hpp b/3party/opening_hours/parse_opening_hours.hpp similarity index 92% rename from 3party/opening_hours/parse.hpp rename to 3party/opening_hours/parse_opening_hours.hpp index 2be3e65d0c..02d742f5a1 100644 --- a/3party/opening_hours/parse.hpp +++ b/3party/opening_hours/parse_opening_hours.hpp @@ -1,6 +1,6 @@ #pragma once -#include "osm_time_range.hpp" +#include "opening_hours.hpp" #include namespace osmoh diff --git a/3party/opening_hours/rules_evaluation.cpp b/3party/opening_hours/rules_evaluation.cpp index e2d0bd9ac0..d43072d21f 100644 --- a/3party/opening_hours/rules_evaluation.cpp +++ b/3party/opening_hours/rules_evaluation.cpp @@ -29,7 +29,7 @@ bool ToHourMinutes(std::tm const & t, THourMinutes & hm) int CompareMonthDayAndTimeTumple(osmoh::MonthDay const & monthDay, std::tm const & date) { if (monthDay.IsVariable()) - // Not implemented yet + // TODO(mgsergio): Not implemented yet return false; if (monthDay.HasYear()) @@ -62,7 +62,7 @@ bool operator==(osmoh::MonthDay const & monthDay, std::tm const & date) return CompareMonthDayAndTimeTumple(monthDay, date) == 0; } -/// Fill result with fields that present in start and missing in end. +// Fill result with fields that present in start and missing in end. osmoh::MonthDay NormalizeEnd(osmoh::MonthDay const & start, osmoh::MonthDay const & end) { osmoh::MonthDay result = start; @@ -96,7 +96,6 @@ bool IsLoopedBetween(Bound const & start, Bound const & end, Point const & p) } } // namespace - namespace osmoh { bool IsActive(Timespan const & span, std::tm const & time) @@ -207,7 +206,7 @@ bool IsActiveAny(std::vector const & selectors, std::tm const & date) bool IsActive(RuleSequence const & rule, std::tm const & date) { - if (rule.Is24Per7()) + if (rule.IsTwentyFourHours()) return true; return diff --git a/3party/opening_hours/rules_evaluation.hpp b/3party/opening_hours/rules_evaluation.hpp index 4942cd676e..e4fdba4345 100644 --- a/3party/opening_hours/rules_evaluation.hpp +++ b/3party/opening_hours/rules_evaluation.hpp @@ -1,6 +1,6 @@ #pragma once -#include "osm_time_range.hpp" +#include "opening_hours.hpp" #include namespace osmoh @@ -44,8 +44,3 @@ private: RuleState GetState(TRuleSequences const & rules, std::tm const & date); RuleState GetState(TRuleSequences const & rules, time_t const dateTime); } // namespace osmoh - - -// bool IsActive(Time const & time, std::tm const & date); -// bool IsActive(NthEntry const & nthEntry, std::tm const & date); -// bool IsActive(MonthDay const & MonthDay, std::tm const & date); diff --git a/3party/opening_hours/rules_evaluation_private.hpp b/3party/opening_hours/rules_evaluation_private.hpp index 270f325ac1..acbf5171dc 100644 --- a/3party/opening_hours/rules_evaluation_private.hpp +++ b/3party/opening_hours/rules_evaluation_private.hpp @@ -1,6 +1,6 @@ #pragma once -#include "osm_time_range.hpp" +#include "opening_hours.hpp" namespace osmoh { diff --git a/map/osm_opening_hours.hpp b/map/osm_opening_hours.hpp index de546c1b4e..8b228b525d 100644 --- a/map/osm_opening_hours.hpp +++ b/map/osm_opening_hours.hpp @@ -1,6 +1,6 @@ #pragma once -#include "3party/opening_hours/parse.hpp" +#include "3party/opening_hours/parse_opening_hours.hpp" #include "3party/opening_hours/rules_evaluation.hpp" #include "std/chrono.hpp" diff --git a/search/intermediate_result.cpp b/search/intermediate_result.cpp index 7fe8ec6aa8..e7a878d1b8 100644 --- a/search/intermediate_result.cpp +++ b/search/intermediate_result.cpp @@ -18,7 +18,7 @@ #ifndef OMIM_OS_LINUX // Lib opening_hours is not built for Linux since stdlib doesn't have required functions. -#include "3party/opening_hours/parse.hpp" +#include "3party/opening_hours/parse_opening_hours.hpp" #include "3party/opening_hours/rules_evaluation.hpp" #endif