diff --git a/base/base_tests/range_iterator_test.cpp b/base/base_tests/range_iterator_test.cpp index f99301af8b..bca5d09096 100644 --- a/base/base_tests/range_iterator_test.cpp +++ b/base/base_tests/range_iterator_test.cpp @@ -10,28 +10,28 @@ UNIT_TEST(RangeIterator) { vector result; - for (auto const i : Range(5)) + for (auto const i : UpTo(5)) result.push_back(i); TEST_EQUAL(result, (vector{0, 1, 2, 3, 4}), ()); } { vector result; - for (auto const i : Range(2, 5)) + for (auto const i : UpTo(2, 5)) result.push_back(i); TEST_EQUAL(result, (vector{2, 3, 4}), ()); } { vector result; - for (auto const i : ReverseRange(5)) + for (auto const i : DownTo(5)) result.push_back(i); TEST_EQUAL(result, (vector{4, 3, 2, 1, 0}), ()); } { vector result; - for (auto const i : ReverseRange(2, 5)) + for (auto const i : DownTo(2, 5)) result.push_back(i); TEST_EQUAL(result, (vector{4, 3, 2}), ()); } diff --git a/base/collection_cast.hpp b/base/collection_cast.hpp index a05780a2eb..8ba6844bbb 100644 --- a/base/collection_cast.hpp +++ b/base/collection_cast.hpp @@ -9,11 +9,11 @@ namespace details template struct ValueType { - using type = typename std::remove_reference::type::value_type; + using TType = typename std::remove_reference::type::value_type; }; template -using ValueTypeT = typename ValueType::type; +using TValueType = typename ValueType::TType; } // namespace details // Use this function to cast one collection to annother. @@ -21,9 +21,9 @@ using ValueTypeT = typename ValueType::type; // More examples: // auto const mySet = collection_cast("aaabcccd"); // auto const myMap = collection_cast(vector>{{1, 2}, {3, 4}}); -template class To, typename From> -auto collection_cast(From && from) -> To> +template class TTo, typename TFrom> +auto collection_cast(TFrom && from) -> TTo> { - return To>(begin(from), end(from)); + return TTo>(begin(from), end(from)); } } // namespace my diff --git a/base/range_iterator.hpp b/base/range_iterator.hpp index cfc7ff11be..7f2ee7ca3a 100644 --- a/base/range_iterator.hpp +++ b/base/range_iterator.hpp @@ -67,28 +67,28 @@ struct RangeWrapper // Use this helper to iterate through 0 to `to'. template -RangeWrapper Range(TCounter const to) +RangeWrapper UpTo(TCounter const to) { return {{}, to}; } // Use this helper to iterate through `from' to `to'. template -RangeWrapper Range(TCounter const from, TCounter const to) +RangeWrapper UpTo(TCounter const from, TCounter const to) { return {from, to}; } // Use this helper to iterate through `from' to 0. template -RangeWrapper ReverseRange(TCounter const from) +RangeWrapper DownTo(TCounter const from) { return {from, {}}; } // Use this helper to iterate through `from' to `to'. template -RangeWrapper ReverseRange(TCounter const from, TCounter const to) +RangeWrapper DownTo(TCounter const from, TCounter const to) { return {to, from}; } diff --git a/editor/osm_auth.cpp b/editor/osm_auth.cpp index 4e95ff2688..3cbc33b42c 100644 --- a/editor/osm_auth.cpp +++ b/editor/osm_auth.cpp @@ -30,7 +30,7 @@ inline bool IsKeySecretValid(TKeySecret const & t) return !(t.first.empty() || t.second.empty()); } -string findAuthenticityToken(string const & body) +string FindAuthenticityToken(string const & body) { auto pos = body.find("name=\"authenticity_token\""); if (pos == string::npos) @@ -44,7 +44,7 @@ string findAuthenticityToken(string const & body) return end == string::npos ? string() : body.substr(start, end - start); } -string buildPostRequest(map const & params) +string BuildPostRequest(map const & params) { string result; for (auto it = params.begin(); it != params.end(); ++it) @@ -57,7 +57,7 @@ string buildPostRequest(map const & params) } // Trying to determine whether it's a login page. -bool isLoggedIn(string const & contents) +bool IsLoggedIn(string const & contents) { return contents.find("
\n" "\n"; - OsmOAuth::Response const response = m_auth.Request("/changeset/create", "PUT", move(stream.str())); + OsmOAuth::Response const response = m_auth.Request("/changeset/create", "PUT", stream.str()); if (response.first == OsmOAuth::ResponseCode::OK) { if (strings::to_uint64(response.second, outChangeSetId)) @@ -48,7 +48,7 @@ bool ServerApi06::CreateChangeSet(TKeyValueTags const & kvTags, uint64_t & outCh bool ServerApi06::CreateNode(string const & nodeXml, uint64_t & outCreatedNodeId) const { - OsmOAuth::Response const response = m_auth.Request("/node/create", "PUT", move(nodeXml)); + OsmOAuth::Response const response = m_auth.Request("/node/create", "PUT", nodeXml); if (response.first == OsmOAuth::ResponseCode::OK) { if (strings::to_uint64(response.second, outCreatedNodeId)) @@ -63,7 +63,7 @@ bool ServerApi06::CreateNode(string const & nodeXml, uint64_t & outCreatedNodeId bool ServerApi06::ModifyNode(string const & nodeXml, uint64_t nodeId) const { - OsmOAuth::Response const response = m_auth.Request("/node/" + strings::to_string(nodeId), "PUT", move(nodeXml)); + OsmOAuth::Response const response = m_auth.Request("/node/" + strings::to_string(nodeId), "PUT", nodeXml); if (response.first == OsmOAuth::ResponseCode::OK) return true; @@ -73,7 +73,7 @@ bool ServerApi06::ModifyNode(string const & nodeXml, uint64_t nodeId) const ServerApi06::DeleteResult ServerApi06::DeleteNode(string const & nodeXml, uint64_t nodeId) const { - OsmOAuth::Response const response = m_auth.Request("/node/" + strings::to_string(nodeId), "DELETE", move(nodeXml)); + OsmOAuth::Response const response = m_auth.Request("/node/" + strings::to_string(nodeId), "DELETE", nodeXml); if (response.first == OsmOAuth::ResponseCode::OK) return DeleteResult::ESuccessfullyDeleted; else if (static_cast(response.first) >= 400) @@ -105,7 +105,7 @@ OsmOAuth::Response ServerApi06::GetXmlFeaturesInRect(m2::RectD const & latLonRec using strings::to_string_dac; // Digits After Comma. - static constexpr double const kDAC = 7; + static constexpr double kDAC = 7; m2::PointD const lb = latLonRect.LeftBottom(); m2::PointD const rt = latLonRect.RightTop(); string const url = "/map?bbox=" + to_string_dac(lb.x, kDAC) + ',' + to_string_dac(lb.y, kDAC) + ',' + diff --git a/editor/ui2oh.cpp b/editor/ui2oh.cpp index 10c0781804..e2338332b8 100644 --- a/editor/ui2oh.cpp +++ b/editor/ui2oh.cpp @@ -1,5 +1,7 @@ #include "editor/ui2oh.hpp" +#include "base/assert.hpp" + #include "std/algorithm.hpp" #include "std/array.hpp" #include "std/string.hpp" @@ -97,8 +99,10 @@ using TWeekdays = vector; vector SplitIntoIntervals(editor::ui::TOpeningDays const & days) { + ASSERT_GREATER(days.size(), 0, ("At least one day must present.")); vector result; auto const & noInversionDays = RemoveInversion(days); + ASSERT(!noInversionDays.empty(), ()); auto previous = *begin(noInversionDays); result.push_back({previous}); @@ -156,6 +160,7 @@ namespace editor { osmoh::OpeningHours MakeOpeningHours(ui::TimeTableSet const & tts) { + ASSERT_GREATER(tts.Size(), 0, ("At least one time table must present.")); osmoh::TRuleSequences rule; for (auto const & tt : tts) { diff --git a/indexer/feature.cpp b/indexer/feature.cpp index f712d1215b..e49dd875a3 100644 --- a/indexer/feature.cpp +++ b/indexer/feature.cpp @@ -77,7 +77,7 @@ void FeatureType::ApplyPatch(editor::XMLFeature const & xml) // m_params.rank = m_bCommonParsed = true; - for (auto const i : my::Range(1u, static_cast(feature::Metadata::FMD_COUNT))) + for (auto const i : my::UpTo(1u, static_cast(feature::Metadata::FMD_COUNT))) { auto const type = static_cast(i); auto const attributeName = DebugPrint(type); diff --git a/indexer/feature_algo.cpp b/indexer/feature_algo.cpp index ac53a029b7..2c64a7ba81 100644 --- a/indexer/feature_algo.cpp +++ b/indexer/feature_algo.cpp @@ -198,4 +198,4 @@ double GetMinDistanceMeters(FeatureType const & ft, m2::PointD const & pt) return GetMinDistanceMeters(ft, pt, FeatureType::BEST_GEOMETRY); } -} // namespace feature +} // namespace feature diff --git a/indexer/feature_algo.hpp b/indexer/feature_algo.hpp index 489201e4c3..f30cd010d1 100644 --- a/indexer/feature_algo.hpp +++ b/indexer/feature_algo.hpp @@ -13,4 +13,4 @@ m2::PointD GetCenter(FeatureType const & f); double GetMinDistanceMeters(FeatureType const & ft, m2::PointD const & pt, int scale); double GetMinDistanceMeters(FeatureType const & ft, m2::PointD const & pt); -} // namespace feature +} // namespace feature diff --git a/indexer/osm_editor.cpp b/indexer/osm_editor.cpp index b24ceb0e28..c5b07677c7 100644 --- a/indexer/osm_editor.cpp +++ b/indexer/osm_editor.cpp @@ -31,6 +31,8 @@ using feature::EGeomType; using feature::Metadata; using editor::XMLFeature; +namespace +{ constexpr char const * kEditorXMLFileName = "edits.xml"; constexpr char const * kXmlRootNode = "mapsme"; constexpr char const * kXmlMwmNode = "mwm"; @@ -44,13 +46,6 @@ constexpr char const * kUploaded = "Uploaded"; constexpr char const * kDeletedFromOSMServer = "Deleted from OSM by someone"; constexpr char const * kNeedsRetry = "Needs Retry"; -namespace osm -{ -// TODO(AlexZ): Normalize osm multivalue strings for correct merging -// (e.g. insert/remove spaces after ';' delimeter); - -namespace -{ string GetEditorFilePath() { return GetPlatform().WritablePathForFile(kEditorXMLFileName); } // TODO(mgsergio): Replace hard-coded value with reading from file. /// type:string -> description:pair, editName:bool, editAddr:bool> @@ -61,16 +56,16 @@ using TEditableFields = vector; struct TypeDescription { TypeDescription(TEditableFields const & fields, bool const name, bool const address) : - fields(fields), - name(name), - address(address) + m_fields(fields), + m_name(name), + m_address(address) { } - TEditableFields const fields; - bool const name; + TEditableFields const m_fields; + bool const m_name; // Address == true implies Street, House Number, Phone, Fax, Opening Hours, Website, EMail, Postcode. - bool const address; + bool const m_address; }; static unordered_map const gEditableTypes = { @@ -213,6 +208,11 @@ uint32_t MigrateFeatureIndex(XMLFeature const & /*xml*/) } // namespace +namespace osm +{ +// TODO(AlexZ): Normalize osm multivalue strings for correct merging +// (e.g. insert/remove spaces after ';' delimeter); + Editor & Editor::Instance() { static Editor instance; @@ -372,12 +372,12 @@ Editor::FeatureStatus Editor::GetFeatureStatus(MwmSet::MwmId const & mwmId, uint if (m_features.empty()) return FeatureStatus::Untouched; - auto const mwmMatched = m_features.find(mwmId); - if (mwmMatched == m_features.end()) + auto const matchedMwm = m_features.find(mwmId); + if (matchedMwm == m_features.end()) return FeatureStatus::Untouched; - auto const matchedIndex = mwmMatched->second.find(index); - if (matchedIndex == mwmMatched->second.end()) + auto const matchedIndex = matchedMwm->second.find(index); + if (matchedIndex == matchedMwm->second.end()) return FeatureStatus::Untouched; return matchedIndex->second.m_status; @@ -474,12 +474,12 @@ void Editor::ForEachFeatureInMwmRectAndScale(MwmSet::MwmId const & id, bool Editor::GetEditedFeature(MwmSet::MwmId const & mwmId, uint32_t index, FeatureType & outFeature) const { - auto const mwmMatched = m_features.find(mwmId); - if (mwmMatched == m_features.end()) + auto const matchedMwm = m_features.find(mwmId); + if (matchedMwm == m_features.end()) return false; - auto const matchedIndex = mwmMatched->second.find(index); - if (matchedIndex == mwmMatched->second.end()) + auto const matchedIndex = matchedMwm->second.find(index); + if (matchedIndex == matchedMwm->second.end()) return false; // TODO(AlexZ): Should we process deleted/created features as well? @@ -498,10 +498,10 @@ vector Editor::EditableMetadataForType(FeatureType const & feat auto const * desc = GetTypeDescription(type); if (desc) { - for (auto field : desc->fields) + for (auto field : desc->m_fields) fields.insert(field); // If address is editable, many metadata fields are editable too. - if (desc->address) + if (desc->m_address) { fields.insert(EType::FMD_EMAIL); fields.insert(EType::FMD_OPEN_HOURS); @@ -524,7 +524,7 @@ bool Editor::IsNameEditable(FeatureType const & feature) const for (auto type : types) { auto const * typeDesc = GetTypeDescription(type); - if (typeDesc && typeDesc->name) + if (typeDesc && typeDesc->m_name) return true; } return false; @@ -540,7 +540,7 @@ bool Editor::IsAddressEditable(FeatureType const & feature) const if (isBuilding.HasTypeValue(type)) return true; auto const * typeDesc = GetTypeDescription(type); - if (typeDesc && typeDesc->address) + if (typeDesc && typeDesc->m_address) return true; } return false; diff --git a/indexer/osm_editor.hpp b/indexer/osm_editor.hpp index 671a7ce987..73592b7fef 100644 --- a/indexer/osm_editor.hpp +++ b/indexer/osm_editor.hpp @@ -47,11 +47,11 @@ public: void LoadMapEdits(); using TFeatureIDFunctor = function; - using TFeatureTypeFunctor = function; void ForEachFeatureInMwmRectAndScale(MwmSet::MwmId const & id, TFeatureIDFunctor const & f, m2::RectD const & rect, uint32_t scale); + using TFeatureTypeFunctor = function; void ForEachFeatureInMwmRectAndScale(MwmSet::MwmId const & id, TFeatureTypeFunctor const & f, m2::RectD const & rect,