Overpass API regression suite coverage (Nova Scotia) / 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);
371506205 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 {
432448612 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 {
49724150 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()
542448612 q {
552448612 q Statement::maker_by_ql_criterion()["w"] = this;
562448612 q Statement::maker_by_ql_criterion()["way_link"] = this;
572448612 q Statement::maker_by_ql_criterion()["way_cnt"] = this;
582448612 q Statement::maker_by_ql_criterion()["r"] = this;
592448612 q Statement::maker_by_ql_criterion()["bn"] = this;
602448612 q Statement::maker_by_ql_criterion()["bw"] = this;
612448612 q Statement::maker_by_ql_criterion()["br"] = this;
622448612 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()
732448612 q {
742448612 q Statement::maker_by_ql_criterion()["<"] = this;
752448612 q Statement::maker_by_ql_criterion()["<<"] = this;
762448612 q Statement::maker_by_ql_criterion()[">"] = this;
772448612 q Statement::maker_by_ql_criterion()[">>"] = this;
782448612 q }
79 };
80 static Criterion_Maker_2 criterion_maker_2;
82 virtual Query_Constraint* get_query_constraint();
83227353 q unsigned int get_type() const { return type; }
8425855 q std::string get_input() const { return input; }
8613853 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
93182151 q {
94182151 q return indent + "<recurse"
95182151 q + (input != "_" ? std::string(" from=\"") + input + "\"" : "")
96182151 q + " type=\"" + to_xml_representation(type) + "\""
97182151 q + (role != "" ? std::string(" role=\"") + escape_xml(role) + "\"" : "")
98182151 q + (restrict_to_role ? " role-restricted=\"yes\"" : "")
99182151 q + dump_xml_pos_restrictions()
100182151 q + (lower <= upper ? std::string(" lower=\"") + to_string(lower) + "\" upper=\"" + to_string(upper) + "\"" : "")
101182151 q + dump_xml_result_name() + "/>\n";
104 virtual std::string dump_ql_in_query(const std::string&) const
10511655 q {
10611655 q return std::string("(") + to_ql_representation(type)
10711655 q + (input != "_" ? std::string(".") + input : "")
10811655 q + (restrict_to_role || !pos.empty() ? ":" : "")
10911655 q + (restrict_to_role ? std::string("\"") + escape_cstr(role) + "\"" : "")
11011655 q + dump_ql_pos_restrictions()
11111655 q + (lower < upper ? ":" + to_string(lower) + "-"
11211655 q + (upper == std::numeric_limits< unsigned int >::max() ? "" : to_string(upper)) : "")
11311655 q + (lower == upper ? ":" + to_string(lower) : "")
11411655 q + ")";
11511655 q }
117 virtual std::string dump_compact_ql(const std::string&) const
119434165 q std::string target_type = to_target_type(type);
120434165 q if (target_type != "")
121256108 q return target_type + "(" + to_ql_representation(type)
122256108 q + (input != "_" ? std::string(".") + input : "")
123256108 q + (restrict_to_role || !pos.empty() ? ":" : "")
124256108 q + (restrict_to_role ? std::string("\"") + escape_cstr(role) + "\"" : "")
125256108 q + dump_ql_pos_restrictions()
126256108 q + (lower < upper ? ":" + to_string(lower) + "-"
127190108 q + (upper == std::numeric_limits< unsigned int >::max() ? "" : to_string(upper)) : "")
128256108 q + (lower == upper ? ":" + to_string(lower) : "")
129256108 q + ")" + dump_ql_result_name() + ";";
13017882 q else
13117882 q return (input != "_" ? std::string(".") + input + " " : "")
13217882 q + to_ql_representation(type) + dump_ql_result_name() + ";";
134217165 q virtual std::string dump_pretty_ql(const std::string& indent) const { return indent + dump_compact_ql(indent); }
1366742 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
152372153 q if (pos.empty())
153360149 q return "";
154126 q std::string result = to_string(pos[0]);
155166 q for (uint i = 1; i < pos.size(); ++i)
15642 q result += "," + to_string(pos[i]);
157126 q return result;
160 std::string dump_xml_pos_restrictions() const
162182151 q if (pos.empty())
163176147 q return "";
16466 q std::string result = " pos=\"" + to_string(pos[0]);
16586 q for (uint i = 1; i < pos.size(); ++i)
16622 q result += "," + to_string(pos[i]);
16766 q return result + "\"";
169};
172#endif