Overpass API regression suite coverage (Nova Scotia) / overpass_api/data/collect_members.h
overpass_api/data/collect_members.h
472 of 500 instrumented lines run by the suite (94.4%) 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 modify6 * it under the terms of the GNU Affero General Public License as7 * published by the Free Software Foundation, either version 3 of the8 * 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 of12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13 * GNU General Public License for more details.14 *15 * You should have received a copy of the GNU Affero General Public License16 * along with Overpass_API. If not, see <http://www.gnu.org/licenses/>.17 */19#ifndef DE__OSM3S___OVERPASS_API__DATA__COLLECT_MEMBERS_H20#define DE__OSM3S___OVERPASS_API__DATA__COLLECT_MEMBERS_H22#include "../core/datatypes.h"23#include "../statements/statement.h"24#include "abstract_processing.h"25#include "collect_items.h"26#include "filenames.h"28#include <map>29#include <set>30#include <vector>33class Resource_Manager;34class Statement;37Timeless< Uint31_Index, Relation_Skeleton > relation_relation_members38 (Request_Context& context,39 const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& parents,40 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_parents,41 const Ranges< Uint31_Index >& children_ranges,42 const std::vector< Relation::Id_Type >& children_ids, bool invert_ids, const uint32* role_id = 0);44Timeless< Uint31_Index, Way_Skeleton > relation_way_members45 (Request_Context& context,46 const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& relations,47 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_relations,48 const Ranges< Uint31_Index >& way_ranges,49 const std::vector< Way::Id_Type >& way_ids, bool invert_ids, const uint32* role_id = 0);51std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > > relation_way_members52 (Request_Context& context,53 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& relations,54 const Ranges< Uint31_Index >& way_ranges);56Timeless< Uint32_Index, Node_Skeleton > relation_node_members57 (Request_Context& context,58 const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& relations,59 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_relations,60 const Ranges< Uint32_Index >& node_ranges,61 const std::vector< Node::Id_Type >& node_ids, bool invert_ids = false, const uint32* role_id = 0);63std::map< Uint32_Index, std::vector< Attic< Node_Skeleton > > > relation_node_members64 (Request_Context& context,65 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& relations,66 const Ranges< Uint32_Index >& node_ranges);68Timeless< Uint32_Index, Node_Skeleton > way_members(69 Request_Context& context,70 const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways,71 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& attic_ways,72 const std::vector< int >* pos,73 const Ranges< Uint32_Index >& node_ranges,74 const std::vector< Node::Id_Type >& node_ids, bool invert_ids = false);76Timeless< Uint32_Index, Node_Skeleton > way_cnt_members(77 Request_Context& context,78 const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways,79 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& attic_ways,80 unsigned int lower_limit, unsigned int upper_limit,81 const Ranges< Uint32_Index >& node_ranges,82 const std::vector< Node::Id_Type >& node_ids, bool invert_ids = false);84Timeless< Uint32_Index, Node_Skeleton > way_link_members(85 Request_Context& context,86 const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways,87 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& attic_ways,88 unsigned int lower_limit, unsigned int upper_limit,89 const Ranges< Uint32_Index >& node_ranges,90 const std::vector< Node::Id_Type >& node_ids, bool invert_ids = false);92template< typename Relation_Skeleton >93std::vector< Node::Id_Type > relation_node_member_ids94 (const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& rels,95 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_rels,96 const uint32* role_id = 0);98std::vector< Relation::Id_Type > relation_relation_member_ids(99 const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& rels,100 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_rels,101 const uint32* role_id = 0);103std::vector< Node::Id_Type > way_nd_ids(104 const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways,105 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& attic_ways,106 const std::vector< int >* pos);108std::vector< Node::Id_Type > way_cnt_nd_ids(109 const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways,110 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& attic_ways,111 unsigned int lower_limit, unsigned int upper_limit);113std::vector< Node::Id_Type > way_link_nd_ids(114 const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways,115 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& attic_ways,116 unsigned int lower_limit, unsigned int upper_limit);118const std::map< uint32, std::string >& relation_member_roles(Transaction& transaction);119uint32 determine_role_id(Transaction& transaction, const std::string& role);122bool add_way_to_area_blocks(const std::vector< Quad_Coord >& coords,123 uint32 id, std::map< Uint31_Index, std::vector< Area_Block > >& areas);126std::vector< Quad_Coord > make_geometry(const Way_Skeleton& way, const std::vector< Node >& nodes);129void filter_ways_by_ranges(std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways,130 const Ranges< Uint31_Index >& ranges);131void filter_ways_by_ranges(std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& ways,132 const Ranges< Uint31_Index >& ranges);135template< typename Relation_Skeleton >136void filter_relations_by_ranges(137 std::map< Uint31_Index, std::vector< Relation_Skeleton > >& relations, const Ranges< Uint31_Index >& ranges)140886328 q typename std::map< Uint31_Index, std::vector< Relation_Skeleton > >::iterator it = relations.begin();158//-----------------------------------------------------------------------------161template < typename Index, typename Skeleton >162Timeless< Index, Skeleton > get_elements_from_db(163 const Ranges< Index >& ranges, const Statement& query, Resource_Manager& rman)1665348 q return collect_items_range< Index, Skeleton >(context, ranges, Trivial_Predicate< Skeleton >());170template < typename Index, typename Object >171class Collect_Items172{173public:174 Collect_Items(175 const std::vector< typename Object::Id_Type >& ids_, bool invert_ids_,176 const Ranges< Index >& ranges_,177 const Statement& query_, Resource_Manager& rman_)181 bool get_chunk(182 std::map< Index, std::vector< Object > >& elements,183 std::map< Index, std::vector< Attic< Object > > >& attic_elements);185private:186 const std::vector< typename Object::Id_Type >* ids;187 bool invert_ids;188 Ranges< Index > ranges;189 const Statement* query;190 Resource_Manager* rman;191 Index min_idx;192};195template < typename Index, typename Object, typename Predicate >196bool get_elements_by_id_from_db_generic(197 std::map< Index, std::vector< Object > >& elements,198 std::map< Index, std::vector< Attic< Object > > >& attic_elements,199 const Predicate& pred,200 const Ranges< Index >& ranges, Index& cur_idx,201 const Statement& query, Resource_Manager& rman)210template < typename Index, typename Object >211bool Collect_Items< Index, Object >::get_chunk(212 std::map< Index, std::vector< Object > >& elements,213 std::map< Index, std::vector< Attic< Object > > >& attic_elements)221617289 q elements, attic_elements, Trivial_Predicate< Object >(), ranges, min_idx, *query, *rman);22496 q elements, attic_elements, Not_Predicate< Object, Id_Predicate< Object > >(Id_Predicate< Object >(*ids)),228353207 q elements, attic_elements, Id_Predicate< Object >(*ids), ranges, min_idx, *query, *rman);232template< typename Index, typename Skeleton >233void filter_attic_elements234 (Resource_Manager& rman, uint64 timestamp,235 std::map< Index, std::vector< Skeleton > >& current,236 std::map< Index, std::vector< Attic< Skeleton > > >& attic)2417206246 q for (typename std::map< Index, std::vector< Skeleton > >::const_iterator it = current.begin();2447206246 q for (typename std::map< Index, std::vector< Attic< Skeleton > > >::const_iterator it = attic.begin();250 // Remove elements that have been deleted at the given point of time2537206246 q Block_Backend< Index, Attic< typename Skeleton::Id_Type >, typename std::vector< Index >::const_iterator >2547206246 q undeleted_db(rman.get_transaction()->data_index(attic_undeleted_file_properties< Skeleton >()));261920863209 q typename std::map< Index, std::vector< Skeleton > >::iterator cit = current.find(it.index());26411273879209 q for (typename std::vector< Skeleton >::iterator it2 = cit->second.begin(); it2 != cit->second.end(); )276920863209 q typename std::map< Index, std::vector< Attic< Skeleton > > >::iterator ait = attic.find(it.index());294 // Confirm elements that are backed by meta data295 // Update element's expiration timestamp if a meta exists that is older than the current296 // expiration date and younger than timestamp2997206246 q for (typename std::map< Index, std::vector< Skeleton > >::const_iterator it = current.begin();3087206246 q for (typename std::map< Index, std::vector< Attic< Skeleton > > >::const_iterator it = attic.begin();3131238196231 q for (typename std::vector< Attic< Skeleton > >::const_iterator it2 = it->second.begin();335 // Same thing with current meta data354 // Filter current: only keep elements that have already existed at timestamp3557206246 q for (typename std::map< Index, std::vector< Skeleton > >::iterator it = current.begin();377 // Filter attic: only keep elements that have already existed at timestamp3787206246 q for (typename std::map< Index, std::vector< Attic< Skeleton > > >::iterator it = attic.begin();3851238268231 q for (typename std::vector< Attic< Skeleton > >::const_iterator it2 = it->second.begin();401//-----------------------------------------------------------------------------404template< typename Ref_Type, typename Relation_Skeleton >405void filter_for_member_ids(const std::vector< Relation_Skeleton >& relations,406 std::vector< Ref_Type >& ids, uint32 type)408288595193 q for (typename std::vector< Relation_Skeleton >::const_iterator it2(relations.begin());421template< typename Ref_Type, typename Relation_Skeleton >422void filter_for_member_ids(const std::vector< Relation_Skeleton >& relations,423 std::vector< Ref_Type >& ids, uint32 type, uint32 role_id)438template< typename Relation_Skeleton >439std::vector< Node::Id_Type > relation_node_member_ids440 (const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& rels,441 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_rels,442 const uint32* role_id)474inline std::vector< Way::Id_Type > relation_way_member_ids475 (const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& rels,476 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_rels,477 const uint32* role_id = 0)509template< typename Index, typename Skeleton >510void keep_matching_skeletons511 (std::map< Index, std::vector< Skeleton > >& current,512 std::map< Index, std::vector< Attic< Skeleton > > >& attic,513 uint64 timestamp)5346787030 q if (it2->timestamp > timestamp && (stored_timestamp == 0 || stored_timestamp > it2->timestamp))563template< typename Index, typename Skeleton >564void keep_matching_skeletons565 (std::map< Index, std::vector< Attic< Skeleton > > >& result,566 const std::map< Index, std::vector< Skeleton > >& current,567 const std::map< Index, std::vector< Attic< Skeleton > > >& attic,568 uint64 timestamp)58257108460 q for (typename std::vector< Attic< Skeleton > >::const_iterator it2 = it->second.begin();5862178059 q if (it2->timestamp > timestamp && (stored_timestamp == 0 || stored_timestamp > it2->timestamp))611void keep_matching_skeletons612 (std::vector< Node >& result,613 const std::map< Uint32_Index, std::vector< Node_Skeleton > >& current,614 const std::map< Uint32_Index, std::vector< Attic< Node_Skeleton > > >& attic,615 uint64 timestamp);618template< typename TIndex, typename TObject >619void item_filter_map620 (std::map< TIndex, std::vector< TObject > >& modify,621 const std::map< TIndex, std::vector< TObject > >& read)646template< typename First, typename Second >647void swap_components(std::pair< First, Second > pair, First& first, Second& second)648{649 first.swap(pair.first);650 second.swap(pair.second);651}654template< typename Index, typename Skeleton, typename Order_By_Id >655std::vector< std::pair< Index, const Skeleton* > > order_by_id656 (const std::map< Index, std::vector< Skeleton > >& skels,657 const Order_By_Id& order_by_id)660970325 q for (typename std::map< Index, std::vector< Skeleton > >::const_iterator it = skels.begin();673template< typename Index, typename Skeleton, typename Order_By_Id >674std::vector< std::pair< Index, const Skeleton* > > order_attic_by_id675 (const std::map< Index, std::vector< Attic< Skeleton > > >& skels,676 const Order_By_Id& order_by_id)67923898 q for (typename std::map< Index, std::vector< Attic< Skeleton > > >::const_iterator it = skels.begin();6821114452 q for (typename std::vector< Attic< Skeleton > >::const_iterator iit = it->second.begin();692template< typename Relation_Skeleton >693void filter_relations_expensive(const std::vector< std::pair< Uint32_Index, const Node_Skeleton* > > node_members_by_id,694 const std::vector< std::pair< Uint31_Index, const Way_Skeleton* > > way_members_by_id,695 std::map< Uint31_Index, std::vector< Relation_Skeleton > >& relations)69712793 q for (typename std::map< Uint31_Index, std::vector< Relation_Skeleton > >::iterator it = relations.begin();701579751 q for (typename std::vector< Relation_Skeleton >::const_iterator iit = it->second.begin();734Ranges< Uint31_Index > collect_way_req(735 const std::vector< Uint31_Index >& parents,736 const std::vector< Uint31_Index >& children_idxs);739Ranges< Uint31_Index > relation_way_member_indices740 (const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& current_rels,741 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_rels);744Ranges< Uint32_Index > calc_node_children_ranges(const std::vector< uint32 >& way_rel_idxs);747Ranges< Uint32_Index > relation_node_member_indices(748 const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& current_rels,749 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_rels);752Ranges< Uint32_Index > way_nd_indices(753 const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways,754 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& attic_ways);757Ranges< Uint32_Index > way_covered_indices(758 const std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways,759 const std::map< Uint31_Index, std::vector< Attic< Way_Skeleton > > >& attic_ways);762struct Order_By_Node_Id763{764 bool operator() (const std::pair< Uint32_Index, const Node_Skeleton* >& a,765 const std::pair< Uint32_Index, const Node_Skeleton* >& b)769};772struct Order_By_Way_Id773{774 bool operator() (const std::pair< Uint31_Index, const Way_Skeleton* >& a,775 const std::pair< Uint31_Index, const Way_Skeleton* >& b)779};782template< typename Index, typename Object, typename Id_Type = Relation_Entry::Ref_Type >783std::vector< Id_Type > extract_ids(const std::map< Index, std::vector< Object > >& elems)799template< typename Index, typename Object, typename Id_Type = Relation_Entry::Ref_Type >800std::vector< Id_Type > extract_ids(801 const std::map< Index, std::vector< Object > >& current,802 const std::map< Index, std::vector< Attic< Object > > >& attic)823template< class TIndex, class TObject >824std::set< Uint31_Index > extract_parent_indices(const std::map< TIndex, std::vector< TObject > >& elems)836100114111 q for (std::vector< uint32 >::const_iterator it = parents.begin(); it != parents.end(); ++it)843Timeless< Uint31_Index, Way_Skeleton > collect_ways(844 Request_Context& context,845 const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& rels,846 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_rels,847 const Ranges< Uint31_Index >& ranges,848 const std::vector< Way::Id_Type >& ids, bool invert_ids,849 uint32* role_id = 0);852Timeless< Uint31_Index, Way_Skeleton > collect_ways(853 Request_Context& context,854 const std::map< Uint32_Index, std::vector< Node_Skeleton > >& nodes,855 const std::map< Uint32_Index, std::vector< Attic< Node_Skeleton > > >& attic_nodes,856 const std::vector< int >* pos,857 const std::vector< Way::Id_Type >& ids, bool invert_ids);860void add_nw_member_objects(Request_Context& context, const Set& input_set, Set& into,861 const Ranges< Uint32_Index >* ranges_32 = 0, const Ranges< Uint31_Index >* ranges_31 = 0);864template< typename Index, typename Object >865void filter_elems_for_closed_ways(std::map< Index, std::vector< Object > >& arg)8671670961 q for (typename std::map< Index, std::vector< Object > >::iterator it1 = arg.begin(); it1 != arg.end(); ++it1)8703178643 q for (typename std::vector< Object >::iterator it2 = it1->second.begin(); it2 != it1->second.end(); ++it2)880template< typename Index, typename Object >881Timeless< Index, Object >& Timeless< Index, Object >::filter_by_id(882 const std::vector< typename Object::Id_Type >& ids)909#endif