Overpass API regression suite coverage (Nova Scotia) / 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)
5210749597 q : Statement(line_number_),
5310749597 q mode(0), order(order_by_id), limit(std::numeric_limits< unsigned int >::max()),
5410749597 q collection_print_target(0), diff_valid(true),
5510749597 q south(1.0), north(0.0), west(0.0), east(0.0)
5610749597 q{
5710749597 q std::map< std::string, std::string > attributes;
5910749597 q attributes["from"] = "_";
6010749597 q attributes["ids"] = "yes";
6110749597 q attributes["mode"] = "body";
6210749597 q attributes["order"] = "id";
6310749597 q attributes["limit"] = "";
6410749597 q attributes["geometry"] = "skeleton";
6510749597 q attributes["s"] = "";
6610749597 q attributes["n"] = "";
6710749597 q attributes["w"] = "";
6810749597 q attributes["e"] = "";
7010749597 q eval_attributes_array(get_name(), attributes, input_attributes);
7210749597 q input = attributes["from"];
7410749597 q if (attributes["mode"] == "ids_only")
754545580 q mode = Output_Mode::ID;
766204595 q else if (attributes["mode"] == "skeleton")
776020 q mode = Output_Mode::ID
786020 q | Output_Mode::COORDS | Output_Mode::NDS | Output_Mode::MEMBERS;
796144595 q else if (attributes["mode"] == "tags")
80124 q mode = Output_Mode::ID | Output_Mode::TAGS;
816132594 q else if (attributes["mode"] == "body")
821431457 q mode = Output_Mode::ID
831431457 q | Output_Mode::COORDS | Output_Mode::NDS | Output_Mode::MEMBERS
841431457 q | Output_Mode::TAGS;
854701579 q else if (attributes["mode"] == "meta")
867224 q mode = Output_Mode::ID
877224 q | Output_Mode::COORDS | Output_Mode::NDS | Output_Mode::MEMBERS
887224 q | Output_Mode::TAGS | Output_Mode::VERSION | Output_Mode::META;
894629579 q else if (attributes["mode"] == "count")
904626579 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());
10010749597 q if (attributes["order"] == "id")
10110635596 q order = order_by_id;
10211438 q else if (attributes["order"] == "quadtile")
10311438 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 }
11210749597 q if (attributes["limit"] != "")
1134560578 q limit = atoll(attributes["limit"].c_str());
11510749597 q if (attributes["geometry"] == "skeleton")
11610596593 q ;
11715348 q else if (attributes["geometry"] == "full")
1187222 q mode = mode | Output_Mode::GEOMETRY | Output_Mode::BOUNDS;
1198127 q else if (attributes["geometry"] == "bounds")
1204515 q mode = mode | Output_Mode::BOUNDS;
1213612 q else if (attributes["geometry"] == "center")
1223612 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 }
13110749597 q if (attributes["ids"] == "yes")
13210719597 q ;
1333010 q else if (attributes["ids"] == "no")
1343010 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 }
14310749597 q south = atof(attributes["s"].c_str());
14410749597 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 }
15110749597 q north = atof(attributes["n"].c_str());
15210749597 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 }
15910749597 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 }
16710749597 q west = atof(attributes["w"].c_str());
16810749597 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 }
17510749597 q east = atof(attributes["e"].c_str());
17610749597 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 }
18310749597 q if ((attributes["n"] == "") && (attributes["s"] == "") &&
18410749597 q (attributes["w"] == "") && (attributes["e"] == ""))
18510641597 q {
18610641597 q south = 1.0;
18710641597 q north = 0.0;
18810641597 q }
18910749597 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)
2177583514 q : mode(mode_), action(action_), way_geometry_store(0), attic_way_geometry_store(0),
2187583514 q relation_geometry_store(0), attic_relation_geometry_store(0), roles(0), users(0)
2207583514 q if (mode & (Output_Mode::GEOMETRY | Output_Mode::BOUNDS | Output_Mode::CENTER))
2224138 q way_geometry_store = new Way_Bbox_Geometry_Store(to_print.ways, stmt, rman, south, north, west, east);
2234138 q if (rman.get_desired_timestamp() < NOW)
2251211 q attic_way_geometry_store = new Way_Bbox_Geometry_Store(
2261211 q to_print.attic_ways, stmt, rman,
2271211 q south, north, west, east);
2304138 q relation_geometry_store = new Relation_Geometry_Store(
2314138 q to_print.relations, stmt, rman, south, north, west, east);
2324138 q if (rman.get_desired_timestamp() < NOW)
2341211 q attic_relation_geometry_store = new Relation_Geometry_Store(
2351211 q to_print.attic_relations, stmt, rman,
2361211 q south, north, west, east);
2407583514 q roles = &relation_member_roles(*rman.get_transaction());
2427583514 q if (mode & Output_Mode::META)
2432222 q users = &rman.users();
247const std::map< uint32, std::string >* Extra_Data::get_users() const
2482403413424 q{
2492403413424 q return users;
2502403413424 q}
253Extra_Data::~Extra_Data()
2557583514 q delete way_geometry_store;
2567583514 q delete attic_way_geometry_store;
2577583514 q delete relation_geometry_store;
2587583514 q delete attic_relation_geometry_store;
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)
2651160764245 q{
2661160764245 q output.print_item(skel, Point_Geometry(::lat(ll_upper, skel.ll_lower), ::lon(ll_upper, skel.ll_lower)),
2671160764245 q tags, meta, extra_data.get_users(), Output_Mode(extra_data.mode), extra_data.action);
2681160764245 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)
2741036208250 q{
2751036208250 q Geometry_From_Quad_Coords broker;
2761036208250 q output.print_item(skel,
2771036208250 q broker.make_way_geom(skel, extra_data.mode, extra_data.way_geometry_store),
2781036208250 q tags, meta, extra_data.get_users(), Output_Mode(extra_data.mode), extra_data.action);
2791036208250 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)
2854884072 q{
2864884072 q Geometry_From_Quad_Coords broker;
2874884072 q output.print_item(skel,
2884884072 q broker.make_way_geom(skel, extra_data.mode, extra_data.attic_way_geometry_store),
2894884072 q tags, meta, extra_data.get_users(), Output_Mode(extra_data.mode), extra_data.action);
2904884072 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)
296148128148 q{
297148128148 q Geometry_From_Quad_Coords broker;
298148128148 q output.print_item(skel,
299148128148 q broker.make_relation_geom(skel, extra_data.mode, extra_data.relation_geometry_store),
300148128148 q tags, meta, extra_data.roles, extra_data.get_users(), Output_Mode(extra_data.mode), extra_data.action);
301148128148 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)
307947344 q{
308947344 q Geometry_From_Quad_Coords broker;
309947344 q output.print_item(skel,
310947344 q broker.make_relation_geom(skel, extra_data.mode, extra_data.attic_relation_geometry_store),
311947344 q tags, meta, extra_data.roles, extra_data.get_users(), Output_Mode(extra_data.mode), extra_data.action);
312947344 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)
318380982 q{
319380982 q Derived_Skeleton derived("area", Uint64(skel.id.val()));
320380982 q output.print_item(derived, Null_Geometry(), tags, Output_Mode(extra_data.mode), extra_data.action);
321380982 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)
32773471494 q{
32873471494 q if (skel.get_geometry())
3293826348 q output.print_item(skel, *skel.get_geometry(), tags, Output_Mode(extra_data.mode), extra_data.action);
33035208494 q else
33135208494 q output.print_item(skel, Null_Geometry(), tags, Output_Mode(extra_data.mode), extra_data.action);
33273471494 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)
34012417 q typename std::map< TIndex, std::vector< TObject > >::const_iterator
34112417 q item_it(items.begin());
342 // print the result
343831817 q while (item_it != items.end())
344820016 q {
345820016 q for (typename std::vector< TObject >::const_iterator it2(item_it->second.begin());
3462908116 q it2 != item_it->second.end(); ++it2)
3472088714 q {
3482088714 q if (++element_count > limit)
34964 q return;
3502088114 q print_item(extra_data, output, item_it->first.val(), *it2);
3512088114 q }
352819414 q ++item_it;
353819414 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)
3638420 q Tag_Store< Index, Object > tag_store(*rman.get_transaction());
3648420 q tag_store.prefetch_all(items);
366 // formulate meta query if meta data shall be printed
3678420 q Meta_Collector< Index, typename Object::Id_Type > meta_printer(items, transaction,
3688420 q (extra_data.mode & Output_Mode::META) ? current_meta_file_properties< Object >() : 0);
3708420 q typename std::map< Index, std::vector< Object > >::const_iterator
3718420 q item_it(items.begin());
372 // print the result
373775020 q while (item_it != items.end())
374767118 q {
375767118 q for (typename std::vector< Object >::const_iterator it2(item_it->second.begin());
3762004418 q it2 != item_it->second.end(); ++it2)
3771237816 q {
3781237816 q if (++element_count > limit)
37955 q return;
3801237316 q print_item(extra_data, output, item_it->first.val(), *it2, tag_store.get(item_it->first, *it2),
3811237316 q meta_printer.get(item_it->first, it2->id));
3821237316 q }
383766617 q ++item_it;
384766617 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)
3943311 q Tag_Store< Index, Object > tag_store(transaction);
3953311 q tag_store.prefetch_all(items);
3973311 q Attic_Meta_Collector< Index, Object > meta_printer(items, transaction, extra_data.mode & Output_Mode::META);
3993311 q typename std::map< Index, std::vector< Attic< Object > > >::const_iterator
4003311 q item_it(items.begin());
401719611 q while (item_it != items.end())
40271659 q {
40371659 q for (typename std::vector< Attic< Object > >::const_iterator it2(item_it->second.begin());
40475689 q it2 != item_it->second.end(); ++it2)
4054058 q {
4064058 q if (++element_count > limit)
40722 q return;
4084036 q print_item(extra_data, output, item_it->first.val(), *it2, tag_store.get(item_it->first, *it2),
4094036 q meta_printer.get(item_it->first, it2->id, it2->timestamp));
4104036 q }
41171639 q ++item_it;
41271639 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)
42040201095249 q {
42140201095249 q return (a.first->id < b.first->id);
42240201095249 q }
423};
426template< typename Index, typename Object >
427struct Maybe_Attic_Ref
429public:
430 Maybe_Attic_Ref(Index idx_, const Object* obj_, uint64 timestamp_)
43115821058411 q : idx(idx_), obj(obj_), timestamp(timestamp_) {}
433 Index idx;
434 const Object* obj;
435 uint64 timestamp;
437391220430364 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)
44419103513 q{
44519103513 q std::vector< std::pair< const Object*, uint32 > > items_by_id;
44719103513 q for (typename std::map< Index, std::vector< Object > >::const_iterator
448357545513 q it(items.begin()); it != items.end(); ++it)
449338442506 q {
450338442506 q for (typename std::vector< Object >::const_iterator it2(it->second.begin());
4512386755506 q it2 != it->second.end(); ++it2)
4522048313506 q items_by_id.push_back(std::make_pair(&(*it2), it->first.val()));
453338442506 q }
45419103513 q sort(items_by_id.begin(), items_by_id.end(),
45519103513 q Skeleton_Comparator_By_Id< Object >());
45719103513 q return items_by_id;
45819103513 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)
46511835496 q{
46611835496 q std::vector< Maybe_Attic_Ref< Index, Object > > items_by_id;
46711835496 q for (typename std::map< Index, std::vector< Object > >::const_iterator
4681358241496 q it(items.begin()); it != items.end(); ++it)
4691346406401 q {
4701346406401 q for (typename std::vector< Object >::const_iterator it2(it->second.begin());
47116772483401 q it2 != it->second.end(); ++it2)
47215426077386 q items_by_id.push_back(Maybe_Attic_Ref< Index, Object >(it->first, &(*it2), NOW));
4731346406401 q }
47411835496 q for (typename std::map< Index, std::vector< Attic< Object > > >::const_iterator
475143039496 q it(attic_items.begin()); it != attic_items.end(); ++it)
476131204136 q {
477131204136 q for (typename std::vector< Attic< Object > >::const_iterator it2(it->second.begin());
478526185136 q it2 != it->second.end(); ++it2)
479394981109 q items_by_id.push_back(Maybe_Attic_Ref< Index, Object >(it->first, &(*it2), it2->timestamp));
480131204136 q }
48111835496 q sort(items_by_id.begin(), items_by_id.end());
48311835496 q return items_by_id;
48411835496 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)
4921919491 q std::vector< std::pair< const Object*, uint32 > > items_by_id = collect_items_by_id(items);
494 // iterate over the result
49534622491 q for (uint32 i(0); i < items_by_id.size(); ++i)
49632731184 q {
49732731184 q if (++element_count > limit)
4982825 q return;
49932703183 q print_item(extra_data, output, items_by_id[i].second, *(items_by_id[i].first));
50032703183 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)
5114800491 q std::vector< Maybe_Attic_Ref< Index, Object > > items_by_id = collect_items_by_id(items, attic_items);
513 // iterate over the result
514472050491 q for (uint32 i(0); i < items_by_id.size(); ++i)
515467601410 q {
516467601410 q if (++element_count > limit)
517351143 q return;
518467250410 q if (items_by_id[i].timestamp == NOW)
519321449386 q print_item(extra_data, output, items_by_id[i].idx.val(), *items_by_id[i].obj);
520145801107 q else
521145801107 q print_item(extra_data, output, items_by_id[i].idx.val(),
522145801107 q Attic< Object >(*items_by_id[i].obj, items_by_id[i].timestamp));
523467250410 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)
53314278 q for (typename std::map< Index, std::vector< Object > >::const_iterator
5345629978 q it(items.begin()); it != items.end(); ++it)
5355615762 q {
5365615762 q for (typename std::vector< Object >::const_iterator it2(it->second.begin());
53723948362 q it2 != it->second.end(); ++it2)
53818332658 q {
53918332658 q if (!(it2->id < lower_id_bound) && (it2->id < upper_id_bound))
54018332658 q {
54118332658 q const OSM_Element_Metadata_Skeleton< typename Object::Id_Type >* meta
54218332658 q = meta_printer.get(it->first, it2->id);
54318332658 q if (meta)
54410134216 q metadata.insert(*meta);
54518332658 q }
54618332658 q }
5475615762 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)
55712469 q for (typename std::map< Index, std::vector< Attic< Object > > >::const_iterator
558738169 q it(items.begin()); it != items.end(); ++it)
559725763 q {
560725763 q for (typename std::vector< Attic< Object > >::const_iterator it2(it->second.begin());
5613474063 q it2 != it->second.end(); ++it2)
5622748359 q {
5632748359 q if (!(it2->id < lower_id_bound) && (it2->id < upper_id_bound))
5642748359 q {
5652748359 q const OSM_Element_Metadata_Skeleton< typename Object::Id_Type >* meta
5662748359 q = meta_printer.get(it->first, it2->id, it2->timestamp);
5672748359 q if (meta)
5688578 q metadata.insert(*meta);
5692748359 q }
5702748359 q }
571725763 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)
5802560959 q{
5812560959 q typename std::set< OSM_Element_Metadata_Skeleton< Id_Type > >::iterator it
5822560959 q = metadata.lower_bound(OSM_Element_Metadata_Skeleton< Id_Type >(ref, timestamp));
5832560959 q if (it == metadata.begin())
5842475252 q return metadata.end();
5858578 q --it;
5868578 q if (it->ref == ref)
5878578 q return it;
5880 else
5890 return metadata.end();
5908578 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)
59917184511 q{
60017184511 q std::vector< std::pair< const Object*, uint32 > > items_by_id = collect_items_by_id(items);
602 // iterate over the result
60323053511 q for (typename Object::Id_Type id_pos; id_pos < items_by_id.size(); id_pos += FLUSH_SIZE)
6045877506 q {
605 // Disable health_check: This ensures that a result will be always printed completely
606 //rman.health_check(*this);
6085877506 q typename Object::Id_Type lower_id_bound(items_by_id[id_pos.val()].first->id);
6095877506 q typename Object::Id_Type upper_id_bound;
6105877506 q if (id_pos + FLUSH_SIZE < items_by_id.size())
6110 upper_id_bound = items_by_id[(id_pos + FLUSH_SIZE).val()].first->id;
6125877506 q else
6135877506 q {
6145877506 q upper_id_bound = items_by_id[items_by_id.size()-1].first->id;
6155877506 q ++upper_id_bound;
6165877506 q }
6185877506 q tag_store.prefetch_chunk(items, lower_id_bound, upper_id_bound);
6205877506 q std::set< OSM_Element_Metadata_Skeleton< typename Object::Id_Type > > metadata;
6215877506 q if (meta_printer)
622189 q {
623 // collect metadata if required
624189 q collect_metadata(metadata, items, lower_id_bound, upper_id_bound, *meta_printer);
625189 q meta_printer->reset();
626189 q }
628 // print the result
6295877506 q for (typename Object::Id_Type i(id_pos);
6301835908506 q (i < id_pos + FLUSH_SIZE) && (i < items_by_id.size()); ++i)
6311830039506 q {
6321830039506 q if (++element_count > limit)
63386 q return;
6341830031506 q typename std::set< OSM_Element_Metadata_Skeleton< typename Object::Id_Type > >::const_iterator meta_it
6351830031506 q = metadata.lower_bound(OSM_Element_Metadata_Skeleton< typename Object::Id_Type >
6361830031506 q (items_by_id[i.val()].first->id));
6371830031506 q print_item(extra_data, output, items_by_id[i.val()].second, *(items_by_id[i.val()].first),
6381830031506 q tag_store.get(Index(items_by_id[i.val()].second), *items_by_id[i.val()].first),
6391830031506 q (meta_it != metadata.end() && meta_it->ref == items_by_id[i.val()].first->id) ?
6401739358506 q &*meta_it : 0);
6411830031506 q }
6425877506 q }
64317184511 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)
6547035176 q std::vector< Maybe_Attic_Ref< Index, Object > > items_by_id = collect_items_by_id(current_items, attic_items);
6567035176 q Tag_Store< Index, Object > current_tag_store(transaction);
6577035176 q Tag_Store< Index, Object > attic_tag_store(transaction);
659 // formulate meta query if meta data shall be printed
6607035176 q Meta_Collector< Index, typename Object::Id_Type > only_current_meta_printer
6617035176 q (current_items, transaction,
6627035176 q (extra_data.mode & Output_Mode::META) ? current_meta_file_properties< Object >() : 0);
6647153176 q for (typename Object::Id_Type id_pos; id_pos < items_by_id.size(); id_pos += FLUSH_SIZE)
66512469 q {
666 // Disable health_check: This ensures that a result will be always printed completely
667 //rman.health_check(*this);
66912469 q typename Object::Id_Type lower_id_bound(items_by_id[id_pos.val()].obj->id);
67012469 q typename Object::Id_Type upper_id_bound;
67112469 q if (id_pos + FLUSH_SIZE < items_by_id.size())
6720 upper_id_bound = items_by_id[(id_pos + FLUSH_SIZE).val()].obj->id;
67312469 q else
67412469 q {
67512469 q upper_id_bound = items_by_id[items_by_id.size()-1].obj->id;
67612469 q ++upper_id_bound;
67712469 q }
67912469 q current_tag_store.prefetch_chunk(current_items, lower_id_bound, upper_id_bound);
68012469 q attic_tag_store.prefetch_chunk(attic_items, lower_id_bound, upper_id_bound);
682 // collect metadata if required
68312469 q std::set< OSM_Element_Metadata_Skeleton< typename Object::Id_Type > > only_current_metadata;
68412469 q collect_metadata(only_current_metadata, current_items, lower_id_bound, upper_id_bound,
68512469 q only_current_meta_printer);
68612469 q only_current_meta_printer.reset();
68812469 q Attic_Meta_Collector< Index, Object > meta_printer(attic_items, transaction, extra_data.mode & Output_Mode::META);
68912469 q std::set< OSM_Element_Metadata_Skeleton< typename Object::Id_Type > > attic_metadata;
69012469 q collect_metadata(attic_metadata, attic_items, lower_id_bound, upper_id_bound, meta_printer);
692 // print the result
69312469 q for (typename Object::Id_Type i(id_pos);
69411717669 q (i < id_pos + FLUSH_SIZE) && (i < items_by_id.size()); ++i)
69511705869 q {
69611705869 q if (++element_count > limit)
69763 q return;
69811705269 q if (items_by_id[i.val()].timestamp == NOW)
6999144349 q {
7009144349 q typename std::set< OSM_Element_Metadata_Skeleton< typename Object::Id_Type > >::const_iterator meta_it
7019144349 q = only_current_metadata.lower_bound(OSM_Element_Metadata_Skeleton< typename Object::Id_Type >
7029144349 q (items_by_id[i.val()].obj->id));
7039144349 q print_item(extra_data, output, items_by_id[i.val()].idx.val(), *items_by_id[i.val()].obj,
7049144349 q current_tag_store.get(items_by_id[i.val()].idx, *items_by_id[i.val()].obj),
7059144349 q (meta_it != only_current_metadata.end() && meta_it->ref == items_by_id[i.val()].obj->id) ?
7068077449 q &*meta_it : 0);
7079144349 q }
7082560959 q else
7092560959 q {
7102560959 q typename std::set< OSM_Element_Metadata_Skeleton< typename Object::Id_Type > >::const_iterator meta_it
7112560959 q = find_matching_metadata(attic_metadata,
7122560959 q items_by_id[i.val()].obj->id, items_by_id[i.val()].timestamp);
7132560959 q print_item(extra_data, output, items_by_id[i.val()].idx.val(),
7142560959 q Attic< Object >(*items_by_id[i.val()].obj, items_by_id[i.val()].timestamp),
7152560959 q attic_tag_store.get(items_by_id[i.val()].idx, *items_by_id[i.val()].obj),
7162560959 q meta_it != attic_metadata.end() ? &*meta_it : 0);
7172560959 q }
71811705269 q }
71912469 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)
72917838511 q{
73017838511 q if (mode & Output_Mode::META)
7325719 q if (rman.get_desired_timestamp() == NOW)
7343010 q Tag_Store< Index, Object > tag_store(*rman.get_transaction());
7353010 q Meta_Collector< Index, typename Object::Id_Type > meta_printer(items, *rman.get_transaction(),
7363010 q current_meta_file_properties< Object >());
7373010 q tags_by_id(extra_data, items, FLUSH_SIZE, output, rman, &meta_printer, tag_store, limit, element_count);
739279 q else
740279 q tags_by_id_attic(items, attic_items, extra_data, FLUSH_SIZE, output, rman, *rman.get_transaction(),
741279 q limit, element_count);
74317781511 q else
74417781511 q {
74517781511 q if (rman.get_desired_timestamp() == NOW)
74610773340 q {
74710773340 q Tag_Store< Index, Object > tag_store(*rman.get_transaction());
74810773340 q tags_by_id(extra_data, items, FLUSH_SIZE, output, rman,
74910773340 q (Meta_Collector< Index, typename Object::Id_Type >*)0, tag_store, limit, element_count);
75010773340 q }
7517008176 q else
7527008176 q tags_by_id_attic(items, attic_items, extra_data, FLUSH_SIZE, output, rman, *rman.get_transaction(),
7537008176 q limit, element_count);
75417781511 q }
75517838511 q}
758std::vector< std::pair< std::string, std::string > > make_count_tags(const Set& set, bool include_areas)
7603177494 q unsigned int num_nodes = count(set.nodes) + count(set.attic_nodes);
7613177494 q unsigned int num_ways = count(set.ways) + count(set.attic_ways);
7623177494 q unsigned int num_relations = count(set.relations) + count(set.attic_relations);
7633177494 q unsigned int num_areas = include_areas ? count(set.areas) : 0;
7653177494 q std::vector< std::pair< std::string, std::string > > count_tags;
7663177494 q count_tags.push_back(std::make_pair("nodes", to_string(num_nodes)));
7673177494 q count_tags.push_back(std::make_pair("ways", to_string(num_ways)));
7683177494 q count_tags.push_back(std::make_pair("relations", to_string(num_relations)));
7693177494 q if (include_areas)
770366100 q count_tags.push_back(std::make_pair("areas", to_string(num_areas)));
7713177494 q count_tags.push_back(std::make_pair("total", to_string(num_nodes + num_ways + num_relations + num_areas)));
7733177494 q return count_tags;
777void Print_Statement::execute(Resource_Manager& rman)
7798549585 q Cpu_Timer cpu(rman, 2);
7818549585 q Diff_Action::_ action = rman.get_desired_action();
7828549585 q if (action == Diff_Action::collect_lhs
7838549585 q || action == Diff_Action::collect_rhs_no_del || action == Diff_Action::collect_rhs_with_del)
78493676 q {
78593676 q execute_comparison(rman);
78693676 q return;
78793676 q }
7897613514 q if (action == Diff_Action::positive && rman.area_updater())
7900 rman.area_updater()->flush();
7927613514 q const Set* input_set = rman.get_set(input);
7947613514 q Set count_set;
7957613514 q const Set* output_items = 0;
7967613514 q if (mode & Output_Mode::COUNT)
7973177494 q {
7983177494 q count_set.deriveds[Uint31_Index(0u)].push_back(Derived_Structure("count", Uint64(0ull),
7993177494 q make_count_tags(input_set ? *input_set : Set(), rman.get_area_transaction()), 0));
8003177494 q output_items = &count_set;
8013177494 q mode = mode | Output_Mode::TAGS;
8023177494 q }
8034436510 q else
8044436510 q {
8054436510 q if (!input_set)
8063027 q return;
8084406509 q output_items = input_set;
8094406509 q }
8117583514 q Output_Handler::Feature_Action feature_action = Output_Handler::keep;
8127583514 q if (action == Diff_Action::show_old)
81355 q feature_action = Output_Handler::show_from;
8147578514 q else if (action == Diff_Action::show_new)
81555 q feature_action = Output_Handler::show_to;
8177583514 q Extra_Data extra_data(rman, *this, *output_items, mode, feature_action, south, north, west, east);
8187583514 q Output_Handler& output_handler = *rman.get_global_settings().get_output_handler();
8197583514 q uint32 element_count = 0;
8217583514 q if (order == order_by_id)
8227546513 q {
8237546513 q if (mode & Output_Mode::TAGS)
8245946511 q {
8255946511 q tags_by_id(extra_data, output_items->nodes, output_items->attic_nodes, mode, NODE_FLUSH_SIZE,
8265946511 q output_handler, rman, limit, element_count);
8275946511 q tags_by_id(extra_data, output_items->ways, output_items->attic_ways, mode, WAY_FLUSH_SIZE,
8285946511 q output_handler, rman, limit, element_count);
8295946511 q tags_by_id(extra_data, output_items->relations, output_items->attic_relations, mode, RELATION_FLUSH_SIZE,
8305946511 q output_handler, rman, limit, element_count);
8325946511 q if (rman.get_area_transaction())
834435100 q Tag_Store< Uint31_Index, Area_Skeleton > tag_store(*rman.get_transaction());
835435100 q tags_by_id(extra_data, output_items->areas, AREA_FLUSH_SIZE, output_handler, rman,
836435100 q (Meta_Collector< Uint31_Index, Area_Skeleton::Id_Type >*)0,
837435100 q tag_store, limit, element_count);
8405946511 q Tag_Store< Uint31_Index, Derived_Structure > tag_store;
8415946511 q tags_by_id(extra_data, output_items->deriveds, std::numeric_limits< uint32 >::max(), output_handler, rman,
8425946511 q (Meta_Collector< Uint31_Index, Derived_Structure::Id_Type >*)0, tag_store, limit, element_count);
8435946511 q }
8441600491 q else
8451600491 q {
8461600491 q by_id(output_items->nodes, output_items->attic_nodes,
8471600491 q output_handler, *rman.get_transaction(), extra_data, limit, element_count);
8481600491 q by_id(output_items->ways, output_items->attic_ways,
8491600491 q output_handler, *rman.get_transaction(), extra_data, limit, element_count);
8501600491 q by_id(output_items->relations, output_items->attic_relations,
8511600491 q output_handler, *rman.get_transaction(), extra_data, limit, element_count);
8521600491 q if (rman.get_area_transaction())
85331999 q by_id(output_items->areas, output_handler, *rman.get_area_transaction(), extra_data, limit, element_count);
8541600491 q by_id(output_items->deriveds, output_handler, *rman.get_transaction(), extra_data, limit, element_count);
8551600491 q }
8567546513 q }
8573737 q else
8593737 q if (mode & Output_Mode::TAGS)
8612020 q tags_quadtile_(extra_data, output_items->nodes,
8622020 q output_handler, rman, *rman.get_transaction(), limit, element_count);
8642020 q if (rman.get_desired_timestamp() != NOW)
8651111 q tags_quadtile_attic_(extra_data, output_items->attic_nodes,
8661111 q output_handler, rman, *rman.get_transaction(), limit, element_count);
8682020 q tags_quadtile_(extra_data, output_items->ways,
8692020 q output_handler, rman, *rman.get_transaction(), limit, element_count);
8712020 q if (rman.get_desired_timestamp() != NOW)
8721111 q tags_quadtile_attic_(extra_data, output_items->attic_ways,
8731111 q output_handler, rman, *rman.get_transaction(), limit, element_count);
8752020 q tags_quadtile_(extra_data, output_items->relations,
8762020 q output_handler, rman, *rman.get_transaction(), limit, element_count);
8782020 q if (rman.get_desired_timestamp() != NOW)
8791111 q tags_quadtile_attic_(extra_data, output_items->attic_relations,
8801111 q output_handler, rman, *rman.get_transaction(), limit, element_count);
8822020 q if (rman.get_area_transaction())
88344 q tags_quadtile_(extra_data, output_items->areas,
88444 q output_handler, rman, *rman.get_area_transaction(), limit, element_count);
8862020 q tags_quadtile_(extra_data, output_items->deriveds,
8872020 q output_handler, rman, *rman.get_transaction(), limit, element_count);
8891717 q else
8911717 q quadtile_(output_items->nodes, output_handler, *rman.get_transaction(), extra_data, limit, element_count);
8921717 q quadtile_(output_items->attic_nodes, output_handler, *rman.get_transaction(), extra_data, limit, element_count);
8941717 q quadtile_(output_items->ways, output_handler, *rman.get_transaction(), extra_data, limit, element_count);
8951717 q quadtile_(output_items->attic_ways, output_handler, *rman.get_transaction(), extra_data, limit, element_count);
8971717 q quadtile_(output_items->relations, output_handler, *rman.get_transaction(), extra_data, limit, element_count);
8981717 q quadtile_(output_items->attic_relations, output_handler, *rman.get_transaction(), extra_data, limit, element_count);
9001717 q if (rman.get_area_transaction())
90155 q quadtile_(output_items->areas, output_handler, *rman.get_area_transaction(), extra_data, limit, element_count);
9031717 q quadtile_(output_items->deriveds, output_handler, *rman.get_transaction(), extra_data, limit, element_count);
9077583514 q rman.health_check(*this);
911void Print_Statement::execute_comparison(Resource_Manager& rman)
91393676 q Diff_Action::_ action = rman.get_desired_action();
91593676 q const Diff_Set* input_diff_set = rman.get_diff_set(input);
91693676 q if (input_diff_set)
9183616 q print_diff_set(*input_diff_set, mode, rman.get_global_settings().get_output_handler(),
9193616 q rman.users(), relation_member_roles(*rman.get_transaction()), action == Diff_Action::collect_rhs_with_del);
9203616 q return;
92390076 q const Set* input_set = rman.get_set(input);
92490076 q if (!input_set)
925226 q return;
92787876 q if (action == Diff_Action::collect_lhs)
92845376 q {
92945376 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;
93745276 q delete collection_print_target;
93845276 q collection_print_target = new Set_Comparison(
93945276 q *rman.get_transaction(), *input_set, rman.get_desired_timestamp());
94045276 q }
94142576 q else
94242576 q {
94342576 q if (!diff_valid || !collection_print_target)
944102 q return;
94641576 q Diff_Set result = collection_print_target->compare_to_lhs(rman, *this, *input_set,
94741576 q south, north, west, east, action == Diff_Action::collect_rhs_with_del);
94941576 q print_diff_set(result, mode, rman.get_global_settings().get_output_handler(),
95041576 q rman.users(), relation_member_roles(*rman.get_transaction()), action == Diff_Action::collect_rhs_with_del);
95141576 q }
95386776 q rman.health_check(*this);
957Print_Statement::~Print_Statement()
95810749597 q{
95910749597 q delete collection_print_target;
96010749597 q}