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

overpass_api/statements/ternary_operator.h

37 of 49 instrumented lines run by the suite (75.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__TERNARY_OPERATORS_H
20#define DE__OSM3S___OVERPASS_API__STATEMENTS__TERNARY_OPERATORS_H
23#include "../data/tag_store.h"
24#include "../data/utils.h"
25#include "evaluator.h"
26#include "statement.h"
28#include <map>
29#include <string>
30#include <vector>
33/* === The Ternary Operator ===
35The ternary operator needs for execution three operands.
36If the first operand evaluates to boolean true
37then it evaluates to what the second operand evaluates.
38Otherwise it evaluates to what the third operand evaluates.
40The two variants
42 <Evaulator>?<Evaluator>:<Evaluator>
44and
46 (<Evaulator>?<Evaluator>:<Evaluator>)
48have as standalone expressions precisely the same semantics.
49The parenthesis variant exists to override operator precedence.
50For the precendence, see the binary operators.
51*/
53struct Ternary_Eval_Task : public Eval_Task
55 Ternary_Eval_Task(Eval_Task* condition_, Eval_Task* lhs_, Eval_Task* rhs_)
5611869 q : condition(condition_), lhs(lhs_), rhs(rhs_) {}
57 ~Ternary_Eval_Task()
5811869 q {
5911869 q delete condition;
6011869 q delete lhs;
6111869 q delete rhs;
6211869 q }
64 virtual std::string eval(const std::string* key) const;
66 virtual std::string eval(const Element_With_Context< Node_Skeleton >& data, const std::string* key) const;
67 virtual std::string eval(const Element_With_Context< Attic< Node_Skeleton > >& data, const std::string* key) const;
68 virtual std::string eval(const Element_With_Context< Way_Skeleton >& data, const std::string* key) const;
69 virtual std::string eval(const Element_With_Context< Attic< Way_Skeleton > >& data, const std::string* key) const;
70 virtual std::string eval(const Element_With_Context< Relation_Skeleton >& data, const std::string* key) const;
71 virtual std::string eval(const Element_With_Context< Attic< Relation_Skeleton > >& data, const std::string* key) const;
72 virtual std::string eval(const Element_With_Context< Area_Skeleton >& data, const std::string* key) const;
73 virtual std::string eval(const Element_With_Context< Derived_Skeleton >& data, const std::string* key) const;
75 virtual std::string eval(uint pos, const Element_With_Context< Way_Skeleton >& data, const std::string* key) const;
76 virtual std::string eval(uint pos, const Element_With_Context< Attic< Way_Skeleton > >& data, const std::string* key) const;
77 virtual std::string eval(uint pos, const Element_With_Context< Relation_Skeleton >& data, const std::string* key) const;
78 virtual std::string eval(uint pos, const Element_With_Context< Attic< Relation_Skeleton > >& data, const std::string* key) const;
80private:
81 Eval_Task* condition;
82 Eval_Task* lhs;
83 Eval_Task* rhs;
84};
87struct Ternary_Eval_Geometry_Task : public Eval_Geometry_Task
89 Ternary_Eval_Geometry_Task(Eval_Task* condition_, Eval_Geometry_Task* lhs_, Eval_Geometry_Task* rhs_)
900 : condition(condition_), lhs(lhs_), rhs(rhs_) {}
91 ~Ternary_Eval_Geometry_Task()
920 {
930 delete condition;
940 delete lhs;
950 delete rhs;
960 }
98 virtual Opaque_Geometry* eval() const;
100 virtual Opaque_Geometry* eval(const Element_With_Context< Node_Skeleton >& data) const;
101 virtual Opaque_Geometry* eval(const Element_With_Context< Attic< Node_Skeleton > >& data) const;
102 virtual Opaque_Geometry* eval(const Element_With_Context< Way_Skeleton >& data) const;
103 virtual Opaque_Geometry* eval(const Element_With_Context< Attic< Way_Skeleton > >& data) const;
104 virtual Opaque_Geometry* eval(const Element_With_Context< Relation_Skeleton >& data) const;
105 virtual Opaque_Geometry* eval(const Element_With_Context< Attic< Relation_Skeleton > >& data) const;
106 virtual Opaque_Geometry* eval(const Element_With_Context< Area_Skeleton >& data) const;
107 virtual Opaque_Geometry* eval(const Element_With_Context< Derived_Skeleton >& data) const;
109private:
110 Eval_Task* condition;
111 Eval_Geometry_Task* lhs;
112 Eval_Geometry_Task* rhs;
113};
116struct Ternary_Evaluator : public Evaluator
118 static Operator_Stmt_Maker< Ternary_Evaluator > statement_maker;
119 static Operator_Eval_Maker< Ternary_Evaluator > evaluator_maker;
1204020692 q static std::string stmt_operator() { return "?"; }
1213470692 q static std::string stmt_name() { return "eval-ternary"; }
123 Ternary_Evaluator(int line_number_, const std::map< std::string, std::string >& input_attributes,
12446872 q Parsed_Query& global_settings) : Evaluator(line_number_), condition(0), lhs(0), rhs(0),
12546872 q return_type_(Statement::string)
12646872 q {
12746872 q std::map< std::string, std::string > attributes;
12846872 q eval_attributes_array(stmt_name(), attributes, input_attributes);
12946872 q }
131 virtual void add_statement(Statement* statement, std::string text);
1320 virtual void execute(Resource_Manager& rman) {}
1330 virtual std::string get_result_name() const { return ""; }
135 virtual Requested_Context request_context() const;
13751672 q virtual Statement::Eval_Return_Type return_type() const { return return_type_; };
138 virtual Eval_Task* get_string_task(Prepare_Task_Context& context, const std::string* key);
139 virtual Eval_Geometry_Task* get_geometry_task(Prepare_Task_Context& context);
141 static bool applicable_by_subtree_structure(const Token_Node_Ptr& tree_it)
14246872 q { return tree_it->lhs && tree_it->rhs; }
143 static void add_substatements(Statement* result, const std::string& operator_name, const Token_Node_Ptr& tree_it,
144 Statement::QL_Context tree_context, Statement::Factory& stmt_factory, Error_Output* error_output);
146 virtual std::string dump_xml(const std::string& indent) const
14711772 q {
14811772 q return indent + "<" + stmt_name() + ">\n"
14911772 q + (condition ? condition->dump_xml(indent + " ") : "")
15011772 q + (lhs ? lhs->dump_xml(indent + " ") : "")
15111772 q + (rhs ? rhs->dump_xml(indent + " ") : "")
15211772 q + indent + "</" + stmt_name() + ">\n";
15311772 q }
155 virtual std::string dump_compact_ql(const std::string&) const
15623472 q {
15723472 q return (condition ?
15823271 q (condition->get_operator_priority() < get_operator_priority() ?
1590 std::string("(") + condition->dump_compact_ql("") + ")"
16023272 q : condition->dump_compact_ql("")) : "")
16123472 q + "?"
16223472 q + (lhs ?
16323070 q (lhs->get_operator_priority() < get_operator_priority() ?
1640 std::string("(") + lhs->dump_compact_ql("") + ")"
16523072 q : lhs->dump_compact_ql("")) : "")
16623472 q + ":"
16723472 q + (rhs ?
16823070 q (rhs->get_operator_priority() < get_operator_priority() ?
1690 std::string("(") + rhs->dump_compact_ql("") + ")"
17023072 q : rhs->dump_compact_ql("")) : "");
17123472 q }
1730 virtual std::string get_name() const { return stmt_name(); }
17478471 q virtual int get_operator_priority() const { return operator_priority(stmt_operator(), false); }
176private:
177 Evaluator* condition;
178 Evaluator* lhs;
179 Evaluator* rhs;
180 Statement::Eval_Return_Type return_type_;
181};
184#endif