Overpass API regression suite coverage (Nova Scotia) / overpass_api/statements/unary_operators.h
overpass_api/statements/unary_operators.h
24 of 26 instrumented lines run by the suite (92.3%) 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__UNARY_OPERATORS_H20#define DE__OSM3S___OVERPASS_API__STATEMENTS__UNARY_OPERATORS_H23#include "../data/tag_store.h"24#include "../data/utils.h"25#include "evaluator.h"26#include "statement.h"27#include "unary_functions.h"29#include <map>30#include <string>31#include <vector>34/* === Unary Operators ===36Unary operators need for execution an operand.37They are always written in prefix notation.38The operators can be grouped with parentheses:39The two variants41 <Operator><Evaluator>43and45 (<Operator><Evaluator>)47have as standalone expressions precisely the same semantics.48The parenthesis variant exists to override operator precedence.50The order of precedence is as follows, ordered weak to strong binding:51* logical disjunction52* logical conjunction53* equality, inequality54* less, less-equal, greater, greater-equal55* plus, binary minus56* times, divided57* logical negation58* unary minus60In the following, the operators are ordered by precedence, stronger binding last.61*/63class Evaluator_Prefix_Operator : public Evaluator_Unary_Function64{65public:66 Evaluator_Prefix_Operator(int line_number_);6822444 q static bool applicable_by_subtree_structure(const Token_Node_Ptr& tree_it) { return !tree_it->lhs && tree_it->rhs; }69 static void add_substatements(Statement* result, const std::string& operator_name, const Token_Node_Ptr& tree_it,70 Statement::QL_Context tree_context, Statement::Factory& stmt_factory, Error_Output* error_output);71};74template< typename Evaluator_ >75struct Evaluator_Prefix_Operator_Syntax : public Evaluator_Prefix_Operator76{77 Evaluator_Prefix_Operator_Syntax(int line_number_, const std::map< std::string, std::string >& input_attributes)84 virtual std::string dump_xml(const std::string& indent) const91 virtual std::string dump_compact_ql(const std::string&) const10111634 q virtual int get_operator_priority() const { return operator_priority(Evaluator_::stmt_operator(), true); }102};105/* ==== Boolean Negation ====107The boolean negation evaluates to "1" if its argument evaluates to a representation of boolean false.108Otherwise it evaluates to "1".109Representations of boolean false are the empty std::string and every std::string that is a numerical representation of zero.110Every other std::string represents boolean true.112Its syntax is114 ! <Evaluator>116The whitespace is optional.117*/119class Evaluator_Not : public Evaluator_Prefix_Operator_Syntax< Evaluator_Not >120{121public:122 static Operator_Stmt_Maker< Evaluator_Not > statement_maker;123 static Operator_Eval_Maker< Evaluator_Not > evaluator_maker;127 Evaluator_Not(int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)130 virtual std::string process(const std::string& rhs_result) const;131};134/* ==== Unary Minus ====136The unary minus operator negates its argument.137If the argument is an integer or a floating point number then it is negated as integer resp. floating point number.138Otherwise the unary minus operator returns "NaN".140The syntax for unary minus is:142 - <Evaluator>144The whitespace is optional.145*/147class Evaluator_Negate : public Evaluator_Prefix_Operator_Syntax< Evaluator_Negate >148{149public:150 static Operator_Stmt_Maker< Evaluator_Negate > statement_maker;151 static Operator_Eval_Maker< Evaluator_Negate > evaluator_maker;155 Evaluator_Negate(int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)158 virtual std::string process(const std::string& rhs_result) const;159};162#endif