From abc28557e2cff5d6298489f370d8dd95bbba32ed Mon Sep 17 00:00:00 2001 From: Maxim Pimenov Date: Tue, 24 Jul 2018 15:22:21 +0300 Subject: [PATCH] Review fixes. --- drape/texture_manager.cpp | 1 + drape_frontend/animation/interpolators.cpp | 1 - editor/xml_feature.cpp | 9 +++- generator/borders_loader.cpp | 6 +-- generator/borders_loader.hpp | 12 ++--- generator/polygonizer.hpp | 8 ++-- geometry/algorithm.cpp | 6 +-- geometry/angles.hpp | 14 +++--- geometry/any_rect2d.hpp | 8 ++-- geometry/screenbase.cpp | 6 +-- platform/measurement_utils.cpp | 12 ++--- platform/measurement_utils.hpp | 53 ++++++++++++---------- transit/transit_types.hpp | 16 +++---- 13 files changed, 75 insertions(+), 77 deletions(-) diff --git a/drape/texture_manager.cpp b/drape/texture_manager.cpp index 874a59cfbd..ee280d80ab 100644 --- a/drape/texture_manager.cpp +++ b/drape/texture_manager.cpp @@ -18,6 +18,7 @@ #include "base/string_utils.hpp" #include +#include #include #include diff --git a/drape_frontend/animation/interpolators.cpp b/drape_frontend/animation/interpolators.cpp index 4a4fc7f3a0..7036a0eeef 100644 --- a/drape_frontend/animation/interpolators.cpp +++ b/drape_frontend/animation/interpolators.cpp @@ -1,5 +1,4 @@ #include "drape_frontend/animation/interpolators.hpp" - #include "drape_frontend/animation/interpolations.hpp" #include "base/assert.hpp" diff --git a/editor/xml_feature.cpp b/editor/xml_feature.cpp index abccd00938..cb3e13017e 100644 --- a/editor/xml_feature.cpp +++ b/editor/xml_feature.cpp @@ -3,6 +3,7 @@ #include "indexer/classificator.hpp" #include "indexer/feature.hpp" +#include "base/exception.hpp" #include "base/macros.hpp" #include "base/string_utils.hpp" #include "base/timer.hpp" @@ -36,11 +37,15 @@ ms::LatLon GetLatLonFromNode(pugi::xml_node const & node) { ms::LatLon ll; if (!strings::to_double(node.attribute("lat").value(), ll.lat)) + { MYTHROW(editor::NoLatLon, - ("Can't parse lat attribute: " + string(node.attribute("lat").value()))); + ("Can't parse lat attribute:", string(node.attribute("lat").value()))); + } if (!strings::to_double(node.attribute("lon").value(), ll.lon)) + { MYTHROW(editor::NoLatLon, - ("Can't parse lon attribute: " + string(node.attribute("lon").value()))); + ("Can't parse lon attribute:", string(node.attribute("lon").value()))); + } return ll; } diff --git a/generator/borders_loader.cpp b/generator/borders_loader.cpp index b39241cfa1..4a6ceaa313 100644 --- a/generator/borders_loader.cpp +++ b/generator/borders_loader.cpp @@ -37,10 +37,10 @@ class PolygonLoader CountryPolygons m_polygons; m2::RectD m_rect; - CountriesContainerT & m_countries; + CountriesContainer & m_countries; public: - PolygonLoader(CountriesContainerT & countries) : m_countries(countries) {} + PolygonLoader(CountriesContainer & countries) : m_countries(countries) {} void operator()(std::string const & name, std::vector const & borders) { @@ -89,7 +89,7 @@ void ForEachCountry(std::string const & baseDir, ToDo & toDo) } } -bool LoadCountriesList(std::string const & baseDir, CountriesContainerT & countries) +bool LoadCountriesList(std::string const & baseDir, CountriesContainer & countries) { countries.Clear(); diff --git a/generator/borders_loader.hpp b/generator/borders_loader.hpp index 9c2b4f8fca..de52b2d089 100644 --- a/generator/borders_loader.hpp +++ b/generator/borders_loader.hpp @@ -11,8 +11,8 @@ namespace borders { - typedef m2::RegionD Region; - typedef m4::Tree RegionsContainerT; + using Region = m2::RegionD; + using RegionsContainer = m4::Tree; struct CountryPolygons { @@ -26,16 +26,16 @@ namespace borders m_index = -1; } - RegionsContainerT m_regions; + RegionsContainer m_regions; std::string m_name; mutable int m_index; }; - typedef m4::Tree CountriesContainerT; + using CountriesContainer = m4::Tree; - bool LoadCountriesList(std::string const & baseDir, CountriesContainerT & countries); + bool LoadCountriesList(std::string const & baseDir, CountriesContainer & countries); void GeneratePackedBorders(std::string const & baseDir); void UnpackBorders(std::string const & baseDir, std::string const & targetDir); bool GetBordersRect(std::string const & baseDir, std::string const & country, m2::RectD & bordersRect); -} +} // namespace borders diff --git a/generator/polygonizer.hpp b/generator/polygonizer.hpp index 0842d271f2..d147f92668 100644 --- a/generator/polygonizer.hpp +++ b/generator/polygonizer.hpp @@ -39,7 +39,7 @@ namespace feature vector m_Buckets; vector m_Names; - borders::CountriesContainerT m_countries; + borders::CountriesContainer m_countries; #if PARALLEL_POLYGONIZER QThreadPool m_ThreadPool; @@ -78,10 +78,10 @@ namespace feature struct PointChecker { - borders::RegionsContainerT const & m_regions; + borders::RegionsContainer const & m_regions; bool m_belongs; - PointChecker(borders::RegionsContainerT const & regions) + PointChecker(borders::RegionsContainer const & regions) : m_regions(regions), m_belongs(false) {} bool operator()(m2::PointD const & pt) @@ -217,4 +217,4 @@ namespace feature FeatureBuilder1 m_fb; }; }; -} +} // namespace feature diff --git a/geometry/algorithm.cpp b/geometry/algorithm.cpp index 751476f7d5..73f4a956d1 100644 --- a/geometry/algorithm.cpp +++ b/geometry/algorithm.cpp @@ -7,9 +7,7 @@ using namespace std; namespace m2 { -// CalculatePolyLineCenter -// ----------------------------------------------------------------------------- - +// CalculatePolyLineCenter ------------------------------------------------------------------------- void CalculatePolyLineCenter::operator()(m2::PointD const & pt) { m_length += (m_poly.empty() ? 0.0 : m_poly.back().m_p.Length(pt)); @@ -42,7 +40,6 @@ PointD CalculatePolyLineCenter::GetResult() const } // CalculatePointOnSurface ------------------------------------------------------------------------- - CalculatePointOnSurface::CalculatePointOnSurface(m2::RectD const & rect) : m_rectCenter(rect.Center()) , m_center(m_rectCenter) @@ -74,7 +71,6 @@ void CalculatePointOnSurface::operator()(PointD const & p1, PointD const & p2, P } // CalculateBoundingBox ---------------------------------------------------------------------------- - void CalculateBoundingBox::operator()(PointD const & p) { // Works just fine. If you don't belive me, see geometry/rect2d.hpp. diff --git a/geometry/angles.hpp b/geometry/angles.hpp index ce16c60b78..e4ca1a3a3d 100644 --- a/geometry/angles.hpp +++ b/geometry/angles.hpp @@ -13,7 +13,7 @@ template class Angle { public: - Angle() : m_val(0), m_sin(0), m_cos(1) {} + Angle() = default; Angle(T const & val) : m_val(val), m_sin(::sin(val)), m_cos(::cos(val)) {} Angle(T const & sin, T const & cos) : m_val(::atan2(sin, cos)), m_sin(sin), m_cos(cos) {} @@ -41,9 +41,9 @@ public: friend std::string DebugPrint(Angle const & ang) { return DebugPrint(ang.m_val); } private: - T m_val; - T m_sin; - T m_cos; + T m_val = 0; + T m_sin = 0; + T m_cos = 1; }; using AngleD = Angle; @@ -102,8 +102,6 @@ T Azimuth(m2::Point const & p1, m2::Point const & p2, T north = 0) class AverageCalc { public: - AverageCalc() : m_ang(0.0), m_isEmpty(true) {} - void Add(double a) { m_ang = (m_isEmpty ? a : GetMiddleAngle(m_ang, a)); @@ -113,7 +111,7 @@ public: double GetAverage() const { return m_ang; } private: - double m_ang; - bool m_isEmpty; + double m_ang = 0.0; + bool m_isEmpty = true; }; } // namespace ang diff --git a/geometry/any_rect2d.hpp b/geometry/any_rect2d.hpp index 0a507c719f..5e118f0047 100644 --- a/geometry/any_rect2d.hpp +++ b/geometry/any_rect2d.hpp @@ -16,7 +16,7 @@ template class AnyRect { public: - AnyRect() : m_zero(0, 0), m_rect() {} + AnyRect() = default; /// creating from regular rect explicit AnyRect(Rect const & r) @@ -28,7 +28,7 @@ public: } else { - m_zero = Point(0, 0); + m_zero = Point::Zero(); m_rect = r; } } @@ -211,8 +211,8 @@ private: ang::Angle m_angle; - Point m_zero; - Rect m_rect; + Point m_zero{}; + Rect m_rect{}; }; using AnyRectD = AnyRect; diff --git a/geometry/screenbase.cpp b/geometry/screenbase.cpp index fabf1d5b56..f2e05f3056 100644 --- a/geometry/screenbase.cpp +++ b/geometry/screenbase.cpp @@ -18,7 +18,9 @@ double constexpr kEndPerspectiveScale1 = 0.3e-5; double constexpr kEndPerspectiveScale2 = 0.13e-5; ScreenBase::ScreenBase() - : m_ViewportRect(0, 0, 640, 480) + : m_GlobalRect(m_Org, ang::AngleD(0), m2::RectD(-320, -240, 320, 240)) + , m_ClipRect(m2::RectD(0, 0, 640, 480)) + , m_ViewportRect(0, 0, 640, 480) , m_PixelRect(m_ViewportRect) , m_Scale(0.1) , m_Angle(0.0) @@ -30,8 +32,6 @@ ScreenBase::ScreenBase() , m_3dMaxAngleX(0.0) , m_3dScale(1.0) , m_isPerspective(false) - , m_GlobalRect(m_Org, ang::AngleD(0), m2::RectD(-320, -240, 320, 240)) - , m_ClipRect(m2::RectD(0, 0, 640, 480)) , m_isAutoPerspective(false) { m_GtoP = math::Identity(); diff --git a/platform/measurement_utils.cpp b/platform/measurement_utils.cpp index 42ab2b5fc5..fe5a7d02b7 100644 --- a/platform/measurement_utils.cpp +++ b/platform/measurement_utils.cpp @@ -3,23 +3,22 @@ #include "geometry/mercator.hpp" +#include "base/assert.hpp" #include "base/macros.hpp" #include "base/math.hpp" #include "base/stl_add.hpp" #include "base/string_utils.hpp" -#include "base/logging.hpp" - -#include "std/cstring.hpp" -#include "std/iomanip.hpp" -#include "std/sstream.hpp" +#include +#include +#include using namespace settings; +using namespace std; using namespace strings; namespace measurement_utils { - string ToStringPrecision(double d, int pr) { stringstream ss; @@ -296,5 +295,4 @@ string OSMDistanceToMetersString(string const & osmRawValue, } return {}; } - } // namespace measurement_utils diff --git a/platform/measurement_utils.hpp b/platform/measurement_utils.hpp index d4251b509e..8006bd2fea 100644 --- a/platform/measurement_utils.hpp +++ b/platform/measurement_utils.hpp @@ -2,7 +2,9 @@ #include "geometry/point2d.hpp" -#include "std/string.hpp" +#include "base/assert.hpp" + +#include namespace measurement_utils { @@ -12,7 +14,7 @@ enum class Units Imperial = 1 }; -inline string DebugPrint(Units units) +inline std::string DebugPrint(Units units) { switch (units) { @@ -32,38 +34,41 @@ inline double NauticalMilesToMeters(double nmi) { return nmi * 1852; } /// Takes into an account user settings [metric, imperial] /// @param[in] m meters -/// @param[out] res formatted string for search +/// @param[out] res formatted std::string for search /// @return should be direction arrow drawed? false if distance is to small (< 1.0) -bool FormatDistance(double m, string & res); +bool FormatDistance(double m, std::string & res); /// We always use meters and feet/yards for altitude -string FormatAltitude(double altitudeInMeters); +std::string FormatAltitude(double altitudeInMeters); // Return value is measured in km/h for Metric and in mph for Imperial. -string FormatSpeedWithDeviceUnits(double metersPerSecond); -string FormatSpeedWithUnits(double metersPerSecond, Units units); -string FormatSpeed(double metersPerSecond, Units units); -string FormatSpeedUnits(Units units); +std::string FormatSpeedWithDeviceUnits(double metersPerSecond); +std::string FormatSpeedWithUnits(double metersPerSecond, Units units); +std::string FormatSpeed(double metersPerSecond, Units units); +std::string FormatSpeedUnits(Units units); /// @param[in] dac Digits after comma in seconds. /// Use dac == 3 for our common conversions to DMS. -string FormatLatLonAsDMS(double lat, double lon, int dac = 3); -void FormatLatLonAsDMS(double lat, double lon, string & latText, string & lonText, int dac = 3); -string FormatMercatorAsDMS(m2::PointD const & mercator, int dac = 3); -void FormatMercatorAsDMS(m2::PointD const & mercator, string & lat, string & lon, int dac = 3); +std::string FormatLatLonAsDMS(double lat, double lon, int dac = 3); +void FormatLatLonAsDMS(double lat, double lon, std::string & latText, std::string & lonText, + int dac = 3); +std::string FormatMercatorAsDMS(m2::PointD const & mercator, int dac = 3); +void FormatMercatorAsDMS(m2::PointD const & mercator, std::string & lat, std::string & lon, + int dac = 3); /// Default dac == 6 for the simple decimal formatting. -string FormatLatLon(double lat, double lon, int dac = 6); -string FormatLatLon(double lat, double lon, bool withSemicolon, int dac = 6); -void FormatLatLon(double lat, double lon, string & latText, string & lonText, int dac = 6); -string FormatMercator(m2::PointD const & mercator, int dac = 6); -void FormatMercator(m2::PointD const & mercator, string & lat, string & lon, int dac = 6); +std::string FormatLatLon(double lat, double lon, int dac = 6); +std::string FormatLatLon(double lat, double lon, bool withSemicolon, int dac = 6); +void FormatLatLon(double lat, double lon, std::string & latText, std::string & lonText, + int dac = 6); +std::string FormatMercator(m2::PointD const & mercator, int dac = 6); +void FormatMercator(m2::PointD const & mercator, std::string & lat, std::string & lon, int dac = 6); /// Converts OSM distance (height, ele etc.) to meters. /// @returns false if fails. -bool OSMDistanceToMeters(string const & osmRawValue, double & outMeters); -/// Converts OSM distance (height, ele etc.) to meters string. -/// @returns empty string on failure. -string OSMDistanceToMetersString(string const & osmRawValue, - bool supportZeroAndNegativeValues = true, - int digitsAfterComma = 2); +bool OSMDistanceToMeters(std::string const & osmRawValue, double & outMeters); +/// Converts OSM distance (height, ele etc.) to meters std::string. +/// @returns empty std::string on failure. +std::string OSMDistanceToMetersString(std::string const & osmRawValue, + bool supportZeroAndNegativeValues = true, + int digitsAfterComma = 2); } // namespace measurement_utils diff --git a/transit/transit_types.hpp b/transit/transit_types.hpp index e6314539b6..d872e949a9 100644 --- a/transit/transit_types.hpp +++ b/transit/transit_types.hpp @@ -37,16 +37,12 @@ StopId constexpr kInvalidStopId = std::numeric_limits::max(); TransferId constexpr kInvalidTransferId = std::numeric_limits::max(); Weight constexpr kInvalidWeight = std::numeric_limits::max(); -#define DECLARE_TRANSIT_TYPE_FRIENDS \ - template \ - friend class Serializer; \ - template \ - friend class Deserializer; \ - friend class DeserializerFromJson; \ - template \ - friend class FixedSizeSerializer; \ - template \ - friend class FixedSizeDeserializer; +#define DECLARE_TRANSIT_TYPE_FRIENDS \ + template friend class Serializer; \ + template friend class Deserializer; \ + friend class DeserializerFromJson; \ + template friend class FixedSizeSerializer; \ + template friend class FixedSizeDeserializer; \ struct TransitHeader {