Overpass API regression suite coverage (Nova Scotia) / overpass_api/statements/query.h
overpass_api/statements/query.h
57 of 78 instrumented lines run by the suite (73.1%) 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__QUERY_H20#define DE__OSM3S___OVERPASS_API__STATEMENTS__QUERY_H22#include <map>23#include <string>24#include <vector>25#include "../../expat/escape_json.h"26#include "../../expat/escape_xml.h"27#include "statement.h"30const int QUERY_NODE = 1;31const int QUERY_WAY = 2;32const int QUERY_CLOSED_WAY = 4;33const int QUERY_RELATION = 8;34const int QUERY_DERIVED = 16;35const int QUERY_AREA = 32;38class Regular_Expression;39class Bbox_Query_Statement;42/* === The Query Statement ===44The most important statement is the ''query'' statement. This is not a single statement but rather consists of one of the type specifiers ''node'', ''way'', ''relation'' (or shorthand ''rel''), ''derived'', ''area'', or ''nwr'' (shorthand for nodes, ways or relations) followed by one or more filters. The result set is the set of all elements that match the conditions of all the filters.46Example:48<source lang="cpp">49// one filter50 node[name="Foo"];51 way[name="Foo"];52 rel[name="Foo"];53 nwr[name="Foo"];54 derived[name="Foo"];55 area[name="Foo"];57// many filters58 node[name="Foo"][type="Bar"];59</source>61Here, ''node'', ''way'', ''rel'', ''nwr'', ''derived'', and ''area'' are the type specifier, ''[name="Foo"]'' resp. ''[type="Bar"]'' is the filter and the semicolon ends the statement.63The ''query'' statement has a result set that can be changed with the usual postfix notation.65<source lang="cpp">66 node[name="Foo"]->.a;67</source>69The individual filters may have in addition input sets that can be changed in the individual filters. Please see for this at the respective filter.70*/72class Query_Statement : public Output_Statement73{74 public:75 Query_Statement(int line_number_, const std::map< std::string, std::string >& input_attributes,76 Parsed_Query& global_settings);77 virtual ~Query_Statement();78 virtual void add_statement(Statement* statement, std::string text);80 virtual void execute(Resource_Manager& rman);82 static Generic_Statement_Maker< Query_Statement > statement_maker;86 static std::string to_string(int type)110 virtual std::string dump_xml(const std::string& indent) const1120 std::string result = indent + "<query" + dump_xml_result_name() + " type=\"" + to_string(type) + "\">\n";1140 for (std::vector< Statement* >::const_iterator it = substatements.begin(); it != substatements.end(); ++it)120766518 q virtual std::string dump_compact_ql(const std::string& indent) const { return dump_subquery_map_ql(indent, false); }121766518 q virtual std::string dump_pretty_ql(const std::string& indent) const { return dump_subquery_map_ql(indent, true); }123 std::string dump_subquery_map_ql(const std::string& indent, bool pretty) const1491532518 q return result + (pretty && proper_substatement_count > 1 && dump_ql_result_name() != "" ? "\n " + indent : "")153 private:154 int type;155 std::vector< std::string > keys;156 std::vector< std::pair< std::string, std::string > > key_values;157 std::vector< std::pair< std::string, Regular_Expression* > > key_regexes;158 std::vector< std::pair< Regular_Expression*, Regular_Expression* > > regkey_regexes;159 std::vector< std::pair< std::string, std::string > > key_nvalues;160 std::vector< std::pair< std::string, Regular_Expression* > > key_nregexes;161 std::vector< std::pair< Regular_Expression*, Regular_Expression* > > regkey_nregexes;162 std::vector< Query_Constraint* > constraints;163 std::vector< Statement* > substatements;164 Bbox_Query_Statement* global_bbox_statement;166 static bool area_query_exists_;168 void get_elements_by_id_from_db169 (std::map< Uint31_Index, std::vector< Area_Skeleton > >& elements,170 const std::vector< Area_Skeleton::Id_Type >& ids, bool invert_ids,171 Resource_Manager& rman, File_Properties& file_prop);173 template< class TIndex, class TObject >174 void filter_by_tags175 (std::map< TIndex, std::vector< TObject > >& items,176 std::map< TIndex, std::vector< Attic< TObject > > >* attic_items,177 uint64 timestamp,178 const File_Properties& file_prop, const File_Properties* attic_file_prop,179 Resource_Manager& rman, Transaction& transaction);181 template< class TIndex, class TObject >182 void filter_by_tags183 (std::map< TIndex, std::vector< TObject > >& items,184 const File_Properties& file_prop,185 Resource_Manager& rman, Transaction& transaction);187 void filter_by_tags(std::map< Uint31_Index, std::vector< Derived_Structure > >& items);189 template< class Id_Type >190 void collect_nodes(191 const Id_Constraint< Id_Type >& ids, Answer_State& answer_state, Set& into, Resource_Manager& rman);192 template< class Id_Type >193 void collect_elems(194 int type, const Id_Constraint< Id_Type >& ids, Answer_State& answer_state, Set& into, Resource_Manager& rman);196 void collect_elems(Answer_State& answer_state, Set& into, Resource_Manager& rman);197 void apply_all_filters(198 Resource_Manager& rman, uint64 timestamp, Query_Filter_Strategy check_keys_late, Set& into);199};202class Has_Kv_Statement : public Statement203{204 public:205 Has_Kv_Statement(int line_number_, const std::map< std::string, std::string >& input_attributes,206 Parsed_Query& global_settings);210 virtual ~Has_Kv_Statement();212 static Generic_Statement_Maker< Has_Kv_Statement > statement_maker;220 virtual std::string dump_xml(const std::string& indent) const2230 + (key != "" ? (key_regex ? std::string(" regk=\"") : std::string(" k=\"")) + escape_xml(key) + "\"" : "")2240 + (value != "" ? (regex ? std::string(" regv=\"") : std::string(" v=\"")) + escape_xml(value) + "\"" : "")230 virtual std::string dump_compact_ql(const std::string&) const2341066333 q + (value != "" ? std::string(straight ? "" : "!") + (regex ? "~\"" : "=\"") + escape_cstr(value) + "\"" : "")2380 virtual std::string dump_pretty_ql(const std::string& indent) const { return dump_compact_ql(indent); }240 private:241 std::string key, value;242 Regular_Expression* regex;243 Regular_Expression* key_regex;244 bool straight;245 bool case_sensitive;246};249#endif