1/** Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Roland Olbricht et al. 3 * This file is part of Overpass_API. 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. 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. 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/>. 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" 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) 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"; 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") 831554504 q | Output_Mode::COORDS | Output_Mode::NDS | Output_Mode::MEMBERS 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; 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") 10215050 q else if (attributes["order"] == "quadtile") 10315050 q order = order_by_quadtile; 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()); 11212042679 q if (attributes["limit"] != "") 1135118648 q limit = atoll(attributes["limit"].c_str()); 11512042679 q if (attributes["geometry"] == "skeleton") 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; 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()); 13112042679 q if (attributes["ids"] == "yes") 1334214 q else if (attributes["ids"] == "no") 1344214 q mode = mode & ~Output_Mode::ID; 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()); 14312042679 q south = atof(attributes["s"].c_str()); 14412042679 q if ((south < -90.0) || (south > 90.0)) 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()); 15112042679 q north = atof(attributes["n"].c_str()); 15212042679 q if ((north < -90.0) || (north > 90.0)) 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()); 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()); 16712042679 q west = atof(attributes["w"].c_str()); 16812042679 q if ((west < -180.0) || (west > 180.0)) 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()); 17512042679 q east = atof(attributes["e"].c_str()); 17612042679 q if ((east < -180.0) || (east > 180.0)) 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()); 18312042679 q if ((attributes["n"] == "") && (attributes["s"] == "") && 18412042679 q (attributes["w"] == "") && (attributes["e"] == "")) 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); 200 const std::map< uint32, std::string >* get_users() const; 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; 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) 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) 247const std::map< uint32, std::string >* Extra_Data::get_users() const 253Extra_Data::~Extra_Data() 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; 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) 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); 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) 2751164762270 q Geometry_From_Quad_Coords broker; 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); 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) 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); 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) 297212056155 q Geometry_From_Quad_Coords broker; 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); 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) 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); 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) 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); 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) 32915220850 q output.print_item(skel, *skel.get_geometry(), tags, Output_Mode(extra_data.mode), extra_data.action); 33138432561 q output.print_item(skel, Null_Geometry(), tags, Output_Mode(extra_data.mode), extra_data.action); 335template< class TIndex, class TObject > 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 34380118 q while (item_it != items.end()) 34567718 q for (typename std::vector< TObject >::const_iterator it2(item_it->second.begin()); 3462058718 q it2 != item_it->second.end(); ++it2) 3481991617 q if (++element_count > limit) 3501991017 q print_item(extra_data, output, item_it->first.val(), *it2); 357template< class Index, class Object > 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 373709930 q while (item_it != items.end()) 375698125 q for (typename std::vector< Object >::const_iterator it2(item_it->second.begin()); 37613943125 q it2 != item_it->second.end(); ++it2) 37813245821 q if (++element_count > limit) 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)); 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 401117213 q while (item_it != items.end()) 403113411 q for (typename std::vector< Attic< Object > >::const_iterator it2(item_it->second.begin()); 4042602811 q it2 != item_it->second.end(); ++it2) 406248959 q if (++element_count > limit) 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)); 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) 421104278679266 q return (a.first->id < b.first->id); 426template< typename Index, typename Object > 427struct Maybe_Attic_Ref 430 Maybe_Attic_Ref(Index idx_, const Object* obj_, uint64 timestamp_) 43115090256445 q : idx(idx_), obj(obj_), timestamp(timestamp_) {} 437343773833386 q bool operator<(const Maybe_Attic_Ref& rhs) const { return obj->id < rhs.obj->id; } 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) 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) 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())); 45433064587 q sort(items_by_id.begin(), items_by_id.end(), 45533064587 q Skeleton_Comparator_By_Id< Object >()); 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) 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) 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)); 47475843563 q for (typename std::map< Index, std::vector< Attic< Object > > >::const_iterator 475243703563 q it(attic_items.begin()); it != attic_items.end(); ++it) 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)); 48175843563 q sort(items_by_id.begin(), items_by_id.end()); 487template< class Index, class Object > 489 (const std::map< Index, std::vector< Object > >& items, Output_Handler& output, 490 Transaction& transaction, Extra_Data& extra_data, uint32 limit, uint32& element_count) 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) 49741302213 q if (++element_count > limit) 49941261211 q print_item(extra_data, output, items_by_id[i].second, *(items_by_id[i].first)); 504template< class Index, class Object > 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) 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) 516408800444 q if (++element_count > limit) 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); 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)); 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) 536785767 q for (typename std::vector< Object >::const_iterator it2(it->second.begin()); 53753769567 q it2 != it->second.end(); ++it2) 53952983865 q if (!(it2->id < lower_id_bound) && (it2->id < upper_id_bound)) 54152983865 q const OSM_Element_Metadata_Skeleton< typename Object::Id_Type >* meta 54252983865 q = meta_printer.get(it->first, it2->id); 54419314126 q metadata.insert(*meta); 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) 5603442866 q for (typename std::vector< Attic< Object > >::const_iterator it2(it->second.begin()); 56117781266 q it2 != it->second.end(); ++it2) 56314338460 q if (!(it2->id < lower_id_bound) && (it2->id < upper_id_bound)) 56514338460 q const OSM_Element_Metadata_Skeleton< typename Object::Id_Type >* meta 56614338460 q = meta_printer.get(it->first, it2->id, it2->timestamp); 5681752310 q metadata.insert(*meta); 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) 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(); 5890 return metadata.end(); 593template< class Index, class Object > 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) 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; 6143415577 q upper_id_bound = items_by_id[items_by_id.size()-1].first->id; 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; 623 // collect metadata if required 6242316 q collect_metadata(metadata, items, lower_id_bound, upper_id_bound, *meta_printer); 6293415577 q for (typename Object::Id_Type i(id_pos); 6303814582577 q (i < id_pos + FLUSH_SIZE) && (i < items_by_id.size()); ++i) 6323811175577 q if (++element_count > limit) 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) ? 647template< class Index, class Object > 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) 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; 67514270 q upper_id_bound = items_by_id[items_by_id.size()-1].obj->id; 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); 69314270 q for (typename Object::Id_Type i(id_pos); 69446218670 q (i < id_pos + FLUSH_SIZE) && (i < items_by_id.size()); ++i) 69646205170 q if (++element_count > limit) 69846204470 q if (items_by_id[i.val()].timestamp == NOW) 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) ? 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); 723template< class Index, class Object > 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) 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); 7404515 q tags_by_id_attic(items, attic_items, extra_data, FLUSH_SIZE, output, rman, *rman.get_transaction(), 74510497585 q if (rman.get_desired_timestamp() == NOW) 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); 7525313206 q tags_by_id_attic(items, attic_items, extra_data, FLUSH_SIZE, output, rman, *rman.get_transaction(), 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))); 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))); 777void Print_Statement::execute(Resource_Manager& rman) 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) 78598381 q execute_comparison(rman); 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); 79527108590 q const Set* output_items = 0; 79627108590 q if (mode & Output_Mode::COUNT) 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)); 8013034561 q mode = mode | Output_Mode::TAGS; 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(); 82327026587 q if (mode & Output_Mode::TAGS) 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); 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); 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); 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); 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); 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); 92393781 q const Set* input_set = rman.get_set(input); 92792381 q if (action == Diff_Action::collect_lhs) 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."); 93311 q delete collection_print_target; 93411 q collection_print_target = 0; 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()); 94344281 q if (!diff_valid || !collection_print_target) 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); 95391781 q rman.health_check(*this); 957Print_Statement::~Print_Statement() 95912042679 q delete collection_print_target;