Merge pull request #1312 from joto/const
Some cleanups in the extractor code.
This commit is contained in:
		
						commit
						cb79f769c9
					
				@ -117,14 +117,14 @@ int Extractor::Run(int argc, char *argv[])
 | 
				
			|||||||
        auto extractor_callbacks =
 | 
					        auto extractor_callbacks =
 | 
				
			||||||
            osrm::make_unique<ExtractorCallbacks>(extraction_containers, string_map);
 | 
					            osrm::make_unique<ExtractorCallbacks>(extraction_containers, string_map);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        osmium::io::File input_file(extractor_config.input_path.string());
 | 
					        const osmium::io::File input_file(extractor_config.input_path.string());
 | 
				
			||||||
        osmium::io::Reader reader(input_file);
 | 
					        osmium::io::Reader reader(input_file);
 | 
				
			||||||
        osmium::io::Header header = reader.header();
 | 
					        const osmium::io::Header header = reader.header();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        unsigned number_of_nodes = 0;
 | 
					        std::atomic<unsigned> number_of_nodes {0};
 | 
				
			||||||
        unsigned number_of_ways = 0;
 | 
					        std::atomic<unsigned> number_of_ways {0};
 | 
				
			||||||
        unsigned number_of_relations = 0;
 | 
					        std::atomic<unsigned> number_of_relations {0};
 | 
				
			||||||
        unsigned number_of_others = 0;
 | 
					        std::atomic<unsigned> number_of_others {0};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        SimpleLogger().Write() << "Parsing in progress..";
 | 
					        SimpleLogger().Write() << "Parsing in progress..";
 | 
				
			||||||
        TIMER_START(parsing);
 | 
					        TIMER_START(parsing);
 | 
				
			||||||
@ -155,17 +155,14 @@ int Extractor::Run(int argc, char *argv[])
 | 
				
			|||||||
            resulting_restrictions;
 | 
					            resulting_restrictions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // setup restriction parser
 | 
					        // setup restriction parser
 | 
				
			||||||
        RestrictionParser restriction_parser(scripting_environment.getLuaState());
 | 
					        const RestrictionParser restriction_parser(scripting_environment.getLuaState());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        while (osmium::memory::Buffer buffer = reader.read())
 | 
					        while (const osmium::memory::Buffer buffer = reader.read())
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            // create a vector of iterators into the buffer
 | 
					            // create a vector of iterators into the buffer
 | 
				
			||||||
            std::vector<osmium::memory::Buffer::iterator> osm_elements;
 | 
					            std::vector<osmium::memory::Buffer::const_iterator> osm_elements;
 | 
				
			||||||
            osmium::memory::Buffer::iterator iter = std::begin(buffer);
 | 
					            for (auto iter = std::begin(buffer); iter != std::end(buffer); ++iter) {
 | 
				
			||||||
            while (iter != std::end(buffer))
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                osm_elements.push_back(iter);
 | 
					                osm_elements.push_back(iter);
 | 
				
			||||||
                iter = std::next(iter);
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // clear resulting vectors
 | 
					            // clear resulting vectors
 | 
				
			||||||
@ -179,7 +176,7 @@ int Extractor::Run(int argc, char *argv[])
 | 
				
			|||||||
                              {
 | 
					                              {
 | 
				
			||||||
                for (auto x = range.begin(); x != range.end(); ++x)
 | 
					                for (auto x = range.begin(); x != range.end(); ++x)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    auto entity = osm_elements[x];
 | 
					                    const auto entity = osm_elements[x];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    ExtractionNode result_node;
 | 
					                    ExtractionNode result_node;
 | 
				
			||||||
                    ExtractionWay result_way;
 | 
					                    ExtractionWay result_way;
 | 
				
			||||||
@ -191,7 +188,7 @@ int Extractor::Run(int argc, char *argv[])
 | 
				
			|||||||
                        luabind::call_function<void>(
 | 
					                        luabind::call_function<void>(
 | 
				
			||||||
                            scripting_environment.getLuaState(),
 | 
					                            scripting_environment.getLuaState(),
 | 
				
			||||||
                            "node_function",
 | 
					                            "node_function",
 | 
				
			||||||
                            boost::cref(static_cast<osmium::Node &>(*entity)),
 | 
					                            boost::cref(static_cast<const osmium::Node &>(*entity)),
 | 
				
			||||||
                            boost::ref(result_node));
 | 
					                            boost::ref(result_node));
 | 
				
			||||||
                        resulting_nodes.push_back(std::make_pair(x, result_node));
 | 
					                        resulting_nodes.push_back(std::make_pair(x, result_node));
 | 
				
			||||||
                        break;
 | 
					                        break;
 | 
				
			||||||
@ -200,14 +197,14 @@ int Extractor::Run(int argc, char *argv[])
 | 
				
			|||||||
                        luabind::call_function<void>(
 | 
					                        luabind::call_function<void>(
 | 
				
			||||||
                            scripting_environment.getLuaState(),
 | 
					                            scripting_environment.getLuaState(),
 | 
				
			||||||
                            "way_function",
 | 
					                            "way_function",
 | 
				
			||||||
                            boost::cref(static_cast<osmium::Way &>(*entity)),
 | 
					                            boost::cref(static_cast<const osmium::Way &>(*entity)),
 | 
				
			||||||
                            boost::ref(result_way));
 | 
					                            boost::ref(result_way));
 | 
				
			||||||
                        resulting_ways.push_back(std::make_pair(x, result_way));
 | 
					                        resulting_ways.push_back(std::make_pair(x, result_way));
 | 
				
			||||||
                        break;
 | 
					                        break;
 | 
				
			||||||
                    case osmium::item_type::relation:
 | 
					                    case osmium::item_type::relation:
 | 
				
			||||||
                        ++number_of_relations;
 | 
					                        ++number_of_relations;
 | 
				
			||||||
                        resulting_restrictions.push_back(
 | 
					                        resulting_restrictions.push_back(
 | 
				
			||||||
                            restriction_parser.TryParse(static_cast<osmium::Relation &>(*entity)));
 | 
					                            restriction_parser.TryParse(static_cast<const osmium::Relation &>(*entity)));
 | 
				
			||||||
                        break;
 | 
					                        break;
 | 
				
			||||||
                    default:
 | 
					                    default:
 | 
				
			||||||
                        ++number_of_others;
 | 
					                        ++number_of_others;
 | 
				
			||||||
@ -220,12 +217,12 @@ int Extractor::Run(int argc, char *argv[])
 | 
				
			|||||||
            for (const auto &result : resulting_nodes)
 | 
					            for (const auto &result : resulting_nodes)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                extractor_callbacks->ProcessNode(
 | 
					                extractor_callbacks->ProcessNode(
 | 
				
			||||||
                    static_cast<osmium::Node &>(*(osm_elements[result.first])), result.second);
 | 
					                    static_cast<const osmium::Node &>(*(osm_elements[result.first])), result.second);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            for (const auto &result : resulting_ways)
 | 
					            for (const auto &result : resulting_ways)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                extractor_callbacks->ProcessWay(
 | 
					                extractor_callbacks->ProcessWay(
 | 
				
			||||||
                    static_cast<osmium::Way &>(*(osm_elements[result.first])), result.second);
 | 
					                    static_cast<const osmium::Way &>(*(osm_elements[result.first])), result.second);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            for (const auto &result : resulting_restrictions)
 | 
					            for (const auto &result : resulting_restrictions)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
@ -234,9 +231,16 @@ int Extractor::Run(int argc, char *argv[])
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        TIMER_STOP(parsing);
 | 
					        TIMER_STOP(parsing);
 | 
				
			||||||
        SimpleLogger().Write() << "Parsing finished after " << TIMER_SEC(parsing) << " seconds";
 | 
					        SimpleLogger().Write() << "Parsing finished after " << TIMER_SEC(parsing) << " seconds";
 | 
				
			||||||
        SimpleLogger().Write() << "Raw input contains " << number_of_nodes << " nodes, "
 | 
					
 | 
				
			||||||
                               << number_of_ways << " ways, and " << number_of_relations
 | 
					        unsigned nn = number_of_nodes;
 | 
				
			||||||
                               << " relations, and " << number_of_others << " unknown entities";
 | 
					        unsigned nw = number_of_ways;
 | 
				
			||||||
 | 
					        unsigned nr = number_of_relations;
 | 
				
			||||||
 | 
					        unsigned no = number_of_others;
 | 
				
			||||||
 | 
					        SimpleLogger().Write() << "Raw input contains "
 | 
				
			||||||
 | 
					                               << nn << " nodes, "
 | 
				
			||||||
 | 
					                               << nw << " ways, and "
 | 
				
			||||||
 | 
					                               << nr << " relations, and "
 | 
				
			||||||
 | 
					                               << no << " unknown entities";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        extractor_callbacks.reset();
 | 
					        extractor_callbacks.reset();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -102,7 +102,7 @@ void RestrictionParser::ReadRestrictionExceptions(lua_State *lua_state)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
mapbox::util::optional<InputRestrictionContainer>
 | 
					mapbox::util::optional<InputRestrictionContainer>
 | 
				
			||||||
RestrictionParser::TryParse(osmium::Relation &relation) const
 | 
					RestrictionParser::TryParse(const osmium::Relation &relation) const
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    // return if turn restrictions should be ignored
 | 
					    // return if turn restrictions should be ignored
 | 
				
			||||||
    if (!use_turn_restrictions)
 | 
					    if (!use_turn_restrictions)
 | 
				
			||||||
 | 
				
			|||||||
@ -46,7 +46,7 @@ class RestrictionParser
 | 
				
			|||||||
  public:
 | 
					  public:
 | 
				
			||||||
    // RestrictionParser(ScriptingEnvironment &scripting_environment);
 | 
					    // RestrictionParser(ScriptingEnvironment &scripting_environment);
 | 
				
			||||||
    RestrictionParser(lua_State *lua_state);
 | 
					    RestrictionParser(lua_State *lua_state);
 | 
				
			||||||
    mapbox::util::optional<InputRestrictionContainer> TryParse(osmium::Relation &relation) const;
 | 
					    mapbox::util::optional<InputRestrictionContainer> TryParse(const osmium::Relation &relation) const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private:
 | 
					  private:
 | 
				
			||||||
    void ReadUseRestrictionsSetting(lua_State *lua_state);
 | 
					    void ReadUseRestrictionsSetting(lua_State *lua_state);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user