diff --git a/generator/generator_tests/intermediate_data_test.cpp b/generator/generator_tests/intermediate_data_test.cpp index 4a534ef..206cdae 100644 --- a/generator/generator_tests/intermediate_data_test.cpp +++ b/generator/generator_tests/intermediate_data_test.cpp @@ -30,7 +30,7 @@ using namespace generator; using namespace std; using namespace std::literals; -using OsmFormatParser = std::function)>; +using OsmFormatParser = std::function)>; UNIT_TEST(Intermediate_Data_empty_way_element_save_load_test) { @@ -130,10 +130,10 @@ std::vector ReadOsmElements( auto stream = std::fstream{filename}; SourceReader reader(stream); - parser(reader, [&elements, type](OsmElement * e) + parser(reader, [&elements, type](OsmElement && e) { - if (e->m_type == type) - elements.push_back(*e); + if (e.m_type == type) + elements.push_back(std::move(e)); }); return elements; diff --git a/generator/generator_tests/source_to_element_test.cpp b/generator/generator_tests/source_to_element_test.cpp index 67365a7..e75f48c 100644 --- a/generator/generator_tests/source_to_element_test.cpp +++ b/generator/generator_tests/source_to_element_test.cpp @@ -19,9 +19,9 @@ UNIT_TEST(Source_To_Element_create_from_xml_test) SourceReader reader(ss); std::vector elements; - ProcessOsmElementsFromXML(reader, [&elements](OsmElement * e) + ProcessOsmElementsFromXML(reader, [&elements](OsmElement && e) { - elements.push_back(*e); + elements.push_back(std::move(e)); }); TEST_EQUAL(elements.size(), 10, (elements)); @@ -34,9 +34,9 @@ UNIT_TEST(Source_To_Element_create_from_o5m_test) SourceReader reader(ss); std::vector elements; - ProcessOsmElementsFromO5M(reader, [&elements](OsmElement * e) + ProcessOsmElementsFromO5M(reader, [&elements](OsmElement && e) { - elements.push_back(*e); + elements.push_back(std::move(e)); }); TEST_EQUAL(elements.size(), 11, (elements)); @@ -49,9 +49,9 @@ UNIT_TEST(Source_To_Element_check_equivalence) SourceReader readerXML(ss1); std::vector elementsXML; - ProcessOsmElementsFromXML(readerXML, [&elementsXML](OsmElement * e) + ProcessOsmElementsFromXML(readerXML, [&elementsXML](OsmElement && e) { - elementsXML.push_back(*e); + elementsXML.push_back(std::move(e)); }); std::string src(std::begin(relation_o5m_data), std::end(relation_o5m_data)); @@ -59,9 +59,9 @@ UNIT_TEST(Source_To_Element_check_equivalence) SourceReader readerO5M(ss2); std::vector elementsO5M; - ProcessOsmElementsFromO5M(readerO5M, [&elementsO5M](OsmElement * e) + ProcessOsmElementsFromO5M(readerO5M, [&elementsO5M](OsmElement && e) { - elementsO5M.push_back(*e); + elementsO5M.push_back(std::move(e)); }); TEST_EQUAL(elementsXML.size(), elementsO5M.size(), ()); diff --git a/generator/osm_source.cpp b/generator/osm_source.cpp index fb35272..0e03331 100644 --- a/generator/osm_source.cpp +++ b/generator/osm_source.cpp @@ -49,29 +49,29 @@ uint64_t SourceReader::Read(char * buffer, uint64_t bufferSize) // Functions --------------------------------------------------------------------------------------- -void BuildIntermediateNode(OsmElement const & element, NodeElement & node) +void BuildIntermediateNode(OsmElement && element, NodeElement & node) { auto position = MercatorBounds::FromLatLon(element.m_lat, element.m_lon); node = {element.m_id, position.y, position.x}; } -bool BuildIntermediateWay(OsmElement const & element, WayElement & way) +bool BuildIntermediateWay(OsmElement && element, WayElement & way) { way.m_wayOsmId = element.m_id; - way.nodes = element.Nodes(); + way.nodes = std::move(element.Nodes()); return way.IsValid(); } -bool BuildIntermediateRelation(OsmElement const & element, RelationElement & relation) +bool BuildIntermediateRelation(OsmElement && element, RelationElement & relation) { - for (auto const & member : element.Members()) + for (auto & member : element.Members()) { switch (member.m_type) { case OsmElement::EntityType::Node: - relation.nodes.emplace_back(member.m_ref, string(member.m_role)); + relation.nodes.emplace_back(member.m_ref, std::move(member.m_role)); break; case OsmElement::EntityType::Way: - relation.ways.emplace_back(member.m_ref, string(member.m_role)); + relation.ways.emplace_back(member.m_ref, std::move(member.m_role)); break; case OsmElement::EntityType::Relation: // we just ignore type == "relation" @@ -81,37 +81,39 @@ bool BuildIntermediateRelation(OsmElement const & element, RelationElement & rel } } - for (auto const & tag : element.Tags()) - relation.tags.emplace(tag.m_key, tag.m_value); + for (auto & tag : element.Tags()) + relation.tags.emplace(std::move(tag.m_key), std::move(tag.m_value)); return relation.IsValid(); } -void AddElementToCache(cache::IntermediateDataWriter & cache, OsmElement & element) +void AddElementToCache(cache::IntermediateDataWriter & cache, OsmElement && element) { switch (element.m_type) { case OsmElement::EntityType::Node: { NodeElement node; - BuildIntermediateNode(element, node); + BuildIntermediateNode(std::move(element), node); cache.AddNode(node.m_nodeOsmId, node.m_lat, node.m_lon); break; } case OsmElement::EntityType::Way: { // Store way. - WayElement way(element.m_id); - if (BuildIntermediateWay(element, way)) - cache.AddWay(element.m_id, way); + auto const id = element.m_id; + WayElement way(id); + if (BuildIntermediateWay(std::move(element), way)) + cache.AddWay(id, way); break; } case OsmElement::EntityType::Relation: { // store relation + auto const id = element.m_id; RelationElement relation; - if (BuildIntermediateRelation(element, relation)) - cache.AddRelation(element.m_id, relation); + if (BuildIntermediateRelation(std::move(element), relation)) + cache.AddRelation(id, relation); break; } default: @@ -127,7 +129,7 @@ void BuildIntermediateDataFromXML(SourceReader & stream, cache::IntermediateData while (processorOsmElementsFromXml.TryRead(element)) { towns.CheckElement(element); - AddElementToCache(cache, element); + AddElementToCache(cache, std::move(element)); } } @@ -138,20 +140,20 @@ void BuildIntermediateDataFromXML( BuildIntermediateDataFromXML(reader, cache, towns); } -void ProcessOsmElementsFromXML(SourceReader & stream, function processor) +void ProcessOsmElementsFromXML(SourceReader & stream, function processor) { ProcessorOsmElementsFromXml processorOsmElementsFromXml(stream); OsmElement element; while (processorOsmElementsFromXml.TryRead(element)) - processor(&element); + processor(std::move(element)); } void BuildIntermediateDataFromO5M(SourceReader & stream, cache::IntermediateDataWriter & cache, TownsDumper & towns) { - auto processor = [&](OsmElement * element) { - towns.CheckElement(*element); - AddElementToCache(cache, *element); + auto processor = [&](OsmElement && element) { + towns.CheckElement(element); + AddElementToCache(cache, std::move(element)); }; // Use only this function here, look into ProcessOsmElementsFromO5M @@ -177,13 +179,13 @@ void BuildIntermediateDataFromO5M( BuildIntermediateDataFromO5M(reader, cache, towns); } -void ProcessOsmElementsFromO5M(SourceReader & stream, function processor) +void ProcessOsmElementsFromO5M(SourceReader & stream, function processor) { ProcessorOsmElementsFromO5M processorOsmElementsFromO5M(stream); OsmElement element; while (processorOsmElementsFromO5M.TryRead(element)) - processor(&element); + processor(std::move(element)); } ProcessorOsmElementsFromO5M::ProcessorOsmElementsFromO5M(SourceReader & stream) diff --git a/generator/osm_source.hpp b/generator/osm_source.hpp index 9c82108..6079d90 100644 --- a/generator/osm_source.hpp +++ b/generator/osm_source.hpp @@ -45,8 +45,8 @@ public: bool GenerateIntermediateData(feature::GenerateInfo & info); -void ProcessOsmElementsFromO5M(SourceReader & stream, std::function processor); -void ProcessOsmElementsFromXML(SourceReader & stream, std::function processor); +void ProcessOsmElementsFromO5M(SourceReader & stream, std::function processor); +void ProcessOsmElementsFromXML(SourceReader & stream, std::function processor); class ProcessorOsmElementsInterface {