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

overpass_api/statements/geometry_endomorphisms.h

40 of 45 instrumented lines run by the suite (88.9%) 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__GEOMETRY_ENDOMORPHISMS_H
20#define DE__OSM3S___OVERPASS_API__STATEMENTS__GEOMETRY_ENDOMORPHISMS_H
23#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>
33/* === Geometry Endomorphisms ===
35Geometry endomorphisms are functions with one argument.
36Many of them help to normalize or check the value of its argument.
37They always first let their argument be evaluated.
38Their syntax is always
40 <Function Name>(<Evaluator>)
41*/
43template< typename Evaluator_ >
44struct Geometry_Endom_Statement_Maker : public Generic_Statement_Maker< Evaluator_ >
468304692 q Geometry_Endom_Statement_Maker() : Generic_Statement_Maker< Evaluator_ >(Evaluator_::stmt_name()) {}
47};
50template< typename Evaluator_ >
51struct Geometry_Endom_Evaluator_Maker : public Statement::Evaluator_Maker
53 virtual Statement* create_evaluator(const Token_Node_Ptr& tree_it, Statement::QL_Context tree_context,
54 Statement::Factory& stmt_factory, Parsed_Query& global_settings, Error_Output* error_output)
5520433 q {
5620433 q if (!tree_it.assert_is_function(error_output) || !tree_it.assert_has_input_set(error_output, false)
5720433 q || !tree_it.assert_has_arguments(error_output, true))
580 return 0;
6020433 q std::map< std::string, std::string > attributes;
6120433 q Statement* result = new Evaluator_(tree_it->line_col.first, attributes, global_settings);
6220433 q if (result)
6320433 q {
6420433 q Statement* rhs = stmt_factory.create_evaluator(
6520433 q tree_it.rhs(), tree_context, Statement::Single_Return_Type_Checker(Statement::geometry));
6620433 q if (rhs)
6720433 q result->add_statement(rhs, "");
680 else if (error_output)
690 error_output->add_parse_error(Evaluator_::stmt_func_name() + "(...) needs an argument",
700 tree_it->line_col.first);
7120433 q }
7220433 q return result;
7320433 q }
75 Geometry_Endom_Evaluator_Maker()
768304692 q {
778304692 q Statement::maker_by_func_name()[Evaluator_::stmt_func_name()].push_back(this);
788304692 q }
79};
82template< typename Evaluator_ >
83struct Evaluator_Geometry_Endom_Syntax : public Evaluator_Geometry_Unary_Function
85 Evaluator_Geometry_Endom_Syntax(int line_number_, const std::map< std::string, std::string >& input_attributes)
8620433 q : Evaluator_Geometry_Unary_Function(line_number_)
8720433 q {
8820433 q std::map< std::string, std::string > attributes;
8920433 q eval_attributes_array(Evaluator_::stmt_name(), attributes, input_attributes);
9020433 q }
92 virtual std::string dump_xml(const std::string& indent) const
935133 q {
945133 q return indent + "<" + Evaluator_::stmt_name() + ">\n"
955133 q + (rhs ? rhs->dump_xml(indent + " ") : "")
965133 q + indent + "</" + Evaluator_::stmt_name() + ">\n";
975133 q }
99 virtual std::string dump_compact_ql(const std::string&) const
10010233 q {
10110233 q return Evaluator_::stmt_func_name() + "(" + (rhs ? rhs->dump_compact_ql("") : "") + ")";
10210233 q }
1040 virtual std::string get_name() const { return Evaluator_::stmt_name(); }
105};
108/* ==== Center ====
110The function <em>center</em> returns the center of its argument.
111It expects a function that evaluates to a geometry.
112It then delivers the point that is at the center of the bounding box of the geometry.
114Its syntax is
116 center(<Evaluator>)
118*/
120class Evaluator_Center : public Evaluator_Geometry_Endom_Syntax< Evaluator_Center >
122public:
123 static Geometry_Endom_Statement_Maker< Evaluator_Center > statement_maker;
124 static Geometry_Endom_Evaluator_Maker< Evaluator_Center > evaluator_maker;
1252830692 q static std::string stmt_func_name() { return "center"; }
1262954692 q static std::string stmt_name() { return "eval-center"; }
128 Evaluator_Center(int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)
12912421 q : Evaluator_Geometry_Endom_Syntax< Evaluator_Center >(line_number_, input_attributes) {}
131 virtual Opaque_Geometry* process(Opaque_Geometry* geom) const;
132};
135/* ==== Trace ====
137The function <em>trace</em> returns the trace of its argument.
138It expects a function that evaluates to a geometry.
139It then delivers a collection of all segments and nodes that appear in its input.
140Ways are split at points that are explicitly in the set
141and at points that belong to more than one way in the set.
142Every node and segment is contained at most once.
144Its syntax is
146 trace(<Evaluator>)
148*/
150class Evaluator_Trace : public Evaluator_Geometry_Endom_Syntax< Evaluator_Trace >
152public:
153 static Geometry_Endom_Statement_Maker< Evaluator_Trace > statement_maker;
154 static Geometry_Endom_Evaluator_Maker< Evaluator_Trace > evaluator_maker;
1552788692 q static std::string stmt_func_name() { return "trace"; }
1562828692 q static std::string stmt_name() { return "eval-trace"; }
158 Evaluator_Trace(int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)
1594010 q : Evaluator_Geometry_Endom_Syntax< Evaluator_Trace >(line_number_, input_attributes) {}
161 virtual Opaque_Geometry* process(Opaque_Geometry* geom) const;
162};
165/* ==== Hull ====
167The function <em>hull</em> returns the convex hull of its argument.
168It expects a function that evaluates to a geometry
169It then delivers a polygon without holes that contains all of its arguments.
171Its syntax is
173 hull(<Evaluator>)
175*/
177class Evaluator_Hull : public Evaluator_Geometry_Endom_Syntax< Evaluator_Hull >
179public:
180 static Geometry_Endom_Statement_Maker< Evaluator_Hull > statement_maker;
181 static Geometry_Endom_Evaluator_Maker< Evaluator_Hull > evaluator_maker;
1822788692 q static std::string stmt_func_name() { return "hull"; }
1832828692 q static std::string stmt_name() { return "eval-hull"; }
185 Evaluator_Hull(int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)
1864010 q : Evaluator_Geometry_Endom_Syntax< Evaluator_Hull >(line_number_, input_attributes) {}
188 virtual Opaque_Geometry* process(Opaque_Geometry* geom) const;
189};
192#endif