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 2632197 q Item_Constraint(Item_Statement& item_) : item(&item_) {} 2811093 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) 4922491 q for (typename std::map< TIndex, std::vector< TObject > >::const_iterator iit = from.begin(); 506148791 q iit != from.end(); ++iit) 545717758 q for (typename std::vector< TObject >::const_iterator cit = iit->second.begin(); 5535662458 q cit != iit->second.end(); ++cit) 5629944754 q into[iit->first].push_back(*cit); 5840869 q else if (!invert_ids) 6040869 q for (typename std::vector< TObject >::const_iterator cit = iit->second.begin(); 612349399 q cit != iit->second.end(); ++cit) 632308537 q if (binary_search(ids.begin(), ids.end(), cit->id)) 6454 q 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) 834034 q const Set* input = rman.get_set(item->get_input_name()); 864034 q collect_elements(input->nodes, into.nodes, ids, invert_ids); 874034 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) 1017461 q const Set* input = rman.get_set(item->get_input_name()); 1064134 q collect_elements(input->ways, into.ways, ids, invert_ids); 1074134 q collect_elements(input->attic_ways, into.attic_ways, ids, invert_ids); 1097259 q if (type & QUERY_RELATION) 1113127 q collect_elements(input->relations, into.relations, ids, invert_ids); 1123127 q collect_elements(input->attic_relations, into.attic_relations, ids, invert_ids); 1150 collect_elements(input->areas, into.areas, ids, invert_ids); 12022 q into.attic_ways.clear(); 12122 q into.relations.clear(); 12222 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) 14311093 q const Set* input = rman.get_set(item->get_input_name()); 14610891 q item_filter_map(into.nodes, input->nodes); 14710891 q item_filter_map(into.attic_nodes, input->attic_nodes); 14810891 q item_filter_map(into.ways, input->ways); 14910891 q item_filter_map(into.attic_ways, input->attic_ways); 15010891 q item_filter_map(into.relations, input->relations); 15110891 q item_filter_map(into.attic_relations, input->attic_relations); 15210891 q item_filter_map(into.areas, input->areas); 15310891 q item_filter_map(into.deriveds, input->deriveds); 15822 q into.attic_nodes.clear(); 16022 q into.attic_ways.clear(); 16122 q into.relations.clear(); 16222 q into.attic_relations.clear(); 16422 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) 174651159 q : Output_Statement(line_number_) 176651159 q std::map< std::string, std::string > attributes; 182651159 q eval_attributes_array(get_name(), attributes, input_attributes); 184651159 q if (attributes["set"] == "_") 187651159 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) 20216271 q if (input != get_result_name()) 20614570 q const Set* input_set = rman.get_set(input); 21014570 q transfer_output(rman, into); 215Item_Statement::~Item_Statement() 217651159 q for (std::vector< Query_Constraint* >::const_iterator it = constraints.begin(); 218972159 q it != constraints.end(); ++it) 223Query_Constraint* Item_Statement::get_query_constraint() 22532197 q constraints.push_back(new Item_Constraint(*this)); 22632197 q return constraints.back();