From b57027ae67b10be24c2bc0457adf47fddc7a864b Mon Sep 17 00:00:00 2001 From: Maksim Andrianov Date: Wed, 17 Apr 2019 14:29:17 +0300 Subject: [PATCH] [generator] Refactored OsmElement: writing class members with prefix m_. --- generator/collector_camera.cpp | 12 +- generator/feature_maker.cpp | 12 +- generator/feature_maker_base.cpp | 2 +- generator/filter_elements.cpp | 12 +- generator/generator_tests/common.cpp | 4 +- .../generator_tests/filter_elements_tests.cpp | 6 +- generator/generator_tests/node_mixer_test.cpp | 12 +- .../region_info_collector_tests.cpp | 20 +-- generator/generator_tests/regions_tests.cpp | 4 +- generator/holes.cpp | 10 +- generator/maxspeeds_collector.cpp | 18 +-- generator/metalines_builder.cpp | 2 +- generator/node_mixer.cpp | 12 +- generator/osm2type.cpp | 52 +++---- generator/osm_element.cpp | 38 ++--- generator/osm_element.hpp | 137 +++++++++--------- generator/osm_element_helpers.cpp | 8 +- generator/osm_source.cpp | 32 ++-- generator/osm_xml_source.hpp | 28 ++-- generator/relation_tags.cpp | 4 +- generator/relation_tags_enricher.cpp | 8 +- generator/road_access_generator.cpp | 8 +- generator/tag_admixer.hpp | 18 +-- generator/towns_dumper.cpp | 7 +- generator/translator_country.cpp | 4 +- generator/translator_region.cpp | 4 +- 26 files changed, 236 insertions(+), 238 deletions(-) diff --git a/generator/collector_camera.cpp b/generator/collector_camera.cpp index a0f9527080..6c0c1c68e1 100644 --- a/generator/collector_camera.cpp +++ b/generator/collector_camera.cpp @@ -35,9 +35,9 @@ std::string ValidateMaxSpeedString(std::string const & maxSpeedString) } CameraProcessor::CameraInfo::CameraInfo(OsmElement const & element) - : m_id(element.id) - , m_lon(element.lon) - , m_lat(element.lat) + : m_id(element.m_id) + , m_lon(element.m_lon) + , m_lat(element.m_lat) { auto const maxspeed = element.GetTag("maxspeed"); if (!maxspeed.empty()) @@ -62,7 +62,7 @@ void CameraProcessor::ProcessWay(OsmElement const & element) continue; auto & ways = m_cameraToWays[node]; - ways.push_back(element.id); + ways.push_back(element.m_id); } } @@ -70,7 +70,7 @@ void CameraProcessor::ProcessNode(OsmElement const & element) { CameraInfo camera(element); CHECK_LESS(camera.m_speed.size(), kMaxSpeedSpeedStringLength, ()); - m_speedCameras.emplace(element.id, std::move(camera)); + m_speedCameras.emplace(element.m_id, std::move(camera)); } CameraCollector::CameraCollector(std::string const & writerFile) : @@ -78,7 +78,7 @@ CameraCollector::CameraCollector(std::string const & writerFile) : void CameraCollector::CollectFeature(FeatureBuilder1 const & feature, OsmElement const & element) { - switch (element.type) + switch (element.m_type) { case OsmElement::EntityType::Node: { diff --git a/generator/feature_maker.cpp b/generator/feature_maker.cpp index 99d945cb19..560612b6da 100644 --- a/generator/feature_maker.cpp +++ b/generator/feature_maker.cpp @@ -23,8 +23,8 @@ void FeatureMakerSimple::ParseParams(FeatureParams & params, OsmElement & p) con bool FeatureMakerSimple::BuildFromNode(OsmElement & p, FeatureParams const & params) { FeatureBuilder1 fb; - fb.SetCenter(MercatorBounds::FromLatLon(p.lat, p.lon)); - fb.SetOsmId(base::MakeOsmNode(p.id)); + fb.SetCenter(MercatorBounds::FromLatLon(p.m_lat, p.m_lon)); + fb.SetOsmId(base::MakeOsmNode(p.m_id)); fb.SetParams(params); m_queue.push(std::move(fb)); return true; @@ -46,12 +46,12 @@ bool FeatureMakerSimple::BuildFromWay(OsmElement & p, FeatureParams const & para fb.AddPoint(pt); } - fb.SetOsmId(base::MakeOsmWay(p.id)); + fb.SetOsmId(base::MakeOsmWay(p.m_id)); fb.SetParams(params); if (fb.IsGeometryClosed()) { - HolesProcessor processor(p.id, m_cache); - m_cache.ForEachRelationByWay(p.id, processor); + HolesProcessor processor(p.m_id, m_cache); + m_cache.ForEachRelationByWay(p.m_id, processor); fb.SetAreaAddHoles(processor.GetHoles()); } else @@ -79,7 +79,7 @@ bool FeatureMakerSimple::BuildFromRelation(OsmElement & p, FeatureParams const & for (auto const & pt : pts) fb.AddPoint(pt); - fb.AddOsmId(base::MakeOsmRelation(p.id)); + fb.AddOsmId(base::MakeOsmRelation(p.m_id)); if (!fb.IsGeometryClosed()) return; diff --git a/generator/feature_maker_base.cpp b/generator/feature_maker_base.cpp index 93a4c57cde..69dbff50c9 100644 --- a/generator/feature_maker_base.cpp +++ b/generator/feature_maker_base.cpp @@ -14,7 +14,7 @@ bool FeatureMakerBase::Add(OsmElement & element) { FeatureParams params; ParseParams(params, element); - switch (element.type) + switch (element.m_type) { case OsmElement::EntityType::Node: return BuildFromNode(element, params); diff --git a/generator/filter_elements.cpp b/generator/filter_elements.cpp index c36d963e5a..6f8a92cf20 100644 --- a/generator/filter_elements.cpp +++ b/generator/filter_elements.cpp @@ -37,9 +37,9 @@ bool FilterData::IsMatch(Tags const & elementTags, Tags const & tags) { auto const fn = [&](OsmElement::Tag const & t) { - auto const pred = [&](OsmElement::Tag const & tag) { return tag.key == t.key; }; + auto const pred = [&](OsmElement::Tag const & tag) { return tag.m_key == t.m_key; }; auto const it = std::find_if(std::begin(elementTags), std::end(elementTags), pred); - return it == std::end(elementTags) ? false : t.value == "*" || it->value == t.value; + return it == std::end(elementTags) ? false : t.m_value == "*" || it->m_value == t.m_value; }; return std::all_of(std::begin(tags), std::end(tags), fn); @@ -54,7 +54,7 @@ void FilterData::AddSkippedTags(Tags const & tags) { m_rulesStorage.push_back(tags); for (auto const & t : tags) - m_skippedTags.emplace(t.key, m_rulesStorage.back()); + m_skippedTags.emplace(t.m_key, m_rulesStorage.back()); } bool FilterData::NeedSkipWithId(uint64_t id) const @@ -67,7 +67,7 @@ bool FilterData::NeedSkipWithTags(Tags const & tags) const Set s; for (auto const & tag : tags) { - auto const t = m_skippedTags.equal_range(tag.key); + auto const t = m_skippedTags.equal_range(tag.m_key); for (auto it = t.first; it != t.second; ++it) { Tags const & t = it->second; @@ -167,7 +167,7 @@ bool FilterElements::IsAccepted(OsmElement const & element) bool FilterElements::NeedSkip(OsmElement const & element) const { - switch (element.type) + switch (element.m_type) { case OsmElement::EntityType::Node: return NeedSkip(element, m_nodes); case OsmElement::EntityType::Way: return NeedSkip(element, m_ways); @@ -178,7 +178,7 @@ bool FilterElements::NeedSkip(OsmElement const & element) const bool FilterElements::NeedSkip(OsmElement const & element, FilterData const & fdata) const { - return fdata.NeedSkipWithId(element.id) || fdata.NeedSkipWithTags(element.Tags()); + return fdata.NeedSkipWithId(element.m_id) || fdata.NeedSkipWithTags(element.Tags()); } bool FilterElements::ParseString(std::string const & str) diff --git a/generator/generator_tests/common.cpp b/generator/generator_tests/common.cpp index a3bfaf09be..8246adaac0 100644 --- a/generator/generator_tests/common.cpp +++ b/generator/generator_tests/common.cpp @@ -9,8 +9,8 @@ namespace generator_tests OsmElement MakeOsmElement(uint64_t id, Tags const & tags, OsmElement::EntityType t) { OsmElement el; - el.id = id; - el.type = t; + el.m_id = id; + el.m_type = t; for (auto const & t : tags) el.AddTag(t.first, t.second); diff --git a/generator/generator_tests/filter_elements_tests.cpp b/generator/generator_tests/filter_elements_tests.cpp index d55d9d74aa..c2302cf09a 100644 --- a/generator/generator_tests/filter_elements_tests.cpp +++ b/generator/generator_tests/filter_elements_tests.cpp @@ -26,10 +26,10 @@ auto const kOsmElementCountry = MakeOsmElement(2, {{"admin_level", "2"}, UNIT_TEST(FilterData_Ids) { FilterData fd; - fd.AddSkippedId(kOsmElementEmpty.id); + fd.AddSkippedId(kOsmElementEmpty.m_id); - TEST(fd.NeedSkipWithId(kOsmElementEmpty.id), ()); - TEST(!fd.NeedSkipWithId(kOsmElementCity.id), ()); + TEST(fd.NeedSkipWithId(kOsmElementEmpty.m_id), ()); + TEST(!fd.NeedSkipWithId(kOsmElementCity.m_id), ()); } UNIT_TEST(FilterData_Tags) diff --git a/generator/generator_tests/node_mixer_test.cpp b/generator/generator_tests/node_mixer_test.cpp index ea139278ec..b9184cc1ba 100644 --- a/generator/generator_tests/node_mixer_test.cpp +++ b/generator/generator_tests/node_mixer_test.cpp @@ -26,9 +26,9 @@ UNIT_TEST(NodeMixerTests) int count4 = 0; generator::MixFakeNodes(stream4, [&](OsmElement & p) { count4++; - TEST_EQUAL(p.type, OsmElement::EntityType::Node, ()); - TEST_EQUAL(p.lat, 10.0, ()); - TEST_EQUAL(p.lon, -4.8, ()); + TEST_EQUAL(p.m_type, OsmElement::EntityType::Node, ()); + TEST_EQUAL(p.m_lat, 10.0, ()); + TEST_EQUAL(p.m_lon, -4.8, ()); TEST_EQUAL(p.Tags().size(), 2, ()); TEST_EQUAL(p.GetTag("name"), "Shop", ()); }); @@ -38,7 +38,7 @@ UNIT_TEST(NodeMixerTests) int count5 = 0; generator::MixFakeNodes(stream5, [&](OsmElement & p) { count5++; - TEST_EQUAL(p.type, OsmElement::EntityType::Node, ()); + TEST_EQUAL(p.m_type, OsmElement::EntityType::Node, ()); TEST_EQUAL(p.Tags().size(), 2, ()); std::string id = p.GetTag("id"); TEST(!id.empty(), ("No id tag when every object has it.")); @@ -50,8 +50,8 @@ UNIT_TEST(NodeMixerTests) int count6 = 0; generator::MixFakeNodes(stream6, [&](OsmElement & p) { count6++; - TEST_EQUAL(p.lat, 0.0, ()); - TEST_EQUAL(p.lon, -4.8, ()); + TEST_EQUAL(p.m_lat, 0.0, ()); + TEST_EQUAL(p.m_lon, -4.8, ()); }); TEST_EQUAL(count6, 1, ()); } diff --git a/generator/generator_tests/region_info_collector_tests.cpp b/generator/generator_tests/region_info_collector_tests.cpp index 54c8fab9d8..e735182615 100644 --- a/generator/generator_tests/region_info_collector_tests.cpp +++ b/generator/generator_tests/region_info_collector_tests.cpp @@ -48,8 +48,8 @@ UNIT_TEST(RegionInfoCollector_Collect) RegionInfo regionInfo(filename); { - auto const regionData = regionInfo.Get(MakeOsmRelation(kOsmElementCity.id)); - TEST_EQUAL(regionData.GetOsmId(), MakeOsmRelation(kOsmElementCity.id), ()); + auto const regionData = regionInfo.Get(MakeOsmRelation(kOsmElementCity.m_id)); + TEST_EQUAL(regionData.GetOsmId(), MakeOsmRelation(kOsmElementCity.m_id), ()); TEST_EQUAL(regionData.GetAdminLevel(), AdminLevel::Six, ()); TEST_EQUAL(regionData.GetPlaceType(), PlaceType::City, ()); TEST(!regionData.HasIsoCodeAlpha2(), ()); @@ -58,8 +58,8 @@ UNIT_TEST(RegionInfoCollector_Collect) } { - auto const regionData = regionInfo.Get(MakeOsmRelation(kOsmElementCountry.id)); - TEST_EQUAL(regionData.GetOsmId(), MakeOsmRelation(kOsmElementCountry.id), ()); + auto const regionData = regionInfo.Get(MakeOsmRelation(kOsmElementCountry.m_id)); + TEST_EQUAL(regionData.GetOsmId(), MakeOsmRelation(kOsmElementCountry.m_id), ()); TEST_EQUAL(regionData.GetAdminLevel(), AdminLevel::Two, ()); TEST_EQUAL(regionData.GetPlaceType(), PlaceType::Unknown, ()); @@ -72,8 +72,8 @@ UNIT_TEST(RegionInfoCollector_Collect) } { - auto const regionDataEmpty = regionInfo.Get(MakeOsmRelation(kOsmElementEmpty.id)); - TEST_EQUAL(regionDataEmpty.GetOsmId(), MakeOsmRelation(kOsmElementEmpty.id), ()); + auto const regionDataEmpty = regionInfo.Get(MakeOsmRelation(kOsmElementEmpty.m_id)); + TEST_EQUAL(regionDataEmpty.GetOsmId(), MakeOsmRelation(kOsmElementEmpty.m_id), ()); TEST_EQUAL(regionDataEmpty.GetAdminLevel(), AdminLevel::Unknown, ()); TEST_EQUAL(regionDataEmpty.GetPlaceType(), PlaceType::Unknown, ()); TEST(!regionDataEmpty.HasIsoCodeAlpha2(), ()); @@ -90,8 +90,8 @@ UNIT_TEST(RegionInfoCollector_Get) regionInfoCollector.Save(); RegionInfo regionInfo(filename); - auto const regionData = regionInfo.Get(MakeOsmRelation(kOsmElementCity.id)); - TEST_EQUAL(regionData.GetOsmId(), MakeOsmRelation(kOsmElementCity.id), ()); + auto const regionData = regionInfo.Get(MakeOsmRelation(kOsmElementCity.m_id)); + TEST_EQUAL(regionData.GetOsmId(), MakeOsmRelation(kOsmElementCity.m_id), ()); TEST_EQUAL(regionData.GetAdminLevel(), AdminLevel::Six, ()); TEST_EQUAL(regionData.GetPlaceType(), PlaceType::City, ()); } @@ -106,7 +106,7 @@ UNIT_TEST(RegionInfoCollector_Exists) RegionInfo regionInfo(filename); { - auto const rg = regionInfo.Get(MakeOsmRelation(kOsmElementCountry.id)); + auto const rg = regionInfo.Get(MakeOsmRelation(kOsmElementCountry.m_id)); TEST(rg.HasAdminLevel(), ()); TEST(!rg.HasPlaceType(), ()); TEST(rg.HasIsoCodeAlpha2(), ()); @@ -115,7 +115,7 @@ UNIT_TEST(RegionInfoCollector_Exists) } { - auto const rg = regionInfo.Get(MakeOsmRelation(kOsmElementCity.id)); + auto const rg = regionInfo.Get(MakeOsmRelation(kOsmElementCity.m_id)); TEST(rg.HasAdminLevel(), ()); TEST(rg.HasPlaceType(), ()); TEST(!rg.HasIsoCodeAlpha2(), ()); diff --git a/generator/generator_tests/regions_tests.cpp b/generator/generator_tests/regions_tests.cpp index dba5c11f0a..f62f206ca9 100644 --- a/generator/generator_tests/regions_tests.cpp +++ b/generator/generator_tests/regions_tests.cpp @@ -36,8 +36,8 @@ OsmElement CreateOsmRelation(uint64_t id, std::string const & adminLevel, std::string const & place = "") { OsmElement el; - el.id = id; - el.type = OsmElement::EntityType::Relation; + el.m_id = id; + el.m_type = OsmElement::EntityType::Relation; el.AddTag("place", place); el.AddTag("admin_level", adminLevel); diff --git a/generator/holes.cpp b/generator/holes.cpp index 9f4abdbd74..da6083d54c 100644 --- a/generator/holes.cpp +++ b/generator/holes.cpp @@ -62,13 +62,13 @@ void HolesRelation::Build(OsmElement const * p) // Iterate ways to get 'outer' and 'inner' geometries. for (auto const & e : p->Members()) { - if (e.type != OsmElement::EntityType::Way) + if (e.m_type != OsmElement::EntityType::Way) continue; - if (e.role == "outer") - m_outer.AddWay(e.ref); - else if (e.role == "inner") - m_holes(e.ref); + if (e.m_role == "outer") + m_outer.AddWay(e.m_ref); + else if (e.m_role == "inner") + m_holes(e.m_ref); } } } // namespace generator diff --git a/generator/maxspeeds_collector.cpp b/generator/maxspeeds_collector.cpp index 3b56ca9737..fab398f1d2 100644 --- a/generator/maxspeeds_collector.cpp +++ b/generator/maxspeeds_collector.cpp @@ -38,7 +38,7 @@ void MaxspeedsCollector::CollectFeature(FeatureBuilder1 const &, OsmElement cons return; ostringstream ss; - ss << p.id << ","; + ss << p.m_id << ","; auto const & tags = p.Tags(); string maxspeedForwardStr; @@ -47,21 +47,21 @@ void MaxspeedsCollector::CollectFeature(FeatureBuilder1 const &, OsmElement cons for (auto const & t : tags) { - if (t.key == "maxspeed") + if (t.m_key == "maxspeed") { SpeedInUnits dummySpeed; - if (!ParseMaxspeedAndWriteToStream(t.value, dummySpeed, ss)) + if (!ParseMaxspeedAndWriteToStream(t.m_value, dummySpeed, ss)) return; m_data.push_back(ss.str()); return; } - if (t.key == "maxspeed:forward") - maxspeedForwardStr = t.value; - else if (t.key == "maxspeed:backward") - maxspeedBackwardStr = t.value; - else if (t.key == "oneway") - isReverse = (t.value == "-1"); + if (t.m_key == "maxspeed:forward") + maxspeedForwardStr = t.m_value; + else if (t.m_key == "maxspeed:backward") + maxspeedBackwardStr = t.m_value; + else if (t.m_key == "oneway") + isReverse = (t.m_value == "-1"); } // Note 1. isReverse == true means feature |p| has tag "oneway" with value "-1". Now (10.2018) diff --git a/generator/metalines_builder.cpp b/generator/metalines_builder.cpp index db14339937..299b266d99 100644 --- a/generator/metalines_builder.cpp +++ b/generator/metalines_builder.cpp @@ -36,7 +36,7 @@ public: { std::string const oneway = way.GetTag("oneway"); m_oneway = !oneway.empty() && oneway != "no"; - int32_t const wayId = base::checked_cast(way.id); + int32_t const wayId = base::checked_cast(way.m_id); m_ways.push_back(oneway == "-1" ? -wayId : wayId); CHECK_GREATER_OR_EQUAL(way.Nodes().size(), 2, ()); m_start = way.Nodes().front(); diff --git a/generator/node_mixer.cpp b/generator/node_mixer.cpp index b003a042c8..b096ac0965 100644 --- a/generator/node_mixer.cpp +++ b/generator/node_mixer.cpp @@ -21,8 +21,8 @@ void MixFakeNodes(istream & stream, function processor) uint64_t count = 0; uint8_t completionFlag = 0; OsmElement p; - p.id = baseNodeId; - p.type = OsmElement::EntityType::Node; + p.m_id = baseNodeId; + p.m_type = OsmElement::EntityType::Node; string line; while (getline(stream, line)) @@ -34,8 +34,8 @@ void MixFakeNodes(istream & stream, function processor) processor(p); count++; p.Clear(); - p.id = baseNodeId + count; - p.type = OsmElement::EntityType::Node; + p.m_id = baseNodeId + count; + p.m_type = OsmElement::EntityType::Node; completionFlag = 0; } continue; @@ -51,12 +51,12 @@ void MixFakeNodes(istream & stream, function processor) if (key == "lat") { - if (strings::to_double(value, p.lat)) + if (strings::to_double(value, p.m_lat)) completionFlag |= kCFLat; } else if (key == "lon") { - if (strings::to_double(value, p.lon)) + if (strings::to_double(value, p.m_lon)) completionFlag |= kCFLon; } else diff --git a/generator/osm2type.cpp b/generator/osm2type.cpp index 202202c21d..6f8ff7fc2e 100644 --- a/generator/osm2type.cpp +++ b/generator/osm2type.cpp @@ -78,10 +78,10 @@ Result ForEachTag(OsmElement * p, ToDo && toDo) Result res = {}; for (auto & e : p->m_tags) { - if (IgnoreTag(e.key, e.value)) + if (IgnoreTag(e.m_key, e.m_value)) continue; - res = toDo(e.key, e.value); + res = toDo(e.m_key, e.m_value); if (res) return res; } @@ -169,12 +169,12 @@ public: template struct Rule { - char const * key; + char const * m_key; // * - take any values // ! - take only negative values // ~ - take only positive values - char const * value; - function func; + char const * m_value; + function m_func; }; template @@ -184,18 +184,18 @@ public: { for (auto const & rule : rules) { - if (e.key != rule.key) + if (e.m_key != rule.m_key) continue; bool take = false; - if (rule.value[0] == '*') + if (rule.m_value[0] == '*') take = true; - else if (rule.value[0] == '!') - take = IsNegative(e.value); - else if (rule.value[0] == '~') - take = !IsNegative(e.value); + else if (rule.m_value[0] == '!') + take = IsNegative(e.m_value); + else if (rule.m_value[0] == '~') + take = !IsNegative(e.m_value); - if (take || e.value == rule.value) - Call(rule.func, e.key, e.value); + if (take || e.m_value == rule.m_value) + Call(rule.m_func, e.m_key, e.m_value); } } } @@ -445,7 +445,7 @@ string MatchCity(OsmElement const * p) {"wien", {16.0894775391, 48.0633965378, 16.6387939453, 48.3525987075}}, }; - m2::PointD const pt(p->lon, p->lat); + m2::PointD const pt(p->m_lon, p->m_lat); for (auto const & city : cities) { @@ -464,13 +464,13 @@ string DetermineSurface(OsmElement * p) for (auto const & tag : p->m_tags) { - if (tag.key == "surface") - surface = tag.value; - else if (tag.key == "smoothness") - smoothness = tag.value; - else if (tag.key == "surface:grade") - surface_grade = tag.value; - else if (tag.key == "highway") + if (tag.m_key == "surface") + surface = tag.m_value; + else if (tag.m_key == "smoothness") + smoothness = tag.m_value; + else if (tag.m_key == "surface:grade") + surface_grade = tag.m_value; + else if (tag.m_key == "highway") isHighway = true; } @@ -562,7 +562,7 @@ void PreprocessElement(OsmElement * p) p->AddTag("layer", layer); // Tag 'city' is needed for correct selection of metro icons. - if (isSubway && p->type == OsmElement::EntityType::Node) + if (isSubway && p->m_type == OsmElement::EntityType::Node) { string const city = MatchCity(p); if (!city.empty()) @@ -574,16 +574,16 @@ void PreprocessElement(OsmElement * p) // Convert public_transport tags to the older schema. for (auto const & tag : p->m_tags) { - if (tag.key == "public_transport") + if (tag.m_key == "public_transport") { - if (tag.value == "platform" && isBus) + if (tag.m_value == "platform" && isBus) { - if (p->type == OsmElement::EntityType::Node) + if (p->m_type == OsmElement::EntityType::Node) p->AddTag("highway", "bus_stop"); else p->AddTag("highway", "platform"); } - else if (tag.value == "stop_position" && isTram && p->type == OsmElement::EntityType::Node) + else if (tag.m_value == "stop_position" && isTram && p->m_type == OsmElement::EntityType::Node) { p->AddTag("railway", "tram_stop"); } diff --git a/generator/osm_element.cpp b/generator/osm_element.cpp index 576c6bffa4..7dd7c62e85 100644 --- a/generator/osm_element.cpp +++ b/generator/osm_element.cpp @@ -80,17 +80,17 @@ bool OsmElement::HasTag(std::string_view const & key) const bool OsmElement::HasTag(std::string_view const & k, std::string_view const & v) const { return std::any_of(m_tags.begin(), m_tags.end(), [&](auto const & t) { - return t.key == k && t.value == v; + return t.m_key == k && t.m_value == v; }); } bool OsmElement::HasAnyTag(std::unordered_multimap const & tags) const { return std::any_of(std::begin(m_tags), std::end(m_tags), [&](auto const & t) { - auto beginEnd = tags.equal_range(t.key); + auto beginEnd = tags.equal_range(t.m_key); for (auto it = beginEnd.first; it != beginEnd.second; ++it) { - if (it->second == t.value) + if (it->second == t.m_value) return true; } @@ -102,17 +102,17 @@ std::string OsmElement::ToString(std::string const & shift) const { std::stringstream ss; ss << (shift.empty() ? "\n" : shift); - switch (type) + switch (m_type) { case EntityType::Node: - ss << "Node: " << id << " (" << std::fixed << std::setw(7) << lat << ", " << lon << ")" + ss << "Node: " << m_id << " (" << std::fixed << std::setw(7) << m_lat << ", " << m_lon << ")" << " tags: " << m_tags.size(); break; case EntityType::Nd: - ss << "Nd ref: " << ref; + ss << "Nd ref: " << m_ref; break; case EntityType::Way: - ss << "Way: " << id << " nds: " << m_nds.size() << " tags: " << m_tags.size(); + ss << "Way: " << m_id << " nds: " << m_nds.size() << " tags: " << m_tags.size(); if (!m_nds.empty()) { std::string shift2 = shift; @@ -122,20 +122,20 @@ std::string OsmElement::ToString(std::string const & shift) const } break; case EntityType::Relation: - ss << "Relation: " << id << " members: " << m_members.size() << " tags: " << m_tags.size(); + ss << "Relation: " << m_id << " members: " << m_members.size() << " tags: " << m_tags.size(); if (!m_members.empty()) { std::string shift2 = shift; shift2 += shift2.empty() ? "\n " : " "; for (auto const & e : m_members) - ss << shift2 << e.ref << " " << DebugPrint(e.type) << " " << e.role; + ss << shift2 << e.m_ref << " " << DebugPrint(e.m_type) << " " << e.m_role; } break; case EntityType::Tag: - ss << "Tag: " << k << " = " << v; + ss << "Tag: " << m_k << " = " << m_v; break; case EntityType::Member: - ss << "Member: " << ref << " type: " << DebugPrint(memberType) << " role: " << role; + ss << "Member: " << m_ref << " type: " << DebugPrint(m_memberType) << " role: " << m_role; break; case EntityType::Unknown: case EntityType::Osm: @@ -148,7 +148,7 @@ std::string OsmElement::ToString(std::string const & shift) const std::string shift2 = shift; shift2 += shift2.empty() ? "\n " : " "; for (auto const & e : m_tags) - ss << shift2 << e.key << " = " << e.value; + ss << shift2 << e.m_key << " = " << e.m_value; } return ss.str(); } @@ -156,9 +156,9 @@ std::string OsmElement::ToString(std::string const & shift) const std::string OsmElement::GetTag(std::string const & key) const { auto const it = std::find_if(m_tags.cbegin(), m_tags.cend(), - [&key](Tag const & tag) { return tag.key == key; }); + [&key](Tag const & tag) { return tag.m_key == key; }); - return it == m_tags.cend() ? std::string() : it->value; + return it == m_tags.cend() ? std::string() : it->m_value; } std::string_view OsmElement::GetTagValue(std::string_view const & key, @@ -178,20 +178,20 @@ std::string DebugPrint(OsmElement const & e) std::string DebugPrint(OsmElement::Tag const & tag) { std::stringstream ss; - ss << tag.key << '=' << tag.value; + ss << tag.m_key << '=' << tag.m_value; return ss.str(); } base::GeoObjectId GetGeoObjectId(OsmElement const & element) { - switch (element.type) + switch (element.m_type) { case OsmElement::EntityType::Node: - return base::MakeOsmNode(element.id); + return base::MakeOsmNode(element.m_id); case OsmElement::EntityType::Way: - return base::MakeOsmWay(element.id); + return base::MakeOsmWay(element.m_id); case OsmElement::EntityType::Relation: - return base::MakeOsmRelation(element.id); + return base::MakeOsmRelation(element.m_id); case OsmElement::EntityType::Member: case OsmElement::EntityType::Nd: case OsmElement::EntityType::Osm: diff --git a/generator/osm_element.hpp b/generator/osm_element.hpp index e55b1ff071..6b9f14a383 100644 --- a/generator/osm_element.hpp +++ b/generator/osm_element.hpp @@ -31,82 +31,39 @@ struct OsmElement struct Member { - uint64_t ref = 0; - EntityType type = EntityType::Unknown; - std::string role; - Member() = default; Member(uint64_t ref, EntityType type, std::string const & role) - : ref(ref), type(type), role(role) - {} + : m_ref(ref), m_type(type), m_role(role) {} - bool operator == (Member const & e) const + bool operator==(Member const & e) const { - return ref == e.ref && type == e.type && role == e.role; + return m_ref == e.m_ref && m_type == e.m_type && m_role == e.m_role; } + + uint64_t m_ref = 0; + EntityType m_type = EntityType::Unknown; + std::string m_role; }; struct Tag { - std::string key; - std::string value; - Tag() = default; - Tag(std::string const & k, std::string const & v) : key(k), value(v) {} + Tag(std::string const & k, std::string const & v) : m_key(k), m_value(v) {} - bool operator == (Tag const & e) const + bool operator==(Tag const & e) const { - return key == e.key && value == e.value; + return m_key == e.m_key && m_value == e.m_value; } - bool operator < (Tag const & e) const + + bool operator<(Tag const & e) const { - if (key == e.key) - return value < e.value; - return key < e.key; + return m_key == e.m_key ? m_value < e.m_value : m_key < e.m_key; } + + std::string m_key; + std::string m_value; }; - EntityType type = EntityType::Unknown; - uint64_t id = 0; - double lon = 0; - double lat = 0; - uint64_t ref = 0; - std::string k; - std::string v; - EntityType memberType = EntityType::Unknown; - std::string role; - - std::vector m_nds; - std::vector m_members; - std::vector m_tags; - - void Clear() - { - type = EntityType::Unknown; - id = 0; - lon = 0; - lat = 0; - ref = 0; - k.clear(); - v.clear(); - memberType = EntityType::Unknown; - role.clear(); - - m_nds.clear(); - m_members.clear(); - m_tags.clear(); - } - - std::string ToString(std::string const & shift = std::string()) const; - - std::vector const & Nodes() const { return m_nds; } - std::vector const & Members() const { return m_members; } - std::vector const & Tags() const { return m_tags; } - - bool IsNode() const { return type == EntityType::Node; } - bool IsWay() const { return type == EntityType::Way; } - bool IsRelation() const { return type == EntityType::Relation; } - static EntityType StringToEntityType(std::string const & t) { if (t == "way") @@ -119,17 +76,44 @@ struct OsmElement return EntityType::Unknown; } + void Clear() + { + m_type = EntityType::Unknown; + m_id = 0; + m_lon = 0; + m_lat = 0; + m_ref = 0; + m_k.clear(); + m_v.clear(); + m_memberType = EntityType::Unknown; + m_role.clear(); + + m_nds.clear(); + m_members.clear(); + m_tags.clear(); + } + + std::string ToString(std::string const & shift = std::string()) const; + + std::vector const & Nodes() const { return m_nds; } + std::vector const & Members() const { return m_members; } + std::vector const & Tags() const { return m_tags; } + + bool IsNode() const { return m_type == EntityType::Node; } + bool IsWay() const { return m_type == EntityType::Way; } + bool IsRelation() const { return m_type == EntityType::Relation; } + bool operator==(OsmElement const & e) const { - return type == e.type - && id == e.id - && base::AlmostEqualAbs(lon, e.lon, 1e-7) - && base::AlmostEqualAbs(lat, e.lat, 1e-7) - && ref == e.ref - && k == e.k - && v == e.v - && memberType == e.memberType - && role == e.role + return m_type == e.m_type + && m_id == e.m_id + && base::AlmostEqualAbs(m_lon, e.m_lon, 1e-7) + && base::AlmostEqualAbs(m_lat, e.m_lat, 1e-7) + && m_ref == e.m_ref + && m_k == e.m_k + && m_v == e.m_v + && m_memberType == e.m_memberType + && m_role == e.m_role && m_nds == e.m_nds && m_members == e.m_members && m_tags == e.m_tags; @@ -151,9 +135,9 @@ struct OsmElement { for (auto & tag : m_tags) { - if (tag.key == k) + if (tag.m_key == k) { - fn(tag.value); + fn(tag.m_value); return; } } @@ -166,6 +150,19 @@ struct OsmElement std::string GetTag(std::string const & key) const; std::string_view GetTagValue(std::string_view const & key, std::string_view const & defaultValue) const; + EntityType m_type = EntityType::Unknown; + uint64_t m_id = 0; + double m_lon = 0; + double m_lat = 0; + uint64_t m_ref = 0; + std::string m_k; + std::string m_v; + EntityType m_memberType = EntityType::Unknown; + std::string m_role; + + std::vector m_nds; + std::vector m_members; + std::vector m_tags; }; base::GeoObjectId GetGeoObjectId(OsmElement const & element); diff --git a/generator/osm_element_helpers.cpp b/generator/osm_element_helpers.cpp index 76fc3ec311..cb4a835d05 100644 --- a/generator/osm_element_helpers.cpp +++ b/generator/osm_element_helpers.cpp @@ -14,7 +14,7 @@ bool IsPoi(OsmElement const & osmElement) { auto const & tags = osmElement.Tags(); return std::any_of(std::cbegin(tags), std::cend(tags), [](OsmElement::Tag const & t) { - return ftypes::IsPoiChecker::kPoiTypes.find(t.key) != std::end(ftypes::IsPoiChecker::kPoiTypes); + return ftypes::IsPoiChecker::kPoiTypes.find(t.m_key) != std::end(ftypes::IsPoiChecker::kPoiTypes); }); } @@ -22,7 +22,7 @@ bool IsBuilding(OsmElement const & osmElement) { auto const & tags = osmElement.Tags(); return std::any_of(std::cbegin(tags), std::cend(tags), [](OsmElement::Tag const & t) { - return t.key == "building"; + return t.m_key == "building"; }); } @@ -30,7 +30,7 @@ bool HasHouse(OsmElement const & osmElement) { auto const & tags = osmElement.Tags(); return std::any_of(std::cbegin(tags), std::cend(tags), [](OsmElement::Tag const & t) { - return t.key == "addr:housenumber" || t.key == "addr:housename"; + return t.m_key == "addr:housenumber" || t.m_key == "addr:housename"; }); } @@ -38,7 +38,7 @@ bool HasStreet(OsmElement const & osmElement) { auto const & tags = osmElement.Tags(); return std::any_of(std::cbegin(tags), std::cend(tags), [](OsmElement::Tag const & t) { - return t.key == "addr:street"; + return t.m_key == "addr:street"; }); } } // namespace osm_element diff --git a/generator/osm_source.cpp b/generator/osm_source.cpp index bb171aad49..5e47c92d74 100644 --- a/generator/osm_source.cpp +++ b/generator/osm_source.cpp @@ -55,23 +55,23 @@ uint64_t SourceReader::Read(char * buffer, uint64_t bufferSize) // Functions --------------------------------------------------------------------------------------- void AddElementToCache(cache::IntermediateDataWriter & cache, OsmElement & em) { - switch (em.type) + switch (em.m_type) { case OsmElement::EntityType::Node: { - auto const pt = MercatorBounds::FromLatLon(em.lat, em.lon); - cache.AddNode(em.id, pt.y, pt.x); + auto const pt = MercatorBounds::FromLatLon(em.m_lat, em.m_lon); + cache.AddNode(em.m_id, pt.y, pt.x); break; } case OsmElement::EntityType::Way: { // Store way. - WayElement way(em.id); + WayElement way(em.m_id); for (uint64_t nd : em.Nodes()) way.nodes.push_back(nd); if (way.IsValid()) - cache.AddWay(em.id, way); + cache.AddWay(em.m_id, way); break; } case OsmElement::EntityType::Relation: @@ -80,12 +80,12 @@ void AddElementToCache(cache::IntermediateDataWriter & cache, OsmElement & em) RelationElement relation; for (auto const & member : em.Members()) { - switch (member.type) { + switch (member.m_type) { case OsmElement::EntityType::Node: - relation.nodes.emplace_back(member.ref, string(member.role)); + relation.nodes.emplace_back(member.m_ref, string(member.m_role)); break; case OsmElement::EntityType::Way: - relation.ways.emplace_back(member.ref, string(member.role)); + relation.ways.emplace_back(member.m_ref, string(member.m_role)); break; case OsmElement::EntityType::Relation: // we just ignore type == "relation" @@ -96,10 +96,10 @@ void AddElementToCache(cache::IntermediateDataWriter & cache, OsmElement & em) } for (auto const & tag : em.Tags()) - relation.tags.emplace(tag.key, tag.value); + relation.tags.emplace(tag.m_key, tag.m_value); if (relation.IsValid()) - cache.AddRelation(em.id, relation); + cache.AddRelation(em.m_id, relation); break; } @@ -166,27 +166,27 @@ void ProcessOsmElementsFromO5M(SourceReader & stream, functionid), ("Unknown element with invalid id:", value)); + CHECK(strings::to_uint64(value, m_current->m_id), ("Unknown element with invalid id:", value)); else if (key == "lon") - CHECK(strings::to_double(value, m_current->lon), ("Bad node lon:", value)); + CHECK(strings::to_double(value, m_current->m_lon), ("Bad node lon:", value)); else if (key == "lat") - CHECK(strings::to_double(value, m_current->lat), ("Bad node lat:", value)); + CHECK(strings::to_double(value, m_current->m_lat), ("Bad node lat:", value)); else if (key == "ref") - CHECK(strings::to_uint64(value, m_current->ref), ("Bad node ref in way:", value)); + CHECK(strings::to_uint64(value, m_current->m_ref), ("Bad node ref in way:", value)); else if (key == "k") - m_current->k = value; + m_current->m_k = value; else if (key == "v") - m_current->v = value; + m_current->m_v = value; else if (key == "type") - m_current->memberType = OsmElement::StringToEntityType(value); + m_current->m_memberType = OsmElement::StringToEntityType(value); else if (key == "role") - m_current->role = value; + m_current->m_role = value; } bool Push(std::string const & tagName) @@ -55,11 +55,11 @@ public: break; case 2: m_current = &m_parent; - m_current->type = tagKey; + m_current->m_type = tagKey; break; default: m_current = &m_child; - m_current->type = tagKey; + m_current->m_type = tagKey; break; } return true; @@ -78,16 +78,16 @@ public: break; default: - switch (m_child.type) + switch (m_child.m_type) { case OsmElement::EntityType::Member: - m_parent.AddMember(m_child.ref, m_child.memberType, m_child.role); + m_parent.AddMember(m_child.m_ref, m_child.m_memberType, m_child.m_role); break; case OsmElement::EntityType::Tag: - m_parent.AddTag(m_child.k, m_child.v); + m_parent.AddTag(m_child.m_k, m_child.m_v); break; case OsmElement::EntityType::Nd: - m_parent.AddNd(m_child.ref); + m_parent.AddNd(m_child.m_ref); break; default: break; diff --git a/generator/relation_tags.cpp b/generator/relation_tags.cpp index ba86d7c9b3..98d66a004b 100644 --- a/generator/relation_tags.cpp +++ b/generator/relation_tags.cpp @@ -22,7 +22,7 @@ bool RelationTagsBase::IsKeyTagExists(std::string const & key) const { auto const & tags = m_current->m_tags; return std::any_of(std::begin(tags), std::end(tags), [&](OsmElement::Tag const & p) { - return p.key == key; + return p.m_key == key; }); } @@ -100,7 +100,7 @@ void RelationTagsWay::Process(RelationElement const & e) if (type == "building") { // If this way has "outline" role, add [building=has_parts] type. - if (e.GetWayRole(m_current->id) == "outline") + if (e.GetWayRole(m_current->m_id) == "outline") Base::AddCustomTag({"building", "has_parts"}); return; } diff --git a/generator/relation_tags_enricher.cpp b/generator/relation_tags_enricher.cpp index 896d46d04d..4ec44bcbe4 100644 --- a/generator/relation_tags_enricher.cpp +++ b/generator/relation_tags_enricher.cpp @@ -12,13 +12,13 @@ void RelationTagsEnricher::operator()(OsmElement & p) { if (p.IsNode()) { - m_nodeRelations.Reset(p.id, &p); - m_cache.ForEachRelationByNodeCached(p.id, m_nodeRelations); + m_nodeRelations.Reset(p.m_id, &p); + m_cache.ForEachRelationByNodeCached(p.m_id, m_nodeRelations); } else if (p.IsWay()) { - m_wayRelations.Reset(p.id, &p); - m_cache.ForEachRelationByWayCached(p.id, m_wayRelations); + m_wayRelations.Reset(p.m_id, &p); + m_cache.ForEachRelationByWayCached(p.m_id, m_wayRelations); } } } // namespace generator diff --git a/generator/road_access_generator.cpp b/generator/road_access_generator.cpp index 06c07c069f..9c7f5c5c5a 100644 --- a/generator/road_access_generator.cpp +++ b/generator/road_access_generator.cpp @@ -292,21 +292,21 @@ void RoadAccessTagProcessor::Process(OsmElement const & elem, ofstream & oss) { // We will process all nodes before ways because of o5m format: // all nodes are first, then all ways, then all relations. - if (elem.type == OsmElement::EntityType::Node) + if (elem.m_type == OsmElement::EntityType::Node) { RoadAccess::Type accessType = GetAccessType(elem); if (accessType != RoadAccess::Type::Yes) - m_barriers[elem.id] = accessType; + m_barriers[elem.m_id] = accessType; return; } - if (elem.type != OsmElement::EntityType::Way) + if (elem.m_type != OsmElement::EntityType::Way) return; // All feature tags. auto const accessType = GetAccessType(elem); if (accessType != RoadAccess::Type::Yes) - oss << ToString(m_vehicleType) << " " << ToString(accessType) << " " << elem.id << " " + oss << ToString(m_vehicleType) << " " << ToString(accessType) << " " << elem.m_id << " " << 0 /* wildcard segment Idx */ << endl; // Barrier tags. diff --git a/generator/tag_admixer.hpp b/generator/tag_admixer.hpp index 24f9ce928b..971d2e41c9 100644 --- a/generator/tag_admixer.hpp +++ b/generator/tag_admixer.hpp @@ -108,13 +108,13 @@ public: void operator()(OsmElement & element) { - if (element.type == OsmElement::EntityType::Way && m_ways.find(element.id) != m_ways.end()) + if (element.m_type == OsmElement::EntityType::Way && m_ways.find(element.m_id) != m_ways.end()) { // Exclude ferry routes. if (find(element.Tags().begin(), element.Tags().end(), m_ferryTag) == element.Tags().end()) - element.AddTag("highway", m_ways[element.id]); + element.AddTag("highway", m_ways[element.m_id]); } - else if (element.type == OsmElement::EntityType::Node && m_capitals.find(element.id) != m_capitals.end()) + else if (element.m_type == OsmElement::EntityType::Node && m_capitals.find(element.m_id) != m_capitals.end()) { // Our goal here - to make some capitals visible in World map. // The simplest way is to upgrade population to 45000, @@ -153,11 +153,11 @@ public: strings::SimpleTokenizer iter(line, " \t=,:"); if (!iter) continue; - tag.key = *iter; + tag.m_key = *iter; ++iter; if (!iter) continue; - tag.value = *iter; + tag.m_value = *iter; values.clear(); while (++iter) @@ -176,8 +176,8 @@ public: if (it != m_entries.end()) { auto const & v = it->second; - tag.key = v[0]; - tag.value = v[1]; + tag.m_key = v[0]; + tag.m_value = v[1]; for (size_t i = 2; i < v.size(); i += 2) element.AddTag(v[i], v[i + 1]); } @@ -227,12 +227,12 @@ public: void operator()(OsmElement & element) { - std::pair elementId = {element.type, element.id}; + std::pair elementId = {element.m_type, element.m_id}; auto elements = m_elements.find(elementId); if (elements != m_elements.end()) { for (OsmElement::Tag tag : elements->second) - element.UpdateTag(tag.key, [&tag](std::string & v) { v = tag.value; }); + element.UpdateTag(tag.m_key, [&tag](std::string & v) { v = tag.m_value; }); } } }; diff --git a/generator/towns_dumper.cpp b/generator/towns_dumper.cpp index 87073f1cfd..9e96f9a666 100644 --- a/generator/towns_dumper.cpp +++ b/generator/towns_dumper.cpp @@ -60,7 +60,7 @@ void TownsDumper::FilterTowns() void TownsDumper::CheckElement(OsmElement const & em) { - if (em.type != OsmElement::EntityType::Node) + if (em.m_type != OsmElement::EntityType::Node) return; uint64_t population = 1; @@ -69,7 +69,8 @@ void TownsDumper::CheckElement(OsmElement const & em) int admin_level = std::numeric_limits::max(); for (auto const & tag : em.Tags()) { - std::string key(tag.key), value(tag.value); + auto const & key = tag.m_key; + auto const & value = tag.m_value; if (key == "population") { if (!strings::to_uint64(value, population)) @@ -95,7 +96,7 @@ void TownsDumper::CheckElement(OsmElement const & em) capital = false; if (town || capital) - m_records.emplace_back(em.lat, em.lon, em.id, capital, population); + m_records.emplace_back(em.m_lat, em.m_lon, em.m_id, capital, population); } void TownsDumper::Dump(std::string const & filePath) diff --git a/generator/translator_country.cpp b/generator/translator_country.cpp index 2050d65714..4c486e113f 100644 --- a/generator/translator_country.cpp +++ b/generator/translator_country.cpp @@ -104,9 +104,9 @@ void TranslatorCountry::CollectFromRelations(OsmElement const & element) { RelationCollector collector(m_collectors); if (element.IsNode()) - m_cache.ForEachRelationByNodeCached(element.id, collector); + m_cache.ForEachRelationByNodeCached(element.m_id, collector); else if (element.IsWay()) - m_cache.ForEachRelationByWayCached(element.id, collector); + m_cache.ForEachRelationByWayCached(element.m_id, collector); } TranslatorCountryWithAds::TranslatorCountryWithAds(std::shared_ptr emitter, diff --git a/generator/translator_region.cpp b/generator/translator_region.cpp index 8a0222146d..90a82ef093 100644 --- a/generator/translator_region.cpp +++ b/generator/translator_region.cpp @@ -24,10 +24,10 @@ public: { for (auto const & t : element.Tags()) { - if (t.key == "place" && regions::EncodePlaceType(t.value) != regions::PlaceType::Unknown) + if (t.m_key == "place" && regions::EncodePlaceType(t.m_value) != regions::PlaceType::Unknown) return true; - if (t.key == "boundary" && t.value == "administrative") + if (t.m_key == "boundary" && t.m_value == "administrative") return true; }