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

overpass_api/statements/item.cc

115 of 148 instrumented lines run by the suite (77.7%) 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:
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() {}
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)
4717066 q{
4817066 q into.clear();
4917066 q for (typename std::map< TIndex, std::vector< TObject > >::const_iterator iit = from.begin();
5018290866 q iit != from.end(); ++iit)
5118273854 q {
5218273854 q if (ids.empty())
5317895846 q {
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);
5717895846 q }
5837809 q else if (!invert_ids)
5937809 q {
6037809 q for (typename std::vector< TObject >::const_iterator cit = iit->second.begin();
611878849 q cit != iit->second.end(); ++cit)
621841049 q {
631841049 q if (binary_search(ids.begin(), ids.end(), cit->id))
640 into[iit->first].push_back(*cit);
651841049 q }
6637809 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 }
7618273854 q }
7717066 q}
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());
842519 q if (input)
852519 q {
862519 q collect_elements(input->nodes, into.nodes, ids, invert_ids);
872519 q collect_elements(input->attic_nodes, into.attic_nodes, ids, invert_ids);
882519 q }
890 else
900 {
910 into.nodes.clear();
920 into.attic_nodes.clear();
930 }
942519 q return true;
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());
1026152 q if (input)
1046051 q if (type & QUERY_WAY)
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);
1146051 q if (type & QUERY_AREA)
1150 collect_elements(input->areas, into.areas, ids, invert_ids);
11711 q else
11911 q into.ways.clear();
12011 q into.attic_ways.clear();
12111 q into.relations.clear();
12211 q into.attic_relations.clear();
12311 q into.areas.clear();
1256152 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)
1438267 q const Set* input = rman.get_set(item->get_input_name());
1448267 q if (input)
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);
15511 q else
15711 q into.nodes.clear();
15811 q into.attic_nodes.clear();
15911 q into.ways.clear();
16011 q into.attic_ways.clear();
16111 q into.relations.clear();
16211 q into.attic_relations.clear();
16311 q into.areas.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;
178513125 q attributes["from"] = "_";
179513125 q attributes["into"] = "_";
180513125 q attributes["set"] = "_";
182513125 q eval_attributes_array(get_name(), attributes, input_attributes);
184513125 q if (attributes["set"] == "_")
186513125 q input = attributes["from"];
187513125 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)
20223157 q if (input != get_result_name())
20322656 q {
20422656 q Set into;
20622656 q const Set* input_set = rman.get_set(input);
20722656 q if (input_set)
20822355 q into = *input_set;
21022656 q transfer_output(rman, into);
21122656 q }
215Item_Statement::~Item_Statement()
217513125 q for (std::vector< Query_Constraint* >::const_iterator it = constraints.begin();
218762125 q it != constraints.end(); ++it)
21924972 q delete *it;
223Query_Constraint* Item_Statement::get_query_constraint()
22524972 q constraints.push_back(new Item_Constraint(*this));
22624972 q return constraints.back();