Overpass API regression suite coverage (Nova Scotia) / overpass_api/statements/statement.h
overpass_api/statements/statement.h
55 of 72 instrumented lines run by the suite (76.4%) 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__STATEMENTS__STATEMENT_H20#define DE__OSM3S___OVERPASS_API__STATEMENTS__STATEMENT_H22#include <map>23#include <set>24#include <vector>26#include "../core/datatypes.h"27#include "../core/parsed_query.h"28#include "../core/settings.h"29#include "../data/diff_set.h"30#include "../dispatch/resource_manager.h"31#include "../frontend/tokenizer_utils.h"32#include "../osm-backend/area_updater.h"35typedef enum { ids_required, ids_useful, prefer_ranges } Query_Filter_Strategy;37typedef enum { nothing, /*ids_collected,*/ ranges_collected, data_collected } Answer_State;40template< typename Id >41struct Id_Constraint42{45 void restrict_to(const std::vector< Id >& ids);47 std::vector< Id > ids;48 bool invert;49};52class Query_Constraint53{54 public:56 virtual Query_Filter_Strategy delivers_data(Resource_Manager& rman) = 0;58 virtual bool collect_nodes(Resource_Manager& rman, Set& into,60 virtual bool collect(Resource_Manager& rman, Set& into,64 virtual bool get_ranges(Resource_Manager& rman, Ranges< Uint31_Index >& ranges)66 virtual bool get_ranges(Resource_Manager& rman, Ranges< Uint32_Index >& ranges)69 virtual Ranges< Uint32_Index > get_node_ranges(Resource_Manager& rman)76 virtual Ranges< Uint31_Index > get_way_ranges(Resource_Manager& rman)83 virtual Ranges< Uint31_Index > get_relation_ranges(Resource_Manager& rman)91 virtual bool get_node_ids92 (Resource_Manager& rman, std::vector< Node_Skeleton::Id_Type >& ids)94 virtual bool get_way_ids95 (Resource_Manager& rman, std::vector< Way_Skeleton::Id_Type >& ids)97 virtual bool get_relation_ids98 (Resource_Manager& rman, std::vector< Relation_Skeleton::Id_Type >& ids)100 virtual bool get_area_ids101 (Resource_Manager& rman, std::vector< Area_Skeleton::Id_Type >& ids)104 virtual bool get_data(const Statement& query, Resource_Manager& rman, Set& into,105 const Ranges< Uint32_Index >& ranges,106 const std::vector< Node::Id_Type >& ids,107 bool invert_ids)109 virtual bool get_data(const Statement& query, Resource_Manager& rman, Set& into,110 const Ranges< Uint31_Index >& ranges,111 int type,112 const std::vector< Uint32_Index >& ids,113 bool invert_ids)116 // Cheap filter. No health_check in between needed and should be called first.119 // Expensive filter. Health_check may be needed in between. These are called last120 // to minimize the number of elements that need to be processed.124};126/**127 * The base class for all statements128 */129class Statement130{131 public:132 enum QL_Context { generic, in_convert, evaluator_expected, elem_eval_possible, member_eval_possible };134 enum Eval_Return_Type { non_evaluator, string, container, geometry };135 static std::string eval_to_string(Statement::Eval_Return_Type eval_type);137 struct Return_Type_Checker138 {139 virtual bool eval_required() const = 0;140 virtual bool matches(Eval_Return_Type eval_type) const = 0;141 virtual std::string expectation() const = 0;143 };145 struct Single_Return_Type_Checker : Return_Type_Checker146 {15010708200 q virtual bool matches(Eval_Return_Type eval_type) const { return eval_type == expected; }154 private:155 Eval_Return_Type expected;156 };158 struct Factory159 {1602448612 q Factory(Parsed_Query& global_settings_) : error_output_(error_output), global_settings(global_settings_) {}161 ~Factory();163 Statement* create_statement(std::string element, int line_number,164 const std::map< std::string, std::string >& attributes);165 Statement* create_evaluator(166 const Token_Node_Ptr& tree_it, QL_Context tree_context, const Statement::Return_Type_Checker& eval_type);167 Statement* create_criterion(const Token_Node_Ptr& tree_it,168 const std::string& type, bool& can_standalone, const std::string& into);170 std::vector< Statement* > created_statements;171 Error_Output* error_output_;172 Parsed_Query& global_settings;173 };175 struct Statement_Maker176 {177 virtual Statement* create_statement178 (int line_number, const std::map< std::string, std::string >& attributes, Parsed_Query& global_settings) = 0;180 };182 struct Criterion_Maker183 {184 virtual bool can_standalone(const std::string& type) = 0;185 virtual Statement* create_criterion(const Token_Node_Ptr& tree_it,186 const std::string& type, const std::string& into,187 Statement::Factory& stmt_factory, Parsed_Query& global_settings, Error_Output* error_output) = 0;189 };191 struct Evaluator_Maker192 {193 virtual Statement* create_evaluator(const Token_Node_Ptr& tree_it, QL_Context tree_context,194 Statement::Factory& stmt_factory, Parsed_Query& global_settings, Error_Output* error_output) = 0;196 };198 static std::map< std::string, Statement_Maker* >& maker_by_name();199 static std::map< std::string, Criterion_Maker* >& maker_by_ql_criterion();200 static std::map< std::string, std::vector< Evaluator_Maker* > >& maker_by_token();201 static std::map< std::string, std::vector< Evaluator_Maker* > >& maker_by_func_name();205 virtual void add_statement(Statement* statement, std::string text);206 virtual void add_final_text(std::string text);207 virtual std::string get_name() const = 0;208 virtual std::string get_result_name() const = 0;209 virtual void execute(Resource_Manager& rman) = 0;211 // May return 0. The ownership of the Query_Constraint remains at the called212 // object.226 void display_full();227 void display_starttag();2321236378 q virtual std::string dump_ql_in_query(const std::string& indent) const { return dump_compact_ql(indent); }234 static void set_error_output(Error_Output* error_output_)239 void runtime_error(std::string error) const;240 void runtime_remark(std::string error) const;242 const static int NODE = 1;243 const static int WAY = 2;244 const static int RELATION = 4;245 const static int AREA = 8;246 const static int DERIVED = 16;248 private:249 static Error_Output* error_output;251 int line_number;252 int startpos, endpos, tagendpos;253 int progress;255 protected:256 void eval_attributes_array257 (std::string element, std::map< std::string, std::string >& attributes,258 const std::map< std::string, std::string >& input);259 void assure_no_text(std::string text, std::string name);260 void substatement_error(std::string parent, Statement* child);262 void add_static_error(std::string error);263 void add_static_remark(std::string remark);266};269std::map< std::string, std::string > convert_c_pairs(const char** attr);272template< class TStatement >273class Generic_Statement_Maker : public Statement::Statement_Maker274{275 public:276 virtual Statement* create_statement277 (int line_number, const std::map< std::string, std::string >& attributes, Parsed_Query& global_settings)282239904612 q Generic_Statement_Maker(const std::string& name) { Statement::maker_by_name()[name] = this; }283 virtual ~Generic_Statement_Maker() {}284};287class Output_Statement : public Statement288{289 public:2943584605 q std::string dump_ql_result_name() const { return output != "_" ? std::string("->.") + output : ""; }295683477 q std::string dump_xml_result_name() const { return output != "_" ? std::string(" into=\"") + output + "\"" : ""; }297 protected:300 void transfer_output(Resource_Manager& rman, Set& into) const;301 void transfer_output(Resource_Manager& rman, Diff_Set& into) const;303 private:304 std::string output;305};308#endif