inline void PBFParser::parseWay(ParserThreadData *thread_data) { const int number_of_ways = thread_data->PBFprimitiveBlock.primitivegroup(thread_data->currentGroupID).ways_size(); std::vector<ExtractionWay> parsed_way_vector(number_of_ways); for (int i = 0; i < number_of_ways; ++i) { const OSMPBF::Way &input_way = thread_data->PBFprimitiveBlock.primitivegroup(thread_data->currentGroupID).ways(i); parsed_way_vector[i].id = static_cast<EdgeID>(input_way.id()); unsigned node_id_in_path = 0; const auto number_of_referenced_nodes = input_way.refs_size(); for (auto j = 0; j < number_of_referenced_nodes; ++j) { node_id_in_path += static_cast<NodeID>(input_way.refs(j)); parsed_way_vector[i].path.push_back(node_id_in_path); } BOOST_ASSERT(input_way.keys_size() == input_way.vals_size()); const auto number_of_keys = input_way.keys_size(); for (auto j = 0; j < number_of_keys; ++j) { const std::string &key = thread_data->PBFprimitiveBlock.stringtable().s(input_way.keys(j)); const std::string &val = thread_data->PBFprimitiveBlock.stringtable().s(input_way.vals(j)); parsed_way_vector[i].keyVals.Add(std::move(key), std::move(val)); } } // TODO: investigate if schedule guided will be handled by tbb automatically tbb::parallel_for(tbb::blocked_range<size_t>(0, parsed_way_vector.size()), [this, &parsed_way_vector](const tbb::blocked_range<size_t> &range) { lua_State *lua_state = this->scripting_environment.getLuaState(); for (size_t i = range.begin(); i != range.end(); i++) { ExtractionWay &extraction_way = parsed_way_vector[i]; if (2 <= extraction_way.path.size()) { ParseWayInLua(extraction_way, lua_state); } } }); for (ExtractionWay &extraction_way : parsed_way_vector) { if (2 <= extraction_way.path.size()) { extractor_callbacks->ProcessWay(extraction_way); } } }
bool XMLParser::Parse() { while (xmlTextReaderRead(inputReader) == 1) { const int type = xmlTextReaderNodeType(inputReader); // 1 is Element if (type != 1) { continue; } xmlChar *currentName = xmlTextReaderName(inputReader); if (currentName == nullptr) { continue; } if (xmlStrEqual(currentName, (const xmlChar *)"node") == 1) { ImportNode current_node = ReadXMLNode(); ParseNodeInLua(current_node, lua_state); extractor_callbacks->ProcessNode(current_node); } if (xmlStrEqual(currentName, (const xmlChar *)"way") == 1) { ExtractionWay way = ReadXMLWay(); ParseWayInLua(way, lua_state); extractor_callbacks->ProcessWay(way); } if (use_turn_restrictions && xmlStrEqual(currentName, (const xmlChar *)"relation") == 1) { InputRestrictionContainer current_restriction = ReadXMLRestriction(); if ((UINT_MAX != current_restriction.fromWay) && !extractor_callbacks->ProcessRestriction(current_restriction)) { std::cerr << "[XMLParser] restriction not parsed" << std::endl; } } xmlFree(currentName); } return true; }
bool XMLParser::Parse() { while ( xmlTextReaderRead( inputReader ) == 1 ) { const int type = xmlTextReaderNodeType( inputReader ); //1 is Element if ( type != 1 ) { continue; } xmlChar* currentName = xmlTextReaderName( inputReader ); if ( currentName == NULL ) { continue; } if ( xmlStrEqual( currentName, ( const xmlChar* ) "node" ) == 1 ) { ImportNode n = _ReadXMLNode(); ParseNodeInLua( n, luaState ); extractor_callbacks->nodeFunction(n); // if(!extractor_callbacks->nodeFunction(n)) // std::cerr << "[XMLParser] dense node not parsed" << std::endl; } if ( xmlStrEqual( currentName, ( const xmlChar* ) "way" ) == 1 ) { ExtractionWay way = _ReadXMLWay( ); ParseWayInLua( way, luaState ); extractor_callbacks->wayFunction(way); // if(!extractor_callbacks->wayFunction(way)) // std::cerr << "[PBFParser] way not parsed" << std::endl; } if( use_turn_restrictions ) { if ( xmlStrEqual( currentName, ( const xmlChar* ) "relation" ) == 1 ) { InputRestrictionContainer r = _ReadXMLRestriction(); if(r.fromWay != UINT_MAX) { if(!extractor_callbacks->restrictionFunction(r)) { std::cerr << "[XMLParser] restriction not parsed" << std::endl; } } } } xmlFree( currentName ); } return true; }