Overpass API regression suite coverage (Saxony) / overpass_api/data/meta_collector.h

overpass_api/data/meta_collector.h

104 of 128 instrumented lines run by the suite (81.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#ifndef DE__OSM3S___OVERPASS_API__STATEMENTS__META_COLLECTOR_H
20#define DE__OSM3S___OVERPASS_API__STATEMENTS__META_COLLECTOR_H
22#include <map>
23#include <set>
24#include <vector>
26#include "../../template_db/block_backend.h"
27#include "../../template_db/random_file.h"
28#include "../../template_db/transaction.h"
29#include "../core/datatypes.h"
30#include "../core/settings.h"
31#include "filenames.h"
34template< typename Index, typename Id_Type >
35struct Meta_Collector
37public:
38 template< typename Object >
39 Meta_Collector(const std::map< Index, std::vector< Object > >& items,
40 Transaction& transaction, const File_Properties* meta_file_prop = 0);
42 Meta_Collector(const Ranges< Index >& used_ranges,
43 Transaction& transaction, const File_Properties* meta_file_prop = 0);
45 void reset();
46 const OSM_Element_Metadata_Skeleton< Id_Type >* get
47 (const Index& index, Id_Type ref);
48 const OSM_Element_Metadata_Skeleton< Id_Type >* get
49 (const Index& index, Id_Type ref, uint64 timestamp);
51 ~Meta_Collector()
5213004380 q {
5313004380 q delete last_index;
5413004380 q delete current_index;
5513004380 q delete range_it;
5613004380 q delete db_it;
5713004380 q delete meta_db;
5813004380 q }
60private:
61 std::set< Index > used_indices;
62 Ranges< Index > used_ranges;
63 Block_Backend< Index, OSM_Element_Metadata_Skeleton< Id_Type >, typename std::set< Index >::const_iterator >* meta_db;
64 typename Block_Backend< Index, OSM_Element_Metadata_Skeleton< Id_Type >, typename std::set< Index >::const_iterator >
65 ::Discrete_Iterator* db_it;
66 typename Block_Backend< Index, OSM_Element_Metadata_Skeleton< Id_Type >, typename std::set< Index >::const_iterator >
67 ::Range_Iterator* range_it;
68 Index* current_index;
69 Index* last_index;
70 std::set< OSM_Element_Metadata_Skeleton< Id_Type > > current_objects;
72 void update_current_objects(const Index&);
73};
76template< typename Index, typename Object >
77struct Attic_Meta_Collector
79public:
80 Attic_Meta_Collector(const std::map< Index, std::vector< Attic< Object > > >& items,
81 Transaction& transaction, bool turn_on);
83 const OSM_Element_Metadata_Skeleton< typename Object::Id_Type >* get
84 (const Index& index, typename Object::Id_Type ref, uint64 timestamp = NOW);
86private:
87 Meta_Collector< Index, typename Object::Id_Type > current;
88 Meta_Collector< Index, typename Object::Id_Type > attic;
89};
92/** Implementation --------------------------------------------------------- */
94template< typename Index, typename Object >
95void generate_index_query
96 (std::set< Index >& indices,
97 const std::map< Index, std::vector< Object > >& items)
987274216 q{
99345858216 q for (auto it = items.begin(); it != items.end(); ++it)
100338584183 q indices.insert(it->first);
104template< typename Index, typename Id_Type >
105template< typename Object >
106Meta_Collector< Index, Id_Type >::Meta_Collector
107 (const std::map< Index, std::vector< Object > >& items,
108 Transaction& transaction, const File_Properties* meta_file_prop)
10913004380 q : meta_db(0), db_it(0), range_it(0), current_index(0), last_index(0)
11013004380 q{
11113004380 q if (!meta_file_prop)
1125730223 q return;
1147274216 q generate_index_query(used_indices, items);
1157274216 q meta_db = new Block_Backend< Index, OSM_Element_Metadata_Skeleton< Id_Type >, typename std::set< Index >::const_iterator >
1167274216 q (transaction.data_index(meta_file_prop));
1187274216 q reset();
122template< typename Index, typename Id_Type >
123Meta_Collector< Index, Id_Type >::Meta_Collector
124 (const Ranges< Index >& used_ranges_,
125 Transaction& transaction, const File_Properties* meta_file_prop)
126 : used_ranges(used_ranges_), meta_db(0), db_it(0), range_it(0), current_index(0), last_index(0)
128 if (!meta_file_prop)
129 return;
131 meta_db = new Block_Backend< Index, OSM_Element_Metadata_Skeleton< Id_Type >, typename std::set< Index >::const_iterator >
132 (transaction.data_index(meta_file_prop));
134 reset();
138template< typename Index, typename Id_Type >
139void Meta_Collector< Index, Id_Type >::reset()
1417491265 q if (!meta_db)
14212660 q return;
1447365216 q delete db_it;
1457365216 q db_it = 0;
1467365216 q delete range_it;
1477365216 q range_it = 0;
1487365216 q delete current_index;
1497365216 q current_index = 0;
1507365216 q delete last_index;
1517365216 q last_index = 0;
1537365216 q if (used_ranges.empty())
1547365216 q {
1557365216 q if (!used_indices.empty())
1561893183 q last_index = new Index(*used_indices.begin());
1587365216 q db_it = new typename Block_Backend< Index, OSM_Element_Metadata_Skeleton< Id_Type >, typename std::set< Index >::const_iterator >
1597365216 q ::Discrete_Iterator(meta_db->discrete_begin(used_indices.begin(), used_indices.end()));
1617365216 q if (!(*db_it == meta_db->discrete_end()))
1621805183 q current_index = new Index(db_it->index());
1634204942216 q while (!(*db_it == meta_db->discrete_end()) && (*current_index == db_it->index()))
1644197577183 q {
1654197577183 q current_objects.insert(db_it->object());
1664197577183 q ++(*db_it);
1674197577183 q }
1687365216 q }
1690 else
1700 {
1710 last_index = new Index(used_ranges.begin().lower_bound());
1720 range_it = new auto(meta_db->range_begin(used_ranges));
1740 if (!(*range_it == meta_db->range_end()))
1750 current_index = new Index(range_it->index());
1760 while (!(*range_it == meta_db->range_end()) && (*current_index == range_it->index()))
1770 {
1780 current_objects.insert(range_it->object());
1790 ++(*range_it);
1800 }
1810 }
185template< typename Index, typename Id_Type >
186void Meta_Collector< Index, Id_Type >::update_current_objects(const Index& index)
187300906146 q{
188300906146 q current_objects.clear();
189300906146 q if (last_index)
190300906146 q *last_index = index;
192300906146 q if (db_it)
193300906146 q {
1943232340146 q while (!(*db_it == meta_db->discrete_end()) && (db_it->index() < index))
195293143461 q ++(*db_it);
196300906146 q if (!(*db_it == meta_db->discrete_end()))
197300869146 q *current_index = db_it->index();
19847319625146 q while (!(*db_it == meta_db->discrete_end()) && (*current_index == db_it->index()))
19947018719146 q {
20047018719146 q current_objects.insert(db_it->object());
20147018719146 q ++(*db_it);
20247018719146 q }
203300906146 q }
2040 else if (range_it)
2050 {
2060 while (!(*range_it == meta_db->range_end()) && (range_it->index() < index))
2070 ++(*range_it);
2080 if (!(*range_it == meta_db->range_end()))
2090 *current_index = range_it->index();
2100 while (!(*range_it == meta_db->range_end()) && (*current_index == range_it->index()))
2110 {
2120 current_objects.insert(range_it->object());
2130 ++(*range_it);
2140 }
2150 }
216300906146 q}
219template< typename Index, typename Id_Type >
220const OSM_Element_Metadata_Skeleton< Id_Type >* Meta_Collector< Index, Id_Type >::get
221 (const Index& index, Id_Type ref)
2227132018208 q{
2237132018208 q if (!meta_db)
22437629258 q return 0;
2266755726162 q if (current_index && index < *last_index)
227449 q reset();
2286755726162 q if (current_index && *current_index < index)
229265946135 q update_current_objects(index);
2316755726162 q typename std::set< OSM_Element_Metadata_Skeleton< Id_Type > >::iterator it
2326755726162 q = current_objects.lower_bound(OSM_Element_Metadata_Skeleton< Id_Type >(ref));
2336755726162 q if (it != current_objects.end() && it->ref == ref)
2346745248162 q return &*it;
235104786 q else
236104786 q return 0;
2376755726162 q}
240template< typename Index, typename Id_Type >
241const OSM_Element_Metadata_Skeleton< Id_Type >* Meta_Collector< Index, Id_Type >::get
242 (const Index& index, Id_Type ref, uint64 timestamp)
243791419134 q{
244791419134 q if (!meta_db)
24525366855 q return 0;
24753775188 q if (current_index && index < *last_index)
24882 q reset();
24953775188 q if (current_index && *current_index < index)
2503496077 q update_current_objects(index);
25253775188 q typename std::set< OSM_Element_Metadata_Skeleton< Id_Type > >::iterator it
25353775188 q = current_objects.lower_bound(OSM_Element_Metadata_Skeleton< Id_Type >(ref, timestamp));
25453775188 q if (it == current_objects.begin())
2551290652 q return 0;
25652484588 q --it;
25752484588 q if (it->ref == ref)
25830293688 q return &*it;
25922190976 q else
26022190976 q return 0;
26152484588 q}
264template< typename Index, typename Object >
265Attic_Meta_Collector< Index, Object >::Attic_Meta_Collector(
266 const std::map< Index, std::vector< Attic< Object > > >& items, Transaction& transaction, bool turn_on)
2672049176 q : current(items, transaction, turn_on ? current_meta_file_properties< Object >() : 0),
2682049176 q attic(items, transaction, turn_on ? attic_meta_file_properties< Object >() : 0)
2692049176 q{}
272template< typename Index, typename Object >
273const OSM_Element_Metadata_Skeleton< typename Object::Id_Type >* Attic_Meta_Collector< Index, Object >::get(
274 const Index& index, typename Object::Id_Type ref, uint64 timestamp)
275375142130 q{
276375142130 q const OSM_Element_Metadata_Skeleton< typename Object::Id_Type >* meta
277375142130 q = current.get(index, ref, timestamp);
278375142130 q if (meta)
2791349340 q return meta;
280361649127 q return attic.get(index, ref, timestamp);
281375142130 q}
284#endif