[bookmarks] Review fixes.

This commit is contained in:
Daria Volvenkova 2019-08-06 19:41:55 +03:00 committed by mpimenov
parent 8f111ebda4
commit 60322166a5
6 changed files with 38 additions and 43 deletions

View file

@ -19,8 +19,8 @@ using namespace std;
namespace
{
template <typename PtrT>
bool SamePtrValue(PtrT const & lhs, PtrT const & rhs)
template <typename Ptr>
bool SamePtrValue(Ptr const & lhs, Ptr const & rhs)
{
return (!lhs && !rhs) || (lhs && rhs && *lhs == *rhs);
}
@ -233,12 +233,12 @@ UNIT_TEST(SerdesJsonTest)
{
struct Hasher
{
hash<string> m_hasher;
size_t operator()(pair<string, string> const & item) const
{
return m_hasher(item.first + item.second);
}
hash<string> m_hasher;
};
unordered_set<pair<string, string>, Hasher> testValue = {{"ab", "ab"}, {"ef", "ef"},

View file

@ -173,8 +173,8 @@ public:
});
}
template <typename Key, typename T>
void operator()(std::pair<Key, T> const & p, char const * name = nullptr)
template <typename Key, typename Value>
void operator()(std::pair<Key, Value> const & p, char const * name = nullptr)
{
NewScopeWith(base::NewJSONObject(), name, [this, &p] {
(*this)(p.first, "key");
@ -288,7 +288,7 @@ public:
MYTHROW(base::Json::Exception, ("The field", name, "must contain a json array."));
T tmp;
size_t size = json_array_size(m_json);
size_t const size = json_array_size(m_json);
dest.reserve(size);
for (size_t index = 0; index < size; ++index)
{
@ -316,7 +316,7 @@ public:
if (N != json_array_size(m_json))
{
MYTHROW(base::Json::Exception, ("The field", name, "must contain a json array of size", N,
"but size is", json_array_size(m_json)));
"but size is", json_array_size(m_json)));
}
for (size_t index = 0; index < N; ++index)
@ -341,7 +341,7 @@ public:
("The field", name, "must contain a json array.", json_dumps(m_json, 0)));
}
size_t size = json_array_size(m_json);
size_t const size = json_array_size(m_json);
for (size_t index = 0; index < size; ++index)
{
json_t * context = SaveContext();
@ -355,8 +355,8 @@ public:
RestoreContext(outerContext);
}
template <typename Key, typename T>
void operator()(std::pair<Key, T> & dst, char const * name = nullptr)
template <typename Key, typename Value>
void operator()(std::pair<Key, Value> & dst, char const * name = nullptr)
{
json_t * outerContext = SaveContext(name);
(*this)(dst.first, "key");

View file

@ -865,7 +865,7 @@ void BookmarkManager::ResetLastSortingType(kml::MarkGroupId groupId)
SaveMetadata();
}
std::set<BookmarkManager::SortingType> BookmarkManager::GetAvailableSortingTypes(
std::vector<BookmarkManager::SortingType> BookmarkManager::GetAvailableSortingTypes(
kml::MarkGroupId groupId, bool hasMyPosition) const
{
CHECK_THREAD_CHECKER(m_threadChecker, ());
@ -891,16 +891,8 @@ std::set<BookmarkManager::SortingType> BookmarkManager::GetAvailableSortingTypes
}
else
{
auto it = typesCount.find(type);
if (it == typesCount.end())
{
typesCount.insert(std::make_pair(type, 1));
}
else
{
++it->second;
byTypeChecked = it->second == kMinCommonTypesCount;
}
auto const count = ++typesCount[type];
byTypeChecked = (count == kMinCommonTypesCount);
}
}
@ -923,13 +915,13 @@ std::set<BookmarkManager::SortingType> BookmarkManager::GetAvailableSortingTypes
}
}
std::set<SortingType> sortingTypes;
if (hasMyPosition)
sortingTypes.insert(SortingType::ByDistance);
std::vector<SortingType> sortingTypes;
if (byTypeChecked)
sortingTypes.insert(SortingType::ByType);
sortingTypes.push_back(SortingType::ByType);
if (hasMyPosition)
sortingTypes.push_back(SortingType::ByDistance);
if (byTimeChecked)
sortingTypes.insert(SortingType::ByTime);
sortingTypes.push_back(SortingType::ByTime);
return sortingTypes;
}
@ -990,7 +982,7 @@ std::string BookmarkManager::GetLocalizedRegionAddress(m2::PointD const & pt)
std::unique_lock<std::mutex> lock(m_regionAddressMutex);
if (m_regionAddressGetter == nullptr)
{
LOG(LWARNING, ("Region address getter in no set. Address getting failed."));
LOG(LWARNING, ("Region address getter is not set. Address getting failed."));
return {};
}
return m_regionAddressGetter->GetLocalizedRegionAddress(pt);
@ -1179,11 +1171,7 @@ void BookmarkManager::SortByType(std::vector<SortBookmarkData> const & bookmarks
continue;
}
auto it = typesCount.find(type);
if (it != typesCount.end())
++it->second;
else
typesCount.insert(std::make_pair(type, 1));
++typesCount[type];
}
std::vector<std::pair<BookmarkBaseType, size_t>> sortedTypes;

View file

@ -231,7 +231,8 @@ public:
OnResults m_onResults;
};
std::set<SortingType> GetAvailableSortingTypes(kml::MarkGroupId groupId, bool hasMyPosition) const;
std::vector<SortingType> GetAvailableSortingTypes(kml::MarkGroupId groupId,
bool hasMyPosition) const;
void GetSortedBookmarks(SortParams const & params);
bool GetLastSortingType(kml::MarkGroupId groupId, SortingType & sortingType) const;

View file

@ -799,10 +799,10 @@ UNIT_TEST(Bookmarks_Sorting)
kml::MarkGroupId catId = bmManager.CreateBookmarkCategory("test", false);
fillCategory(catId, testData);
std::set<BookmarkManager::SortingType> expectedSortingTypes = {
BookmarkManager::SortingType::ByTime,
std::vector<BookmarkManager::SortingType> expectedSortingTypes = {
BookmarkManager::SortingType::ByType,
BookmarkManager::SortingType::ByDistance,
BookmarkManager::SortingType::ByType};
BookmarkManager::SortingType::ByTime};
auto const sortingTypes = bmManager.GetAvailableSortingTypes(catId, true);
TEST(sortingTypes == expectedSortingTypes, ());
@ -825,14 +825,15 @@ UNIT_TEST(Bookmarks_Sorting)
kml::MarkGroupId catId2 = bmManager.CreateBookmarkCategory("test2", false);
fillCategory(catId2, testData2);
std::set<BookmarkManager::SortingType> expectedSortingTypes2 = {
BookmarkManager::SortingType::ByDistance,
BookmarkManager::SortingType::ByType};
std::vector<BookmarkManager::SortingType> expectedSortingTypes2 = {
BookmarkManager::SortingType::ByType,
BookmarkManager::SortingType::ByDistance};
auto const sortingTypes2 = bmManager.GetAvailableSortingTypes(catId2, true);
TEST(sortingTypes2 == expectedSortingTypes2, ());
std::set<BookmarkManager::SortingType> expectedSortingTypes2_2 = {BookmarkManager::SortingType::ByType};
std::vector<BookmarkManager::SortingType> expectedSortingTypes2_2 = {
BookmarkManager::SortingType::ByType};
auto const sortingTypes2_2 = bmManager.GetAvailableSortingTypes(catId2, false);
TEST(sortingTypes2_2 == expectedSortingTypes2_2, ());
@ -851,7 +852,7 @@ UNIT_TEST(Bookmarks_Sorting)
kml::MarkGroupId catId3 = bmManager.CreateBookmarkCategory("test3", false);
fillCategory(catId3, testData3);
std::set<BookmarkManager::SortingType> expectedSortingTypes3 = {};
std::vector<BookmarkManager::SortingType> expectedSortingTypes3 = {};
auto const sortingTypes3 = bmManager.GetAvailableSortingTypes(catId3, false);
TEST(sortingTypes3 == expectedSortingTypes3, ());
}
@ -860,7 +861,7 @@ UNIT_TEST(Bookmarks_Sorting)
kml::MarkGroupId catId4 = bmManager.CreateBookmarkCategory("test4", false);
fillCategory(catId4, testData4);
std::set<BookmarkManager::SortingType> expectedSortingTypes4 = { BookmarkManager::SortingType::ByType };
std::vector<BookmarkManager::SortingType> expectedSortingTypes4 = { BookmarkManager::SortingType::ByType };
auto const sortingTypes4 = bmManager.GetAvailableSortingTypes(catId4, false);
TEST(sortingTypes4 == expectedSortingTypes4, ());

View file

@ -137,6 +137,7 @@
67E8DB771BBC17490053C5BA /* zip_reader_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 67E8DB2D1BBC16C70053C5BA /* zip_reader_test.cpp */; };
BB537C5F1E8490120074D9D3 /* transliteration.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BB537C5D1E8490120074D9D3 /* transliteration.cpp */; };
BB537C601E8490120074D9D3 /* transliteration.hpp in Headers */ = {isa = PBXBuildFile; fileRef = BB537C5E1E8490120074D9D3 /* transliteration.hpp */; };
BB87BF8422F9E2D1008A8A72 /* serdes_json_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BB87BF8322F9E2D1008A8A72 /* serdes_json_test.cpp */; };
F65AFA361F18B8AB00979A50 /* libplatform_tests_support.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F65AFA351F18B8AB00979A50 /* libplatform_tests_support.a */; };
F65AFA381F18C7A500979A50 /* libplatform.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F65AFA371F18C7A500979A50 /* libplatform.a */; };
F6C269FE1F176FFE00EB6519 /* csv_reader_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6C269FD1F176FFE00EB6519 /* csv_reader_test.cpp */; };
@ -291,6 +292,7 @@
67E8DB2D1BBC16C70053C5BA /* zip_reader_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = zip_reader_test.cpp; sourceTree = "<group>"; };
BB537C5D1E8490120074D9D3 /* transliteration.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = transliteration.cpp; sourceTree = "<group>"; };
BB537C5E1E8490120074D9D3 /* transliteration.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = transliteration.hpp; sourceTree = "<group>"; };
BB87BF8322F9E2D1008A8A72 /* serdes_json_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = serdes_json_test.cpp; sourceTree = "<group>"; };
F65AFA351F18B8AB00979A50 /* libplatform_tests_support.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libplatform_tests_support.a; path = ../platform/build/Debug/libplatform_tests_support.a; sourceTree = "<group>"; };
F65AFA371F18C7A500979A50 /* libplatform.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libplatform.a; path = "../../../../Library/Developer/Xcode/DerivedData/omim-fbvotunmmtqmjnezabjibwxwryev/Build/Products/Debug/libplatform.a"; sourceTree = "<group>"; };
F6C269FD1F176FFE00EB6519 /* csv_reader_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = csv_reader_test.cpp; sourceTree = "<group>"; };
@ -337,6 +339,7 @@
394916901BAC3A5F002A8C4F /* coding_tests */ = {
isa = PBXGroup;
children = (
BB87BF8322F9E2D1008A8A72 /* serdes_json_test.cpp */,
4098EA6221D12088005612FF /* map_uint32_to_val_tests.cpp */,
3973743321C17F160003807A /* string_utf8_multilang_tests.cpp */,
39C3C0BE21A431BF003B4712 /* point_coding_tests.cpp */,
@ -645,6 +648,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
);
mainGroup = 675342121A3F586300A0A8C3;
@ -724,6 +728,7 @@
676818201DC3ABD80094C0AC /* traffic_test.cpp in Sources */,
BB537C5F1E8490120074D9D3 /* transliteration.cpp in Sources */,
675342C51A3F588C00A0A8C3 /* uri.cpp in Sources */,
BB87BF8422F9E2D1008A8A72 /* serdes_json_test.cpp in Sources */,
675342BB1A3F588C00A0A8C3 /* reader.cpp in Sources */,
670BAACB1D0B0C1E000302DA /* huffman.cpp in Sources */,
675342A71A3F588C00A0A8C3 /* hex.cpp in Sources */,