Overpass API regression suite coverage (Nova Scotia) / overpass_api/statements/newer.cc

overpass_api/statements/newer.cc

86 of 91 instrumented lines run by the suite (94.5%) 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#include "../../template_db/block_backend.h"
20#include "../../template_db/random_file.h"
21#include "../core/settings.h"
22#include "../data/meta_collector.h"
23#include "newer.h"
25#include <algorithm>
26#include <cmath>
27#include <sstream>
28#include <vector>
31//-----------------------------------------------------------------------------
33class Newer_Constraint : public Query_Constraint
35 public:
363913 q Newer_Constraint(Newer_Statement& newer) : timestamp(newer.get_timestamp()) {}
381311 q Query_Filter_Strategy delivers_data(Resource_Manager& rman) { return ids_required; }
40 void filter(const Statement& query, Resource_Manager& rman, Set& into);
410 virtual ~Newer_Constraint() {}
43 private:
44 uint64 timestamp;
45};
48template< typename TIndex, typename TObject >
49void newer_filter_map
50 (std::map< TIndex, std::vector< TObject > >& modify,
51 Resource_Manager& rman, uint64 timestamp, File_Properties* file_properties)
533911 q if (modify.empty())
54189 q return;
552110 q Meta_Collector< TIndex, typename TObject::Id_Type > meta_collector
562110 q (modify, *rman.get_transaction(), file_properties);
572110 q for (typename std::map< TIndex, std::vector< TObject > >::iterator it = modify.begin();
58982110 q it != modify.end(); ++it)
59980010 q {
60980010 q std::vector< TObject > local_into;
61980010 q for (typename std::vector< TObject >::const_iterator iit = it->second.begin();
6216152910 q iit != it->second.end(); ++iit)
631517299 q {
641517299 q const OSM_Element_Metadata_Skeleton< typename TObject::Id_Type >* meta_skel
651517299 q = meta_collector.get(it->first, iit->id);
661517299 q if ((meta_skel) && (meta_skel->timestamp >= timestamp))
671298449 q local_into.push_back(*iit);
681517299 q }
69980010 q it->second.swap(local_into);
70980010 q }
74template< typename TIndex, typename TObject >
75void newer_filter_map_attic
76 (std::map< TIndex, std::vector< TObject > >& modify,
77 Resource_Manager& rman, uint64 timestamp,
78 File_Properties* current_file_properties, File_Properties* attic_file_properties)
80138 q if (modify.empty())
810 return;
83138 q Meta_Collector< TIndex, typename TObject::Id_Type > current_meta_collector
84138 q (modify, *rman.get_transaction(), current_file_properties);
85138 q Meta_Collector< TIndex, typename TObject::Id_Type > attic_meta_collector
86138 q (modify, *rman.get_transaction(), attic_file_properties);
88138 q for (typename std::map< TIndex, std::vector< TObject > >::iterator it = modify.begin();
8922988 q it != modify.end(); ++it)
9022858 q {
9122858 q std::vector< TObject > local_into;
9222858 q for (typename std::vector< TObject >::const_iterator iit = it->second.begin();
931227538 q iit != it->second.end(); ++iit)
941204687 q {
951204687 q const OSM_Element_Metadata_Skeleton< typename TObject::Id_Type >* meta_skel
961204687 q = current_meta_collector.get(it->first, iit->id);
971204687 q if (!meta_skel || !(meta_skel->timestamp < iit->timestamp))
981189326 q meta_skel = attic_meta_collector.get(it->first, iit->id, iit->timestamp);
991204687 q if ((meta_skel) && (meta_skel->timestamp >= timestamp))
1001080307 q local_into.push_back(*iit);
1011204687 q }
10222858 q it->second.swap(local_into);
10322858 q }
107void Newer_Constraint::filter(const Statement& query, Resource_Manager& rman, Set& into)
1091311 q newer_filter_map(into.nodes, rman, this->timestamp, meta_settings().NODES_META);
1101311 q newer_filter_map(into.ways, rman, this->timestamp, meta_settings().WAYS_META);
1111311 q newer_filter_map(into.relations, rman, this->timestamp, meta_settings().RELATIONS_META);
1131311 q if (!into.attic_nodes.empty())
11433 q newer_filter_map_attic(into.attic_nodes, rman, this->timestamp,
11533 q meta_settings().NODES_META, attic_settings().NODES_META);
1171311 q if (!into.attic_ways.empty())
11855 q newer_filter_map_attic(into.attic_ways, rman, this->timestamp,
11955 q meta_settings().WAYS_META, attic_settings().WAYS_META);
1211311 q if (!into.attic_relations.empty())
12255 q newer_filter_map_attic(into.attic_relations, rman, this->timestamp,
12355 q meta_settings().RELATIONS_META, attic_settings().RELATIONS_META);
1251311 q into.areas.clear();
128//-----------------------------------------------------------------------------
130Newer_Statement::Statement_Maker Newer_Statement::statement_maker;
131Newer_Statement::Criterion_Maker Newer_Statement::criterion_maker;
134Statement* Newer_Statement::Criterion_Maker::create_criterion(const Token_Node_Ptr& tree_it,
135 const std::string& type, const std::string& into,
136 Statement::Factory& stmt_factory, Parsed_Query& global_settings, Error_Output* error_output)
1385213 q uint line_nr = tree_it->line_col.first;
1405213 q if (tree_it->token == ":" && tree_it->rhs)
1425213 q std::map< std::string, std::string > attributes;
1435213 q attributes["than"] = decode_json(tree_it.rhs()->token, error_output);
1445213 q return new Newer_Statement(line_nr, attributes, global_settings);
1470 return 0;
151Newer_Statement::Newer_Statement
152 (int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)
1535213 q : Statement(line_number_), than_timestamp(0)
1555213 q std::map< std::string, std::string > attributes;
1575213 q attributes["than"] = "";
1595213 q eval_attributes_array(get_name(), attributes, input_attributes);
1615213 q than_timestamp = Timestamp(attributes["than"]).timestamp;
1625213 q if (than_timestamp == 0)
1630 add_static_error("The attribute \"than\" must contain a timestamp exactly in the form yyyy-mm-ddThh:mm:ssZ.");
166Newer_Statement::~Newer_Statement()
1685213 q for (std::vector< Query_Constraint* >::const_iterator it = constraints.begin();
1699113 q it != constraints.end(); ++it)
1703913 q delete *it;
1740void Newer_Statement::execute(Resource_Manager& rman) {}
176Query_Constraint* Newer_Statement::get_query_constraint()
1783913 q constraints.push_back(new Newer_Constraint(*this));
1793913 q return constraints.back();