diff --git a/routing_common/maxspeed_conversion.cpp b/routing_common/maxspeed_conversion.cpp index e887aa37cc..bb1a46e102 100644 --- a/routing_common/maxspeed_conversion.cpp +++ b/routing_common/maxspeed_conversion.cpp @@ -29,7 +29,7 @@ bool SpeedInUnits::IsNumeric() const } // Maxspeed ---------------------------------------------------------------------------------------- -Maxspeed::Maxspeed(Units units, uint16_t forward, uint16_t backward) +Maxspeed::Maxspeed(Units units, MaxspeedType forward, MaxspeedType backward) : m_units(units), m_forward(forward), m_backward(backward) { } @@ -39,24 +39,24 @@ bool Maxspeed::operator==(Maxspeed const & rhs) const return m_units == rhs.m_units && m_forward == rhs.m_forward && m_backward == rhs.m_backward; } -uint16_t Maxspeed::GetSpeedInUnits(bool forward) const +MaxspeedType Maxspeed::GetSpeedInUnits(bool forward) const { return (forward || !IsBidirectional()) ? m_forward : m_backward; } -uint16_t Maxspeed::GetSpeedKmPH(bool forward) const +MaxspeedType Maxspeed::GetSpeedKmPH(bool forward) const { auto speedInUnits = GetSpeedInUnits(forward); if (speedInUnits == kInvalidSpeed) return kInvalidSpeed; // That means IsValid() returns false. if (IsNumeric(speedInUnits)) - return static_cast(ToSpeedKmPH(speedInUnits, m_units)); + return static_cast(ToSpeedKmPH(speedInUnits, m_units)); // A feature is marked as a feature without any speed limits. (maxspeed=="none"). if (kNoneMaxSpeed) { - uint16_t constexpr kNoneSpeedLimitKmPH = 130; + MaxspeedType constexpr kNoneSpeedLimitKmPH = 130; return kNoneSpeedLimitKmPH; } @@ -64,7 +64,7 @@ uint16_t Maxspeed::GetSpeedKmPH(bool forward) const // should drive with a speed of a walking person. if (kWalkMaxSpeed) { - uint16_t constexpr kWalkSpeedLimitKmPH = 6; + MaxspeedType constexpr kWalkSpeedLimitKmPH = 6; return kWalkSpeedLimitKmPH; } @@ -72,8 +72,8 @@ uint16_t Maxspeed::GetSpeedKmPH(bool forward) const } // FeatureMaxspeed --------------------------------------------------------------------------------- -FeatureMaxspeed::FeatureMaxspeed(uint32_t fid, measurement_utils::Units units, uint16_t forward, - uint16_t backward /* = kInvalidSpeed */) noexcept +FeatureMaxspeed::FeatureMaxspeed(uint32_t fid, measurement_utils::Units units, MaxspeedType forward, + MaxspeedType backward /* = kInvalidSpeed */) noexcept : m_featureId(fid), m_maxspeed(units, forward, backward) { } @@ -96,7 +96,7 @@ SpeedInUnits FeatureMaxspeed::GetBackwardSpeedInUnits() const // MaxspeedConverter ------------------------------------------------------------------------------- MaxspeedConverter::MaxspeedConverter() { - vector> const table = { + vector> const table = { // Special values. {SpeedMacro::Undefined, kInvalidSpeed /* speed */, Units::Metric}, {SpeedMacro::None, kNoneMaxSpeed /* speed */, Units::Metric}, @@ -308,7 +308,7 @@ bool IsFeatureIdLess(FeatureMaxspeed const & lhs, FeatureMaxspeed const & rhs) return lhs.IsFeatureIdLess(rhs); } -bool IsNumeric(uint16_t speed) +bool IsNumeric(MaxspeedType speed) { return speed != kNoneMaxSpeed && speed != kWalkMaxSpeed && speed != kInvalidSpeed; } diff --git a/routing_common/maxspeed_conversion.hpp b/routing_common/maxspeed_conversion.hpp index 11d70fa987..2bf276af67 100644 --- a/routing_common/maxspeed_conversion.hpp +++ b/routing_common/maxspeed_conversion.hpp @@ -157,21 +157,23 @@ enum class SpeedMacro : uint8_t Speed125MPH, }; -uint16_t constexpr kInvalidSpeed = std::numeric_limits::max(); -uint16_t constexpr kNoneMaxSpeed = std::numeric_limits::max() - 1; -uint16_t constexpr kWalkMaxSpeed = std::numeric_limits::max() - 2; -uint16_t constexpr kCommonMaxSpeedValue = std::numeric_limits::max() - 3; +using MaxspeedType = uint16_t; + +MaxspeedType constexpr kInvalidSpeed = std::numeric_limits::max(); +MaxspeedType constexpr kNoneMaxSpeed = std::numeric_limits::max() - 1; +MaxspeedType constexpr kWalkMaxSpeed = std::numeric_limits::max() - 2; +MaxspeedType constexpr kCommonMaxSpeedValue = std::numeric_limits::max() - 3; class SpeedInUnits { public: SpeedInUnits() = default; - SpeedInUnits(uint16_t speed, measurement_utils::Units units) noexcept : m_speed(speed), m_units(units) {} + SpeedInUnits(MaxspeedType speed, measurement_utils::Units units) noexcept : m_speed(speed), m_units(units) {} - void SetSpeed(uint16_t speed) { m_speed = speed; } + void SetSpeed(MaxspeedType speed) { m_speed = speed; } void SetUnits(measurement_utils::Units units) { m_units = units; } - uint16_t GetSpeed() const { return m_speed; } + MaxspeedType GetSpeed() const { return m_speed; } measurement_utils::Units GetUnits() const { return m_units; } bool operator==(SpeedInUnits const & rhs) const; @@ -182,7 +184,7 @@ public: private: // Speed in km per hour or mile per hour depends on m_units value. - uint16_t m_speed = kInvalidSpeed; + MaxspeedType m_speed = kInvalidSpeed; // |m_units| is undefined in case of SpeedMacro::None and SpeedMacro::Walk. measurement_utils::Units m_units = measurement_utils::Units::Metric; }; @@ -191,17 +193,17 @@ class Maxspeed { public: Maxspeed() = default; - Maxspeed(measurement_utils::Units units, uint16_t forward, uint16_t backward); + Maxspeed(measurement_utils::Units units, MaxspeedType forward, MaxspeedType backward); bool operator==(Maxspeed const & rhs) const; void SetUnits(measurement_utils::Units units) { m_units = units; } - void SetForward(uint16_t forward) { m_forward = forward; } - void SetBackward(uint16_t backward) { m_backward = backward; } + void SetForward(MaxspeedType forward) { m_forward = forward; } + void SetBackward(MaxspeedType backward) { m_backward = backward; } measurement_utils::Units GetUnits() const { return m_units; } - uint16_t GetForward() const { return m_forward; } - uint16_t GetBackward() const { return m_backward; } + MaxspeedType GetForward() const { return m_forward; } + MaxspeedType GetBackward() const { return m_backward; } bool IsValid() const { return m_forward != kInvalidSpeed; } /// \returns true if Maxspeed is considered as Bidirectional(). It means different @@ -211,20 +213,20 @@ public: /// \brief returns speed according to |m_units|. |kInvalidSpeed|, |kNoneMaxSpeed| or /// |kWalkMaxSpeed| may be returned. - uint16_t GetSpeedInUnits(bool forward) const; + MaxspeedType GetSpeedInUnits(bool forward) const; /// \brief returns speed in km per hour. If it's not valid |kInvalidSpeed| is /// returned. Otherwise forward or backward speed in km per hour is returned. |kNoneMaxSpeed| and /// |kWalkMaxSpeed| are converted to some numbers. - uint16_t GetSpeedKmPH(bool forward) const; + MaxspeedType GetSpeedKmPH(bool forward) const; private: measurement_utils::Units m_units = measurement_utils::Units::Metric; // Speed in km per hour or mile per hour depends on |m_units|. - uint16_t m_forward = kInvalidSpeed; + MaxspeedType m_forward = kInvalidSpeed; // Speed in km per hour or mile per hour depends on |m_units|. If |m_backward| == kInvalidSpeed // |m_forward| speed should be used for the both directions. - uint16_t m_backward = kInvalidSpeed; + MaxspeedType m_backward = kInvalidSpeed; }; /// \brief Feature id and corresponding maxspeed tag value. |m_forward| and |m_backward| fields @@ -235,8 +237,8 @@ private: class FeatureMaxspeed { public: - FeatureMaxspeed(uint32_t fid, measurement_utils::Units units, uint16_t forward, - uint16_t backward = kInvalidSpeed) noexcept; + FeatureMaxspeed(uint32_t fid, measurement_utils::Units units, MaxspeedType forward, + MaxspeedType backward = kInvalidSpeed) noexcept; bool operator==(FeatureMaxspeed const & rhs) const; bool IsFeatureIdLess(FeatureMaxspeed const & rhs) const { return m_featureId < rhs.m_featureId; } @@ -282,7 +284,7 @@ bool IsFeatureIdLess(FeatureMaxspeed const & lhs, FeatureMaxspeed const & rhs); /// \returns false if |speed| is equal to |kInvalidSpeed|, |kNoneMaxSpeed| or /// |kWalkMaxSpeed|. /// \param speed in km per hour or mile per hour. -bool IsNumeric(uint16_t speed); +bool IsNumeric(MaxspeedType speed); std::string DebugPrint(Maxspeed maxspeed); std::string DebugPrint(SpeedMacro maxspeed); diff --git a/track_analyzing/track_analyzer/cmd_table.cpp b/track_analyzing/track_analyzer/cmd_table.cpp index 177a2ea2d5..f0df0361fa 100644 --- a/track_analyzing/track_analyzer/cmd_table.cpp +++ b/track_analyzing/track_analyzer/cmd_table.cpp @@ -46,7 +46,7 @@ using namespace track_analyzing; namespace { -uint16_t constexpr kMaxspeedTopBound = 200; +MaxspeedType constexpr kMaxspeedTopBound = 200; string TypeToString(uint32_t type) { @@ -189,7 +189,7 @@ struct RoadInfo } CarModelTypes::Type m_type; - uint16_t m_maxspeedKMpH = kInvalidSpeed; + MaxspeedType m_maxspeedKMpH = kInvalidSpeed; bool m_isCityRoad = false; bool m_isOneWay = false; };