1/** Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Roland Olbricht et al. 3 * This file is part of Overpass_API. 5 * Overpass_API is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU Affero General Public License as 7 * published by the Free Software Foundation, either version 3 of the 8 * License, or (at your option) any later version. 10 * Overpass_API is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 15 * You should have received a copy of the GNU Affero General Public License 16 * along with Overpass_API. If not, see <http://www.gnu.org/licenses/>. 19#include "../data/tag_store.h" 20#include "../data/utils.h" 25Generic_Statement_Maker< Convert_Statement > Convert_Statement::statement_maker("convert"); 28Convert_Statement::Convert_Statement 29 (int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings) 3025579 q : Output_Statement(line_number_), geom_evaluator(0), id_evaluator(0), multi_evaluator(0) 3225579 q std::map< std::string, std::string > attributes; 3425579 q attributes["from"] = "_"; 3525579 q attributes["into"] = "_"; 3625579 q attributes["type"] = ""; 3825579 q eval_attributes_array(get_name(), attributes, input_attributes); 4025579 q set_output(attributes["into"]); 4225579 q input = attributes["from"]; 4425579 q if (attributes["type"] == "") 450 add_static_error("The attribute type must be set to a nonempty string."); 4625579 q type = attributes["type"]; 50Convert_Statement::~Convert_Statement() 55void Convert_Statement::add_statement(Statement* statement, std::string text) 57108379 q Set_Prop_Statement* set_prop = dynamic_cast< Set_Prop_Statement* >(statement); 60108379 q if (set_prop->get_key()) 62233779 q for (std::vector< Set_Prop_Statement* >::const_iterator it = evaluators.begin(); it != evaluators.end(); ++it) 64157273 q if ((*it)->get_key() && *(*it)->get_key() == *set_prop->get_key()) 650 add_static_error(std::string("A key cannot be added twice to an element: \"") + *set_prop->get_key() + '\"'); 6831870 q else if (set_prop->get_mode() == Set_Prop_Task::set_id) 7115649 q id_evaluator = set_prop; 730 add_static_error("A convert statement can have at most one set-prop statement of subtype setting the id."); 7516243 q else if (set_prop->get_mode() == Set_Prop_Task::set_geometry) 789030 q geom_evaluator = set_prop; 800 add_static_error("A make statement can have at most one set-prop statement of subtype setting the geometry."); 827224 q else if (!multi_evaluator) 837224 q multi_evaluator = set_prop; 850 add_static_error("A convert statement can have at most one any-key set-prop statement."); 86108379 q evaluators.push_back(set_prop); 890 substatement_error(get_name(), statement); 93template< typename Index, typename Maybe_Attic > 94void generate_elems(const std::string& set_name, 95 const std::map< Index, std::vector< Maybe_Attic > >& items, Set_With_Context& context_from, 96 Owning_Array< Set_Prop_Task* >& tasks, const std::vector< std::string >& declared_keys, 97 Set& into, Resource_Manager& rman, const std::string& type) 9935672 q for (typename std::map< Index, std::vector< Maybe_Attic > >::const_iterator it_idx = items.begin(); 1006835472 q it_idx != items.end(); ++it_idx) 1026799869 q for (typename std::vector< Maybe_Attic >::const_iterator it_elem = it_idx->second.begin(); 103101294269 q it_elem != it_idx->second.end(); ++it_elem) 10594494468 q Derived_Structure result(type, 0ull); 10694494468 q bool id_fixed = false; 108554968368 q for (uint i = 0; i < tasks.size(); ++i) 111460473968 q tasks[i]->process(context_from.get_context(it_idx->first, *it_elem), declared_keys, result, id_fixed); 11557631427 q result.id = rman.get_global_settings().dispense_derived_id(); 11794494468 q into.deriveds[Uint31_Index(0u)].push_back(result); 123void Convert_Statement::execute(Resource_Manager& rman) 1258473 q std::vector< std::string > declared_keys; 12643273 q for (std::vector< Set_Prop_Statement* >::const_iterator it = evaluators.begin(); it != evaluators.end(); ++it) 12924373 q declared_keys.push_back(*(*it)->get_key()); 1318473 q std::sort(declared_keys.begin(), declared_keys.end()); 1328473 q declared_keys.erase(std::unique(declared_keys.begin(), declared_keys.end()), declared_keys.end()); 1348473 q Requested_Context requested_context; 13543273 q for (std::vector< Set_Prop_Statement* >::const_iterator it = evaluators.begin(); it != evaluators.end(); ++it) 13634873 q requested_context.add((*it)->request_context()); 1378473 q requested_context.bind(input); 1398473 q Prepare_Task_Context context(requested_context, *this, rman); 1418473 q Owning_Array< Set_Prop_Task* > tasks; 14243273 q for (std::vector< Set_Prop_Statement* >::const_iterator it = evaluators.begin(); it != evaluators.end(); ++it) 14334873 q tasks.push_back((*it)->get_task(context, declared_keys)); 1468473 q Set_With_Context* context_from = context.get_set(input); 1488473 q if (context_from && context_from->base) 1508372 q generate_elems< Uint32_Index, Node_Skeleton >( 1518372 q context_from->name, context_from->base->nodes, *context_from, tasks, 1528372 q declared_keys, into, rman, type); 1538372 q if (!context_from->base->attic_nodes.empty()) 15455 q generate_elems< Uint32_Index, Attic< Node_Skeleton > >( 15555 q context_from->name, context_from->base->attic_nodes, *context_from, tasks, 15655 q declared_keys, into, rman, type); 1578372 q generate_elems< Uint31_Index, Way_Skeleton >( 1588372 q context_from->name, context_from->base->ways, *context_from, tasks, 1598372 q declared_keys, into, rman, type); 1608372 q if (!context_from->base->attic_ways.empty()) 161108 q generate_elems< Uint31_Index, Attic< Way_Skeleton > >( 162108 q context_from->name, context_from->base->attic_ways, *context_from, tasks, 163108 q declared_keys, into, rman, type); 1648372 q generate_elems< Uint31_Index, Relation_Skeleton >( 1658372 q context_from->name, context_from->base->relations, *context_from, tasks, 1668372 q declared_keys, into, rman, type); 1678372 q if (!context_from->base->attic_relations.empty()) 16844 q generate_elems< Uint31_Index, Attic< Relation_Skeleton > >( 16944 q context_from->name, context_from->base->attic_relations, *context_from, tasks, 17044 q declared_keys, into, rman, type); 1718372 q if (!context_from->base->areas.empty()) 17255 q generate_elems< Uint31_Index, Area_Skeleton >( 17355 q context_from->name, context_from->base->areas, *context_from, tasks, 17455 q declared_keys, into, rman, type); 1758372 q generate_elems< Uint31_Index, Derived_Structure >( 1768372 q context_from->name, context_from->base->deriveds, *context_from, tasks, 1778372 q declared_keys, into, rman, type); 1808473 q transfer_output(rman, into); 1818473 q rman.health_check(*this);