Overpass API regression suite coverage (Saxony) / overpass_api/data/diff_set.cc

overpass_api/data/diff_set.cc

250 of 273 instrumented lines run by the suite (91.6%) 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 "diff_set.h"
20#include "geometry_from_quad_coords.h"
21#include "../frontend/output_handler.h"
24Set Diff_Set::make_from_set() const
261111 q Set result;
281111 q for (std::vector< std::pair< Node_With_Context, Node_With_Context > >::const_iterator
2913037911 q it = different_nodes.begin(); it != different_nodes.end(); ++it)
301303683 q {
311303683 q if (it->first.idx.val() != 0xffu)
3262761 q {
3362761 q if (it->first.expiration_date == NOW)
340 result.nodes[it->first.idx].push_back(it->first.elem);
3562761 q else
3662761 q result.attic_nodes[it->first.idx].push_back(
3762761 q Attic< Node_Skeleton >(it->first.elem, it->first.expiration_date));
3862761 q }
391303683 q }
411111 q for (std::vector< std::pair< Way_With_Context, Way_With_Context > >::const_iterator it = different_ways.begin();
421945511 q it != different_ways.end(); ++it)
43194443 q {
44194443 q if (it->first.idx.val() != 0xffu)
4518642 q {
4618642 q if (it->first.expiration_date == NOW)
470 result.ways[it->first.idx].push_back(it->first.elem);
4818642 q else
4918642 q result.attic_ways[it->first.idx].push_back(
5018642 q Attic< Way_Skeleton >(it->first.elem, it->first.expiration_date));
5118642 q }
52194443 q }
541111 q for (std::vector< std::pair< Relation_With_Context, Relation_With_Context > >::const_iterator it = different_relations.begin();
551611 q it != different_relations.end(); ++it)
5752 q if (it->first.idx.val() != 0xffu)
580 {
590 if (it->first.expiration_date == NOW)
600 result.relations[it->first.idx].push_back(it->first.elem);
610 else
620 result.attic_relations[it->first.idx].push_back(
630 Attic< Relation_Skeleton >(it->first.elem, it->first.expiration_date));
640 }
671111 q return result;
71Set Diff_Set::make_to_set() const
731111 q Set result;
751111 q for (std::vector< std::pair< Node_With_Context, Node_With_Context > >::const_iterator
7613037911 q it = different_nodes.begin(); it != different_nodes.end(); ++it)
771303683 q {
781303683 q if ((it->second.idx.val() | 2) != 0xffu)
791245223 q {
801245223 q if (it->second.expiration_date == NOW)
811245212 q result.nodes[it->second.idx].push_back(it->second.elem);
8211 q else
8311 q result.attic_nodes[it->second.idx].push_back(
8411 q Attic< Node_Skeleton >(it->second.elem, it->second.expiration_date));
851245223 q }
861303683 q }
881111 q for (std::vector< std::pair< Way_With_Context, Way_With_Context > >::const_iterator it = different_ways.begin();
891945511 q it != different_ways.end(); ++it)
90194443 q {
91194443 q if ((it->second.idx.val() | 2) != 0xffu)
92190063 q {
93190063 q if (it->second.expiration_date == NOW)
94190063 q result.ways[it->second.idx].push_back(it->second.elem);
950 else
960 result.attic_ways[it->second.idx].push_back(
970 Attic< Way_Skeleton >(it->second.elem, it->second.expiration_date));
98190063 q }
99194443 q }
1011111 q for (std::vector< std::pair< Relation_With_Context, Relation_With_Context > >::const_iterator it = different_relations.begin();
1021611 q it != different_relations.end(); ++it)
10452 q if ((it->second.idx.val() | 2) != 0xffu)
10652 q if (it->second.expiration_date == NOW)
10741 q result.relations[it->second.idx].push_back(it->second.elem);
10811 q else
10911 q result.attic_relations[it->second.idx].push_back(
11011 q Attic< Relation_Skeleton >(it->second.elem, it->second.expiration_date));
1141111 q return result;
118const std::pair< Quad_Coord, Quad_Coord* >* bound_variant(Double_Coords& double_coords, unsigned int mode)
11951034951 q{
12051034951 q if (mode & Output_Mode::BOUNDS)
121309985 q return &double_coords.bounds();
12247935151 q else if (mode & Output_Mode::CENTER)
12311785 q return &double_coords.center();
12547817351 q return 0;
12651034951 q}
129void print_nodes(const std::vector< std::pair< Node_With_Context, Node_With_Context > >& different_nodes,
130 uint32 output_mode, Output_Handler* output,
131 const std::map< uint32, std::string >& users, bool add_deletion_information)
13348381 q for (std::vector< std::pair< Node_With_Context, Node_With_Context > >::const_iterator
134135483481 q it = different_nodes.begin(); it != different_nodes.end(); ++it)
135135435134 q {
136135435134 q if ((it->second.idx.val() | 2) == 0xffu)
1373957021 q {
1383957021 q if (add_deletion_information)
139909710 q {
140909710 q Node_Skeleton new_skel(it->first.elem.id);
141909710 q output->print_item(it->first.elem,
142909710 q Point_Geometry(::lat(it->first.idx.val(), it->first.elem.ll_lower),
143909710 q ::lon(it->first.idx.val(), it->first.elem.ll_lower)),
144909710 q (output_mode & Output_Mode::TAGS) ? &it->first.tags : 0,
145909710 q (output_mode & Output_Mode::META) ? &it->first.meta : 0,
146909710 q &users, output_mode,
147909710 q it->second.idx.val() == 0xfdu ? Output_Handler::push_away : Output_Handler::erase,
148909710 q &new_skel, 0, 0, &it->second.meta);
149909710 q }
1503047311 q else
1513047311 q output->print_item(it->first.elem,
1523047311 q Point_Geometry(::lat(it->first.idx.val(), it->first.elem.ll_lower),
1533047311 q ::lon(it->first.idx.val(), it->first.elem.ll_lower)),
1543047311 q (output_mode & Output_Mode::TAGS) ? &it->first.tags : 0,
1553047311 q (output_mode & Output_Mode::META) ? &it->first.meta : 0,
1563047311 q &users, output_mode, Output_Handler::erase);
1573957021 q }
158131478134 q else if (it->first.idx.val() != 0xffu)
1596399227 q {
160 // The elements differ
1616399227 q Null_Geometry null_geom;
1626399227 q Point_Geometry old_geom(::lat(it->first.idx.val(), it->first.elem.ll_lower),
1636399227 q ::lon(it->first.idx.val(), it->first.elem.ll_lower));
1646399227 q Point_Geometry new_geom(::lat(it->second.idx.val(), it->second.elem.ll_lower),
1656399227 q ::lon(it->second.idx.val(), it->second.elem.ll_lower));
1666399227 q Opaque_Geometry* old_opaque = &null_geom;
1676399227 q if (it->first.idx.val() != 0xfdu)
1686385925 q old_opaque = &old_geom;
1696399227 q output->print_item(it->first.elem, *old_opaque,
1706399227 q (output_mode & Output_Mode::TAGS) ? &it->first.tags : 0,
1716399227 q (output_mode & Output_Mode::META) ? &it->first.meta : 0,
1726399227 q &users, output_mode, Output_Handler::modify,
1736399227 q &it->second.elem, &new_geom,
1746399227 q (output_mode & Output_Mode::TAGS) ? &it->second.tags : 0,
1756399227 q (output_mode & Output_Mode::META) ? &it->second.meta : 0);
1766399227 q }
177125078933 q else
178 // No old element exists
179125078933 q output->print_item(it->second.elem,
180125078933 q Point_Geometry(::lat(it->second.idx.val(), it->second.elem.ll_lower),
181125078933 q ::lon(it->second.idx.val(), it->second.elem.ll_lower)),
182125078933 q (output_mode & Output_Mode::TAGS) ? &it->second.tags : 0,
183125078933 q (output_mode & Output_Mode::META) ? &it->second.meta : 0,
184125078933 q &users, output_mode, Output_Handler::create);
185135435134 q }
189void print_ways(const std::vector< std::pair< Way_With_Context, Way_With_Context > >& different_ways,
190 uint32 output_mode, Output_Handler* output,
191 const std::map< uint32, std::string >& users, bool add_deletion_information)
19348381 q for (std::vector< std::pair< Way_With_Context, Way_With_Context > >::const_iterator it = different_ways.begin();
19424047881 q it != different_ways.end(); ++it)
19523999540 q {
19623999540 q if ((it->second.idx.val() | 2) == 0xffu)
197416324 q {
198416324 q Double_Coords double_coords(it->first.geometry);
199416324 q Geometry_From_Quad_Coords broker;
200416324 q if (add_deletion_information)
201149711 q {
202149711 q Way_Skeleton new_skel(it->first.elem.id);
203149711 q output->print_item(it->first.elem,
204149711 q broker.make_way_geom((output_mode & Output_Mode::GEOMETRY) ? &it->first.geometry : 0,
205149711 q bound_variant(double_coords, output_mode)),
206149711 q (output_mode & Output_Mode::TAGS) ? &it->first.tags : 0,
207149711 q (output_mode & Output_Mode::META) ? &it->first.meta : 0,
208149711 q &users, output_mode,
209149711 q it->second.idx.val() == 0xfdu ? Output_Handler::push_away : Output_Handler::erase,
210149711 q &new_skel, 0, 0, &it->second.meta);
211149711 q }
212266613 q else
213266613 q output->print_item(it->first.elem,
214266613 q broker.make_way_geom((output_mode & Output_Mode::GEOMETRY) ? &it->first.geometry : 0,
215266613 q bound_variant(double_coords, output_mode)),
216266613 q (output_mode & Output_Mode::TAGS) ? &it->first.tags : 0,
217266613 q (output_mode & Output_Mode::META) ? &it->first.meta : 0,
218266613 q &users, output_mode, Output_Handler::erase);
219416324 q }
22023583240 q else if (it->first.idx.val() != 0xffu)
2211793529 q {
222 // The elements differ
2231793529 q Double_Coords double_coords(it->first.geometry);
2241793529 q Double_Coords double_coords_new(it->second.geometry);
2251793529 q Geometry_From_Quad_Coords broker;
2261793529 q Geometry_From_Quad_Coords new_broker;
2271793529 q output->print_item(it->first.elem,
2281793529 q broker.make_way_geom((output_mode & Output_Mode::GEOMETRY) ? &it->first.geometry : 0,
2291793529 q bound_variant(double_coords, output_mode)),
2301793529 q (output_mode & Output_Mode::TAGS) ? &it->first.tags : 0,
2311793529 q (output_mode & Output_Mode::META) ? &it->first.meta : 0,
2321793529 q &users, output_mode, Output_Handler::modify,
2331793529 q &it->second.elem,
2341793529 q &new_broker.make_way_geom((output_mode & Output_Mode::GEOMETRY) ? &it->second.geometry : 0,
2351793529 q bound_variant(double_coords_new, output_mode)),
2361793529 q (output_mode & Output_Mode::TAGS) ? &it->second.tags : 0,
2371793529 q (output_mode & Output_Mode::META) ? &it->second.meta : 0);
2381793529 q }
23921789737 q else
24021789737 q {
241 // No old element exists
24221789737 q Double_Coords double_coords(it->second.geometry);
24321789737 q Geometry_From_Quad_Coords broker;
24421789737 q output->print_item(it->second.elem,
24521789737 q broker.make_way_geom((output_mode & Output_Mode::GEOMETRY) ? &it->second.geometry : 0,
24621789737 q bound_variant(double_coords, output_mode)),
24721789737 q (output_mode & Output_Mode::TAGS) ? &it->second.tags : 0,
24821789737 q (output_mode & Output_Mode::META) ? &it->second.meta : 0,
24921789737 q &users, output_mode, Output_Handler::create);
25021789737 q }
25123999540 q }
255void print_relations(
256 const std::vector< std::pair< Relation_With_Context, Relation_With_Context > >& different_relations,
257 uint32 output_mode, Output_Handler* output,
258 const std::map< uint32, std::string >& users, const std::map< uint32, std::string >& roles,
259 bool add_deletion_information)
26148381 q for (std::vector< std::pair< Relation_With_Context, Relation_With_Context > >::const_iterator it = different_relations.begin();
262142881 q it != different_relations.end(); ++it)
26394515 q {
26494515 q if ((it->second.idx.val() | 2) == 0xffu)
265233 q {
266233 q Double_Coords double_coords(it->first.geometry);
267233 q Geometry_From_Quad_Coords broker;
268233 q if (add_deletion_information)
2690 {
2700 Relation_Skeleton new_skel(it->first.elem.id);
2710 output->print_item(it->first.elem,
2720 broker.make_relation_geom((output_mode & Output_Mode::GEOMETRY) ? &it->first.geometry : 0,
2730 bound_variant(double_coords, output_mode)),
2740 (output_mode & Output_Mode::TAGS) ? &it->first.tags : 0,
2750 (output_mode & Output_Mode::META) ? &it->first.meta : 0,
2760 &roles, &users, output_mode,
2770 it->second.idx.val() == 0xfdu ? Output_Handler::push_away : Output_Handler::erase,
2780 &new_skel, 0, 0, &it->second.meta);
2790 }
280233 q else
281233 q output->print_item(it->first.elem,
282233 q broker.make_relation_geom((output_mode & Output_Mode::GEOMETRY) ? &it->first.geometry : 0,
283233 q bound_variant(double_coords, output_mode)),
284233 q (output_mode & Output_Mode::TAGS) ? &it->first.tags : 0,
285233 q (output_mode & Output_Mode::META) ? &it->first.meta : 0,
286233 q &roles, &users, output_mode, Output_Handler::erase);
287233 q }
28892215 q else if (it->first.idx.val() != 0xffu)
2891589 q {
290 // The elements differ
2911589 q Double_Coords double_coords(it->first.geometry);
2921589 q Double_Coords double_coords_new(it->second.geometry);
2931589 q Geometry_From_Quad_Coords broker;
2941589 q Geometry_From_Quad_Coords new_broker;
2951589 q output->print_item(it->first.elem,
2961589 q broker.make_relation_geom((output_mode & Output_Mode::GEOMETRY) ? &it->first.geometry : 0,
2971589 q bound_variant(double_coords, output_mode)),
2981589 q (output_mode & Output_Mode::TAGS) ? &it->first.tags : 0,
2991589 q (output_mode & Output_Mode::META) ? &it->first.meta : 0,
3001589 q &roles, &users, output_mode, Output_Handler::modify,
3011589 q &it->second.elem,
3021589 q &new_broker.make_relation_geom((output_mode & Output_Mode::GEOMETRY) ? &it->second.geometry : 0,
3031589 q bound_variant(double_coords_new, output_mode)),
3041589 q (output_mode & Output_Mode::TAGS) ? &it->second.tags : 0,
3051589 q (output_mode & Output_Mode::META) ? &it->second.meta : 0);
3061589 q }
30776413 q else
30876413 q {
309 // No old element exists
31076413 q Double_Coords double_coords(it->second.geometry);
31176413 q Geometry_From_Quad_Coords broker;
31276413 q output->print_item(it->second.elem,
31376413 q broker.make_relation_geom((output_mode & Output_Mode::GEOMETRY) ? &it->second.geometry : 0,
31476413 q bound_variant(double_coords, output_mode)),
31576413 q (output_mode & Output_Mode::TAGS) ? &it->second.tags : 0,
31676413 q (output_mode & Output_Mode::META) ? &it->second.meta : 0,
31776413 q &roles, &users, output_mode, Output_Handler::create);
31876413 q }
31994515 q }
323void print_deriveds(
324 const std::vector< Derived_Structure >& lhs_deriveds, const std::vector< Derived_Structure >& rhs_deriveds,
325 uint32 output_mode, Output_Handler* output)
32748381 q Null_Geometry null_geom;
32949581 q for (std::vector< Derived_Structure >::const_iterator it = lhs_deriveds.begin(); it != lhs_deriveds.end(); ++it)
330123 q output->print_item(*it, it->get_geometry() ? *it->get_geometry() : null_geom, &it->tags,
331123 q output_mode, Output_Handler::erase);
33359481 q for (std::vector< Derived_Structure >::const_iterator it = rhs_deriveds.begin(); it != rhs_deriveds.end(); ++it)
3341114 q output->print_item(*it, it->get_geometry() ? *it->get_geometry() : null_geom, &it->tags,
3351114 q output_mode, Output_Handler::create);
339void print_diff_set(const Diff_Set& result,
340 uint32 output_mode, Output_Handler* output,
341 const std::map< uint32, std::string >& users, const std::map< uint32, std::string >& roles,
342 bool add_deletion_information)
34448381 q print_nodes(result.different_nodes, output_mode, output, users, add_deletion_information);
34548381 q print_ways(result.different_ways, output_mode, output, users, add_deletion_information);
34648381 q print_relations(result.different_relations, output_mode, output, users, roles, add_deletion_information);
34848381 q print_deriveds(result.lhs_deriveds, result.rhs_deriveds, output_mode, output);