Overpass API regression suite coverage (Saxony) / overpass_api/data/abstract_processing.h
overpass_api/data/abstract_processing.h
122 of 154 instrumented lines run by the suite (79.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__ABSTRACT_PROCESSING_H20#define DE__OSM3S___OVERPASS_API__DATA__ABSTRACT_PROCESSING_H22#include "../core/datatypes.h"23#include "../statements/statement.h"24#include "filenames.h"27//-----------------------------------------------------------------------------29template < class Object, class TPredicateA, class TPredicateB >30class And_Predicate31{32public:33 And_Predicate(const TPredicateA& predicate_a_, const TPredicateB& predicate_b_)3587745 q bool match(const Object& obj) const { return (predicate_a.match(obj) && predicate_b.match(obj)); }361620467 q bool match(const Handle< Object >& h) const { return (predicate_a.match(h) && predicate_b.match(h)); }37 bool match(const Handle< Attic< Object > >& h) const { return (predicate_a.match(h) && predicate_b.match(h)); }39private:40 TPredicateA predicate_a;41 TPredicateB predicate_b;42};44template < class Object, class TPredicateA, class TPredicateB >45class Or_Predicate46{47public:48 Or_Predicate(const TPredicateA& predicate_a_, const TPredicateB& predicate_b_)500 bool match(const Object& obj) const { return (predicate_a.match(obj) || predicate_b.match(obj)); }51 bool match(const Handle< Object >& h) const { return (predicate_a.match(h) || predicate_b.match(h)); }52 bool match(const Handle< Attic< Object > >& h) const { return (predicate_a.match(h) || predicate_b.match(h)); }54private:55 TPredicateA predicate_a;56 TPredicateB predicate_b;57};59template < class Object, class TPredicateA >60class Not_Predicate61{62public:63 Not_Predicate(const TPredicateA& predicate_a_)67 bool match(const Handle< Attic< Object > >& h) const { return (!predicate_a.match(h)); }69private:70 TPredicateA predicate_a;71};73template < class Object >74class Trivial_Predicate75{76public:80 bool match(const Handle< Attic< Object > >& h) const { return true; }82};84//-----------------------------------------------------------------------------86template < class Object >87class Id_Predicate88{89public:90 Id_Predicate(const std::vector< typename Object::Id_Type >& ids_)92252443142225 q bool match(const Object& obj) const { return std::binary_search(ids.begin(), ids.end(), obj.id); }93825605707368 q bool match(const Handle< Object >& h) const { return std::binary_search(ids.begin(), ids.end(), h.id()); }94 bool match(const Handle< Attic< Object > >& h) const { return std::binary_search(ids.begin(), ids.end(), h.id()); }97private:98 const std::vector< typename Object::Id_Type >& ids;99};101//-----------------------------------------------------------------------------103inline bool has_a_child_with_id104 (const Relation_Skeleton& relation, const std::vector< Uint64 >& ids, uint32 type)117inline bool has_a_child_with_id_and_role118 (const Relation_Skeleton& relation, const std::vector< Uint64 >& ids, uint32 type, uint32 role_id)131inline bool has_a_child_with_id132 (const Way_Skeleton& way, const std::vector< int >* pos, const std::vector< Node::Id_Type >& ids)163class Get_Parent_Rels_Predicate164{165public:166 Get_Parent_Rels_Predicate(const std::vector< Uint64 >& ids_, uint32 child_type_)168 bool match(const Relation_Skeleton& obj) const170 bool match(const Handle< Relation_Skeleton >& h) const172 bool match(const Handle< Attic< Relation_Skeleton > >& h) const175private:176 const std::vector< Uint64 >& ids;177 uint32 child_type;178};181class Get_Parent_Rels_Role_Predicate182{183public:184 Get_Parent_Rels_Role_Predicate(const std::vector< Uint64 >& ids_, uint32 child_type_, uint32 role_id_)186 bool match(const Relation_Skeleton& obj) const188 bool match(const Handle< Relation_Skeleton >& h) const190 bool match(const Handle< Attic< Relation_Skeleton > >& h) const193private:194 const std::vector< Uint64 >& ids;195 uint32 child_type;196 uint32 role_id;197};200class Get_Parent_Ways_Predicate201{202public:203 Get_Parent_Ways_Predicate(const std::vector< Node::Id_Type >& ids_, const std::vector< int >* pos_)20549951734 q bool match(const Way_Skeleton& obj) const { return has_a_child_with_id(obj, pos, ids); }206194017922 q bool match(const Handle< Way_Skeleton >& h) const { return has_a_child_with_id(h.object(), pos, ids); }2070 bool match(const Handle< Attic< Way_Skeleton > >& h) const { return has_a_child_with_id(h.object(), pos, ids); }209private:210 const std::vector< Node::Id_Type >& ids;211 const std::vector< int >* pos;212};215//-----------------------------------------------------------------------------218template < typename Attic_Skeleton >219struct Attic_Comparator220{221public:222 bool operator()(const Attic_Skeleton& lhs, const Attic_Skeleton& rhs)223 {224 if (lhs.id < rhs.id)225 return true;226 if (rhs.id < lhs.id)227 return false;228 return (lhs.timestamp < rhs.timestamp);229 }230};233template < class TIndex, class TObject >234void keep_only_least_younger_than235 (std::map< TIndex, std::vector< Attic< TObject > > >& attic_result,236 std::map< TIndex, std::vector< TObject > >& result,237 uint64 timestamp)238{239 std::map< typename TObject::Id_Type, uint64 > timestamp_per_id;241 for (typename std::map< TIndex, std::vector< Attic< TObject > > >::iterator242 it = attic_result.begin(); it != attic_result.end(); ++it)243 {244 std::sort(it->second.begin(), it->second.end(), Attic_Comparator< Attic< TObject > >());245 typename std::vector< Attic< TObject > >::iterator it_from = it->second.begin();246 typename std::vector< Attic< TObject > >::iterator it_to = it->second.begin();247 while (it_from != it->second.end())248 {249 if (it_from->timestamp <= timestamp)250 ++it_from;251 else252 {253 *it_to = *it_from;254 if (timestamp_per_id[it_to->id] == 0 || timestamp_per_id[it_to->id] > it_to->timestamp)255 timestamp_per_id[it_to->id] = it_to->timestamp;256 ++it_from;257 while (it_from != it->second.end() && it_from->id == it_to->id)258 ++it_from;259 ++it_to;260 }261 }262 it->second.erase(it_to, it->second.end());263 }265 for (typename std::map< TIndex, std::vector< Attic< TObject > > >::iterator266 it = attic_result.begin(); it != attic_result.end(); ++it)267 {268 typename std::vector< Attic< TObject > >::iterator it_from = it->second.begin();269 typename std::vector< Attic< TObject > >::iterator it_to = it->second.begin();270 while (it_from != it->second.end())271 {272 if (timestamp_per_id[it_from->id] == it_from->timestamp)273 {274 *it_to = *it_from;275 ++it_to;276 }277 ++it_from;278 }279 it->second.erase(it_to, it->second.end());280 }282 for (typename std::map< TIndex, std::vector< TObject > >::iterator283 it = result.begin(); it != result.end(); ++it)284 {285 typename std::vector< TObject >::iterator it_from = it->second.begin();286 typename std::vector< TObject >::iterator it_to = it->second.begin();287 while (it_from != it->second.end())288 {289 if (timestamp_per_id.find(it_from->id) == timestamp_per_id.end())290 {291 *it_to = *it_from;292 ++it_to;293 }294 ++it_from;295 }296 it->second.erase(it_to, it->second.end());297 }298}301//-----------------------------------------------------------------------------303template < class TIndex, class TObject, class TPredicate >304void filter_items(const TPredicate& predicate, std::map< TIndex, std::vector< TObject > >& data)320template< class TIndex, class TObject >321std::vector< typename TObject::Id_Type > filter_for_ids(const std::map< TIndex, std::vector< TObject > >& elems)336//-----------------------------------------------------------------------------339template< typename TObject >340struct Compare_By_Id341{343};346template< class TIndex, class TObject >347bool indexed_set_union(std::map< TIndex, std::vector< TObject > >& result,348 const std::map< TIndex, std::vector< TObject > >& summand)395//-----------------------------------------------------------------------------397template< class TIndex, class TObject >398void indexed_set_difference(std::map< TIndex, std::vector< TObject > >& result,399 const std::map< TIndex, std::vector< TObject > >& to_substract)412#endif