Overpass API regression suite coverage (Nova Scotia) / overpass_api/statements/per_member.h
overpass_api/statements/per_member.h
97 of 135 instrumented lines run by the suite (71.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 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__PER_MEMBER_H20#define DE__OSM3S___OVERPASS_API__STATEMENTS__PER_MEMBER_H23#include "../../expat/escape_json.h"24#include "../../expat/escape_xml.h"25#include "../data/tag_store.h"26#include "../data/utils.h"27#include "evaluator.h"28#include "statement.h"30#include <map>31#include <string>32#include <vector>35struct Per_Member_Aggregator : public Evaluator36{38 virtual void add_statement(Statement* statement, std::string text);40 Evaluator* rhs;41};44template< typename Evaluator_ >45struct Per_Member_Aggregator_Syntax : public Per_Member_Aggregator46{49 virtual std::string dump_xml(const std::string& indent) const56 virtual std::string dump_compact_ql(const std::string&) const65};68template< typename Evaluator_ >69struct Per_Member_Aggregator_Maker : Statement::Evaluator_Maker70{71 virtual Statement* create_evaluator(72 const Token_Node_Ptr& tree_it, Statement::QL_Context tree_context,73 Statement::Factory& stmt_factory, Parsed_Query& global_settings, Error_Output* error_output)758017 q if (!tree_it.assert_is_function(error_output) || !tree_it.assert_has_input_set(error_output, false)96 Per_Member_Aggregator_Maker()100};103/* === Per Member Aggregators ===105Aggregators per member help to process information that does apply to only a single member of a way or relation.106Examples of this are the position within the way or relation, geometric properties like the angles, or roles.107A per member aggregator needs an element to operate on and executes its argument multiple times,108passing the possible positions one by one in addition to the element to its argument.110==== Per Member ====112For each element, the aggregator executes its argument once per member of the element.113The return value is a semicolon separated list of the return values.114No deduplication or sotring takes place.115Note that the aggregator returns an empty value for nodes and deriveds116and does not execute its argument in that case.118The syntax is120 per_member(<Evaluator>)121*/123struct Per_Member_Eval_Task : public Eval_Task124{129 virtual std::string eval(const Element_With_Context< Way_Skeleton >& data, const std::string* key) const;130 virtual std::string eval(const Element_With_Context< Attic< Way_Skeleton > >& data, const std::string* key) const;131 virtual std::string eval(const Element_With_Context< Relation_Skeleton >& data, const std::string* key) const;132 virtual std::string eval(const Element_With_Context< Attic< Relation_Skeleton > >& data, const std::string* key) const;134private:135 Owner< Eval_Task > rhs_task;136};139class Evaluator_Per_Member : public Per_Member_Aggregator_Syntax< Evaluator_Per_Member >140{141public:142 struct Statement_Maker : public Generic_Statement_Maker< Evaluator_Per_Member >143 {1442448612 q Statement_Maker() : Generic_Statement_Maker< Evaluator_Per_Member >("eval-per-member") {}145 };146 static Statement_Maker statement_maker;147 static Per_Member_Aggregator_Maker< Evaluator_Per_Member > evaluator_maker;152 Evaluator_Per_Member(int line_number_, const std::map< std::string, std::string >& input_attributes,153 Parsed_Query& global_settings);158 virtual Requested_Context request_context() const1591110 q { return (rhs ? rhs->request_context() : Requested_Context()).add_usage(Set_Usage::SKELETON); }162 virtual Eval_Task* get_string_task(Prepare_Task_Context& context, const std::string* key);163};166/* ==== Per Vertex ====168For each element, the aggregator executes its argument once per (inner) vertex of the element.169Otherwise it behaves similar to the per_member operator.170For closed ways, this means that it is executed once for all vertices but the first member.171For open ways, it is executed once for all vertices but the first and last member.172For relations its behaviour is currently undefined.174The syntax is176 per_vertex(<Evaluator>)177*/179struct Per_Vertex_Eval_Task : public Eval_Task180{185 virtual std::string eval(const Element_With_Context< Way_Skeleton >& data, const std::string* key) const;186 virtual std::string eval(const Element_With_Context< Attic< Way_Skeleton > >& data, const std::string* key) const;188private:189 Owner< Eval_Task > rhs_task;190};193class Evaluator_Per_Vertex : public Per_Member_Aggregator_Syntax< Evaluator_Per_Vertex >194{195public:196 struct Statement_Maker : public Generic_Statement_Maker< Evaluator_Per_Vertex >197 {1982448612 q Statement_Maker() : Generic_Statement_Maker< Evaluator_Per_Vertex >("eval-per-vertex") {}199 };200 static Statement_Maker statement_maker;201 static Per_Member_Aggregator_Maker< Evaluator_Per_Vertex > evaluator_maker;206 Evaluator_Per_Vertex(int line_number_, const std::map< std::string, std::string >& input_attributes,207 Parsed_Query& global_settings);212 virtual Requested_Context request_context() const21398 q { return (rhs ? rhs->request_context() : Requested_Context()).add_usage(Set_Usage::SKELETON); }216 virtual Eval_Task* get_string_task(Prepare_Task_Context& context, const std::string* key);217};220/* === Member Dependend Functions ===222Member dependend functions can only be used when an element plus a position within the element is in context.223They then deliver specific information for that member.225==== Position of the Member ====227The position function returns for a member its one-based position within the element.229The syntax is231 pos()232*/234struct Pos_Eval_Task : public Eval_Task235{238 virtual std::string eval(uint pos, const Element_With_Context< Way_Skeleton >& data, const std::string* key) const240 virtual std::string eval(uint pos, const Element_With_Context< Attic< Way_Skeleton > >& data, const std::string* key) const242 virtual std::string eval(uint pos, const Element_With_Context< Relation_Skeleton >& data, const std::string* key) const244 virtual std::string eval(uint pos, const Element_With_Context< Attic< Relation_Skeleton > >& data, const std::string* key) const246};249class Evaluator_Pos : public Evaluator250{251public:252 struct Statement_Maker : public Generic_Statement_Maker< Evaluator_Pos >253 {255 };256 static Statement_Maker statement_maker;257 static Member_Function_Maker< Evaluator_Pos > evaluator_maker;260 virtual std::string dump_xml(const std::string& indent) const264 Evaluator_Pos(int line_number_, const std::map< std::string, std::string >& input_attributes,265 Parsed_Query& global_settings);27154 q virtual Requested_Context request_context() const { return Requested_Context().add_usage(Set_Usage::SKELETON); }27454 q virtual Eval_Task* get_string_task(Prepare_Task_Context& context, const std::string* key) { return new Pos_Eval_Task(); }275};278/* ==== Reference to the Member ====280The functions mtype and reference return for a member the type resp. id of the referenced object.282The syntax is284 mtype()286resp.288 ref()289*/291struct Membertype_Eval_Task : public Eval_Task292{295 virtual std::string eval(uint pos, const Element_With_Context< Way_Skeleton >& data, const std::string* key) const297 virtual std::string eval(uint pos, const Element_With_Context< Attic< Way_Skeleton > >& data, const std::string* key) const299 virtual std::string eval(uint pos, const Element_With_Context< Relation_Skeleton >& data, const std::string* key) const301 virtual std::string eval(uint pos, const Element_With_Context< Attic< Relation_Skeleton > >& data, const std::string* key) const303};306class Evaluator_Membertype : public Evaluator307{308public:309 struct Statement_Maker : public Generic_Statement_Maker< Evaluator_Membertype >310 {3112448612 q Statement_Maker() : Generic_Statement_Maker< Evaluator_Membertype >("eval-membertype") {}312 };313 static Statement_Maker statement_maker;314 static Member_Function_Maker< Evaluator_Membertype > evaluator_maker;317 virtual std::string dump_xml(const std::string& indent) const321 Evaluator_Membertype(int line_number_, const std::map< std::string, std::string >& input_attributes,322 Parsed_Query& global_settings);32833 q virtual Requested_Context request_context() const { return Requested_Context().add_usage(Set_Usage::SKELETON); }33133 q virtual Eval_Task* get_string_task(Prepare_Task_Context& context, const std::string* key) { return new Membertype_Eval_Task(); }332};335struct Ref_Eval_Task : public Eval_Task336{339 virtual std::string eval(uint pos, const Element_With_Context< Way_Skeleton >& data, const std::string* key) const341 virtual std::string eval(uint pos, const Element_With_Context< Attic< Way_Skeleton > >& data, const std::string* key) const343 virtual std::string eval(uint pos, const Element_With_Context< Relation_Skeleton >& data, const std::string* key) const345 virtual std::string eval(uint pos, const Element_With_Context< Attic< Relation_Skeleton > >& data, const std::string* key) const347};350class Evaluator_Ref : public Evaluator351{352public:353 struct Statement_Maker : public Generic_Statement_Maker< Evaluator_Ref >354 {356 };357 static Statement_Maker statement_maker;358 static Member_Function_Maker< Evaluator_Ref > evaluator_maker;361 virtual std::string dump_xml(const std::string& indent) const365 Evaluator_Ref(int line_number_, const std::map< std::string, std::string >& input_attributes,366 Parsed_Query& global_settings);37233 q virtual Requested_Context request_context() const { return Requested_Context().add_usage(Set_Usage::SKELETON); }37533 q virtual Eval_Task* get_string_task(Prepare_Task_Context& context, const std::string* key) { return new Ref_Eval_Task(); }376};379/* ==== Role of the Member ====381The role function returns the role of the member.383The syntax is385 role()386*/388struct Role_Eval_Task : public Eval_Task389{394 virtual std::string eval(uint pos, const Element_With_Context< Way_Skeleton >& data, const std::string* key) const396 virtual std::string eval(uint pos, const Element_With_Context< Attic< Way_Skeleton > >& data, const std::string* key) const398 virtual std::string eval(uint pos, const Element_With_Context< Relation_Skeleton >& data, const std::string* key) const3993869851 q { return roles ? roles->find(data.object->members[pos].role)->second : std::string(); }400 virtual std::string eval(uint pos, const Element_With_Context< Attic< Relation_Skeleton > >& data, const std::string* key) const403private:404 const std::map< uint32, std::string >* roles;405};408class Evaluator_Role : public Evaluator409{410public:411 struct Statement_Maker : public Generic_Statement_Maker< Evaluator_Role >412 {414 };415 static Statement_Maker statement_maker;416 static Member_Function_Maker< Evaluator_Role > evaluator_maker;419 virtual std::string dump_xml(const std::string& indent) const423 Evaluator_Role(int line_number_, const std::map< std::string, std::string >& input_attributes,424 Parsed_Query& global_settings);430 virtual Requested_Context request_context() const434 virtual Eval_Task* get_string_task(Prepare_Task_Context& context, const std::string* key)436};439/* ==== Angle of a Way at the Position of a Member ====441This function returns the angle between the segment ending at this member and the segment starting there.442It is so far only defined for ways.443If the way is a closed way then for the last member the first segment is used as the starting segment.444This function is intended to be used within the per_vertex() enumerator.446The syntax is448 role()449*/451struct Angle_Eval_Task : public Eval_Task452{457 virtual std::string eval(uint pos, const Element_With_Context< Way_Skeleton >& data, const std::string* key) const;458 virtual std::string eval(uint pos, const Element_With_Context< Attic< Way_Skeleton > >& data, const std::string* key) const;460private:461 mutable Way_Skeleton::Id_Type cache_way_ref;462 mutable const Opaque_Geometry* cache_geom_ref;463 mutable std::vector< Cartesian > cached;465 std::string prettyprinted_angle(uint pos) const;466 void keep_cartesians_up_to_date(Way_Skeleton::Id_Type, const Opaque_Geometry*) const;467};470class Evaluator_Angle : public Evaluator471{472public:473 struct Statement_Maker : public Generic_Statement_Maker< Evaluator_Angle >474 {476 };477 static Statement_Maker statement_maker;478 static Member_Function_Maker< Evaluator_Angle > evaluator_maker;481 virtual std::string dump_xml(const std::string& indent) const485 Evaluator_Angle(int line_number_, const std::map< std::string, std::string >& input_attributes,486 Parsed_Query& global_settings);492 virtual Requested_Context request_context() const496 virtual Eval_Task* get_string_task(Prepare_Task_Context& context, const std::string* key)498};501#endif