diff --git a/coding/coding_tests/serdes_json_test.cpp b/coding/coding_tests/serdes_json_test.cpp index 42c976705a..6ffb7e7504 100644 --- a/coding/coding_tests/serdes_json_test.cpp +++ b/coding/coding_tests/serdes_json_test.cpp @@ -20,7 +20,7 @@ using namespace std; namespace { template -bool samePtrValue(PtrT const & lhs, PtrT const & rhs) +bool SamePtrValue(PtrT const & lhs, PtrT const & rhs) { return (!lhs && !rhs) || (lhs && rhs && *lhs == *rhs); } @@ -28,7 +28,7 @@ bool samePtrValue(PtrT const & lhs, PtrT const & rhs) template bool TestSerDes(T const & value) { - std::string jsonStr; + string jsonStr; { using Sink = MemWriter; Sink sink(jsonStr); @@ -62,53 +62,53 @@ enum class TestEnum struct ValueTypes { DECLARE_VISITOR(visitor(m_boolValue, "boolValue"), - visitor(m_uint8_tValue, "uint8_tValue"), - visitor(m_uint32_tValue, "uint32_tValue"), - visitor(m_uint64_tValue, "uint64_tValue"), - visitor(m_int8_tValue, "int8_tValue"), - visitor(m_int32_tValue, "int32_tValue"), - visitor(m_int64_tValue, "int64_tValue"), + visitor(m_uint8Value, "uint8Value"), + visitor(m_uint32Value, "uint32Value"), + visitor(m_uint64Value, "uint64Value"), + visitor(m_int8Value, "int8Value"), + visitor(m_int32Value, "int32Value"), + visitor(m_int64Value, "int64Value"), visitor(m_doubleValue, "doubleValue"), visitor(m_stringValue, "stringValue"), visitor(m_enumValue, "enumValue"), - visitor(m_time_pointValue, "time_pointValue")); + visitor(m_timePointValue, "timePointValue")); ValueTypes() = default; ValueTypes(uint32_t testCounter) : m_boolValue(static_cast(testCounter % 2)) - , m_uint8_tValue(numeric_limits::max() - static_cast(testCounter)) - , m_uint32_tValue(numeric_limits::max() - testCounter) - , m_uint64_tValue(numeric_limits::max() - testCounter) - , m_int8_tValue(numeric_limits::min() + static_cast(testCounter)) - , m_int32_tValue(numeric_limits::min() + static_cast(testCounter)) - , m_int64_tValue(numeric_limits::min() + static_cast(testCounter)) + , m_uint8Value(numeric_limits::max() - static_cast(testCounter)) + , m_uint32Value(numeric_limits::max() - testCounter) + , m_uint64Value(numeric_limits::max() - testCounter) + , m_int8Value(numeric_limits::min() + static_cast(testCounter)) + , m_int32Value(numeric_limits::min() + static_cast(testCounter)) + , m_int64Value(numeric_limits::min() + static_cast(testCounter)) , m_doubleValue(numeric_limits::max() - testCounter) , m_stringValue(strings::to_string(testCounter)) , m_enumValue(static_cast(testCounter % static_cast(TestEnum::Count))) - , m_time_pointValue(chrono::system_clock::now()) + , m_timePointValue(chrono::system_clock::now()) {} bool operator==(ValueTypes const & rhs) const { - return m_boolValue == rhs.m_boolValue && m_uint8_tValue == rhs.m_uint8_tValue && - m_uint32_tValue == rhs.m_uint32_tValue && m_uint64_tValue == rhs.m_uint64_tValue && - m_int8_tValue == rhs.m_int8_tValue && m_int32_tValue == rhs.m_int32_tValue && - m_int64_tValue == rhs.m_int64_tValue && m_doubleValue == rhs.m_doubleValue && + return m_boolValue == rhs.m_boolValue && m_uint8Value == rhs.m_uint8Value && + m_uint32Value == rhs.m_uint32Value && m_uint64Value == rhs.m_uint64Value && + m_int8Value == rhs.m_int8Value && m_int32Value == rhs.m_int32Value && + m_int64Value == rhs.m_int64Value && m_doubleValue == rhs.m_doubleValue && m_stringValue == rhs.m_stringValue && m_enumValue == rhs.m_enumValue && - m_time_pointValue == rhs.m_time_pointValue; + m_timePointValue == rhs.m_timePointValue; } bool m_boolValue; - uint8_t m_uint8_tValue; - uint32_t m_uint32_tValue; - uint64_t m_uint64_tValue; - int8_t m_int8_tValue; - int32_t m_int32_tValue; - int64_t m_int64_tValue; + uint8_t m_uint8Value; + uint32_t m_uint32Value; + uint64_t m_uint64Value; + int8_t m_int8Value; + int32_t m_int32Value; + int64_t m_int64Value; double m_doubleValue; string m_stringValue; TestEnum m_enumValue; - chrono::system_clock::time_point m_time_pointValue; + chrono::system_clock::time_point m_timePointValue; }; struct ObjectTypes @@ -137,24 +137,24 @@ struct ObjectTypes struct PointerTypes { - DECLARE_VISITOR(visitor(m_unique_ptrValue, "unique_ptrValue"), - visitor(m_shared_ptrValue, "shared_ptrValue")); + DECLARE_VISITOR(visitor(m_uniquePtrValue, "uniquePtrValue"), + visitor(m_sharedPtrValue, "sharedPtrValue")); PointerTypes() = default; PointerTypes(uint32_t testCounter) { - m_unique_ptrValue = make_unique(testCounter); - m_shared_ptrValue = make_shared(testCounter); + m_uniquePtrValue = make_unique(testCounter); + m_sharedPtrValue = make_shared(testCounter); } bool operator==(PointerTypes const & rhs) const { - return samePtrValue(m_unique_ptrValue, rhs.m_unique_ptrValue) && - samePtrValue(m_shared_ptrValue, rhs.m_shared_ptrValue); + return SamePtrValue(m_uniquePtrValue, rhs.m_uniquePtrValue) && + SamePtrValue(m_sharedPtrValue, rhs.m_sharedPtrValue); } - unique_ptr m_unique_ptrValue; - shared_ptr m_shared_ptrValue; + unique_ptr m_uniquePtrValue; + shared_ptr m_sharedPtrValue; }; struct ArrayTypes @@ -163,7 +163,7 @@ struct ArrayTypes visitor(m_dequeValue, "dequeValue"), visitor(m_vectorValue, "vectorValue"), visitor(m_mapValue, "mapValue"), - visitor(m_unordered_setValue, "unordered_setValue")); + visitor(m_unorderedSetValue, "unorderedSetValue")); ArrayTypes() = default; ArrayTypes(uint32_t testCounter) @@ -171,21 +171,21 @@ struct ArrayTypes , m_dequeValue({testCounter + 2, testCounter + 1, testCounter}) , m_vectorValue({testCounter, testCounter + 2, testCounter + 1}) , m_mapValue({{testCounter, testCounter}, {testCounter + 1, testCounter + 1}}) - , m_unordered_setValue({testCounter + 2, testCounter, testCounter + 1}) + , m_unorderedSetValue({testCounter + 2, testCounter, testCounter + 1}) {} bool operator==(ArrayTypes const & rhs) const { return m_arrayValue == rhs.m_arrayValue && m_dequeValue == rhs.m_dequeValue && m_vectorValue == rhs.m_vectorValue && m_mapValue == rhs.m_mapValue && - m_unordered_setValue == rhs.m_unordered_setValue; + m_unorderedSetValue == rhs.m_unorderedSetValue; } array m_arrayValue; deque m_dequeValue; vector m_vectorValue; map m_mapValue; - unordered_set m_unordered_setValue; + unordered_set m_unorderedSetValue; }; } // namespace @@ -233,7 +233,7 @@ UNIT_TEST(SerdesJsonTest) { struct Hasher { - std::hash m_hasher; + hash m_hasher; size_t operator()(pair const & item) const { diff --git a/coding/serdes_json.hpp b/coding/serdes_json.hpp index c5a482d251..07494f60cd 100644 --- a/coding/serdes_json.hpp +++ b/coding/serdes_json.hpp @@ -308,8 +308,10 @@ public: json_t * outerContext = SaveContext(name); if (!json_is_array(m_json)) + { MYTHROW(base::Json::Exception, ("The field", name, "must contain a json array.", json_dumps(m_json, 0))); + } if (N != json_array_size(m_json)) { @@ -334,8 +336,10 @@ public: json_t * outerContext = SaveContext(name); if (!json_is_array(m_json)) + { MYTHROW(base::Json::Exception, ("The field", name, "must contain a json array.", json_dumps(m_json, 0))); + } size_t size = json_array_size(m_json); for (size_t index = 0; index < size; ++index) diff --git a/map/bookmark_helpers.cpp b/map/bookmark_helpers.cpp index 0e3ae4837a..ea16dfbd00 100644 --- a/map/bookmark_helpers.cpp +++ b/map/bookmark_helpers.cpp @@ -627,56 +627,45 @@ void ResetIds(kml::FileData & kmlData) trackData.m_id = kml::kInvalidTrackId; } +bool TruncType(std::string & type) +{ + static std::string const kDelim = "-"; + auto const pos = type.rfind(kDelim); + if (pos == std::string::npos) + return false; + type.resize(pos); + return true; +} + BookmarkBaseType GetBookmarkBaseType(std::vector const & featureTypes) { auto const & c = classif(); for (auto typeIndex : featureTypes) { auto const type = c.GetTypeForIndex(typeIndex); - auto const typeStr = c.GetReadableObjectName(type); + auto typeStr = c.GetReadableObjectName(type); - static std::string const kDelim = "-"; - - std::vector tokens; - strings::Tokenize(typeStr, kDelim.c_str(), [&tokens](std::string const & s) { tokens.push_back(s); }); - - for (size_t sz = tokens.size(); sz > 0; --sz) + do { - std::stringstream ss; - for (size_t i = 0; i < sz; ++i) - { - ss << tokens[i]; - if (i + 1 < sz) - ss << kDelim; - } - auto const itType = kFeatureTypeToBookmarkType.find(ss.str()); + auto const itType = kFeatureTypeToBookmarkType.find(typeStr); if (itType != kFeatureTypeToBookmarkType.cend()) return itType->second; - } + } while (TruncType(typeStr)); } return BookmarkBaseType::None; } kml::BookmarkIcon GetBookmarkIconByFeatureType(uint32_t type) { - auto const typeStr = classif().GetReadableObjectName(type); + auto typeStr = classif().GetReadableObjectName(type); - static std::string const kDelim = "-"; - std::vector v; - strings::Tokenize(typeStr, kDelim.c_str(), [&v] (std::string const & s) {v.push_back(s);}); - for (size_t sz = v.size(); sz > 0; sz--) + do { - std::stringstream ss; - for (size_t i = 0; i < sz; i++) - { - ss << v[i]; - if (i + 1 < sz) - ss << kDelim; - } - auto const itIcon = kFeatureTypeToBookmarkIcon.find(ss.str()); + auto const itIcon = kFeatureTypeToBookmarkIcon.find(typeStr); if (itIcon != kFeatureTypeToBookmarkIcon.cend()) return itIcon->second; - } + } while (TruncType(typeStr)); + return kml::BookmarkIcon::None; } @@ -713,7 +702,7 @@ std::string GetLocalizedBookmarkBaseType(BookmarkBaseType type) { switch (type) { - case BookmarkBaseType::None: return ""; + case BookmarkBaseType::None: return {}; case BookmarkBaseType::Hotel: return platform::GetLocalizedString("hotels"); case BookmarkBaseType::Animals: return platform::GetLocalizedString("animals"); case BookmarkBaseType::Building: return platform::GetLocalizedString("buildings"); @@ -731,7 +720,7 @@ std::string GetLocalizedBookmarkBaseType(BookmarkBaseType type) case BookmarkBaseType::Sights: return platform::GetLocalizedString("tourist_places"); case BookmarkBaseType::Swim: return platform::GetLocalizedString("swim_places"); case BookmarkBaseType::Water: return platform::GetLocalizedString("water"); - case BookmarkBaseType::Count: CHECK(false, ("Invalid bookmark base type")); return ""; + case BookmarkBaseType::Count: CHECK(false, ("Invalid bookmark base type")); return {}; } UNREACHABLE(); } diff --git a/map/bookmark_manager.cpp b/map/bookmark_manager.cpp index 7ae9180496..b3f7f52025 100644 --- a/map/bookmark_manager.cpp +++ b/map/bookmark_manager.cpp @@ -29,6 +29,7 @@ #include "base/file_name_utils.hpp" #include "base/macros.hpp" +#include "base/stl_helpers.hpp" #include "base/string_utils.hpp" #include "std/target_os.hpp" @@ -217,13 +218,24 @@ Cloud::ConvertionResult ConvertAfterDownloading(std::string const & filePath, return result; } +std::string ToString(BookmarkManager::SortingType type) +{ + switch (type) + { + case BookmarkManager::SortingType::ByTime: return "ByTime"; + case BookmarkManager::SortingType::ByType: return "ByType"; + case BookmarkManager::SortingType::ByDistance: return "ByDistance"; + } + UNREACHABLE(); +} + bool GetSortingType(std::string const & typeStr, BookmarkManager::SortingType & type) { - if (typeStr == DebugPrint(BookmarkManager::SortingType::ByTime)) + if (typeStr == ToString(BookmarkManager::SortingType::ByTime)) type = BookmarkManager::SortingType::ByTime; - else if (typeStr == DebugPrint(BookmarkManager::SortingType::ByType)) + else if (typeStr == ToString(BookmarkManager::SortingType::ByType)) type = BookmarkManager::SortingType::ByType; - else if (typeStr == DebugPrint(BookmarkManager::SortingType::ByDistance)) + else if (typeStr == ToString(BookmarkManager::SortingType::ByDistance)) type = BookmarkManager::SortingType::ByDistance; else return false; @@ -838,7 +850,7 @@ void BookmarkManager::SetLastSortingType(kml::MarkGroupId groupId, SortingType s if (entryName.empty()) return; - m_metadata.m_entriesProperties[entryName].m_values[kSortingTypeProperty] = DebugPrint(sortingType); + m_metadata.m_entriesProperties[entryName].m_values[kSortingTypeProperty] = ToString(sortingType); SaveMetadata(); } @@ -853,7 +865,8 @@ void BookmarkManager::ResetLastSortingType(kml::MarkGroupId groupId) SaveMetadata(); } -std::set BookmarkManager::GetAvailableSortingTypes(kml::MarkGroupId groupId, bool hasMyPosition) const +std::set BookmarkManager::GetAvailableSortingTypes( + kml::MarkGroupId groupId, bool hasMyPosition) const { CHECK_THREAD_CHECKER(m_threadChecker, ()); ASSERT(IsBookmarkCategory(groupId), ()); @@ -922,7 +935,8 @@ std::set BookmarkManager::GetAvailableSortingTypes } template -BookmarkManager::SortedByTimeBlockType GetSortedByTimeBlockType(std::chrono::duration const & timePeriod) +BookmarkManager::SortedByTimeBlockType GetSortedByTimeBlockType( + std::chrono::duration const & timePeriod) { static auto const kDay = std::chrono::hours(24); static auto const kWeek = 7 * kDay; @@ -943,11 +957,16 @@ std::string BookmarkManager::GetSortedByTimeBlockName(SortedByTimeBlockType bloc { switch (blockType) { - case SortedByTimeBlockType::WeekAgo: return platform::GetLocalizedString("week_ago_sorttype"); - case SortedByTimeBlockType::MonthAgo: return platform::GetLocalizedString("month_ago_sorttype"); - case SortedByTimeBlockType::MoreThanMonthAgo: return platform::GetLocalizedString("moremonth_ago_sorttype"); - case SortedByTimeBlockType::MoreThanYearAgo: return platform::GetLocalizedString("moreyear_ago_sorttype"); - case SortedByTimeBlockType::Others: return GetOthersSortedBlockName(); + case SortedByTimeBlockType::WeekAgo: + return platform::GetLocalizedString("week_ago_sorttype"); + case SortedByTimeBlockType::MonthAgo: + return platform::GetLocalizedString("month_ago_sorttype"); + case SortedByTimeBlockType::MoreThanMonthAgo: + return platform::GetLocalizedString("moremonth_ago_sorttype"); + case SortedByTimeBlockType::MoreThanYearAgo: + return platform::GetLocalizedString("moreyear_ago_sorttype"); + case SortedByTimeBlockType::Others: + return GetOthersSortedBlockName(); } UNREACHABLE(); } @@ -1004,19 +1023,16 @@ void BookmarkManager::FilterInvalidData(SortedBlocksCollection & sortedBlocks, FilterInvalidTracks(block.m_trackIds); } - sortedBlocks.erase(std::remove_if(sortedBlocks.begin(), sortedBlocks.end(), - [](SortedBlock const & block) - { - return block.m_trackIds.empty() && block.m_markIds.empty(); - }), - sortedBlocks.end()); + base::EraseIf(sortedBlocks, [](SortedBlock const & block) + { + return block.m_trackIds.empty() && block.m_markIds.empty(); + }); - newAddresses.erase(std::remove_if(newAddresses.begin(), newAddresses.end(), - [this](std::pair const & item) - { - return GetBookmark(item.first) == nullptr; - }), - newAddresses.end()); + base::EraseIf(newAddresses, [this](std::pair const & item) + { + return GetBookmark(item.first) == nullptr; + }); } void BookmarkManager::SetBookmarksAddresses(AddressesCollection const & addresses) @@ -1030,7 +1046,8 @@ void BookmarkManager::SetBookmarksAddresses(AddressesCollection const & addresse } } -void BookmarkManager::SortByDistance(std::vector const & bookmarksForSort, m2::PointD const & myPosition, +void BookmarkManager::SortByDistance(std::vector const & bookmarksForSort, + m2::PointD const & myPosition, SortedBlocksCollection & sortedBlocks) { CHECK(m_regionAddressGetter != nullptr, ()); @@ -1043,11 +1060,12 @@ void BookmarkManager::SortByDistance(std::vector const & bookm sortedMarks.push_back(std::make_pair(&mark, distance)); } - std::sort(sortedMarks.begin(), sortedMarks.end(), [](std::pair const & lbm, - std::pair const & rbm) - { - return lbm.second < rbm.second; - }); + std::sort(sortedMarks.begin(), sortedMarks.end(), + [](std::pair const & lbm, + std::pair const & rbm) + { + return lbm.second < rbm.second; + }); std::map regionBlockIndices; SortedBlock othersBlock; @@ -1062,8 +1080,8 @@ void BookmarkManager::SortByDistance(std::vector const & bookm continue; } - auto const currentRegion = distance < kNearDistanceInMeters ? search::ReverseGeocoder::RegionAddress() - : mark.m_address; + auto const currentRegion = + distance < kNearDistanceInMeters ? search::ReverseGeocoder::RegionAddress() : mark.m_address; size_t blockIndex; auto const it = regionBlockIndices.find(currentRegion); @@ -1102,10 +1120,11 @@ void BookmarkManager::SortByTime(std::vector const & bookmarks for (auto const & mark : bookmarksForSort) sortedMarks.push_back(&mark); - std::sort(sortedMarks.begin(), sortedMarks.end(), [](SortBookmarkData const * lbm, SortBookmarkData const * rbm) - { - return lbm->m_timestamp > rbm->m_timestamp; - }); + std::sort(sortedMarks.begin(), sortedMarks.end(), + [](SortBookmarkData const * lbm, SortBookmarkData const * rbm) + { + return lbm->m_timestamp > rbm->m_timestamp; + }); auto const currentTime = std::chrono::system_clock::now(); @@ -1143,10 +1162,11 @@ void BookmarkManager::SortByType(std::vector const & bookmarks for (auto const & mark : bookmarksForSort) sortedMarks.push_back(&mark); - std::sort(sortedMarks.begin(), sortedMarks.end(), [](SortBookmarkData const * lbm, SortBookmarkData const * rbm) - { - return lbm->m_timestamp > rbm->m_timestamp; - }); + std::sort(sortedMarks.begin(), sortedMarks.end(), + [](SortBookmarkData const * lbm, SortBookmarkData const * rbm) + { + return lbm->m_timestamp > rbm->m_timestamp; + }); std::map typesCount; size_t othersTypeMarksCount = 0; @@ -1172,13 +1192,12 @@ void BookmarkManager::SortByType(std::vector const & bookmarks if (typeCount.second < kMinCommonTypesCount && typeCount.first != BookmarkBaseType::Hotel) othersTypeMarksCount += typeCount.second; else - sortedTypes.push_back(std::make_pair(typeCount.first, typeCount.second)); + sortedTypes.push_back(typeCount); } - std::sort(sortedTypes.begin(), sortedTypes.end(), [](std::pair const & l, - std::pair const & r) - { - return l.second > r.second; - }); + + std::sort(sortedTypes.begin(), sortedTypes.end(), + [](std::pair const & l, + std::pair const & r){ return l.second > r.second; }); std::map blockIndices; sortedBlocks.resize(sortedTypes.size() + (othersTypeMarksCount > 0 ? 1 : 0)); @@ -1198,10 +1217,15 @@ void BookmarkManager::SortByType(std::vector const & bookmarks for (auto mark : sortedMarks) { auto const type = mark->m_type; - if (type == BookmarkBaseType::None || (type != BookmarkBaseType::Hotel && typesCount[type] < kMinCommonTypesCount)) + if (type == BookmarkBaseType::None || + (type != BookmarkBaseType::Hotel && typesCount[type] < kMinCommonTypesCount)) + { sortedBlocks.back().m_markIds.push_back(mark->m_id); + } else + { sortedBlocks[blockIndices[type]].m_markIds.push_back(mark->m_id); + } } } @@ -1247,7 +1271,7 @@ void BookmarkManager::GetSortedBookmarks(SortParams const & params) std::unique_lock lock(m_regionAddressMutex); if (m_regionAddressGetter == nullptr) { - LOG(LWARNING, ("Region address getter in no set, bookmarks sorting failed.")); + LOG(LWARNING, ("Region address getter is not set, bookmarks sorting failed.")); params.m_onResults({} /* sortedBlocks */, SortParams::Status::Cancelled); return; } @@ -1260,14 +1284,15 @@ void BookmarkManager::GetSortedBookmarks(SortParams const & params) return; } - GetPlatform().RunTask(Platform::Thread::File, [this, params, bookmarksForSort = std::move(bookmarksForSort)]() mutable + GetPlatform().RunTask(Platform::Thread::File, + [this, params, bookmarksForSort = std::move(bookmarksForSort)]() mutable { std::unique_lock lock(m_regionAddressMutex); if (m_regionAddressGetter == nullptr) { GetPlatform().RunTask(Platform::Thread::Gui, [params] { - LOG(LWARNING, ("Region address getter in no set, bookmarks sorting failed.")); + LOG(LWARNING, ("Region address getter is not set, bookmarks sorting failed.")); params.m_onResults({} /* sortedBlocks */, SortParams::Status::Cancelled); }); return; @@ -1279,7 +1304,8 @@ void BookmarkManager::GetSortedBookmarks(SortParams const & params) SortedBlocksCollection sortedBlocks; GetSortedBookmarksImpl(params, bookmarksForSort, sortedBlocks); - GetPlatform().RunTask(Platform::Thread::Gui, [this, params, newAddresses = std::move(newAddresses), + GetPlatform().RunTask(Platform::Thread::Gui, [this, params, + newAddresses = std::move(newAddresses), sortedBlocks = std::move(sortedBlocks)]() mutable { FilterInvalidData(sortedBlocks, newAddresses); @@ -1616,7 +1642,8 @@ void BookmarkManager::LoadMetadata() } catch (base::Json::Exception const & exception) { - LOG(LWARNING, ("Exception while parsing file:", metadataFilePath, "reason:", exception.what(), "json:", jsonStr)); + LOG(LWARNING, ("Exception while parsing file:", metadataFilePath, "reason:", exception.what(), + "json:", jsonStr)); return; } @@ -3167,20 +3194,13 @@ void BookmarkManager::ResetInvalidCategories() void BookmarkManager::FilterInvalidBookmarks(kml::MarkIdCollection & bookmarks) const { CHECK_THREAD_CHECKER(m_threadChecker, ()); - bookmarks.erase(std::remove_if(bookmarks.begin(), bookmarks.end(), - [this](kml::MarkId const & id) - { - return GetBookmark(id) == nullptr; - }), - bookmarks.end()); + base::EraseIf(bookmarks, [this](kml::MarkId const & id){ return GetBookmark(id) == nullptr; }); } void BookmarkManager::FilterInvalidTracks(kml::TrackIdCollection & tracks) const { CHECK_THREAD_CHECKER(m_threadChecker, ()); - tracks.erase(std::remove_if(tracks.begin(), tracks.end(), - [this](kml::TrackId const & id) { return GetTrack(id) == nullptr; }), - tracks.end()); + base::EraseIf(tracks, [this](kml::TrackId const & id){ return GetTrack(id) == nullptr; }); } kml::GroupIdSet BookmarkManager::MarksChangesTracker::GetAllGroupIds() const @@ -3332,6 +3352,33 @@ void BookmarkManager::MarksChangesTracker::ResetChanges() m_detachedBookmarks.clear(); } +bool BookmarkManager::SortedBlock::operator==(SortedBlock const & other) const +{ + return m_blockName == other.m_blockName && m_markIds == other.m_markIds && + m_trackIds == other.m_trackIds; +} + +bool BookmarkManager::Properties::GetProperty(std::string const & propertyName, + std::string & value) const +{ + auto const it = m_values.find(propertyName); + if (it == m_values.end()) + return false; + value = it->second; + return true; +} + +bool BookmarkManager::Metadata::GetEntryProperty(std::string const & entryName, + std::string const & propertyName, + std::string & value) const +{ + auto const it = m_entriesProperties.find(entryName); + if (it == m_entriesProperties.end()) + return false; + + return it->second.GetProperty(propertyName, value); +} + // static std::string BookmarkManager::RemoveInvalidSymbols(std::string const & name, std::string const & defaultName) { @@ -3531,17 +3578,6 @@ void BookmarkManager::EditSession::NotifyChanges() m_bmManager.NotifyChanges(); } -std::string DebugPrint(BookmarkManager::SortingType type) -{ - switch (type) - { - case BookmarkManager::SortingType::ByTime: return "ByTime"; - case BookmarkManager::SortingType::ByType: return "ByType"; - case BookmarkManager::SortingType::ByDistance: return "ByDistance"; - } - UNREACHABLE(); -} - namespace lightweight { namespace impl diff --git a/map/bookmark_manager.hpp b/map/bookmark_manager.hpp index 9b22ee0a35..8605e0f6a7 100644 --- a/map/bookmark_manager.hpp +++ b/map/bookmark_manager.hpp @@ -206,14 +206,11 @@ public: struct SortedBlock { + bool operator==(SortedBlock const & other) const; + std::string m_blockName; kml::MarkIdCollection m_markIds; kml::MarkIdCollection m_trackIds; - - bool operator==(SortedBlock const & other) const - { - return m_blockName == other.m_blockName && m_markIds == other.m_markIds && m_trackIds == other.m_trackIds; - } }; using SortedBlocksCollection = std::vector; @@ -304,10 +301,6 @@ public: ArchiveError, FileError }; - kml::MarkGroupId m_categoryId; - Code m_code; - std::string m_sharingPath; - std::string m_errorString; SharingResult(kml::MarkGroupId categoryId, std::string const & sharingPath) : m_categoryId(categoryId) @@ -325,6 +318,11 @@ public: , m_code(code) , m_errorString(errorString) {} + + kml::MarkGroupId m_categoryId; + Code m_code; + std::string m_sharingPath; + std::string m_errorString; }; using SharingHandler = platform::SafeCallback; @@ -629,7 +627,8 @@ private: struct SortBookmarkData { SortBookmarkData() = default; - SortBookmarkData(kml::BookmarkData const & bmData, search::ReverseGeocoder::RegionAddress const & address) + SortBookmarkData(kml::BookmarkData const & bmData, + search::ReverseGeocoder::RegionAddress const & address) : m_id(bmData.m_id) , m_point(bmData.m_point) , m_type(GetBookmarkBaseType(bmData.m_featureTypes)) @@ -699,12 +698,13 @@ private: bool m_asyncLoadingInProgress = false; struct BookmarkLoaderInfo { - std::string m_filename; - bool m_isTemporaryFile = false; BookmarkLoaderInfo() = default; BookmarkLoaderInfo(std::string const & filename, bool isTemporaryFile) : m_filename(filename), m_isTemporaryFile(isTemporaryFile) {} + + std::string m_filename; + bool m_isTemporaryFile = false; }; std::list m_bookmarkLoadingQueue; @@ -734,36 +734,23 @@ private: struct Properties { - std::map m_values; - - bool GetProperty(std::string const & propertyName, std::string & value) const - { - auto const it = m_values.find(propertyName); - if (it == m_values.end()) - return false; - value = it->second; - return true; - } - DECLARE_VISITOR_AND_DEBUG_PRINT(Properties, visitor(m_values, "values")) + + bool GetProperty(std::string const & propertyName, std::string & value) const; + + std::map m_values; }; struct Metadata { - std::map m_entriesProperties; - Properties m_commonProperties; - - bool GetEntryProperty(std::string const & entryName, std::string const & propertyName, std::string & value) const - { - auto const it = m_entriesProperties.find(entryName); - if (it == m_entriesProperties.end()) - return false; - - return it->second.GetProperty(propertyName, value); - } - DECLARE_VISITOR_AND_DEBUG_PRINT(Metadata, visitor(m_entriesProperties, "entriesProperties"), visitor(m_commonProperties, "commonProperties")) + + bool GetEntryProperty(std::string const & entryName, std::string const & propertyName, + std::string & value) const; + + std::map m_entriesProperties; + Properties m_commonProperties; }; Metadata m_metadata; @@ -773,8 +760,6 @@ private: DISALLOW_COPY_AND_MOVE(BookmarkManager); }; -std::string DebugPrint(BookmarkManager::SortingType type); - namespace lightweight { namespace impl