Overpass API regression suite coverage (Nova Scotia) / overpass_api/data/collect_items.h
overpass_api/data/collect_items.h
350 of 397 instrumented lines run by the suite (88.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 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_ITEMS_H20#define DE__OSM3S___OVERPASS_API__DATA__COLLECT_ITEMS_H22#include "../dispatch/resource_manager.h"23#include "abstract_processing.h"24#include "filenames.h"26#include <exception>29113699070187 qinline uint64 timestamp_of(const Attic< Node_Skeleton >& skel) { return skel.timestamp; }301496533163 qinline uint64 timestamp_of(const Attic< Way_Skeleton >& skel) { return skel.timestamp; }3114824091 qinline uint64 timestamp_of(const Attic< Relation_Skeleton >& skel) { return skel.timestamp; }38template < class Index, class Object, class Iterator, class Predicate >39void reconstruct_items(40 Iterator& it, Iterator end, Index index,41 const Predicate& predicate,42 std::vector< Object >& result,43 std::vector< std::pair< typename Object::Id_Type, uint64 > >& timestamp_by_id,44 uint64 timestamp, uint32& count)51193148819191 q timestamp_by_id.push_back(std::make_pair(it.object().id, timestamp_of(it.object())));60class Statement;63class Health_Guard64{65public:6615104513 q Health_Guard(const Statement* stmt_, Resource_Manager& rman_) : stmt(stmt_), rman(rman_) {}680 void log_and_display_error(const std::string& message) const { rman.log_and_display_error(message); }69 bool check(uint32 extra_time = 0, uint64 extra_space = 0)72private:73 const Statement* stmt;74 Resource_Manager& rman;75};78class Request_Context79{80public:8112804573 q Request_Context(const Statement* stmt_, Resource_Manager& rman_) : stmt(stmt_), rman(rman_) {}85 File_Blocks_Index_Base* data_index(const File_Properties* file_properties)87 Random_File_Index* random_index(const File_Properties* file_properties)90private:91 const Statement* stmt;92 Resource_Manager& rman;93};96template < class Index, class Object, class Attic_Iterator, class Current_Iterator, class Predicate >97void reconstruct_items(Health_Guard& health_guard,98 Current_Iterator& current_it, Current_Iterator current_end,99 Attic_Iterator& attic_it, Attic_Iterator attic_end, Index& idx,100 const Predicate& predicate,101 std::vector< Object >& result, std::vector< Attic< Object > >& attic_result,102 std::vector< std::pair< typename Object::Id_Type, uint64 > >& timestamp_by_id,103 uint64 timestamp)12114305571197 q timestamp_by_id.push_back(std::make_pair(attic_it.object().id, attic_it.object().timestamp));12214305571197 q local_timestamp_by_id.push_back(std::make_pair(attic_it.object().id, attic_it.object().timestamp));1301282062201 q for (typename std::vector< Attic< typename Object::Delta > >::const_iterator it = deltas.begin();1351282062201 q std::sort(delta_refs.begin(), delta_refs.end(), Delta_Ref_Comparator< Attic< typename Object::Delta > >());1411282062201 q for (typename std::vector< const Attic< typename Object::Delta >* >::const_iterator it = delta_refs.begin();15514305571197 q Attic< Object > attic_obj = Attic< Object >((*it)->expand(reference), (*it)->timestamp);15914305571197 q typename std::vector< std::pair< typename Object::Id_Type, uint64 > >::const_iterator16214305571197 q if (tit != local_timestamp_by_id.end() && tit->first == (*it)->id && tit->second == (*it)->timestamp)167 // Relation_Delta without a reference of the same index1836982237201 q for (typename std::vector< Attic< Object > >::const_iterator it = attics.begin(); it != attics.end(); ++it)18915693994201 q for (typename std::vector< Object >::const_iterator it = skels.begin(); it != skels.end(); ++it)197template < class Object >198void filter_items_by_timestamp(199 const std::vector< std::pair< typename Object::Id_Type, uint64 > >& timestamp_by_id,200 std::vector< Object >& result)20616294179224 q typename std::vector< std::pair< typename Object::Id_Type, uint64 > >::const_iterator20916294179224 q if (tit != timestamp_by_id.end() && tit->first == it2->id && tit->second == timestamp_of(*it2))219template < class Index, class Object >220void filter_items_by_timestamp(221 const std::vector< std::pair< typename Object::Id_Type, uint64 > >& timestamp_by_id,222 std::map< Index, std::vector< Object > >& result)223{224 for (typename std::map< Index, std::vector< Object > >::iterator it = result.begin();225 it != result.end(); ++it)226 filter_items_by_timestamp(timestamp_by_id, it->second);227}230template< typename Object >231void check_for_duplicated_objects(232 const std::vector< std::pair< typename Object::Id_Type, uint64 > >& timestamp_by_id,233 Health_Guard& health_guard)234{235 // Debug-Feature. Can be disabled once no further bugs appear236 for (typename std::vector< std::pair< typename Object::Id_Type, uint64 > >::size_type i = 0;237 i+1 < timestamp_by_id.size(); ++i)238 {239 if (timestamp_by_id[i].second == timestamp_by_id[i+1].second240 && timestamp_by_id[i].first == timestamp_by_id[i+1].first)241 {242 std::ostringstream out;243 out<<name_of_type< Object >()<<" "<<timestamp_by_id[i].first.val()244 <<" appears multiple times at timestamp "<<Timestamp(timestamp_by_id[i].second).str();245 health_guard.log_and_display_error(out.str());246 }247 }248}251template < class Index, class Object, class Current_Iterator, class Attic_Iterator, class Predicate >252bool collect_items_by_timestamp(Health_Guard&& health_guard,253 Current_Iterator current_begin, Current_Iterator current_end,254 Attic_Iterator attic_begin, Attic_Iterator attic_end,255 const Predicate& predicate, Index* cur_idx, uint64 timestamp,256 std::map< Index, std::vector< Object > >& result,257 std::map< Index, std::vector< Attic< Object > > >& attic_result)2821183152191 q current_begin, current_end, index, predicate, result[index], timestamp_by_id, timestamp, count);2841183152191 q attic_begin, attic_end, index, predicate, attic_result[index], timestamp_by_id, timestamp, count);291 //check_for_duplicated_objects< Object >(timestamp_by_id, rman);297template < class Index, class Current_Iterator, class Attic_Iterator, class Predicate >298bool collect_items_by_timestamp(Health_Guard&& health_guard,299 Current_Iterator current_begin, Current_Iterator current_end,300 Attic_Iterator attic_begin, Attic_Iterator attic_end,301 const Predicate& predicate, Index* cur_idx, uint64 timestamp,302 std::map< Index, std::vector< Relation_Skeleton > >& result,303 std::map< Index, std::vector< Attic< Relation_Skeleton > > >& attic_result)327224652119 q reconstruct_items(health_guard, current_begin, current_end, attic_begin, attic_end, index,335 //check_for_duplicated_objects< Relation_Skeleton >(timestamp_by_id, rman);341template< typename Index, typename Object >342struct Timeless343{344 Timeless& swap(345 std::map< Index, std::vector< Object > >& rhs_current,346 std::map< Index, std::vector< Attic< Object > > >& rhs_attic)353 Timeless& sort()360 Timeless& set_union(const Timeless< Index, Object >& rhs)367 template< typename Predicate >368 Timeless& filter_items(const Predicate& predicate)375 Timeless& filter_by_id(const std::vector< typename Object::Id_Type >& ids);377 std::map< Index, std::vector< Object > > current;378 std::map< Index, std::vector< Attic< Object > > > attic;379};382template < class Index, class Current_Iterator, class Attic_Iterator, class Predicate >383bool collect_items_by_timestamp(Health_Guard&& health_guard,384 Current_Iterator current_begin, Current_Iterator current_end,385 Attic_Iterator attic_begin, Attic_Iterator attic_end,386 const Predicate& predicate, Index* cur_idx, uint64 timestamp,387 std::map< Index, std::vector< Way_Skeleton > >& result,388 std::map< Index, std::vector< Attic< Way_Skeleton > > >& attic_result)4121057410182 q reconstruct_items(health_guard, current_begin, current_end, attic_begin, attic_end, index,420 //check_for_duplicated_objects< Way_Skeleton >(timestamp_by_id, rman);426template < class Index, class Object, class Container, class Predicate >427void collect_items_discrete(Transaction& transaction,428 File_Properties& file_properties,429 const Container& req, const Predicate& predicate,430 std::map< Index, std::vector< Object > >& result)431{432 Block_Backend< Index, Object, typename Container::const_iterator > db433 (transaction.data_index(&file_properties));434 for (auto it = db.discrete_begin(req.begin(), req.end()); !(it == db.discrete_end()); ++it)435 {436 if (predicate.match(it.handle()))437 result[it.index()].push_back(it.object());438 }439}442// Used by Set_Comparison443template < class Index, class Object, class Container, class Predicate >444void collect_items_discrete(Request_Context& context,445 const Container& req, const Predicate& predicate, uint64 timestamp,446 std::map< Index, std::vector< Object > >& result,447 std::map< Index, std::vector< Attic< Object > > >& attic_result)4531014733145 q for (auto it = current_db.discrete_begin(req.begin(), req.end()); !(it == current_db.discrete_end()); ++it)461992110 q Block_Backend< Index, Attic< typename Object::Delta >, typename Container::const_iterator > attic_db(472template < class Index, class Object, class Container, class Predicate >473void collect_items_discrete(Request_Context& context,474 const Container& req, const Predicate& predicate,475 std::map< Index, std::vector< Object > >& result,476 std::map< Index, std::vector< Attic< Object > > >& attic_result)478505203 q collect_items_discrete(context, req, predicate, context.get_desired_timestamp(), result, attic_result);482template< typename Index, typename Object, typename Predicate >483Timeless< Index, Object > collect_items_range(Request_Context& context,484 const Ranges< Index >& ranges, const Predicate& predicate)494305819893257 q for (auto it = current_db.range_begin(ranges); !(it == current_db.range_end()); ++it)513template < class Index, class Object, class Predicate >514bool collect_items_range(Request_Context& context,515 const Ranges< Index >& ranges, const Predicate& predicate, Index& cur_idx,516 std::map< Index, std::vector< Object > >& result,517 std::map< Index, std::vector< Attic< Object > > >& attic_result)528190797133307 q for (auto it = current_db.range_begin(shortened); !(it == current_db.range_end()); ++it)560// Current called olny for areas and only from Query_Statement.561template < class Index, class Object, class Predicate >562void collect_items_flat(Request_Context& context,563 File_Properties& file_properties, const Predicate& predicate,564 std::map< Index, std::vector< Object > >& result)582template < class Index, class Object, class Predicate >583void collect_items_flat(584 Request_Context& context, const Predicate& predicate,585 std::map< Index, std::vector< Object > >& result,586 std::map< Index, std::vector< Attic< Object > > >& attic_result)618/* Returns for the given std::set of ids the std::set of corresponding indexes.619 * The function requires that the ids are sorted ascending by id.620 */621template< typename Index, typename Skeleton >622std::vector< Index > get_indexes_623 (const std::vector< typename Skeleton::Id_Type >& ids, Resource_Manager& rman, bool get_attic_idxs = false)6271337147 q Random_File< typename Skeleton::Id_Type, Index > current(rman.get_transaction()->random_index6381266102 q Random_File< typename Skeleton::Id_Type, Index > attic_random(rman.get_transaction()->random_index667#endif