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 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__TERNARY_OPERATORS_H20#define DE__OSM3S___OVERPASS_API__STATEMENTS__TERNARY_OPERATORS_H23#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 true37then it evaluates to what the second operand evaluates.38Otherwise it evaluates to what the third operand evaluates.40The two variants42 <Evaulator>?<Evaluator>:<Evaluator>44and46 (<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_Task54{55 Ternary_Eval_Task(Eval_Task* condition_, Eval_Task* lhs_, Eval_Task* rhs_)57 ~Ternary_Eval_Task()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_Task88{89 Ternary_Eval_Geometry_Task(Eval_Task* condition_, Eval_Geometry_Task* lhs_, Eval_Geometry_Task* rhs_)91 ~Ternary_Eval_Geometry_Task()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 Evaluator117{118 static Operator_Stmt_Maker< Ternary_Evaluator > statement_maker;119 static Operator_Eval_Maker< Ternary_Evaluator > evaluator_maker;123 Ternary_Evaluator(int line_number_, const std::map< std::string, std::string >& input_attributes,131 virtual void add_statement(Statement* statement, std::string text);135 virtual Requested_Context request_context() const;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)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) const155 virtual std::string dump_compact_ql(const std::string&) const17478471 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