1/** Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Roland Olbricht et al. 3 * This file is part of Overpass_API. 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. 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. 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/>. 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" 31//----------------------------------------------------------------------------- 33class Newer_Constraint : public Query_Constraint 364515 q Newer_Constraint(Newer_Statement& newer) : timestamp(newer.get_timestamp()) {} 381614 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() {} 48template< typename TIndex, typename TObject > 50 (std::map< TIndex, std::vector< TObject > >& modify, 51 Resource_Manager& rman, uint64 timestamp, File_Properties* file_properties) 552513 q Meta_Collector< TIndex, typename TObject::Id_Type > meta_collector 562513 q (modify, *rman.get_transaction(), file_properties); 572513 q for (typename std::map< TIndex, std::vector< TObject > >::iterator it = modify.begin(); 584071013 q it != modify.end(); ++it) 604068513 q std::vector< TObject > local_into; 614068513 q for (typename std::vector< TObject >::const_iterator iit = it->second.begin(); 6246136713 q iit != it->second.end(); ++iit) 6442068211 q const OSM_Element_Metadata_Skeleton< typename TObject::Id_Type >* meta_skel 6542068211 q = meta_collector.get(it->first, iit->id); 6642068211 q if ((meta_skel) && (meta_skel->timestamp >= timestamp)) 6712147710 q local_into.push_back(*iit); 694068513 q it->second.swap(local_into); 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) 80149 q if (modify.empty()) 83149 q Meta_Collector< TIndex, typename TObject::Id_Type > current_meta_collector 84149 q (modify, *rman.get_transaction(), current_file_properties); 85149 q Meta_Collector< TIndex, typename TObject::Id_Type > attic_meta_collector 86149 q (modify, *rman.get_transaction(), attic_file_properties); 88149 q for (typename std::map< TIndex, std::vector< TObject > >::iterator it = modify.begin(); 8925979 q it != modify.end(); ++it) 9125839 q std::vector< TObject > local_into; 9225839 q for (typename std::vector< TObject >::const_iterator iit = it->second.begin(); 93600479 q iit != it->second.end(); ++iit) 95574648 q const OSM_Element_Metadata_Skeleton< typename TObject::Id_Type >* meta_skel 96574648 q = current_meta_collector.get(it->first, iit->id); 97574648 q if (!meta_skel || !(meta_skel->timestamp < iit->timestamp)) 98546287 q meta_skel = attic_meta_collector.get(it->first, iit->id, iit->timestamp); 99574648 q if ((meta_skel) && (meta_skel->timestamp >= timestamp)) 100208025 q local_into.push_back(*iit); 10225839 q it->second.swap(local_into); 107void Newer_Constraint::filter(const Statement& query, Resource_Manager& rman, Set& into) 1091614 q newer_filter_map(into.nodes, rman, this->timestamp, meta_settings().NODES_META); 1101614 q newer_filter_map(into.ways, rman, this->timestamp, meta_settings().WAYS_META); 1111614 q newer_filter_map(into.relations, rman, this->timestamp, meta_settings().RELATIONS_META); 1131614 q if (!into.attic_nodes.empty()) 11455 q newer_filter_map_attic(into.attic_nodes, rman, this->timestamp, 11555 q meta_settings().NODES_META, attic_settings().NODES_META); 1171614 q if (!into.attic_ways.empty()) 11844 q newer_filter_map_attic(into.attic_ways, rman, this->timestamp, 11944 q meta_settings().WAYS_META, attic_settings().WAYS_META); 1211614 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); 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) 1386015 q uint line_nr = tree_it->line_col.first; 1406015 q if (tree_it->token == ":" && tree_it->rhs) 1426015 q std::map< std::string, std::string > attributes; 1436015 q attributes["than"] = decode_json(tree_it.rhs()->token, error_output); 1446015 q return new Newer_Statement(line_nr, attributes, global_settings); 151Newer_Statement::Newer_Statement 152 (int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings) 1536015 q : Statement(line_number_), than_timestamp(0) 1556015 q std::map< std::string, std::string > attributes; 1596015 q eval_attributes_array(get_name(), attributes, input_attributes); 1616015 q than_timestamp = Timestamp(attributes["than"]).timestamp; 1630 add_static_error("The attribute \"than\" must contain a timestamp exactly in the form yyyy-mm-ddThh:mm:ssZ."); 166Newer_Statement::~Newer_Statement() 1686015 q for (std::vector< Query_Constraint* >::const_iterator it = constraints.begin(); 16910515 q it != constraints.end(); ++it) 1740void Newer_Statement::execute(Resource_Manager& rman) {} 176Query_Constraint* Newer_Statement::get_query_constraint() 1784515 q constraints.push_back(new Newer_Constraint(*this)); 1794515 q return constraints.back();