Overpass API regression suite coverage (Nova Scotia) / overpass_api/statements/if.h

overpass_api/statements/if.h

35 of 55 instrumented lines run by the suite (63.6%) 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__COMPLETE_H
20#define DE__OSM3S___OVERPASS_API__STATEMENTS__COMPLETE_H
22#include <map>
23#include <string>
24#include <vector>
26#include "evaluator.h"
27#include "statement.h"
30/* === The block statement <em>if</em> ===
32''since v0.7.55''
34The block statement <em>if</em> executes its substatements
35only if its condition evaluates to boolean true.
36This allows e.g. to try more loosely search conditions
37if stricter search conditions did not deliver a result.
39The statement does not directly interact with any sets.
41The base syntax is
43 if (<Evaluator>)
44 {
45 <List of Substatements>
46 }
48resp.
50 if (<Evaluator>)
51 {
52 <List of Substatements>
53 }
54 else
55 {
56 <List of Substatements>
57 }
59where <Evaluator> is an evaulator and <List of Substatements> is a list of substatements.
61*/
63class If_Statement : public Statement
65public:
66 If_Statement(int line_number_, const std::map< std::string, std::string >& attributes,
67 Parsed_Query& global_settings);
68 virtual void add_statement(Statement* statement, std::string text);
6911010 q virtual std::string get_name() const { return "if"; }
700 virtual std::string get_result_name() const { return ""; }
71 virtual void execute(Resource_Manager& rman);
723310 q virtual ~If_Statement() {}
74 struct Statement_Maker : public Generic_Statement_Maker< If_Statement >
75 {
762448612 q Statement_Maker() : Generic_Statement_Maker< If_Statement >("if") {}
77 };
78 static Statement_Maker statement_maker;
80 virtual std::string dump_xml(const std::string& indent) const
810 {
820 std::string result = indent + "<if>\n"
830 + (criterion ? criterion->dump_xml(indent + " ") : "");
850 for (std::vector< Statement* >::const_iterator it = substatements.begin(); it != substatements.end(); ++it)
860 result += *it ? (*it)->dump_xml(indent + " ") : "";
880 if (!else_statements.empty())
890 {
900 result = indent + " <else/>\n";
910 for (std::vector< Statement* >::const_iterator it = else_statements.begin();
920 it != else_statements.end(); ++it)
930 result += *it ? (*it)->dump_xml(indent + " ") : "";
940 }
960 return result + indent + "</if>\n";
970 }
99 virtual std::string dump_compact_ql(const std::string& indent) const
1011110 q std::string result = indent + "if(" + (criterion ? criterion->dump_compact_ql("") : "") + "){";
1031610 q for (std::vector< Statement* >::const_iterator it = substatements.begin(); it != substatements.end(); ++it)
10454 q result += (*it)->dump_compact_ql(indent) + ";";
1061110 q if (!else_statements.empty())
10833 q result += "}else{";
10933 q for (std::vector< Statement* >::const_iterator it = else_statements.begin();
11063 q it != else_statements.end(); ++it)
11133 q result += (*it)->dump_compact_ql(indent);
1131110 q result += "}";
1151110 q return result;
118 virtual std::string dump_pretty_ql(const std::string& indent) const
1201110 q std::string result = indent + "if (" + (criterion ? criterion->dump_compact_ql("") : "") + ")\n"
1211110 q + indent + "{";
1231610 q for (std::vector< Statement* >::const_iterator it = substatements.begin(); it != substatements.end(); ++it)
12454 q result += "\n" + (*it)->dump_pretty_ql(indent + " ") + ";";
1261110 q if (!else_statements.empty())
12833 q result += "\n" + indent + "}\n" + indent + "else\n" + indent + "{\n";
12933 q for (std::vector< Statement* >::const_iterator it = else_statements.begin();
13063 q it != else_statements.end(); ++it)
13133 q result += (*it)->dump_compact_ql(indent + " ");
1331110 q result += "\n" + indent + "}";
1351110 q return result;
138private:
139 Evaluator* criterion;
140 bool else_reached;
141 std::vector< Statement* > substatements;
142 std::vector< Statement* > else_statements;
143};
146class Else_Statement : public Statement
148public:
149 Else_Statement(int line_number_, const std::map< std::string, std::string >& attributes,
15093 q Parsed_Query& global_settings) : Statement(line_number_) {}
15193 q virtual std::string get_name() const { return "else"; }
1520 virtual std::string get_result_name() const { return ""; }
1530 virtual void execute(Resource_Manager& rman) {}
155 struct Statement_Maker : public Generic_Statement_Maker< Else_Statement >
156 {
1572448612 q Statement_Maker() : Generic_Statement_Maker< Else_Statement >("else") {}
158 };
159 static Statement_Maker statement_maker;
1610 virtual std::string dump_xml(const std::string& indent) const { return indent + "<else/>\n"; }
1620 virtual std::string dump_compact_ql(const std::string& indent) const { return "else\n"; }
1630 virtual std::string dump_pretty_ql(const std::string& indent) const { return indent + "else\n"; }
164};
167#endif