reformat Extractor

This commit is contained in:
Dennis Luxen 2014-11-18 19:03:44 +01:00
parent 8e73a4a19d
commit 3b9c6a6465

View File

@ -122,15 +122,19 @@ int Extractor::Run(int argc, char *argv[])
// { // {
// SimpleLogger().Write(logWARNING) << "The recommended number of threads is " // SimpleLogger().Write(logWARNING) << "The recommended number of threads is "
// << recommended_num_threads // << recommended_num_threads
// << "! This setting may have performance side-effects."; // << "! This setting may have performance
// side-effects.";
// } // }
auto number_of_threads = std::max(1, auto number_of_threads =
std::min(static_cast<int>(recommended_num_threads), static_cast<int>(extractor_config.requested_num_threads)) ); std::max(1,
std::min(static_cast<int>(recommended_num_threads),
static_cast<int>(extractor_config.requested_num_threads)));
tbb::task_scheduler_init init(number_of_threads); tbb::task_scheduler_init init(number_of_threads);
SimpleLogger().Write() << "requested_num_threads: " << extractor_config.requested_num_threads; SimpleLogger().Write() << "requested_num_threads: "
<< extractor_config.requested_num_threads;
SimpleLogger().Write() << "number_of_threads: " << number_of_threads; SimpleLogger().Write() << "number_of_threads: " << number_of_threads;
// setup scripting environment // setup scripting environment
@ -180,7 +184,8 @@ int Extractor::Run(int argc, char *argv[])
// initialize vectors holding parsed objects // initialize vectors holding parsed objects
tbb::concurrent_vector<std::pair<std::size_t, ExtractionNode>> resulting_nodes; tbb::concurrent_vector<std::pair<std::size_t, ExtractionNode>> resulting_nodes;
tbb::concurrent_vector<std::pair<std::size_t, ExtractionWay>> resulting_ways; tbb::concurrent_vector<std::pair<std::size_t, ExtractionWay>> resulting_ways;
tbb::concurrent_vector<mapbox::util::optional<InputRestrictionContainer>> resulting_restrictions; tbb::concurrent_vector<mapbox::util::optional<InputRestrictionContainer>>
resulting_restrictions;
// setup restriction parser // setup restriction parser
RestrictionParser restriction_parser(scripting_environment.getLuaState()); RestrictionParser restriction_parser(scripting_environment.getLuaState());
@ -190,7 +195,7 @@ int Extractor::Run(int argc, char *argv[])
// create a vector of iterators into the buffer // create a vector of iterators into the buffer
std::vector<osmium::memory::Buffer::iterator> elements; std::vector<osmium::memory::Buffer::iterator> elements;
osmium::memory::Buffer::iterator iter = std::begin(buffer); osmium::memory::Buffer::iterator iter = std::begin(buffer);
while(iter != std::end(buffer)) while (iter != std::end(buffer))
{ {
elements.push_back(iter); elements.push_back(iter);
iter = std::next(iter); iter = std::next(iter);
@ -205,57 +210,60 @@ int Extractor::Run(int argc, char *argv[])
// parse OSM entities in parallel, store in resulting vectors // parse OSM entities in parallel, store in resulting vectors
tbb::parallel_for(tbb::blocked_range<std::size_t>(0, elements.size()), tbb::parallel_for(tbb::blocked_range<std::size_t>(0, elements.size()),
[&](const tbb::blocked_range<std::size_t>& range) [&](const tbb::blocked_range<std::size_t> &range)
{
for (auto x = range.begin(); x != range.end(); ++x)
{ {
for (auto x = range.begin(); x != range.end(); ++x) auto entity = elements[x];
{
auto entity = elements[x];
ExtractionNode result_node; ExtractionNode result_node;
ExtractionWay result_way; ExtractionWay result_way;
switch (entity->type()) switch (entity->type())
{ {
case osmium::item_type::node: case osmium::item_type::node:
++number_of_nodes; ++number_of_nodes;
result_node.Clear(); result_node.Clear();
luabind::call_function<void>(scripting_environment.getLuaState(), luabind::call_function<void>(
"node_function", scripting_environment.getLuaState(),
boost::cref(static_cast<osmium::Node &>(*entity)), "node_function",
boost::ref(result_node)); boost::cref(static_cast<osmium::Node &>(*entity)),
resulting_nodes.emplace_back(x, result_node); boost::ref(result_node));
break; resulting_nodes.emplace_back(x, result_node);
case osmium::item_type::way: break;
++number_of_ways; case osmium::item_type::way:
result_way.Clear(); ++number_of_ways;
luabind::call_function<void>(scripting_environment.getLuaState(), result_way.Clear();
"way_function", luabind::call_function<void>(
boost::cref(static_cast<osmium::Way &>(*entity)), scripting_environment.getLuaState(),
boost::ref(result_way)); "way_function",
resulting_ways.emplace_back(x, result_way); boost::cref(static_cast<osmium::Way &>(*entity)),
break; boost::ref(result_way));
case osmium::item_type::relation: resulting_ways.emplace_back(x, result_way);
++number_of_relations; break;
resulting_restrictions.emplace_back(restriction_parser.TryParse(scripting_environment.getLuaState(), static_cast<osmium::Relation &>(*entity))); case osmium::item_type::relation:
break; ++number_of_relations;
default: resulting_restrictions.emplace_back(
++number_of_others; restriction_parser.TryParse(scripting_environment.getLuaState(),
break; static_cast<osmium::Relation &>(*entity)));
break;
default:
++number_of_others;
break;
}
} }
} });
}
);
// put parsed objects thru extractor callbacks // put parsed objects thru extractor callbacks
for (const auto &result : resulting_nodes) for (const auto &result : resulting_nodes)
{ {
extractor_callbacks->ProcessNode(static_cast<osmium::Node &>(*(elements[result.first])), extractor_callbacks->ProcessNode(
result.second); static_cast<osmium::Node &>(*(elements[result.first])), result.second);
} }
for (const auto &result : resulting_ways) for (const auto &result : resulting_ways)
{ {
extractor_callbacks->ProcessWay(static_cast<osmium::Way &>(*(elements[result.first])), extractor_callbacks->ProcessWay(
result.second); static_cast<osmium::Way &>(*(elements[result.first])), result.second);
} }
for (const auto &result : resulting_restrictions) for (const auto &result : resulting_restrictions)
{ {