Overpass API regression suite coverage (Saxony) / overpass_api/statements/recurse.h

overpass_api/statements/recurse.h

77 of 79 instrumented lines run by the suite (97.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#ifndef DE__OSM3S___OVERPASS_API__STATEMENTS__RECURSE_H
20#define DE__OSM3S___OVERPASS_API__STATEMENTS__RECURSE_H
22#include "../../expat/escape_json.h"
23#include "../../expat/escape_xml.h"
24#include "query.h"
25#include "statement.h"
27#include <map>
28#include <string>
29#include <vector>
32class Recurse_Statement : public Output_Statement
34 public:
35 Recurse_Statement(int line_number_, const std::map< std::string, std::string >& input_attributes,
36 Parsed_Query& global_settings);
371606222 q virtual std::string get_name() const { return "recurse"; }
38 virtual void execute(Resource_Manager& rman);
39 virtual ~Recurse_Statement();
41 struct Statement_Maker : public Generic_Statement_Maker< Recurse_Statement >
42 {
432768692 q Statement_Maker() : Generic_Statement_Maker< Recurse_Statement >("recurse") {}
44 };
45 static Statement_Maker statement_maker;
47 struct Criterion_Maker_1 : public Statement::Criterion_Maker
48 {
49768159 q virtual bool can_standalone(const std::string& type) { return type != "nwr"; }
50 virtual Statement* create_criterion(const Token_Node_Ptr& tree_it,
51 const std::string& type, const std::string& into,
52 Statement::Factory& stmt_factory, Parsed_Query& global_settings, Error_Output* error_output);
53 Criterion_Maker_1()
542768692 q {
552768692 q Statement::maker_by_ql_criterion()["w"] = this;
562768692 q Statement::maker_by_ql_criterion()["way_link"] = this;
572768692 q Statement::maker_by_ql_criterion()["way_cnt"] = this;
582768692 q Statement::maker_by_ql_criterion()["r"] = this;
592768692 q Statement::maker_by_ql_criterion()["bn"] = this;
602768692 q Statement::maker_by_ql_criterion()["bw"] = this;
612768692 q Statement::maker_by_ql_criterion()["br"] = this;
622768692 q }
63 };
64 static Criterion_Maker_1 criterion_maker_1;
66 struct Criterion_Maker_2 : public Statement::Criterion_Maker
67 {
6841 q virtual bool can_standalone(const std::string& type) { return false; }
69 virtual Statement* create_criterion(const Token_Node_Ptr& tree_it,
70 const std::string& type, const std::string& into,
71 Statement::Factory& stmt_factory, Parsed_Query& global_settings, Error_Output* error_output);
72 Criterion_Maker_2()
732768692 q {
742768692 q Statement::maker_by_ql_criterion()["<"] = this;
752768692 q Statement::maker_by_ql_criterion()["<<"] = this;
762768692 q Statement::maker_by_ql_criterion()[">"] = this;
772768692 q Statement::maker_by_ql_criterion()[">>"] = this;
782768692 q }
79 };
80 static Criterion_Maker_2 criterion_maker_2;
82 virtual Query_Constraint* get_query_constraint();
83216448 q unsigned int get_type() const { return type; }
8424651 q std::string get_input() const { return input; }
8612948 q const std::string* get_role() const { return (restrict_to_role ? &role : 0); }
88 static std::string to_target_type(int type);
89 static std::string to_xml_representation(int type);
90 static std::string to_ql_representation(int type);
92 virtual std::string dump_xml(const std::string& indent) const
93193160 q {
94193160 q return indent + "<recurse"
95193160 q + (input != "_" ? std::string(" from=\"") + input + "\"" : "")
96193160 q + " type=\"" + to_xml_representation(type) + "\""
97193160 q + (role != "" ? std::string(" role=\"") + escape_xml(role) + "\"" : "")
98193160 q + (restrict_to_role ? " role-restricted=\"yes\"" : "")
99193160 q + dump_xml_pos_restrictions()
100193160 q + (lower <= upper ? std::string(" lower=\"") + to_string(lower) + "\" upper=\"" + to_string(upper) + "\"" : "")
101193160 q + dump_xml_result_name() + "/>\n";
104 virtual std::string dump_ql_in_query(const std::string&) const
10511051 q {
10611051 q return std::string("(") + to_ql_representation(type)
10711051 q + (input != "_" ? std::string(".") + input : "")
10811051 q + (restrict_to_role || !pos.empty() ? ":" : "")
10911051 q + (restrict_to_role ? std::string("\"") + escape_cstr(role) + "\"" : "")
11011051 q + dump_ql_pos_restrictions()
11111051 q + (lower < upper ? ":" + to_string(lower) + "-"
11211051 q + (upper == std::numeric_limits< unsigned int >::max() ? "" : to_string(upper)) : "")
11311051 q + (lower == upper ? ":" + to_string(lower) : "")
11411051 q + ")";
11511051 q }
117 virtual std::string dump_compact_ql(const std::string&) const
119472191 q std::string target_type = to_target_type(type);
120472191 q if (target_type != "")
121284122 q return target_type + "(" + to_ql_representation(type)
122284122 q + (input != "_" ? std::string(".") + input : "")
123284122 q + (restrict_to_role || !pos.empty() ? ":" : "")
124284122 q + (restrict_to_role ? std::string("\"") + escape_cstr(role) + "\"" : "")
125284122 q + dump_ql_pos_restrictions()
126284122 q + (lower < upper ? ":" + to_string(lower) + "-"
127234122 q + (upper == std::numeric_limits< unsigned int >::max() ? "" : to_string(upper)) : "")
128284122 q + (lower == upper ? ":" + to_string(lower) : "")
129284122 q + ")" + dump_ql_result_name() + ";";
13018887 q else
13118887 q return (input != "_" ? std::string(".") + input + " " : "")
13218887 q + to_ql_representation(type) + dump_ql_result_name() + ";";
134236191 q virtual std::string dump_pretty_ql(const std::string& indent) const { return indent + dump_compact_ql(indent); }
1368248 q const std::vector< int >* get_pos() const { return pos.empty() ? 0 : &pos; }
1370 unsigned int get_lower() const { return lower; }
1380 unsigned int get_upper() const { return upper; }
140 private:
141 std::string input;
142 unsigned int type;
143 std::string role;
144 bool restrict_to_role;
145 std::vector< int > pos;
146 unsigned int lower;
147 unsigned int upper;
148 std::vector< Query_Constraint* > constraints;
150 std::string dump_ql_pos_restrictions() const
152394162 q if (pos.empty())
153378155 q return "";
154168 q std::string result = to_string(pos[0]);
155208 q for (uint i = 1; i < pos.size(); ++i)
15642 q result += "," + to_string(pos[i]);
157168 q return result;
160 std::string dump_xml_pos_restrictions() const
162193160 q if (pos.empty())
163185153 q return "";
16488 q std::string result = " pos=\"" + to_string(pos[0]);
165108 q for (uint i = 1; i < pos.size(); ++i)
16622 q result += "," + to_string(pos[i]);
16788 q return result + "\"";
169};
172#endif