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

overpass_api/statements/print.cc

582 of 638 instrumented lines run by the suite (91.2%) 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 "../core/index_computations.h"
20#include "../data/collect_members.h"
21#include "../data/filenames.h"
22#include "../data/geometry_from_quad_coords.h"
23#include "../data/meta_collector.h"
24#include "../data/relation_geometry_store.h"
25#include "../data/set_comparison.h"
26#include "../data/tag_store.h"
27#include "../data/utils.h"
28#include "../data/way_geometry_store.h"
29#include "print.h"
31#include <algorithm>
32#include <iomanip>
33#include <iostream>
34#include <map>
35#include <set>
36#include <sstream>
37#include <string>
38#include <vector>
41const unsigned int NODE_FLUSH_SIZE = 1024*1024;
42const unsigned int WAY_FLUSH_SIZE = 512*1024;
43const unsigned int RELATION_FLUSH_SIZE = 512*1024;
44const unsigned int AREA_FLUSH_SIZE = 64*1024;
47Generic_Statement_Maker< Print_Statement > Print_Statement::statement_maker("print");
50Print_Statement::Print_Statement
51 (int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)
5212042679 q : Statement(line_number_),
5312042679 q mode(0), order(order_by_id), limit(std::numeric_limits< unsigned int >::max()),
5412042679 q collection_print_target(0), diff_valid(true),
5512042679 q south(1.0), north(0.0), west(0.0), east(0.0)
5612042679 q{
5712042679 q std::map< std::string, std::string > attributes;
5912042679 q attributes["from"] = "_";
6012042679 q attributes["ids"] = "yes";
6112042679 q attributes["mode"] = "body";
6212042679 q attributes["order"] = "id";
6312042679 q attributes["limit"] = "";
6412042679 q attributes["geometry"] = "skeleton";
6512042679 q attributes["s"] = "";
6612042679 q attributes["n"] = "";
6712042679 q attributes["w"] = "";
6812042679 q attributes["e"] = "";
7012042679 q eval_attributes_array(get_name(), attributes, input_attributes);
7212042679 q input = attributes["from"];
7412042679 q if (attributes["mode"] == "ids_only")
755094650 q mode = Output_Mode::ID;
766948677 q else if (attributes["mode"] == "skeleton")
777525 q mode = Output_Mode::ID
787525 q | Output_Mode::COORDS | Output_Mode::NDS | Output_Mode::MEMBERS;
796873677 q else if (attributes["mode"] == "tags")
80186 q mode = Output_Mode::ID | Output_Mode::TAGS;
816855677 q else if (attributes["mode"] == "body")
821554504 q mode = Output_Mode::ID
831554504 q | Output_Mode::COORDS | Output_Mode::NDS | Output_Mode::MEMBERS
841554504 q | Output_Mode::TAGS;
855301650 q else if (attributes["mode"] == "meta")
8612039 q mode = Output_Mode::ID
8712039 q | Output_Mode::COORDS | Output_Mode::NDS | Output_Mode::MEMBERS
8812039 q | Output_Mode::TAGS | Output_Mode::VERSION | Output_Mode::META;
895181650 q else if (attributes["mode"] == "count")
905178650 q mode = Output_Mode::ID | Output_Mode::COUNT;
9131 q else
9331 q mode = Output_Mode::ID;
9431 q std::ostringstream temp;
9531 q temp<<"For the attribute \"mode\" of the element \"print\""
9631 q <<" the only allowed values are \"ids_only\", \"skeleton\", \"body\", \"tags\", \"count\", or \"meta\".";
9731 q add_static_error(temp.str());
10012042679 q if (attributes["order"] == "id")
10111892677 q order = order_by_id;
10215050 q else if (attributes["order"] == "quadtile")
10315050 q order = order_by_quadtile;
1040 else
1050 {
1060 std::ostringstream temp;
1070 temp<<"For the attribute \"order\" of the element \"print\""
1080 <<" the only allowed values are \"id\" or \"quadtile\".";
1090 add_static_error(temp.str());
1100 }
11212042679 q if (attributes["limit"] != "")
1135118648 q limit = atoll(attributes["limit"].c_str());
11512042679 q if (attributes["geometry"] == "skeleton")
11611844672 q ;
11719864 q else if (attributes["geometry"] == "full")
1188127 q mode = mode | Output_Mode::GEOMETRY | Output_Mode::BOUNDS;
11911738 q else if (attributes["geometry"] == "bounds")
1206621 q mode = mode | Output_Mode::BOUNDS;
1215117 q else if (attributes["geometry"] == "center")
1225117 q mode = mode | Output_Mode::CENTER;
1230 else
1240 {
1250 std::ostringstream temp;
1260 temp<<"For the attribute \"geometry\" of the element \"print\""
1270 <<" the only allowed values are \"skeleton\", \"full\", \"bounds\", or \"center\".";
1280 add_static_error(temp.str());
1290 }
13112042679 q if (attributes["ids"] == "yes")
13212000679 q ;
1334214 q else if (attributes["ids"] == "no")
1344214 q mode = mode & ~Output_Mode::ID;
1350 else
1360 {
1370 std::ostringstream temp;
1380 temp<<"For the attribute \"ids\" of the element \"print\""
1390 <<" the only allowed values are \"yes\" or \"no\".";
1400 add_static_error(temp.str());
1410 }
14312042679 q south = atof(attributes["s"].c_str());
14412042679 q if ((south < -90.0) || (south > 90.0))
1450 {
1460 std::ostringstream temp;
1470 temp<<"For the attribute \"s\" of the element \"print\""
1480 <<" the only allowed values are floats between -90.0 and 90.0.";
1490 add_static_error(temp.str());
1500 }
15112042679 q north = atof(attributes["n"].c_str());
15212042679 q if ((north < -90.0) || (north > 90.0))
1530 {
1540 std::ostringstream temp;
1550 temp<<"For the attribute \"n\" of the element \"print\""
1560 <<" the only allowed values are floats between -90.0 and 90.0.";
1570 add_static_error(temp.str());
1580 }
15912042679 q if (north < south)
1600 {
1610 std::ostringstream temp;
1620 temp<<"The value of attribute \"n\" of the element \"print\""
1630 <<" must always be greater or equal than the value of attribute \"s\".";
1640 add_static_error(temp.str());
1650 }
16712042679 q west = atof(attributes["w"].c_str());
16812042679 q if ((west < -180.0) || (west > 180.0))
1690 {
1700 std::ostringstream temp;
1710 temp<<"For the attribute \"w\" of the element \"print\""
1720 <<" the only allowed values are floats between -180.0 and 180.0.";
1730 add_static_error(temp.str());
1740 }
17512042679 q east = atof(attributes["e"].c_str());
17612042679 q if ((east < -180.0) || (east > 180.0))
1770 {
1780 std::ostringstream temp;
1790 temp<<"For the attribute \"e\" of the element \"print\""
1800 <<" the only allowed values are floats between -180.0 and 180.0.";
1810 add_static_error(temp.str());
1820 }
18312042679 q if ((attributes["n"] == "") && (attributes["s"] == "") &&
18412042679 q (attributes["w"] == "") && (attributes["e"] == ""))
18511898679 q {
18611898679 q south = 1.0;
18711898679 q north = 0.0;
18811898679 q }
18912042679 q}
192struct Extra_Data
194 Extra_Data(
195 Resource_Manager& rman, const Statement& stmt, const Set& to_print,
196 unsigned int mode_, Output_Handler::Feature_Action action_,
197 double south, double north, double west, double east);
198 ~Extra_Data();
200 const std::map< uint32, std::string >* get_users() const;
202 unsigned int mode;
203 Output_Handler::Feature_Action action;
204 Way_Bbox_Geometry_Store* way_geometry_store;
205 Way_Bbox_Geometry_Store* attic_way_geometry_store;
206 Relation_Geometry_Store* relation_geometry_store;
207 Relation_Geometry_Store* attic_relation_geometry_store;
208 const std::map< uint32, std::string >* roles;
209 const std::map< uint32, std::string >* users;
210};
213Extra_Data::Extra_Data(
214 Resource_Manager& rman, const Statement& stmt, const Set& to_print,
215 unsigned int mode_, Output_Handler::Feature_Action action_,
216 double south, double north, double west, double east)
21727074589 q : mode(mode_), action(action_), way_geometry_store(0), attic_way_geometry_store(0),
21827074589 q relation_geometry_store(0), attic_relation_geometry_store(0), roles(0), users(0)
21927074589 q{
22027074589 q if (mode & (Output_Mode::GEOMETRY | Output_Mode::BOUNDS | Output_Mode::CENTER))
2225452 q way_geometry_store = new Way_Bbox_Geometry_Store(to_print.ways, stmt, rman, south, north, west, east);
2235452 q if (rman.get_desired_timestamp() < NOW)
2251817 q attic_way_geometry_store = new Way_Bbox_Geometry_Store(
2261817 q to_print.attic_ways, stmt, rman,
2271817 q south, north, west, east);
2305452 q relation_geometry_store = new Relation_Geometry_Store(
2315452 q to_print.relations, stmt, rman, south, north, west, east);
2325452 q if (rman.get_desired_timestamp() < NOW)
2341817 q attic_relation_geometry_store = new Relation_Geometry_Store(
2351817 q to_print.attic_relations, stmt, rman,
2361817 q south, north, west, east);
24027074589 q roles = &relation_member_roles(*rman.get_transaction());
24227074589 q if (mode & Output_Mode::META)
2433736 q users = &rman.users();
24427074589 q}
247const std::map< uint32, std::string >* Extra_Data::get_users() const
2484699103462 q{
2494699103462 q return users;
2504699103462 q}
253Extra_Data::~Extra_Data()
25427074589 q{
25527074589 q delete way_geometry_store;
25627074589 q delete attic_way_geometry_store;
25727074589 q delete relation_geometry_store;
25827074589 q delete attic_relation_geometry_store;
25927074589 q}
262void print_item(Extra_Data& extra_data, Output_Handler& output, uint32 ll_upper, const Node_Skeleton& skel,
263 const std::vector< std::pair< std::string, std::string > >* tags = 0,
264 const OSM_Element_Metadata_Skeleton< Node_Skeleton::Id_Type >* meta = 0)
2653231208246 q{
2663231208246 q output.print_item(skel, Point_Geometry(::lat(ll_upper, skel.ll_lower), ::lon(ll_upper, skel.ll_lower)),
2673231208246 q tags, meta, extra_data.get_users(), Output_Mode(extra_data.mode), extra_data.action);
2683231208246 q}
271void print_item(Extra_Data& extra_data, Output_Handler& output, uint32 ll_upper, const Way_Skeleton& skel,
272 const std::vector< std::pair< std::string, std::string > >* tags = 0,
273 const OSM_Element_Metadata_Skeleton< Way_Skeleton::Id_Type >* meta = 0)
2741164762270 q{
2751164762270 q Geometry_From_Quad_Coords broker;
2761164762270 q output.print_item(skel,
2771164762270 q broker.make_way_geom(skel, extra_data.mode, extra_data.way_geometry_store),
2781164762270 q tags, meta, extra_data.get_users(), Output_Mode(extra_data.mode), extra_data.action);
2791164762270 q}
282void print_item(Extra_Data& extra_data, Output_Handler& output, uint32 ll_upper, const Attic< Way_Skeleton >& skel,
283 const std::vector< std::pair< std::string, std::string > >* tags = 0,
284 const OSM_Element_Metadata_Skeleton< Way_Skeleton::Id_Type >* meta = 0)
2858782277 q{
2868782277 q Geometry_From_Quad_Coords broker;
2878782277 q output.print_item(skel,
2888782277 q broker.make_way_geom(skel, extra_data.mode, extra_data.attic_way_geometry_store),
2898782277 q tags, meta, extra_data.get_users(), Output_Mode(extra_data.mode), extra_data.action);
2908782277 q}
293void print_item(Extra_Data& extra_data, Output_Handler& output, uint32 ll_upper, const Relation_Skeleton& skel,
294 const std::vector< std::pair< std::string, std::string > >* tags = 0,
295 const OSM_Element_Metadata_Skeleton< Relation_Skeleton::Id_Type >* meta = 0)
296212056155 q{
297212056155 q Geometry_From_Quad_Coords broker;
298212056155 q output.print_item(skel,
299212056155 q broker.make_relation_geom(skel, extra_data.mode, extra_data.relation_geometry_store),
300212056155 q tags, meta, extra_data.roles, extra_data.get_users(), Output_Mode(extra_data.mode), extra_data.action);
301212056155 q}
304void print_item(Extra_Data& extra_data, Output_Handler& output, uint32 ll_upper, const Attic< Relation_Skeleton >& skel,
305 const std::vector< std::pair< std::string, std::string > >* tags = 0,
306 const OSM_Element_Metadata_Skeleton< Relation_Skeleton::Id_Type >* meta = 0)
307325544 q{
308325544 q Geometry_From_Quad_Coords broker;
309325544 q output.print_item(skel,
310325544 q broker.make_relation_geom(skel, extra_data.mode, extra_data.attic_relation_geometry_store),
311325544 q tags, meta, extra_data.roles, extra_data.get_users(), Output_Mode(extra_data.mode), extra_data.action);
312325544 q}
315void print_item(Extra_Data& extra_data, Output_Handler& output, uint32 ll_upper, const Area_Skeleton& skel,
316 const std::vector< std::pair< std::string, std::string > >* tags = 0,
317 const OSM_Element_Metadata_Skeleton< Area_Skeleton::Id_Type >* meta = 0)
3181040985 q{
3191040985 q Derived_Skeleton derived("area", Uint64(skel.id.val()));
3201040985 q output.print_item(derived, Null_Geometry(), tags, Output_Mode(extra_data.mode), extra_data.action);
3211040985 q}
324void print_item(Extra_Data& extra_data, Output_Handler& output, uint32 ll_upper, const Derived_Structure& skel,
325 const std::vector< std::pair< std::string, std::string > >* tags = 0,
326 const OSM_Element_Metadata_Skeleton< Derived_Skeleton::Id_Type >* meta = 0)
327190640561 q{
328190640561 q if (skel.get_geometry())
32915220850 q output.print_item(skel, *skel.get_geometry(), tags, Output_Mode(extra_data.mode), extra_data.action);
33038432561 q else
33138432561 q output.print_item(skel, Null_Geometry(), tags, Output_Mode(extra_data.mode), extra_data.action);
332190640561 q}
335template< class TIndex, class TObject >
336void quadtile_
337 (const std::map< TIndex, std::vector< TObject > >& items, Output_Handler& output,
338 Transaction& transaction, Extra_Data& extra_data, uint32 limit, uint32& element_count)
34013018 q typename std::map< TIndex, std::vector< TObject > >::const_iterator
34113018 q item_it(items.begin());
342 // print the result
34380118 q while (item_it != items.end())
34467718 q {
34567718 q for (typename std::vector< TObject >::const_iterator it2(item_it->second.begin());
3462058718 q it2 != item_it->second.end(); ++it2)
3471991617 q {
3481991617 q if (++element_count > limit)
34964 q return;
3501991017 q print_item(extra_data, output, item_it->first.val(), *it2);
3511991017 q }
35267117 q ++item_it;
35367117 q }
357template< class Index, class Object >
358void tags_quadtile_
359 (Extra_Data& extra_data, const std::map< Index, std::vector< Object > >& items,
360 Output_Handler& output,
361 Resource_Manager& rman, Transaction& transaction, uint32 limit, uint32& element_count)
36312630 q Tag_Store< Index, Object > tag_store(*rman.get_transaction());
36412630 q tag_store.prefetch_all(items);
366 // formulate meta query if meta data shall be printed
36712630 q Meta_Collector< Index, typename Object::Id_Type > meta_printer(items, transaction,
36812630 q (extra_data.mode & Output_Mode::META) ? current_meta_file_properties< Object >() : 0);
37012630 q typename std::map< Index, std::vector< Object > >::const_iterator
37112630 q item_it(items.begin());
372 // print the result
373709930 q while (item_it != items.end())
374698125 q {
375698125 q for (typename std::vector< Object >::const_iterator it2(item_it->second.begin());
37613943125 q it2 != item_it->second.end(); ++it2)
37713245821 q {
37813245821 q if (++element_count > limit)
37986 q return;
38013245021 q print_item(extra_data, output, item_it->first.val(), *it2, tag_store.get(item_it->first, *it2),
38113245021 q meta_printer.get(item_it->first, it2->id));
38213245021 q }
383697322 q ++item_it;
384697322 q }
388template< class Index, class Object >
389void tags_quadtile_attic_
390 (Extra_Data& extra_data, const std::map< Index, std::vector< Attic< Object > > >& items,
391 Output_Handler& output,
392 Resource_Manager& rman, Transaction& transaction, uint32 limit, uint32& element_count)
3943913 q Tag_Store< Index, Object > tag_store(transaction);
3953913 q tag_store.prefetch_all(items);
3973913 q Attic_Meta_Collector< Index, Object > meta_printer(items, transaction, extra_data.mode & Output_Mode::META);
3993913 q typename std::map< Index, std::vector< Attic< Object > > >::const_iterator
4003913 q item_it(items.begin());
401117213 q while (item_it != items.end())
402113411 q {
403113411 q for (typename std::vector< Attic< Object > >::const_iterator it2(item_it->second.begin());
4042602811 q it2 != item_it->second.end(); ++it2)
405248959 q {
406248959 q if (++element_count > limit)
40711 q return;
408248948 q print_item(extra_data, output, item_it->first.val(), *it2, tag_store.get(item_it->first, *it2),
409248948 q meta_printer.get(item_it->first, it2->id, it2->timestamp));
410248948 q }
411113310 q ++item_it;
412113310 q }
416template< class TComp >
417struct Skeleton_Comparator_By_Id {
418 bool operator() (const std::pair< const TComp*, uint32 >& a,
419 const std::pair< const TComp*, uint32 >& b)
420104278679266 q {
421104278679266 q return (a.first->id < b.first->id);
422104278679266 q }
423};
426template< typename Index, typename Object >
427struct Maybe_Attic_Ref
429public:
430 Maybe_Attic_Ref(Index idx_, const Object* obj_, uint64 timestamp_)
43115090256445 q : idx(idx_), obj(obj_), timestamp(timestamp_) {}
433 Index idx;
434 const Object* obj;
435 uint64 timestamp;
437343773833386 q bool operator<(const Maybe_Attic_Ref& rhs) const { return obj->id < rhs.obj->id; }
438};
441template< class Index, class Object >
442std::vector< std::pair< const Object*, uint32 > > collect_items_by_id(
443 const std::map< Index, std::vector< Object > >& items)
44433064587 q{
44533064587 q std::vector< std::pair< const Object*, uint32 > > items_by_id;
44733064587 q for (typename std::map< Index, std::vector< Object > >::const_iterator
448225862587 q it(items.begin()); it != items.end(); ++it)
449192798577 q {
450192798577 q for (typename std::vector< Object >::const_iterator it2(it->second.begin());
4515238763577 q it2 != it->second.end(); ++it2)
4525045965577 q items_by_id.push_back(std::make_pair(&(*it2), it->first.val()));
453192798577 q }
45433064587 q sort(items_by_id.begin(), items_by_id.end(),
45533064587 q Skeleton_Comparator_By_Id< Object >());
45733064587 q return items_by_id;
45833064587 q}
461template< class Index, class Object >
462std::vector< Maybe_Attic_Ref< Index, Object > > collect_items_by_id(
463 const std::map< Index, std::vector< Object > >& items,
464 const std::map< Index, std::vector< Attic< Object > > >& attic_items)
46575843563 q{
46675843563 q std::vector< Maybe_Attic_Ref< Index, Object > > items_by_id;
46775843563 q for (typename std::map< Index, std::vector< Object > >::const_iterator
468656026563 q it(items.begin()); it != items.end(); ++it)
469580183440 q {
470580183440 q for (typename std::vector< Object >::const_iterator it2(it->second.begin());
47114913856440 q it2 != it->second.end(); ++it2)
47214333673408 q items_by_id.push_back(Maybe_Attic_Ref< Index, Object >(it->first, &(*it2), NOW));
473580183440 q }
47475843563 q for (typename std::map< Index, std::vector< Attic< Object > > >::const_iterator
475243703563 q it(attic_items.begin()); it != attic_items.end(); ++it)
476167860159 q {
477167860159 q for (typename std::vector< Attic< Object > >::const_iterator it2(it->second.begin());
478924443159 q it2 != it->second.end(); ++it2)
479756583124 q items_by_id.push_back(Maybe_Attic_Ref< Index, Object >(it->first, &(*it2), it2->timestamp));
480167860159 q }
48175843563 q sort(items_by_id.begin(), items_by_id.end());
48375843563 q return items_by_id;
48475843563 q}
487template< class Index, class Object >
488void by_id
489 (const std::map< Index, std::vector< Object > >& items, Output_Handler& output,
490 Transaction& transaction, Extra_Data& extra_data, uint32 limit, uint32& element_count)
49123851556 q{
49223851556 q std::vector< std::pair< const Object*, uint32 > > items_by_id = collect_items_by_id(items);
494 // iterate over the result
49565112556 q for (uint32 i(0); i < items_by_id.size(); ++i)
49641302213 q {
49741302213 q if (++element_count > limit)
4984135 q return;
49941261211 q print_item(extra_data, output, items_by_id[i].second, *(items_by_id[i].first));
50041261211 q }
50123851556 q}
504template< class Index, class Object >
505void by_id
506 (const std::map< Index, std::vector< Object > >& items,
507 const std::map< Index, std::vector< Attic< Object > > >& attic_items,
508 Output_Handler& output,
509 Transaction& transaction, Extra_Data& extra_data, uint32 limit, uint32& element_count)
51070485556 q{
51170485556 q std::vector< Maybe_Attic_Ref< Index, Object > > items_by_id = collect_items_by_id(items, attic_items);
513 // iterate over the result
514478911556 q for (uint32 i(0); i < items_by_id.size(); ++i)
515408800444 q {
516408800444 q if (++element_count > limit)
517374172 q return;
518408426444 q if (items_by_id[i].timestamp == NOW)
519330528407 q print_item(extra_data, output, items_by_id[i].idx.val(), *items_by_id[i].obj);
52077898123 q else
52177898123 q print_item(extra_data, output, items_by_id[i].idx.val(),
52277898123 q Attic< Object >(*items_by_id[i].obj, items_by_id[i].timestamp));
523408426444 q }
52470485556 q}
527template< class Index, class Object >
528void collect_metadata(std::set< OSM_Element_Metadata_Skeleton< typename Object::Id_Type > >& metadata,
529 const std::map< Index, std::vector< Object > >& items,
530 typename Object::Id_Type lower_id_bound, typename Object::Id_Type upper_id_bound,
531 Meta_Collector< Index, typename Object::Id_Type >& meta_printer)
53316586 q for (typename std::map< Index, std::vector< Object > >::const_iterator
534802286 q it(items.begin()); it != items.end(); ++it)
535785767 q {
536785767 q for (typename std::vector< Object >::const_iterator it2(it->second.begin());
53753769567 q it2 != it->second.end(); ++it2)
53852983865 q {
53952983865 q if (!(it2->id < lower_id_bound) && (it2->id < upper_id_bound))
54052983865 q {
54152983865 q const OSM_Element_Metadata_Skeleton< typename Object::Id_Type >* meta
54252983865 q = meta_printer.get(it->first, it2->id);
54352983865 q if (meta)
54419314126 q metadata.insert(*meta);
54552983865 q }
54652983865 q }
547785767 q }
551template< class Index, class Object >
552void collect_metadata(std::set< OSM_Element_Metadata_Skeleton< typename Object::Id_Type > >& metadata,
553 const std::map< Index, std::vector< Attic< Object > > >& items,
554 typename Object::Id_Type lower_id_bound, typename Object::Id_Type upper_id_bound,
555 Attic_Meta_Collector< Index, Object >& meta_printer)
55714270 q for (typename std::map< Index, std::vector< Attic< Object > > >::const_iterator
5583457070 q it(items.begin()); it != items.end(); ++it)
5593442866 q {
5603442866 q for (typename std::vector< Attic< Object > >::const_iterator it2(it->second.begin());
56117781266 q it2 != it->second.end(); ++it2)
56214338460 q {
56314338460 q if (!(it2->id < lower_id_bound) && (it2->id < upper_id_bound))
56414338460 q {
56514338460 q const OSM_Element_Metadata_Skeleton< typename Object::Id_Type >* meta
56614338460 q = meta_printer.get(it->first, it2->id, it2->timestamp);
56714338460 q if (meta)
5681752310 q metadata.insert(*meta);
56914338460 q }
57014338460 q }
5713442866 q }
575template< typename Id_Type >
576typename std::set< OSM_Element_Metadata_Skeleton< Id_Type > >::const_iterator
577 find_matching_metadata
578 (const std::set< OSM_Element_Metadata_Skeleton< Id_Type > >& metadata,
579 Id_Type ref, uint64 timestamp)
58013686459 q{
58113686459 q typename std::set< OSM_Element_Metadata_Skeleton< Id_Type > >::iterator it
58213686459 q = metadata.lower_bound(OSM_Element_Metadata_Skeleton< Id_Type >(ref, timestamp));
58313686459 q if (it == metadata.begin())
58412005250 q return metadata.end();
5851681210 q --it;
5861681210 q if (it->ref == ref)
5871681210 q return it;
5880 else
5890 return metadata.end();
5901681210 q}
593template< class Index, class Object >
594void tags_by_id
595 (Extra_Data& extra_data, const std::map< Index, std::vector< Object > >& items,
596 uint32 FLUSH_SIZE, Output_Handler& output,
597 Resource_Manager& rman, Meta_Collector< Index, typename Object::Id_Type >* meta_printer,
598 Tag_Store< Index, Object >& tag_store, uint32 limit, uint32& element_count)
6009213585 q std::vector< std::pair< const Object*, uint32 > > items_by_id = collect_items_by_id(items);
602 // iterate over the result
60312620585 q for (typename Object::Id_Type id_pos; id_pos < items_by_id.size(); id_pos += FLUSH_SIZE)
6043415577 q {
605 // Disable health_check: This ensures that a result will be always printed completely
606 //rman.health_check(*this);
6083415577 q typename Object::Id_Type lower_id_bound(items_by_id[id_pos.val()].first->id);
6093415577 q typename Object::Id_Type upper_id_bound;
6103415577 q if (id_pos + FLUSH_SIZE < items_by_id.size())
6110 upper_id_bound = items_by_id[(id_pos + FLUSH_SIZE).val()].first->id;
6123415577 q else
6133415577 q {
6143415577 q upper_id_bound = items_by_id[items_by_id.size()-1].first->id;
6153415577 q ++upper_id_bound;
6163415577 q }
6183415577 q tag_store.prefetch_chunk(items, lower_id_bound, upper_id_bound);
6203415577 q std::set< OSM_Element_Metadata_Skeleton< typename Object::Id_Type > > metadata;
6213415577 q if (meta_printer)
623 // collect metadata if required
6242316 q collect_metadata(metadata, items, lower_id_bound, upper_id_bound, *meta_printer);
6252316 q meta_printer->reset();
628 // print the result
6293415577 q for (typename Object::Id_Type i(id_pos);
6303814582577 q (i < id_pos + FLUSH_SIZE) && (i < items_by_id.size()); ++i)
6313811175577 q {
6323811175577 q if (++element_count > limit)
63385 q return;
6343811167577 q typename std::set< OSM_Element_Metadata_Skeleton< typename Object::Id_Type > >::const_iterator meta_it
6353811167577 q = metadata.lower_bound(OSM_Element_Metadata_Skeleton< typename Object::Id_Type >
6363811167577 q (items_by_id[i.val()].first->id));
6373811167577 q print_item(extra_data, output, items_by_id[i.val()].second, *(items_by_id[i.val()].first),
6383811167577 q tag_store.get(Index(items_by_id[i.val()].second), *items_by_id[i.val()].first),
6393811167577 q (meta_it != metadata.end() && meta_it->ref == items_by_id[i.val()].first->id) ?
6403627225577 q &*meta_it : 0);
6413811167577 q }
6423415577 q }
647template< class Index, class Object >
648void tags_by_id_attic
649 (const std::map< Index, std::vector< Object > >& current_items,
650 const std::map< Index, std::vector< Attic< Object > > >& attic_items,
651 Extra_Data& extra_data, uint32 FLUSH_SIZE, Output_Handler& output,
652 Resource_Manager& rman, Transaction& transaction, uint32 limit, uint32& element_count)
6545358206 q std::vector< Maybe_Attic_Ref< Index, Object > > items_by_id = collect_items_by_id(current_items, attic_items);
6565358206 q Tag_Store< Index, Object > current_tag_store(transaction);
6575358206 q Tag_Store< Index, Object > attic_tag_store(transaction);
659 // formulate meta query if meta data shall be printed
6605358206 q Meta_Collector< Index, typename Object::Id_Type > only_current_meta_printer
6615358206 q (current_items, transaction,
6625358206 q (extra_data.mode & Output_Mode::META) ? current_meta_file_properties< Object >() : 0);
6645493206 q for (typename Object::Id_Type id_pos; id_pos < items_by_id.size(); id_pos += FLUSH_SIZE)
66514270 q {
666 // Disable health_check: This ensures that a result will be always printed completely
667 //rman.health_check(*this);
66914270 q typename Object::Id_Type lower_id_bound(items_by_id[id_pos.val()].obj->id);
67014270 q typename Object::Id_Type upper_id_bound;
67114270 q if (id_pos + FLUSH_SIZE < items_by_id.size())
6720 upper_id_bound = items_by_id[(id_pos + FLUSH_SIZE).val()].obj->id;
67314270 q else
67414270 q {
67514270 q upper_id_bound = items_by_id[items_by_id.size()-1].obj->id;
67614270 q ++upper_id_bound;
67714270 q }
67914270 q current_tag_store.prefetch_chunk(current_items, lower_id_bound, upper_id_bound);
68014270 q attic_tag_store.prefetch_chunk(attic_items, lower_id_bound, upper_id_bound);
682 // collect metadata if required
68314270 q std::set< OSM_Element_Metadata_Skeleton< typename Object::Id_Type > > only_current_metadata;
68414270 q collect_metadata(only_current_metadata, current_items, lower_id_bound, upper_id_bound,
68514270 q only_current_meta_printer);
68614270 q only_current_meta_printer.reset();
68814270 q Attic_Meta_Collector< Index, Object > meta_printer(attic_items, transaction, extra_data.mode & Output_Mode::META);
68914270 q std::set< OSM_Element_Metadata_Skeleton< typename Object::Id_Type > > attic_metadata;
69014270 q collect_metadata(attic_metadata, attic_items, lower_id_bound, upper_id_bound, meta_printer);
692 // print the result
69314270 q for (typename Object::Id_Type i(id_pos);
69446218670 q (i < id_pos + FLUSH_SIZE) && (i < items_by_id.size()); ++i)
69546205170 q {
69646205170 q if (++element_count > limit)
69774 q return;
69846204470 q if (items_by_id[i.val()].timestamp == NOW)
69932518049 q {
70032518049 q typename std::set< OSM_Element_Metadata_Skeleton< typename Object::Id_Type > >::const_iterator meta_it
70132518049 q = only_current_metadata.lower_bound(OSM_Element_Metadata_Skeleton< typename Object::Id_Type >
70232518049 q (items_by_id[i.val()].obj->id));
70332518049 q print_item(extra_data, output, items_by_id[i.val()].idx.val(), *items_by_id[i.val()].obj,
70432518049 q current_tag_store.get(items_by_id[i.val()].idx, *items_by_id[i.val()].obj),
70532518049 q (meta_it != only_current_metadata.end() && meta_it->ref == items_by_id[i.val()].obj->id) ?
70631623349 q &*meta_it : 0);
70732518049 q }
70813686459 q else
70913686459 q {
71013686459 q typename std::set< OSM_Element_Metadata_Skeleton< typename Object::Id_Type > >::const_iterator meta_it
71113686459 q = find_matching_metadata(attic_metadata,
71213686459 q items_by_id[i.val()].obj->id, items_by_id[i.val()].timestamp);
71313686459 q print_item(extra_data, output, items_by_id[i.val()].idx.val(),
71413686459 q Attic< Object >(*items_by_id[i.val()].obj, items_by_id[i.val()].timestamp),
71513686459 q attic_tag_store.get(items_by_id[i.val()].idx, *items_by_id[i.val()].obj),
71613686459 q meta_it != attic_metadata.end() ? &*meta_it : 0);
71713686459 q }
71846204470 q }
71914270 q }
723template< class Index, class Object >
724void tags_by_id
725 (Extra_Data& extra_data, const std::map< Index, std::vector< Object > >& items,
726 const std::map< Index, std::vector< Attic< Object > > >& attic_items,
727 unsigned int mode, uint32 FLUSH_SIZE, Output_Handler& output, Resource_Manager& rman,
728 uint32 limit, uint32& element_count)
72910593585 q{
73010593585 q if (mode & Output_Mode::META)
7329632 q if (rman.get_desired_timestamp() == NOW)
7345117 q Tag_Store< Index, Object > tag_store(*rman.get_transaction());
7355117 q Meta_Collector< Index, typename Object::Id_Type > meta_printer(items, *rman.get_transaction(),
7365117 q current_meta_file_properties< Object >());
7375117 q tags_by_id(extra_data, items, FLUSH_SIZE, output, rman, &meta_printer, tag_store, limit, element_count);
7394515 q else
7404515 q tags_by_id_attic(items, attic_items, extra_data, FLUSH_SIZE, output, rman, *rman.get_transaction(),
7414515 q limit, element_count);
74310497585 q else
74410497585 q {
74510497585 q if (rman.get_desired_timestamp() == NOW)
7465184384 q {
7475184384 q Tag_Store< Index, Object > tag_store(*rman.get_transaction());
7485184384 q tags_by_id(extra_data, items, FLUSH_SIZE, output, rman,
7495184384 q (Meta_Collector< Index, typename Object::Id_Type >*)0, tag_store, limit, element_count);
7505184384 q }
7515313206 q else
7525313206 q tags_by_id_attic(items, attic_items, extra_data, FLUSH_SIZE, output, rman, *rman.get_transaction(),
7535313206 q limit, element_count);
75410497585 q }
75510593585 q}
758std::vector< std::pair< std::string, std::string > > make_count_tags(const Set& set, bool include_areas)
7603034561 q unsigned int num_nodes = count(set.nodes) + count(set.attic_nodes);
7613034561 q unsigned int num_ways = count(set.ways) + count(set.attic_ways);
7623034561 q unsigned int num_relations = count(set.relations) + count(set.attic_relations);
7633034561 q unsigned int num_areas = include_areas ? count(set.areas) : 0;
7653034561 q std::vector< std::pair< std::string, std::string > > count_tags;
7663034561 q count_tags.push_back(std::make_pair("nodes", to_string(num_nodes)));
7673034561 q count_tags.push_back(std::make_pair("ways", to_string(num_ways)));
7683034561 q count_tags.push_back(std::make_pair("relations", to_string(num_relations)));
7693034561 q if (include_areas)
770361115 q count_tags.push_back(std::make_pair("areas", to_string(num_areas)));
7713034561 q count_tags.push_back(std::make_pair("total", to_string(num_nodes + num_ways + num_relations + num_areas)));
7733034561 q return count_tags;
777void Print_Statement::execute(Resource_Manager& rman)
77828091665 q{
77928091665 q Cpu_Timer cpu(rman, 2);
78128091665 q Diff_Action::_ action = rman.get_desired_action();
78228091665 q if (action == Diff_Action::collect_lhs
78328091665 q || action == Diff_Action::collect_rhs_no_del || action == Diff_Action::collect_rhs_with_del)
78498381 q {
78598381 q execute_comparison(rman);
78698381 q return;
78798381 q }
78927108590 q if (action == Diff_Action::positive && rman.area_updater())
7900 rman.area_updater()->flush();
79227108590 q const Set* input_set = rman.get_set(input);
79427108590 q Set count_set;
79527108590 q const Set* output_items = 0;
79627108590 q if (mode & Output_Mode::COUNT)
7973034561 q {
7983034561 q count_set.deriveds[Uint31_Index(0u)].push_back(Derived_Structure("count", Uint64(0ull),
7993034561 q make_count_tags(input_set ? *input_set : Set(), rman.get_area_transaction()), 0));
8003034561 q output_items = &count_set;
8013034561 q mode = mode | Output_Mode::TAGS;
8023034561 q }
80324074584 q else
80424074584 q {
80524074584 q if (!input_set)
8063430 q return;
80824040582 q output_items = input_set;
80924040582 q }
81127074589 q Output_Handler::Feature_Action feature_action = Output_Handler::keep;
81227074589 q if (action == Diff_Action::show_old)
81366 q feature_action = Output_Handler::show_from;
81427068589 q else if (action == Diff_Action::show_new)
81566 q feature_action = Output_Handler::show_to;
81727074589 q Extra_Data extra_data(rman, *this, *output_items, mode, feature_action, south, north, west, east);
81827074589 q Output_Handler& output_handler = *rman.get_global_settings().get_output_handler();
81927074589 q uint32 element_count = 0;
82127074589 q if (order == order_by_id)
82227026587 q {
82327026587 q if (mode & Output_Mode::TAGS)
8243531585 q {
8253531585 q tags_by_id(extra_data, output_items->nodes, output_items->attic_nodes, mode, NODE_FLUSH_SIZE,
8263531585 q output_handler, rman, limit, element_count);
8273531585 q tags_by_id(extra_data, output_items->ways, output_items->attic_ways, mode, WAY_FLUSH_SIZE,
8283531585 q output_handler, rman, limit, element_count);
8293531585 q tags_by_id(extra_data, output_items->relations, output_items->attic_relations, mode, RELATION_FLUSH_SIZE,
8303531585 q output_handler, rman, limit, element_count);
8323531585 q if (rman.get_area_transaction())
834447115 q Tag_Store< Uint31_Index, Area_Skeleton > tag_store(*rman.get_transaction());
835447115 q tags_by_id(extra_data, output_items->areas, AREA_FLUSH_SIZE, output_handler, rman,
836447115 q (Meta_Collector< Uint31_Index, Area_Skeleton::Id_Type >*)0,
837447115 q tag_store, limit, element_count);
8403531585 q Tag_Store< Uint31_Index, Derived_Structure > tag_store;
8413531585 q tags_by_id(extra_data, output_items->deriveds, std::numeric_limits< uint32 >::max(), output_handler, rman,
8423531585 q (Meta_Collector< Uint31_Index, Derived_Structure::Id_Type >*)0, tag_store, limit, element_count);
8433531585 q }
84423495556 q else
84523495556 q {
84623495556 q by_id(output_items->nodes, output_items->attic_nodes,
84723495556 q output_handler, *rman.get_transaction(), extra_data, limit, element_count);
84823495556 q by_id(output_items->ways, output_items->attic_ways,
84923495556 q output_handler, *rman.get_transaction(), extra_data, limit, element_count);
85023495556 q by_id(output_items->relations, output_items->attic_relations,
85123495556 q output_handler, *rman.get_transaction(), extra_data, limit, element_count);
85223495556 q if (rman.get_area_transaction())
853356113 q by_id(output_items->areas, output_handler, *rman.get_area_transaction(), extra_data, limit, element_count);
85423495556 q by_id(output_items->deriveds, output_handler, *rman.get_transaction(), extra_data, limit, element_count);
85523495556 q }
85627026587 q }
8574848 q else
8594848 q if (mode & Output_Mode::TAGS)
8613030 q tags_quadtile_(extra_data, output_items->nodes,
8623030 q output_handler, rman, *rman.get_transaction(), limit, element_count);
8643030 q if (rman.get_desired_timestamp() != NOW)
8651313 q tags_quadtile_attic_(extra_data, output_items->attic_nodes,
8661313 q output_handler, rman, *rman.get_transaction(), limit, element_count);
8683030 q tags_quadtile_(extra_data, output_items->ways,
8693030 q output_handler, rman, *rman.get_transaction(), limit, element_count);
8713030 q if (rman.get_desired_timestamp() != NOW)
8721313 q tags_quadtile_attic_(extra_data, output_items->attic_ways,
8731313 q output_handler, rman, *rman.get_transaction(), limit, element_count);
8753030 q tags_quadtile_(extra_data, output_items->relations,
8763030 q output_handler, rman, *rman.get_transaction(), limit, element_count);
8783030 q if (rman.get_desired_timestamp() != NOW)
8791313 q tags_quadtile_attic_(extra_data, output_items->attic_relations,
8801313 q output_handler, rman, *rman.get_transaction(), limit, element_count);
8823030 q if (rman.get_area_transaction())
88366 q tags_quadtile_(extra_data, output_items->areas,
88466 q output_handler, rman, *rman.get_area_transaction(), limit, element_count);
8863030 q tags_quadtile_(extra_data, output_items->deriveds,
8873030 q output_handler, rman, *rman.get_transaction(), limit, element_count);
8891818 q else
8911818 q quadtile_(output_items->nodes, output_handler, *rman.get_transaction(), extra_data, limit, element_count);
8921818 q quadtile_(output_items->attic_nodes, output_handler, *rman.get_transaction(), extra_data, limit, element_count);
8941818 q quadtile_(output_items->ways, output_handler, *rman.get_transaction(), extra_data, limit, element_count);
8951818 q quadtile_(output_items->attic_ways, output_handler, *rman.get_transaction(), extra_data, limit, element_count);
8971818 q quadtile_(output_items->relations, output_handler, *rman.get_transaction(), extra_data, limit, element_count);
8981818 q quadtile_(output_items->attic_relations, output_handler, *rman.get_transaction(), extra_data, limit, element_count);
9001818 q if (rman.get_area_transaction())
90144 q quadtile_(output_items->areas, output_handler, *rman.get_area_transaction(), extra_data, limit, element_count);
9031818 q quadtile_(output_items->deriveds, output_handler, *rman.get_transaction(), extra_data, limit, element_count);
90727074589 q rman.health_check(*this);
90827074589 q}
911void Print_Statement::execute_comparison(Resource_Manager& rman)
91398381 q Diff_Action::_ action = rman.get_desired_action();
91598381 q const Diff_Set* input_diff_set = rman.get_diff_set(input);
91698381 q if (input_diff_set)
9184620 q print_diff_set(*input_diff_set, mode, rman.get_global_settings().get_output_handler(),
9194620 q rman.users(), relation_member_roles(*rman.get_transaction()), action == Diff_Action::collect_rhs_with_del);
9204620 q return;
92393781 q const Set* input_set = rman.get_set(input);
92493781 q if (!input_set)
925145 q return;
92792381 q if (action == Diff_Action::collect_lhs)
92848181 q {
92948181 q if (collection_print_target && diff_valid)
93111 q runtime_error("A print statement cannot be executed in a loop in a diff setting.");
93211 q diff_valid = false;
93311 q delete collection_print_target;
93411 q collection_print_target = 0;
93511 q return;
93748081 q delete collection_print_target;
93848081 q collection_print_target = new Set_Comparison(
93948081 q *rman.get_transaction(), *input_set, rman.get_desired_timestamp());
94048081 q }
94144281 q else
94244281 q {
94344281 q if (!diff_valid || !collection_print_target)
94452 q return;
94643781 q Diff_Set result = collection_print_target->compare_to_lhs(rman, *this, *input_set,
94743781 q south, north, west, east, action == Diff_Action::collect_rhs_with_del);
94943781 q print_diff_set(result, mode, rman.get_global_settings().get_output_handler(),
95043781 q rman.users(), relation_member_roles(*rman.get_transaction()), action == Diff_Action::collect_rhs_with_del);
95143781 q }
95391781 q rman.health_check(*this);
957Print_Statement::~Print_Statement()
95812042679 q{
95912042679 q delete collection_print_target;
96012042679 q}