Overpass API regression suite coverage (Saxony) / overpass_api/statements/item.cc

overpass_api/statements/item.cc

116 of 148 instrumented lines run by the suite (78.4%) at 8edf11b0419c (this file on GitHub).

runnever runcolumns: line, executions, queries (click for the queries that run the line)

1/** Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Roland Olbricht et al.
2 *
3 * This file is part of Overpass_API.
4 *
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.
9 *
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.
14 *
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/>.
17 */
19#include "../data/collect_members.h"
20#include "item.h"
23class Item_Constraint : public Query_Constraint
25 public:
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() {}
38 private:
39 Item_Statement* item;
40};
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)
4722491 q{
4822491 q into.clear();
4922491 q for (typename std::map< TIndex, std::vector< TObject > >::const_iterator iit = from.begin();
506148791 q iit != from.end(); ++iit)
516126365 q {
526126365 q if (ids.empty())
535717758 q {
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);
575717758 q }
5840869 q else if (!invert_ids)
5940869 q {
6040869 q for (typename std::vector< TObject >::const_iterator cit = iit->second.begin();
612349399 q cit != iit->second.end(); ++cit)
622308537 q {
632308537 q if (binary_search(ids.begin(), ids.end(), cit->id))
6454 q into[iit->first].push_back(*cit);
652308537 q }
6640869 q }
670 else
680 {
690 for (typename std::vector< TObject >::const_iterator cit = iit->second.begin();
700 cit != iit->second.end(); ++cit)
710 {
720 if (!binary_search(ids.begin(), ids.end(), cit->id))
730 into[iit->first].push_back(*cit);
740 }
750 }
766126365 q }
7722491 q}
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());
844034 q if (input)
854034 q {
864034 q collect_elements(input->nodes, into.nodes, ids, invert_ids);
874034 q collect_elements(input->attic_nodes, into.attic_nodes, ids, invert_ids);
884034 q }
890 else
900 {
910 into.nodes.clear();
920 into.attic_nodes.clear();
930 }
944034 q return true;
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());
1027461 q if (input)
1047259 q if (type & QUERY_WAY)
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);
1147259 q if (type & QUERY_AREA)
1150 collect_elements(input->areas, into.areas, ids, invert_ids);
11722 q else
11922 q into.ways.clear();
12022 q into.attic_ways.clear();
12122 q into.relations.clear();
12222 q into.attic_relations.clear();
12322 q into.areas.clear();
1257461 q return true;
129bool Item_Constraint::collect(Resource_Manager& rman, Set& into)
1300{
1310 const Set* input = rman.get_set(item->get_input_name());
1320 if (input)
1330 into.deriveds = input->deriveds;
1340 else
1350 into.deriveds.clear();
1370 return true;
1380}
141void Item_Constraint::filter(Resource_Manager& rman, Set& into)
14311093 q const Set* input = rman.get_set(item->get_input_name());
14411093 q if (input)
14510891 q {
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);
15410891 q }
15522 q else
15722 q into.nodes.clear();
15822 q into.attic_nodes.clear();
15922 q into.ways.clear();
16022 q into.attic_ways.clear();
16122 q into.relations.clear();
16222 q into.attic_relations.clear();
16322 q into.areas.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;
178651159 q attributes["from"] = "_";
179651159 q attributes["into"] = "_";
180651159 q attributes["set"] = "_";
182651159 q eval_attributes_array(get_name(), attributes, input_attributes);
184651159 q if (attributes["set"] == "_")
186651159 q input = attributes["from"];
187651159 q set_output(attributes["into"]);
1890 else if (attributes["from"] == "_" && attributes["into"] == "_")
1900 {
1910 input = attributes["set"];
1920 set_output(attributes["set"]);
1930 }
1940 else
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())
20314570 q {
20414570 q Set into;
20614570 q const Set* input_set = rman.get_set(input);
20714570 q if (input_set)
20814369 q into = *input_set;
21014570 q transfer_output(rman, into);
21114570 q }
215Item_Statement::~Item_Statement()
217651159 q for (std::vector< Query_Constraint* >::const_iterator it = constraints.begin();
218972159 q it != constraints.end(); ++it)
21932197 q delete *it;
223Query_Constraint* Item_Statement::get_query_constraint()
22532197 q constraints.push_back(new Item_Constraint(*this));
22632197 q return constraints.back();