From b20c78f4a846dc21deafb208fedb288e4bd544e6 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Tue, 25 Jun 2013 18:47:48 +0300 Subject: [PATCH] [api] Refactored and deleted duplicate ApiPoint --- android/jni/com/mapswithme/maps/Framework.cpp | 30 +++++------- android/jni/com/mapswithme/maps/Framework.hpp | 2 +- iphone/Maps/Classes/MapsAppDelegate.mm | 29 +++++------ map/framework.cpp | 45 ++++++----------- map/framework.hpp | 4 +- map/ge0_parser.cpp | 48 +++++++++---------- map/ge0_parser.hpp | 6 +-- map/map.pro | 1 - map/map_tests/ge0_parser_tests.cpp | 31 ++++++------ map/map_tests/mwm_url_tests.cpp | 22 ++++----- map/mwm_url.cpp | 2 +- map/mwm_url.hpp | 2 +- map/url_api.hpp | 28 ----------- 13 files changed, 96 insertions(+), 154 deletions(-) delete mode 100644 map/url_api.hpp diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index 6c3b9d6f33..cb97ed3d6c 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -601,8 +601,8 @@ namespace android { m2::PointD pivot(MercatorBounds::LonToX(apiPoint.m_lon), MercatorBounds::LatToY(apiPoint.m_lat)); - ActivatePopup(pivot, apiPoint.m_title, "", IMAGE_ARROW); - m_bmBaloon.get()->setOnClickListener(bind(&Framework::OnAcitvateApiPoint, this, _1, apiPoint)); + ActivatePopup(pivot, apiPoint.m_name, "", IMAGE_ARROW); + m_bmBaloon.get()->setOnClickListener(bind(&Framework::OnActivateApiPoint, this, _1, apiPoint)); return; } else @@ -709,7 +709,7 @@ namespace android if (m_bmBaloon == NULL) return; - ScreenBase screen = m_work.GetNavigator().Screen(); + ScreenBase const & screen = m_work.GetNavigator().Screen(); m_bmBaloon->onScreenSize(screen.GetWidth(), screen.GetHeight()); } @@ -762,26 +762,21 @@ namespace android /// @todo this is weird hack, we should reconsider Android lifecycle handling design m_doLoadState = false; - url_api::Request request; - // if we have only one point - // and import is successful - show balloon - if (m_work.SetViewportByURL(url, request) && request.m_points.size() == 1) + url_scheme::ApiPoint apiPoint; + if (m_work.SetViewportByURL(url, apiPoint)) { - //we need it only for one-point-call - url_api::Point const point = request.m_points.front(); - m2::PointD pt(MercatorBounds::LonToX(request.m_viewportLon), - MercatorBounds::LatToY(request.m_viewportLat)); - ActivatePopup(pt, point.m_name, "", IMAGE_ARROW); + // we need it only for one-point-call + m2::PointD const globalPoint(MercatorBounds::LonToX(apiPoint.m_lon), MercatorBounds::LatToY(apiPoint.m_lat)); + ActivatePopup(globalPoint, apiPoint.m_name, "", IMAGE_ARROW); // For geo and ge0 draw placemark if (!strings::StartsWith(url, "mapswithme")) { - m_work.DrawPlacemark(pt); + m_work.DrawPlacemark(globalPoint); m_work.Invalidate(); } - url_scheme::ApiPoint const apiPoint {point.m_lat, point.m_lon, point.m_name, point.m_id}; - m_bmBaloon.get()->setOnClickListener(bind(&Framework::OnAcitvateApiPoint, this, _1, apiPoint)); + m_bmBaloon.get()->setOnClickListener(bind(&Framework::OnActivateApiPoint, this, _1, apiPoint)); return true; } @@ -799,9 +794,8 @@ namespace android m_bookmarkActivatedListener(bmkAndCat); } - void Framework::OnAcitvateApiPoint(gui::Element * e, url_scheme::ApiPoint const & apiPoint) + void Framework::OnActivateApiPoint(gui::Element * e, url_scheme::ApiPoint const & apiPoint) { - LOG(LERROR, ("POINT on api point listener", apiPoint.m_title, apiPoint.m_id)); m_apiPointActivatedListener(apiPoint); } @@ -879,7 +873,7 @@ extern "C" "onApiPointActivated", "(DDLjava/lang/String;Ljava/lang/String;)V"); - jstring j_name = jni::ToJavaString(jniEnv, apiPoint.m_title); + jstring j_name = jni::ToJavaString(jniEnv, apiPoint.m_name); jstring j_id = jni::ToJavaString(jniEnv, apiPoint.m_id); jniEnv->CallVoidMethod(*obj.get(), methodID, apiPoint.m_lat, apiPoint.m_lon, j_name, j_id); } diff --git a/android/jni/com/mapswithme/maps/Framework.hpp b/android/jni/com/mapswithme/maps/Framework.hpp index 537ad70c7c..d296ab29ea 100644 --- a/android/jni/com/mapswithme/maps/Framework.hpp +++ b/android/jni/com/mapswithme/maps/Framework.hpp @@ -89,7 +89,7 @@ namespace android // Balloon click callbacks void OnActivatePoi(gui::Element * e, ::Framework::AddressInfo const & addrInfo, m2::PointD const & globalPoint); void OnActivateBookmark(gui::Element * e, BookmarkAndCategory const & bmkAndCat); - void OnAcitvateApiPoint(gui::Element * e, url_scheme::ApiPoint const & apiPoint); + void OnActivateApiPoint(gui::Element * e, url_scheme::ApiPoint const & apiPoint); void OnActivateMyPosition(gui::Element * e); diff --git a/iphone/Maps/Classes/MapsAppDelegate.mm b/iphone/Maps/Classes/MapsAppDelegate.mm index 6375c45524..b4b37253ee 100644 --- a/iphone/Maps/Classes/MapsAppDelegate.mm +++ b/iphone/Maps/Classes/MapsAppDelegate.mm @@ -62,16 +62,16 @@ void InitLocalizedStrings() - (void)applicationDidBecomeActive:(UIApplication *)application { - UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; + UIPasteboard * pasteboard = [UIPasteboard generalPasteboard]; if (GetPlatform().IsPro() && !m_didOpenedWithUrl) { NSString * url = [pasteboard.string stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; if ([url length]) { - url_api::Request request; - if (GetFramework().SetViewportByURL([url UTF8String], request)) + url_scheme::ApiPoint apiPoint; + if (GetFramework().SetViewportByURL([url UTF8String], apiPoint)) { - [self showParsedBookmarkOnMap: request]; + [self showParsedBookmarkOnMap:apiPoint]; pasteboard.string = @""; } } @@ -178,10 +178,10 @@ void InitLocalizedStrings() // geo scheme support, see http://tools.ietf.org/html/rfc5870 if ([scheme isEqualToString:@"geo"] || [scheme isEqualToString:@"ge0"]) { - url_api::Request request; - if (GetFramework().SetViewportByURL([[url.absoluteString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] UTF8String], request)) + url_scheme::ApiPoint apiPoint; + if (GetFramework().SetViewportByURL([[url.absoluteString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] UTF8String], apiPoint)) { - [self showParsedBookmarkOnMap: request]; + [self showParsedBookmarkOnMap:apiPoint]; m_didOpenedWithUrl = YES; if ([scheme isEqualToString:@"geo"]) [[Statistics instance] logEvent:@"geo Import"]; @@ -192,8 +192,8 @@ void InitLocalizedStrings() } if ([scheme isEqualToString:@"mapswithme"]) { - url_api::Request request; - if (GetFramework().SetViewportByURL([[url.absoluteString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] UTF8String], request)); + url_scheme::ApiPoint apiPoint; + if (GetFramework().SetViewportByURL([[url.absoluteString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] UTF8String], apiPoint)); { [self showMap]; [m_mapViewController prepareForApi]; @@ -251,15 +251,12 @@ void InitLocalizedStrings() m_navController.navigationBarHidden = YES; } --(void) showParsedBookmarkOnMap:(url_api::Request) request +-(void) showParsedBookmarkOnMap:(url_scheme::ApiPoint const &)apiPoint { [self showMap]; - m2::PointD point(MercatorBounds::LonToX(request.m_viewportLon), - MercatorBounds::LatToY(request.m_viewportLat)); - - NSString * name = [NSString stringWithUTF8String: request.m_points.front().m_name.c_str()]; - - [m_mapViewController showBalloonWithText:name andGlobalPoint:point]; + m2::PointD const globalPoint(MercatorBounds::LonToX(apiPoint.m_lon), MercatorBounds::LatToY(apiPoint.m_lat)); + NSString * name = [NSString stringWithUTF8String:apiPoint.m_name.c_str()]; + [m_mapViewController showBalloonWithText:name andGlobalPoint:globalPoint]; } @end diff --git a/map/framework.cpp b/map/framework.cpp index aae7f51a2f..9768bad793 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -1412,7 +1412,7 @@ void Framework::AddBookmarkAndSetViewport(Bookmark & bm, m2::RectD const & viewP ShowRectExVisibleScale(viewPort); } -bool Framework::SetViewportByURL(string const & url, url_api::Request & request) +bool Framework::SetViewportByURL(string const & url, url_scheme::ApiPoint & balloonPoint) { if (strings::StartsWith(url, "geo")) { @@ -1423,29 +1423,24 @@ bool Framework::SetViewportByURL(string const & url, url_api::Request & request) if (info.IsValid()) { - // @TODO this is hack to kick-off release - request.m_points.push_back(url_api::Point()); - url_api::Point & newPoint = request.m_points.back(); - - newPoint.m_name = m_stringsBundle.GetString("dropped_pin"); - request.m_viewportLat = newPoint.m_lat = info.m_lat; - request.m_viewportLon = newPoint.m_lon = info.m_lon; - request.m_viewportZoomLevel = info.m_zoom; + balloonPoint.m_name = m_stringsBundle.GetString("dropped_pin"); + balloonPoint.m_lat = info.m_lat; + balloonPoint.m_lon = info.m_lon; SetViewPortSync(info.GetViewport()); return true; } } else if (strings::StartsWith(url, "ge0")) { - url_api::Ge0Parser parser; - if (parser.Parse(url, request)) + url_scheme::Ge0Parser parser; + double zoomLevel; + if (parser.Parse(url, balloonPoint, zoomLevel)) { - url_api::Point & point = request.m_points.front(); - if (point.m_name.empty()) - point.m_name = m_stringsBundle.GetString("dropped_pin"); + if (balloonPoint.m_name.empty()) + balloonPoint.m_name = m_stringsBundle.GetString("dropped_pin"); - m2::PointD const center(MercatorBounds::LonToX(request.m_viewportLon), MercatorBounds::LatToY(request.m_viewportLat)); - SetViewPortSync(scales::GetRectForLevel(request.m_viewportZoomLevel, center, 1)); + m2::PointD const center(MercatorBounds::LonToX(balloonPoint.m_lon), MercatorBounds::LatToY(balloonPoint.m_lat)); + SetViewPortSync(scales::GetRectForLevel(zoomLevel, center, 1)); return true; } } @@ -1456,23 +1451,11 @@ bool Framework::SetViewportByURL(string const & url, url_api::Request & request) // Can do better consider nav bar size SetViewPortSync(MercatorBounds::FromLatLonRect(m_ParsedMapApi.GetLatLonRect())); - // Populate request if request has only one point - // with this one point to show balloon. - // @todo: refactor to more general model, Point and ApiPoint must not exist together. - if (m_ParsedMapApi.GetPoints().size() == 1) + if (!m_ParsedMapApi.GetPoints().empty()) { - url_scheme::ApiPoint const apiPoint = m_ParsedMapApi.GetPoints().front(); - url_api::Point point; - - request.m_viewportLat = point.m_lat = apiPoint.m_lat; - request.m_viewportLon = point.m_lon = apiPoint.m_lon; - point.m_name = apiPoint.m_title; - point.m_id = apiPoint.m_id; - - request.m_points.push_back(point); + balloonPoint = m_ParsedMapApi.GetPoints().front(); + return true; } - - return true; } } return false; diff --git a/map/framework.hpp b/map/framework.hpp index 158ad8b831..f914d7dfdf 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -10,7 +10,6 @@ #include "feature_vec_model.hpp" #include "bookmark.hpp" #include "bookmark_manager.hpp" -#include "url_api.hpp" #include "mwm_url.hpp" #include "../defines.hpp" @@ -306,7 +305,8 @@ public: m2::PointD GetViewportCenter() const; void SetViewportCenter(m2::PointD const & pt); - bool SetViewportByURL(string const & url, url_api::Request & request); + /// @param[out] outPoint is a point in url, where we need to show balloon + bool SetViewportByURL(string const & url, url_scheme::ApiPoint & balloonPoint); bool NeedRedraw() const; void SetNeedRedraw(bool flag); diff --git a/map/ge0_parser.cpp b/map/ge0_parser.cpp index d37be6d971..b1ef7b3d3e 100644 --- a/map/ge0_parser.cpp +++ b/map/ge0_parser.cpp @@ -1,5 +1,5 @@ #include "ge0_parser.hpp" -#include "url_api.hpp" +#include "mwm_url.hpp" #include "../api/internal/c/api-client-internals.h" @@ -10,8 +10,10 @@ #include "../base/math.hpp" #include "../base/string_utils.hpp" +namespace url_scheme +{ -url_api::Ge0Parser::Ge0Parser() +Ge0Parser::Ge0Parser() { for (size_t i = 0; i < 256; ++i) m_base64ReverseCharTable[i] = 255; @@ -22,7 +24,7 @@ url_api::Ge0Parser::Ge0Parser() } } -bool url_api::Ge0Parser::Parse(string const & url, Request & request) +bool Ge0Parser::Parse(string const & url, url_scheme::ApiPoint & outPoint, double & outZoomLevel) { // URL format: // @@ -38,44 +40,36 @@ bool url_api::Ge0Parser::Parse(string const & url, Request & request) const int LATLON_LENGTH = NAME_POSITON_IN_URL - LATLON_POSITION - 1; const size_t MAX_NAME_LENGTH = 256; - request.Clear(); if (url.size() < 16 || !strings::StartsWith(url, "ge0://")) return false; uint8_t const zoomI = DecodeBase64Char(url[ZOOM_POSITION]); if (zoomI > 63) return false; - request.m_viewportZoomLevel = DecodeZoom(zoomI); + outZoomLevel = DecodeZoom(zoomI); - request.m_points.push_back(url_api::Point()); - url_api::Point & newPt = request.m_points.back(); + DecodeLatLon(url.substr(LATLON_POSITION, LATLON_LENGTH), outPoint.m_lat, outPoint.m_lon); - DecodeLatLon(url.substr(LATLON_POSITION, LATLON_LENGTH), newPt.m_lat, newPt.m_lon); - - ASSERT(MercatorBounds::ValidLon(newPt.m_lon), (newPt.m_lon)); - ASSERT(MercatorBounds::ValidLat(newPt.m_lat), (newPt.m_lat)); - - request.m_viewportLat = newPt.m_lat; - request.m_viewportLon = newPt.m_lon; + ASSERT(MercatorBounds::ValidLon(outPoint.m_lon), (outPoint.m_lon)); + ASSERT(MercatorBounds::ValidLat(outPoint.m_lat), (outPoint.m_lat)); if (url.size() >= NAME_POSITON_IN_URL) - newPt.m_name = DecodeName(url.substr(NAME_POSITON_IN_URL, - min(url.size() - NAME_POSITON_IN_URL, MAX_NAME_LENGTH))); + outPoint.m_name = DecodeName(url.substr(NAME_POSITON_IN_URL, min(url.size() - NAME_POSITON_IN_URL, MAX_NAME_LENGTH))); return true; } -uint8_t url_api::Ge0Parser::DecodeBase64Char(char const c) +uint8_t Ge0Parser::DecodeBase64Char(char const c) { return m_base64ReverseCharTable[static_cast(c)]; } -double url_api::Ge0Parser::DecodeZoom(uint8_t const zoomByte) +double Ge0Parser::DecodeZoom(uint8_t const zoomByte) { //Coding zoom - int newZoom = ((oldZoom - 4) * 4) return static_cast(zoomByte) / 4 + 4; } -void url_api::Ge0Parser::DecodeLatLon(string const & url, double & lat, double & lon) +void Ge0Parser::DecodeLatLon(string const & url, double & lat, double & lon) { int latInt = 0, lonInt = 0; DecodeLatLonToInt(url, latInt, lonInt, url.size()); @@ -83,7 +77,7 @@ void url_api::Ge0Parser::DecodeLatLon(string const & url, double & lat, double & lon = DecodeLonFromInt(lonInt, (1 << MAPSWITHME_MAX_COORD_BITS) - 1); } -void url_api::Ge0Parser::DecodeLatLonToInt(string const & url, int & lat, int & lon, int const bytes) +void Ge0Parser::DecodeLatLonToInt(string const & url, int & lat, int & lon, int const bytes) { for(int i = 0, shift = MAPSWITHME_MAX_COORD_BITS - 3; i < bytes; ++i, shift -= 3) { @@ -102,17 +96,17 @@ void url_api::Ge0Parser::DecodeLatLonToInt(string const & url, int & lat, int & lon += middleOfSquare; } -double url_api::Ge0Parser::DecodeLatFromInt(int const lat, int const maxValue) +double Ge0Parser::DecodeLatFromInt(int const lat, int const maxValue) { return static_cast(lat) / maxValue * 180 - 90; } -double url_api::Ge0Parser::DecodeLonFromInt(int const lon, int const maxValue) +double Ge0Parser::DecodeLonFromInt(int const lon, int const maxValue) { return static_cast(lon) / (maxValue + 1.0) * 360.0 - 180; } -string url_api::Ge0Parser::DecodeName(string name) +string Ge0Parser::DecodeName(string name) { ValidateName(name); name = UrlDecode(name); @@ -120,7 +114,7 @@ string url_api::Ge0Parser::DecodeName(string name) return name; } -void url_api::Ge0Parser::SpacesToUnderscore(string & name) +void Ge0Parser::SpacesToUnderscore(string & name) { for (size_t i = 0; i < name.size(); ++i) if (name[i] == ' ') @@ -129,7 +123,7 @@ void url_api::Ge0Parser::SpacesToUnderscore(string & name) name[i] = ' '; } -void url_api::Ge0Parser::ValidateName(string & name) +void Ge0Parser::ValidateName(string & name) { if (name.empty()) return; @@ -147,7 +141,9 @@ void url_api::Ge0Parser::ValidateName(string & name) name.resize(name.size() - 2); } -bool url_api::Ge0Parser::IsHexChar(char const a) +bool Ge0Parser::IsHexChar(char const a) { return ((a >= '0' && a <= '9') || (a >= 'A' && a <= 'F') || (a >= 'a' && a <= 'f')); } + +} // namespace url_scheme diff --git a/map/ge0_parser.hpp b/map/ge0_parser.hpp index 09bc6d9370..16fc269bcc 100644 --- a/map/ge0_parser.hpp +++ b/map/ge0_parser.hpp @@ -3,17 +3,17 @@ #include "../std/string.hpp" -namespace url_api +namespace url_scheme { -struct Request; +struct ApiPoint; class Ge0Parser { public: Ge0Parser(); - bool Parse(string const & url, Request & request); + bool Parse(string const & url, url_scheme::ApiPoint & outPoint, double & outZoomLevel); protected: uint8_t DecodeBase64Char(char const c); diff --git a/map/map.pro b/map/map.pro index 25e5cf213c..54ad4e6300 100644 --- a/map/map.pro +++ b/map/map.pro @@ -56,7 +56,6 @@ HEADERS += \ geometry_processors.hpp \ bookmark_manager.hpp \ ge0_parser.hpp \ - url_api.hpp \ SOURCES += \ feature_vec_model.cpp \ diff --git a/map/map_tests/ge0_parser_tests.cpp b/map/map_tests/ge0_parser_tests.cpp index 7d097ee7bd..3cb3e2a2c2 100644 --- a/map/map_tests/ge0_parser_tests.cpp +++ b/map/map_tests/ge0_parser_tests.cpp @@ -1,7 +1,7 @@ #include "../../testing/testing.hpp" #include "../ge0_parser.hpp" -#include "../url_api.hpp" +#include "../mwm_url.hpp" #include "../../api/internal/c/api-client-internals.h" #include "../../api/src/c/api-client.h" @@ -9,8 +9,8 @@ #include "../../base/macros.hpp" -using url_api::Ge0Parser; -using url_api::Request; +using url_scheme::Ge0Parser; +using url_scheme::ApiPoint; namespace { @@ -40,29 +40,30 @@ double GetLonEpsilon(int coordBytes) void TestSuccess(char const * s, double lat, double lon, double zoom, char const * name) { Ge0Parser parser; - Request request; - bool const result = parser.Parse(s, request); + ApiPoint apiPoint; + double parsedZoomLevel; + bool const result = parser.Parse(s, apiPoint, parsedZoomLevel); TEST(result, (s, zoom, lat, lon, name)); - TEST_EQUAL(request.m_points.size(), 1, (s, zoom, lat, lon, name)); - TEST_EQUAL(request.m_points[0].m_name, string(name), (s)); - TEST_EQUAL(request.m_points[0].m_id, string(), (s)); + TEST_EQUAL(apiPoint.m_name, string(name), (s)); + TEST_EQUAL(apiPoint.m_id, string(), (s)); double const latEps = GetLatEpsilon(9); double const lonEps = GetLonEpsilon(9); - TEST(fabs(request.m_points[0].m_lat - lat) <= latEps, (s, zoom, lat, lon, name)); - TEST(fabs(request.m_points[0].m_lon - lon) <= lonEps, (s, zoom, lat, lon, name)); + TEST(fabs(apiPoint.m_lat - lat) <= latEps, (s, zoom, lat, lon, name)); + TEST(fabs(apiPoint.m_lon - lon) <= lonEps, (s, zoom, lat, lon, name)); - TEST(fabs(request.m_viewportLat - lat) <= latEps, (s, zoom, lat, lon, name)); - TEST(fabs(request.m_viewportLon - lon) <= lonEps, (s, zoom, lat, lon, name)); - TEST_ALMOST_EQUAL(request.m_viewportZoomLevel, zoom, (s, zoom, lat, lon, name)); + TEST(fabs(apiPoint.m_lat - lat) <= latEps, (s, zoom, lat, lon, name)); + TEST(fabs(apiPoint.m_lon - lon) <= lonEps, (s, zoom, lat, lon, name)); + TEST_ALMOST_EQUAL(parsedZoomLevel, zoom, (s, zoom, lat, lon, name)); } void TestFailure(char const * s) { Ge0Parser parser; - Request request; - bool const result = parser.Parse(s, request); + ApiPoint apiPoint; + double zoomLevel; + bool const result = parser.Parse(s, apiPoint, zoomLevel); TEST_EQUAL(result, false, (s)); } diff --git a/map/map_tests/mwm_url_tests.cpp b/map/map_tests/mwm_url_tests.cpp index dc8c9008e6..0bc8c1a9f7 100644 --- a/map/map_tests/mwm_url_tests.cpp +++ b/map/map_tests/mwm_url_tests.cpp @@ -19,7 +19,7 @@ UNIT_TEST(MapApiSmoke) TEST_EQUAL(api.GetPoints().size(), 1, ()); TEST_EQUAL(api.GetPoints()[0].m_lat, 38.970559, ()); TEST_EQUAL(api.GetPoints()[0].m_lon, -9.419289, ()); - TEST_EQUAL(api.GetPoints()[0].m_title, "Point Name", ()); + TEST_EQUAL(api.GetPoints()[0].m_name, "Point Name", ()); TEST_EQUAL(api.GetPoints()[0].m_id, "", ()); TEST_EQUAL(api.GetGlobalBackUrl(), "", ()); } @@ -47,7 +47,7 @@ UNIT_TEST(MapApiPointNameBeforeLatLon) ParsedMapApi api(Uri("mapswithme://map?n=Name&ll=1,2")); TEST(api.IsValid(), ()); TEST_EQUAL(api.GetPoints().size(), 1, ()); - TEST_EQUAL(api.GetPoints()[0].m_title, "", ()); + TEST_EQUAL(api.GetPoints()[0].m_name, "", ()); } UNIT_TEST(MapApiPointNameOverwritten) @@ -55,7 +55,7 @@ UNIT_TEST(MapApiPointNameOverwritten) ParsedMapApi api(Uri("mapswithme://map?ll=1,2&n=A&N=B")); TEST(api.IsValid(), ()); TEST_EQUAL(api.GetPoints().size(), 1, ()); - TEST_EQUAL(api.GetPoints()[0].m_title, "B", ()); + TEST_EQUAL(api.GetPoints()[0].m_name, "B", ()); } UNIT_TEST(MapApiMultiplePoints) @@ -65,11 +65,11 @@ UNIT_TEST(MapApiMultiplePoints) TEST_EQUAL(api.GetPoints().size(), 3, ()); TEST_EQUAL(api.GetPoints()[0].m_lat, 1.1, ()); TEST_EQUAL(api.GetPoints()[0].m_lon, 1.2, ()); - TEST_EQUAL(api.GetPoints()[0].m_title, "A", ()); - TEST_EQUAL(api.GetPoints()[1].m_title, "", ()); + TEST_EQUAL(api.GetPoints()[0].m_name, "A", ()); + TEST_EQUAL(api.GetPoints()[1].m_name, "", ()); TEST_EQUAL(api.GetPoints()[1].m_lat, 2.1, ()); TEST_EQUAL(api.GetPoints()[1].m_lon, 2.2, ()); - TEST_EQUAL(api.GetPoints()[2].m_title, "C", ()); + TEST_EQUAL(api.GetPoints()[2].m_name, "C", ()); TEST_EQUAL(api.GetPoints()[2].m_lat, -3.1, ()); TEST_EQUAL(api.GetPoints()[2].m_lon, -3.2, ()); } @@ -81,7 +81,7 @@ UNIT_TEST(MapApiInvalidPointLatLonButValidOtherParts) TEST_EQUAL(api.GetPoints().size(), 1, ()); TEST_EQUAL(api.GetPoints()[0].m_lat, 2, ()); TEST_EQUAL(api.GetPoints()[0].m_lon, 2, ()); - TEST_EQUAL(api.GetPoints()[0].m_title, "B", ()); + TEST_EQUAL(api.GetPoints()[0].m_name, "B", ()); } UNIT_TEST(MapApiPointURLEncoded) @@ -89,7 +89,7 @@ UNIT_TEST(MapApiPointURLEncoded) ParsedMapApi api(Uri("mwm://map?ll=1,2&n=%D0%9C%D0%B8%D0%BD%D1%81%D0%BA&id=http%3A%2F%2Fmap%3Fll%3D1%2C2%26n%3Dtest")); TEST(api.IsValid(), ()); TEST_EQUAL(api.GetPoints().size(), 1, ()); - TEST_EQUAL(api.GetPoints()[0].m_title, "\xd0\x9c\xd0\xb8\xd0\xbd\xd1\x81\xd0\xba", ()); + TEST_EQUAL(api.GetPoints()[0].m_name, "\xd0\x9c\xd0\xb8\xd0\xbd\xd1\x81\xd0\xba", ()); TEST_EQUAL(api.GetPoints()[0].m_id, "http://map?ll=1,2&n=test", ()); } @@ -216,7 +216,7 @@ string generatePartOfUrl(url_scheme::ApiPoint const & point) { stringstream stream; stream << "&ll=" << strings::ToString(point.m_lat) << "," << strings::ToString(point.m_lon) - << "&n=" << point.m_title + << "&n=" << point.m_name << "&id=" << point.m_id; return stream.str(); } @@ -241,7 +241,7 @@ void generateRandomTest(size_t numberOfPoints, size_t stringLength) point.m_lat *= random.Generate() % 2 == 0 ? 1 : -1; point.m_lon = random.Generate() % 180; point.m_lon *= random.Generate() % 2 == 0 ? 1 : -1; - point.m_title = randomString(stringLength, i); + point.m_name = randomString(stringLength, i); point.m_id = randomString(stringLength, i); vect[i] = point; } @@ -256,7 +256,7 @@ void generateRandomTest(size_t numberOfPoints, size_t stringLength) { TEST_EQUAL(points[i].m_lat, vect[i].m_lat, ()); TEST_EQUAL(points[i].m_lon, vect[i].m_lon, ()); - TEST_EQUAL(points[i].m_title, vect[i].m_title, ()); + TEST_EQUAL(points[i].m_name, vect[i].m_name, ()); TEST_EQUAL(points[i].m_id, vect[i].m_id, ()); } TEST_EQUAL(api.GetApiVersion(), 1, ()); diff --git a/map/mwm_url.cpp b/map/mwm_url.cpp index 5bc66520a3..220555374b 100644 --- a/map/mwm_url.cpp +++ b/map/mwm_url.cpp @@ -103,7 +103,7 @@ void ParsedMapApi::AddKeyValue(string key, string const & value) else if (key == "n") { if (!m_points.empty()) - m_points.back().m_title = value; + m_points.back().m_name = value; else LOG(LWARNING, ("Map API: Point name with no point. 'll' should come first!")); } diff --git a/map/mwm_url.hpp b/map/mwm_url.hpp index 556292d229..ff71b71c27 100644 --- a/map/mwm_url.hpp +++ b/map/mwm_url.hpp @@ -10,7 +10,7 @@ struct ApiPoint { double m_lat; double m_lon; - string m_title; + string m_name; string m_id; }; diff --git a/map/url_api.hpp b/map/url_api.hpp deleted file mode 100644 index 176c382dea..0000000000 --- a/map/url_api.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "../std/vector.hpp" - -namespace url_api -{ - -struct Point -{ - Point() : m_lat(0), m_lon(0) {} - - double m_lat; - double m_lon; - string m_name; - string m_id; -}; - -struct Request -{ - vector m_points; - double m_viewportLat, m_viewportLon, m_viewportZoomLevel; - - void Clear() - { - m_points.clear(); - m_viewportLat = m_viewportLon = m_viewportZoomLevel = 0; - } -}; - -} // namespace url_api