Overpass API regression suite coverage (Nova Scotia) / overpass_api/data/diff_set.h

overpass_api/data/diff_set.h

92 of 94 instrumented lines run by the suite (97.9%) 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#ifndef DE__OSM3S___OVERPASS_API__DATA__DIFF_SET_H
20#define DE__OSM3S___OVERPASS_API__DATA__DIFF_SET_H
23#include "../core/datatypes.h"
25#include <map>
26#include <string>
27#include <utility>
28#include <vector>
31typedef std::vector< std::pair< std::string, std::string > > Tag_Container;
34struct Node_With_Context
36 Uint31_Index idx;
37 Node_Skeleton elem;
38 uint64 expiration_date;
39 OSM_Element_Metadata_Skeleton< Node_Skeleton::Id_Type > meta;
40 Tag_Container tags;
42 Node_With_Context(Uint31_Index idx_, Node_Skeleton elem_,
43 uint64 expiration_date_, OSM_Element_Metadata_Skeleton< Node_Skeleton::Id_Type > meta_
44 = OSM_Element_Metadata_Skeleton< Node_Skeleton::Id_Type >(),
45 Tag_Container tags_ = Tag_Container())
46225856239 q : idx(idx_), elem(elem_), expiration_date(expiration_date_), meta(meta_), tags(tags_) {}
48 bool operator<(const Node_With_Context& e) const
492831198937 q {
502831198937 q if (this->elem.id < e.elem.id)
512137996337 q return true;
52693202637 q if (e.elem.id < this->elem.id)
53677834837 q return false;
5415367822 q return (this->meta.version < e.meta.version);
55693202637 q }
56};
59struct Way_With_Context
61 Uint31_Index idx;
62 Way_Skeleton elem;
63 uint64 expiration_date;
64 OSM_Element_Metadata_Skeleton< Way_Skeleton::Id_Type > meta;
65 Tag_Container tags;
66 std::vector< Quad_Coord > geometry;
68 Way_With_Context(Uint31_Index idx_, Way_Skeleton elem_, const std::vector< Quad_Coord >& geometry_,
69 uint64 expiration_date_, OSM_Element_Metadata_Skeleton< Way_Skeleton::Id_Type > meta_
70 = OSM_Element_Metadata_Skeleton< Way_Skeleton::Id_Type >(),
71 Tag_Container tags_ = Tag_Container())
7240207847 q : idx(idx_), elem(elem_), expiration_date(expiration_date_), meta(meta_), tags(tags_), geometry(geometry_) {}
74 bool operator<(const Way_With_Context& e) const
75380123643 q {
76380123643 q if (this->elem.id < e.elem.id)
77286113742 q return true;
7894009942 q if (e.elem.id < this->elem.id)
7992579841 q return false;
801430127 q return (this->meta.version < e.meta.version);
8194009942 q }
82};
85struct Relation_With_Context
87 Uint31_Index idx;
88 Relation_Skeleton elem;
89 uint64 expiration_date;
90 OSM_Element_Metadata_Skeleton< Relation_Skeleton::Id_Type > meta;
91 Tag_Container tags;
92 std::vector< std::vector< Quad_Coord > > geometry;
94 Relation_With_Context(Uint31_Index idx_, Relation_Skeleton elem_,
95 const std::vector< std::vector< Quad_Coord > >& geometry_,
96 uint64 expiration_date_, OSM_Element_Metadata_Skeleton< Relation_Skeleton::Id_Type > meta_
97 = OSM_Element_Metadata_Skeleton< Relation_Skeleton::Id_Type >(),
98 Tag_Container tags_ = Tag_Container())
99317125 q : idx(idx_), elem(elem_), expiration_date(expiration_date_), meta(meta_), tags(tags_), geometry(geometry_) {}
101 bool operator<(const Relation_With_Context& e) const
102941124 q {
103941124 q if (this->elem.id < e.elem.id)
104656922 q return true;
105284224 q if (e.elem.id < this->elem.id)
106262721 q return false;
10721515 q return (this->meta.version < e.meta.version);
108284224 q }
109};
112struct Diff_Set
114 std::vector< std::pair< Node_With_Context, Node_With_Context > > different_nodes;
115 std::vector< std::pair< Way_With_Context, Way_With_Context > > different_ways;
116 std::vector< std::pair< Relation_With_Context, Relation_With_Context > > different_relations;
117 std::vector< Derived_Structure > lhs_deriveds;
118 std::vector< Derived_Structure > rhs_deriveds;
120 void clear()
12144776 q {
12244776 q different_nodes.clear();
12344776 q different_ways.clear();
12444776 q different_relations.clear();
12544776 q }
127 const Diff_Set& swap(Diff_Set& rhs)
12844776 q {
12944776 q different_nodes.swap(rhs.different_nodes);
13044776 q different_ways.swap(rhs.different_ways);
13144776 q different_relations.swap(rhs.different_relations);
13244776 q lhs_deriveds.swap(rhs.lhs_deriveds);
13344776 q rhs_deriveds.swap(rhs.rhs_deriveds);
13544776 q return *this;
13644776 q }
138 Set make_from_set() const;
139 Set make_to_set() const;
140};
143class Output_Handler;
146void print_diff_set(const Diff_Set& result,
147 uint32 output_mode, Output_Handler* output,
148 const std::map< uint32, std::string >& users, const std::map< uint32, std::string >& roles,
149 bool add_deletion_information);
152struct Double_Coords
154public:
155 explicit Double_Coords(const std::vector< Quad_Coord >& geometry)
15628546147 q : min_lat(100.0), max_lat(-100.0), min_lon(200.0), max_lon(-200.0)
15728546147 q {
158394253147 q for (std::vector< Quad_Coord >::const_iterator it = geometry.begin(); it != geometry.end(); ++it)
159365707047 q {
160365707047 q if (it->ll_upper != 0 || it->ll_lower != 0)
161365704047 q {
162365704047 q double lat = ::lat(it->ll_upper, it->ll_lower);
163365704047 q double lon = ::lon(it->ll_upper, it->ll_lower);
164365704047 q min_lat = std::min(min_lat, lat);
165365704047 q max_lat = std::max(max_lat, lat);
166365704047 q min_lon = std::min(min_lon, lon);
167365704047 q max_lon = std::max(max_lon, lon);
168365704047 q }
169365707047 q }
17028546147 q }
172 explicit Double_Coords(const std::vector< std::vector< Quad_Coord > >& geometry)
173255925 q : min_lat(100.0), max_lat(-100.0), min_lon(200.0), max_lon(-200.0)
174255925 q {
175255925 q for (std::vector< std::vector< Quad_Coord > >::const_iterator it = geometry.begin();
17627027825 q it != geometry.end(); ++it)
17726771925 q {
178464613425 q for (std::vector< Quad_Coord >::const_iterator it2 = it->begin(); it2 != it->end(); ++it2)
179437841525 q {
180437841525 q if (it2->ll_upper != 0 || it2->ll_lower != 0)
181437799725 q {
182437799725 q double lat = ::lat(it2->ll_upper, it2->ll_lower);
183437799725 q double lon = ::lon(it2->ll_upper, it2->ll_lower);
184437799725 q min_lat = std::min(min_lat, lat);
185437799725 q max_lat = std::max(max_lat, lat);
186437799725 q min_lon = std::min(min_lon, lon);
187437799725 q max_lon = std::max(max_lon, lon);
188437799725 q }
189437841525 q }
19026771925 q }
191255925 q }
193 const std::pair< Quad_Coord, Quad_Coord* >& bounds()
194685 q {
195685 q if (max_lat > -100.0)
196604 q {
197604 q max = Quad_Coord(::ll_upper_(max_lat, max_lon), ::ll_lower(max_lat, max_lon));
198604 q bounds_ = std::make_pair(Quad_Coord(::ll_upper_(min_lat, min_lon), ::ll_lower(min_lat, min_lon)), &max);
199604 q }
20082 q else
20282 q max = Quad_Coord(0u, 0u);
20382 q bounds_ = std::make_pair(Quad_Coord(0u, 0u), &max);
205685 q return bounds_;
206685 q }
208 const std::pair< Quad_Coord, Quad_Coord* >& center()
2092524 q {
2102524 q if (max_lat > -100.0)
2112524 q center_ = std::make_pair(Quad_Coord(
2122524 q ::ll_upper_((min_lat + max_lat) / 2, (min_lon + max_lon) / 2),
2132524 q ::ll_lower((min_lat + max_lat) / 2, (min_lon + max_lon) / 2)
2142524 q ), (Quad_Coord*)0);
2150 else
2160 center_ = std::make_pair(Quad_Coord(0u, 0u), (Quad_Coord*)0);
2172524 q return center_;
2182524 q }
220private:
221 double min_lat;
222 double max_lat;
223 double min_lon;
224 double max_lon;
225 std::pair< Quad_Coord, Quad_Coord* > bounds_;
226 std::pair< Quad_Coord, Quad_Coord* > center_;
227 Quad_Coord max;
228};
231const std::pair< Quad_Coord, Quad_Coord* >* bound_variant(Double_Coords& double_coords, unsigned int mode);
234#endif