Overpass API regression suite coverage (Saxony) / overpass_api/statements/set_list_operators.h
overpass_api/statements/set_list_operators.h
92 of 102 instrumented lines run by the suite (90.2%) 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__SET_LIST_OPERATORS_H20#define DE__OSM3S___OVERPASS_API__STATEMENTS__SET_LIST_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/* === List Represented Set Operators ===36Sometimes there is a need to represent multiple values in a tag's value.37Although by no means mandated by the data format,38the de-facto solution is39to represent a set of values by a a semi-colon separated list of those values.41This section offers some functions to make handling of these lists easier.42Currently, the delimiter is hard-coded to a semi-colon.43For the sake of simplicity,44leading or trailing white space at each list entry is ignored.46Note also that the lists are understood as sets.47This means that the order of list elements does no matter.48*/50template< typename Evaluator_ >51struct Unary_Set_List_Operator_Statement_Maker : public Generic_Statement_Maker< Evaluator_ >52{535536692 q Unary_Set_List_Operator_Statement_Maker() : Generic_Statement_Maker< Evaluator_ >(Evaluator_::stmt_name()) {}54};57template< typename Evaluator_ >58struct Unary_Set_List_Operator_Evaluator_Maker : public Statement::Evaluator_Maker59{60 virtual Statement* create_evaluator(const Token_Node_Ptr& tree_it, Statement::QL_Context tree_context,61 Statement::Factory& stmt_factory, Parsed_Query& global_settings, Error_Output* error_output)6335667 q if (!tree_it.assert_is_function(error_output) || !tree_it.assert_has_input_set(error_output, false)82 Unary_Set_List_Operator_Evaluator_Maker()86};89template< typename Evaluator_ >90struct Evaluator_Unary_Set_List_Operator_Syntax : public Evaluator_Unary_Function91{92 Evaluator_Unary_Set_List_Operator_Syntax(int line_number_, const std::map< std::string, std::string >& input_attributes)99 virtual std::string dump_xml(const std::string& indent) const106 virtual std::string dump_compact_ql(const std::string&) const112};115template< typename Evaluator_ >116struct Binary_Set_List_Operator_Statement_Maker : public Generic_Statement_Maker< Evaluator_ >117{1188304692 q Binary_Set_List_Operator_Statement_Maker() : Generic_Statement_Maker< Evaluator_ >(Evaluator_::stmt_name()) {}119};122template< typename Evaluator_ >123struct Binary_Set_List_Operator_Evaluator_Maker : public Statement::Evaluator_Maker124{125 virtual Statement* create_evaluator(const Token_Node_Ptr& tree_it, Statement::QL_Context tree_context,126 Statement::Factory& stmt_factory, Parsed_Query& global_settings, Error_Output* error_output)12862061 q if (!tree_it.assert_is_function(error_output) || !tree_it.assert_has_input_set(error_output, false)13362061 q Statement* result = new Evaluator_(tree_it->line_col.first, attributes, global_settings);13959255 q tree_it.rhs().lhs(), tree_context, Statement::Single_Return_Type_Checker(Statement::string));14759255 q tree_it.rhs().rhs(), tree_context, Statement::Single_Return_Type_Checker(Statement::string));161 Binary_Set_List_Operator_Evaluator_Maker()165};168template< typename Evaluator_ >169struct Evaluator_Binary_Set_List_Operator_Syntax : public Evaluator_Binary_Function170{171 Evaluator_Binary_Set_List_Operator_Syntax(int line_number_, const std::map< std::string, std::string >& input_attributes)178 virtual std::string dump_xml(const std::string& indent) const186 virtual std::string dump_compact_ql(const std::string&) const193};196/* ==== List Represented Set Theoretic Operators ====198The function <em>lrs_in</em> returns "1"199if its first argument is contained in the second argument treated as set.200It returns "0" otherwise.202The function's syntax is204 lrs_in(<Evaluator>, <Evaluator>)206The function <em>lrs_isect</em> returns the intersection of its two arguments treated as sets.207If the arguments have no values in common then the empty string is returned.209The function's syntax is211 lrs_isect(<Evaluator>, <Evaluator>)213The function <em>lrs_union</em> returns the union of its two arguments treated as sets.215The function's syntax is217 lrs_union(<Evaluator>, <Evaluator>)219*/221class Evaluator_Lrs_In : public Evaluator_Binary_Set_List_Operator_Syntax< Evaluator_Lrs_In >222{223public:224 static Binary_Set_List_Operator_Statement_Maker< Evaluator_Lrs_In > statement_maker;225 static Binary_Set_List_Operator_Evaluator_Maker< Evaluator_Lrs_In > evaluator_maker;229 Evaluator_Lrs_In(int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)2308017 q : Evaluator_Binary_Set_List_Operator_Syntax< Evaluator_Lrs_In >(line_number_, input_attributes) {}232 virtual std::string process(const std::string& first_result, const std::string& second_result) const;233};236class Evaluator_Lrs_Isect : public Evaluator_Binary_Set_List_Operator_Syntax< Evaluator_Lrs_Isect >237{238public:239 static Binary_Set_List_Operator_Statement_Maker< Evaluator_Lrs_Isect > statement_maker;240 static Binary_Set_List_Operator_Evaluator_Maker< Evaluator_Lrs_Isect > evaluator_maker;244 Evaluator_Lrs_Isect(int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)24517226 q : Evaluator_Binary_Set_List_Operator_Syntax< Evaluator_Lrs_Isect >(line_number_, input_attributes) {}247 virtual std::string process(const std::string& first_result, const std::string& second_result) const;248};251class Evaluator_Lrs_Union : public Evaluator_Binary_Set_List_Operator_Syntax< Evaluator_Lrs_Union >252{253public:254 static Binary_Set_List_Operator_Statement_Maker< Evaluator_Lrs_Union > statement_maker;255 static Binary_Set_List_Operator_Evaluator_Maker< Evaluator_Lrs_Union > evaluator_maker;259 Evaluator_Lrs_Union(int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)26036847 q : Evaluator_Binary_Set_List_Operator_Syntax< Evaluator_Lrs_Union >(line_number_, input_attributes) {}262 virtual std::string process(const std::string& first_result, const std::string& second_result) const;263};266/* ==== List Represented Set Statistic Operators ====268The function <em>lrs_min</em> returns the minimum of the elements in its argument treated as set.269If all entries are numbers then the comparsion is numerical.271The function's syntax is273 lrs_min(<Evaluator>)276The function <em>lrs_min</em> returns the minimum of the elements in its argument treated as set.277If all entries are numbers then the comparsion is numerical.279The function's syntax is281 lrs_max(<Evaluator>)282*/284class Evaluator_Lrs_Max : public Evaluator_Unary_Set_List_Operator_Syntax< Evaluator_Lrs_Max >285{286public:287 static Unary_Set_List_Operator_Statement_Maker< Evaluator_Lrs_Max > statement_maker;288 static Unary_Set_List_Operator_Evaluator_Maker< Evaluator_Lrs_Max > evaluator_maker;292 Evaluator_Lrs_Max(int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)2938018 q : Evaluator_Unary_Set_List_Operator_Syntax< Evaluator_Lrs_Max >(line_number_, input_attributes) {}295 virtual std::string process(const std::string& rhs_result) const;296};299class Evaluator_Lrs_Min : public Evaluator_Unary_Set_List_Operator_Syntax< Evaluator_Lrs_Min >300{301public:302 static Unary_Set_List_Operator_Statement_Maker< Evaluator_Lrs_Min > statement_maker;303 static Unary_Set_List_Operator_Evaluator_Maker< Evaluator_Lrs_Min > evaluator_maker;307 Evaluator_Lrs_Min(int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)30827655 q : Evaluator_Unary_Set_List_Operator_Syntax< Evaluator_Lrs_Min >(line_number_, input_attributes) {}310 virtual std::string process(const std::string& rhs_result) const;311};314#endif