From 3701f20d4ed312040f1072ec0d9dbd8d54291e85 Mon Sep 17 00:00:00 2001 From: Daria Volvenkova Date: Fri, 21 Dec 2018 17:49:30 +0300 Subject: [PATCH] Represent feature id as string by its params. --- map/framework_light.cpp | 43 +++++++++++++++++++++++++++++++++++++++++ map/framework_light.hpp | 6 ++++++ 2 files changed, 49 insertions(+) diff --git a/map/framework_light.cpp b/map/framework_light.cpp index c4f4455508..5b8b4e8abb 100644 --- a/map/framework_light.cpp +++ b/map/framework_light.cpp @@ -1,5 +1,15 @@ #include "map/framework_light.hpp" +#include "base/stl_helpers.hpp" +#include "base/string_utils.hpp" + +#include + +namespace +{ +char const * kDelimiter = "|"; +} // namespace + namespace lightweight { Framework::Framework(RequestTypeMask request) : m_request(request) @@ -109,4 +119,37 @@ boost::optional Framework::GetNotification { return m_notificationManager->GetNotification(); } + +std::string FeatureParamsToString(int64_t mwmVersion, std::string const & countryId, uint32_t featureIndex) +{ + std::ostringstream stream; + stream << mwmVersion << kDelimiter << countryId << kDelimiter << featureIndex; + return stream.str(); +} + +bool FeatureParamsFromString(std::string const & str, int64_t & mwmVersion, std::string & countryId, + uint32_t & featureIndex) +{ + std::vector tokens; + strings::Tokenize(str, kDelimiter, base::MakeBackInsertFunctor(tokens)); + if (tokens.size() != 3) + return false; + + int64_t tmpMwmVersion; + if (!strings::to_int64(tokens[0], tmpMwmVersion)) + return false; + + unsigned int tmpFeatureIndex; + if (!strings::to_uint(tokens[2], tmpFeatureIndex)) + return false; + + if (tokens[1].empty()) + return false; + + mwmVersion = tmpMwmVersion; + countryId = tokens[1]; + featureIndex = tmpFeatureIndex; + + return true; +} } // namespace lightweight diff --git a/map/framework_light.hpp b/map/framework_light.hpp index f46bff0acf..61e9203074 100644 --- a/map/framework_light.hpp +++ b/map/framework_light.hpp @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -73,4 +74,9 @@ private: std::unique_ptr m_localAdsStatistics; std::unique_ptr m_notificationManager; }; + +std::string FeatureParamsToString(int64_t mwmVersion, std::string const & countryId, uint32_t featureIndex); + +bool FeatureParamsFromString(std::string const & str, int64_t & mwmVersion, std::string & countryId, + uint32_t & featureIndex); } // namespace lightweight