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/collect_members.h" 23class Item_Constraint : public Query_Constraint 2624972 q Item_Constraint(Item_Statement& item_) : item(&item_) {} 288267 q Query_Filter_Strategy delivers_data(Resource_Manager& rman) { return prefer_ranges; } 30 bool collect_nodes(Resource_Manager& rman, Set& into, 31 const std::vector< Uint64 >& ids, bool invert_ids); 32 bool collect(Resource_Manager& rman, Set& into, int type, 33 const std::vector< Uint32_Index >& ids, bool invert_ids); 34 bool collect(Resource_Manager& rman, Set& into); 35 void filter(Resource_Manager& rman, Set& into); 360 virtual ~Item_Constraint() {} 43template< typename TIndex, typename TObject > 44void collect_elements(const std::map< TIndex, std::vector< TObject > >& from, 45 std::map< TIndex, std::vector< TObject > >& into, 46 const std::vector< typename TObject::Id_Type >& ids, bool invert_ids) 4917066 q for (typename std::map< TIndex, std::vector< TObject > >::const_iterator iit = from.begin(); 5018290866 q iit != from.end(); ++iit) 5417895846 q for (typename std::vector< TObject >::const_iterator cit = iit->second.begin(); 55132059146 q cit != iit->second.end(); ++cit) 56114163346 q into[iit->first].push_back(*cit); 5837809 q else if (!invert_ids) 6037809 q for (typename std::vector< TObject >::const_iterator cit = iit->second.begin(); 611878849 q cit != iit->second.end(); ++cit) 631841049 q if (binary_search(ids.begin(), ids.end(), cit->id)) 640 into[iit->first].push_back(*cit); 690 for (typename std::vector< TObject >::const_iterator cit = iit->second.begin(); 700 cit != iit->second.end(); ++cit) 720 if (!binary_search(ids.begin(), ids.end(), cit->id)) 730 into[iit->first].push_back(*cit); 80bool Item_Constraint::collect_nodes(Resource_Manager& rman, Set& into, 81 const std::vector< Uint64 >& ids, bool invert_ids) 832519 q const Set* input = rman.get_set(item->get_input_name()); 862519 q collect_elements(input->nodes, into.nodes, ids, invert_ids); 872519 q collect_elements(input->attic_nodes, into.attic_nodes, ids, invert_ids); 920 into.attic_nodes.clear(); 98bool Item_Constraint::collect(Resource_Manager& rman, Set& into, 99 int type, const std::vector< Uint32_Index >& ids, bool invert_ids) 1016152 q const Set* input = rman.get_set(item->get_input_name()); 1063733 q collect_elements(input->ways, into.ways, ids, invert_ids); 1073733 q collect_elements(input->attic_ways, into.attic_ways, ids, invert_ids); 1096051 q if (type & QUERY_RELATION) 1112320 q collect_elements(input->relations, into.relations, ids, invert_ids); 1122320 q collect_elements(input->attic_relations, into.attic_relations, ids, invert_ids); 1150 collect_elements(input->areas, into.areas, ids, invert_ids); 12011 q into.attic_ways.clear(); 12111 q into.relations.clear(); 12211 q into.attic_relations.clear(); 129bool Item_Constraint::collect(Resource_Manager& rman, Set& into) 1310 const Set* input = rman.get_set(item->get_input_name()); 1330 into.deriveds = input->deriveds; 1350 into.deriveds.clear(); 141void Item_Constraint::filter(Resource_Manager& rman, Set& into) 1438267 q const Set* input = rman.get_set(item->get_input_name()); 1468166 q item_filter_map(into.nodes, input->nodes); 1478166 q item_filter_map(into.attic_nodes, input->attic_nodes); 1488166 q item_filter_map(into.ways, input->ways); 1498166 q item_filter_map(into.attic_ways, input->attic_ways); 1508166 q item_filter_map(into.relations, input->relations); 1518166 q item_filter_map(into.attic_relations, input->attic_relations); 1528166 q item_filter_map(into.areas, input->areas); 1538166 q item_filter_map(into.deriveds, input->deriveds); 15811 q into.attic_nodes.clear(); 16011 q into.attic_ways.clear(); 16111 q into.relations.clear(); 16211 q into.attic_relations.clear(); 16411 q into.deriveds.clear(); 168//----------------------------------------------------------------------------- 170Generic_Statement_Maker< Item_Statement > Item_Statement::statement_maker("item"); 172Item_Statement::Item_Statement(int line_number_, const std::map< std::string, std::string >& input_attributes, 173 Parsed_Query& global_settings) 174513125 q : Output_Statement(line_number_) 176513125 q std::map< std::string, std::string > attributes; 182513125 q eval_attributes_array(get_name(), attributes, input_attributes); 184513125 q if (attributes["set"] == "_") 187513125 q set_output(attributes["into"]); 1890 else if (attributes["from"] == "_" && attributes["into"] == "_") 1910 input = attributes["set"]; 1920 set_output(attributes["set"]); 1950 add_static_error("The attribute \"set\" of the element \"item\" can only be set " 1960 "if the attributes \"from\" and \"into\" are both empty."); 200void Item_Statement::execute(Resource_Manager& rman) 20223157 q if (input != get_result_name()) 20622656 q const Set* input_set = rman.get_set(input); 21022656 q transfer_output(rman, into); 215Item_Statement::~Item_Statement() 217513125 q for (std::vector< Query_Constraint* >::const_iterator it = constraints.begin(); 218762125 q it != constraints.end(); ++it) 223Query_Constraint* Item_Statement::get_query_constraint() 22524972 q constraints.push_back(new Item_Constraint(*this)); 22624972 q return constraints.back();