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

overpass_api/data/diff_set.h

94 of 94 instrumented lines run by the suite (100.0%) 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())
46381496836 q : idx(idx_), elem(elem_), expiration_date(expiration_date_), meta(meta_), tags(tags_) {}
48 bool operator<(const Node_With_Context& e) const
495273237734 q {
505273237734 q if (this->elem.id < e.elem.id)
514192217333 q return true;
521081020434 q if (e.elem.id < this->elem.id)
531065829533 q return false;
5415190928 q return (this->meta.version < e.meta.version);
551081020434 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())
7267102141 q : idx(idx_), elem(elem_), expiration_date(expiration_date_), meta(meta_), tags(tags_), geometry(geometry_) {}
74 bool operator<(const Way_With_Context& e) const
75728976038 q {
76728976038 q if (this->elem.id < e.elem.id)
77571068737 q return true;
78157907336 q if (e.elem.id < this->elem.id)
79155600033 q return false;
802307329 q return (this->meta.version < e.meta.version);
81157907336 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())
99280315 q : idx(idx_), elem(elem_), expiration_date(expiration_date_), meta(meta_), tags(tags_), geometry(geometry_) {}
101 bool operator<(const Relation_With_Context& e) const
1021082713 q {
1031082713 q if (this->elem.id < e.elem.id)
104815213 q return true;
105267513 q if (e.elem.id < this->elem.id)
106249113 q return false;
1071849 q return (this->meta.version < e.meta.version);
108267513 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()
12147781 q {
12247781 q different_nodes.clear();
12347781 q different_ways.clear();
12447781 q different_relations.clear();
12547781 q }
127 const Diff_Set& swap(Diff_Set& rhs)
12847781 q {
12947781 q different_nodes.swap(rhs.different_nodes);
13047781 q different_ways.swap(rhs.different_ways);
13147781 q different_relations.swap(rhs.different_relations);
13247781 q lhs_deriveds.swap(rhs.lhs_deriveds);
13347781 q rhs_deriveds.swap(rhs.rhs_deriveds);
13547781 q return *this;
13647781 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)
15650812441 q : min_lat(100.0), max_lat(-100.0), min_lon(200.0), max_lon(-200.0)
15750812441 q {
158528789641 q for (std::vector< Quad_Coord >::const_iterator it = geometry.begin(); it != geometry.end(); ++it)
159477977241 q {
160477977241 q if (it->ll_upper != 0 || it->ll_lower != 0)
161477971241 q {
162477971241 q double lat = ::lat(it->ll_upper, it->ll_lower);
163477971241 q double lon = ::lon(it->ll_upper, it->ll_lower);
164477971241 q min_lat = std::min(min_lat, lat);
165477971241 q max_lat = std::max(max_lat, lat);
166477971241 q min_lon = std::min(min_lon, lon);
167477971241 q max_lon = std::max(max_lon, lon);
168477971241 q }
169477977241 q }
17050812441 q }
172 explicit Double_Coords(const std::vector< std::vector< Quad_Coord > >& geometry)
173222515 q : min_lat(100.0), max_lat(-100.0), min_lon(200.0), max_lon(-200.0)
174222515 q {
175222515 q for (std::vector< std::vector< Quad_Coord > >::const_iterator it = geometry.begin();
17636245815 q it != geometry.end(); ++it)
17736023315 q {
178440102915 q for (std::vector< Quad_Coord >::const_iterator it2 = it->begin(); it2 != it->end(); ++it2)
179404079615 q {
180404079615 q if (it2->ll_upper != 0 || it2->ll_lower != 0)
181403905015 q {
182403905015 q double lat = ::lat(it2->ll_upper, it2->ll_lower);
183403905015 q double lon = ::lon(it2->ll_upper, it2->ll_lower);
184403905015 q min_lat = std::min(min_lat, lat);
185403905015 q max_lat = std::max(max_lat, lat);
186403905015 q min_lon = std::min(min_lon, lon);
187403905015 q max_lon = std::max(max_lon, lon);
188403905015 q }
189404079615 q }
19036023315 q }
191222515 q }
193 const std::pair< Quad_Coord, Quad_Coord* >& bounds()
194309985 q {
195309985 q if (max_lat > -100.0)
196309954 q {
197309954 q max = Quad_Coord(::ll_upper_(max_lat, max_lon), ::ll_lower(max_lat, max_lon));
198309954 q bounds_ = std::make_pair(Quad_Coord(::ll_upper_(min_lat, min_lon), ::ll_lower(min_lat, min_lon)), &max);
199309954 q }
20031 q else
20231 q max = Quad_Coord(0u, 0u);
20331 q bounds_ = std::make_pair(Quad_Coord(0u, 0u), &max);
205309985 q return bounds_;
206309985 q }
208 const std::pair< Quad_Coord, Quad_Coord* >& center()
20911785 q {
21011785 q if (max_lat > -100.0)
21111755 q center_ = std::make_pair(Quad_Coord(
21211755 q ::ll_upper_((min_lat + max_lat) / 2, (min_lon + max_lon) / 2),
21311755 q ::ll_lower((min_lat + max_lat) / 2, (min_lon + max_lon) / 2)
21411755 q ), (Quad_Coord*)0);
21532 q else
21632 q center_ = std::make_pair(Quad_Coord(0u, 0u), (Quad_Coord*)0);
21711785 q return center_;
21811785 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