Overpass API regression suite coverage (Nova Scotia) / overpass_api/statements/tag_value.cc

overpass_api/statements/tag_value.cc

362 of 520 instrumented lines run by the suite (69.6%) 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#include "../data/tag_store.h"
20#include "../data/utils.h"
21#include "tag_value.h"
24Evaluator_Fixed::Statement_Maker Evaluator_Fixed::statement_maker;
25Evaluator_Fixed::Evaluator_Maker Evaluator_Fixed::evaluator_maker;
28Statement* Evaluator_Fixed::Evaluator_Maker::create_evaluator(
29 const Token_Node_Ptr& tree_it, Statement::QL_Context tree_context,
30 Statement::Factory& stmt_factory, Parsed_Query& global_settings, Error_Output* error_output)
312456160 q{
322456160 q if (tree_it->lhs || tree_it->rhs)
33327 q return 0;
352424156 q int64 value_l = 0;
362424156 q double value_d = 0;
372424156 q if (tree_it->token.empty() ||
382424156 q (tree_it->token[0] != '\'' && tree_it->token[0] != '\"'
392424156 q && !try_int64(tree_it->token, value_l) && !try_double(tree_it->token, value_d)))
4141 q if (error_output)
4241 q error_output->add_parse_error(std::string("Put quotation marks around \"") + tree_it->token
4341 q + "\" if it should be a constant and not a tag evaluation.", tree_it->line_col.first);
4441 q return 0;
472420155 q std::map< std::string, std::string > attributes;
482420155 q attributes["v"] = decode_json(tree_it->token, error_output);
492420155 q return new Evaluator_Fixed(tree_it->line_col.first, attributes, global_settings);
502424156 q}
53Evaluator_Fixed::Evaluator_Fixed
54 (int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)
552420155 q : Evaluator(line_number_)
562420155 q{
572420155 q std::map< std::string, std::string > attributes;
592420155 q attributes["v"] = "";
612420155 q eval_attributes_array(get_name(), attributes, input_attributes);
632420155 q value = attributes["v"];
642420155 q}
67std::string Evaluator_Fixed::dump_compact_ql(const std::string&) const
681210155 q{
691210155 q int64 value_l = 0;
701210155 q if (try_int64(value, value_l))
7119877 q return to_string(value_l);
731012128 q double value_d = 0;
741012128 q if (try_double(value, value_d))
758220 q return to_string(value_d);
77930126 q return std::string("\"") + escape_cstr(value) + "\"";
781012128 q}
81//-----------------------------------------------------------------------------
84Evaluator_Id::Statement_Maker Evaluator_Id::statement_maker;
85Element_Function_Maker< Evaluator_Id > Evaluator_Id::evaluator_maker;
88Evaluator_Id::Evaluator_Id
89 (int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)
9044474 q : Evaluator(line_number_)
9144474 q{
9244474 q std::map< std::string, std::string > attributes;
9344474 q eval_attributes_array(get_name(), attributes, input_attributes);
9444474 q}
97//-----------------------------------------------------------------------------
100Evaluator_Type::Statement_Maker Evaluator_Type::statement_maker;
101Element_Function_Maker< Evaluator_Type > Evaluator_Type::evaluator_maker;
104Evaluator_Type::Evaluator_Type
105 (int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)
10622837 q : Evaluator(line_number_)
10822837 q std::map< std::string, std::string > attributes;
11022837 q eval_attributes_array(get_name(), attributes, input_attributes);
114//-----------------------------------------------------------------------------
117std::string find_value(const std::vector< std::pair< std::string, std::string > >* tags, const std::string& key)
118186849484 q{
119186849484 q if (!tags)
120142309543 q return "";
12244539979 q for (std::vector< std::pair< std::string, std::string > >::const_iterator it = tags->begin();
123205651679 q it != tags->end(); ++it)
124167452579 q {
125167452579 q if (it->first == key)
1266340835 q return it->second;
127167452579 q }
12938199177 q return "";
13044539979 q}
133Evaluator_Value::Statement_Maker Evaluator_Value::statement_maker;
134Evaluator_Value::Evaluator_Maker Evaluator_Value::evaluator_maker;
137Statement* Evaluator_Value::Evaluator_Maker::create_evaluator(
138 const Token_Node_Ptr& tree_it, Statement::QL_Context tree_context,
139 Statement::Factory& stmt_factory, Parsed_Query& global_settings, Error_Output* error_output)
14198499 q if (!assert_element_in_context(error_output, tree_it, tree_context))
1420 return 0;
14498499 q if (!tree_it->lhs || tree_it.lhs()->lhs || tree_it.lhs()->rhs || tree_it.lhs()->token != "t")
1450 {
1460 if (error_output)
1470 error_output->add_parse_error("Tag evaulation needs function name \"t\" before the left bracket",
1480 tree_it->line_col.first);
1490 return 0;
1500 }
15198499 q if (!tree_it->rhs)
1520 {
1530 if (error_output)
1540 error_output->add_parse_error("Operator \"[\" needs a tag key as argument", tree_it->line_col.first);
1550 return 0;
1560 }
15898499 q std::map< std::string, std::string > attributes;
15998499 q Statement* result = new Evaluator_Value(tree_it->line_col.first, attributes, global_settings);
16098499 q if (result)
16198499 q {
16298499 q Statement* rhs = stmt_factory.create_evaluator(
16398499 q tree_it.rhs(), tree_context, Statement::Single_Return_Type_Checker(Statement::string));
16498499 q if (rhs)
16598499 q result->add_statement(rhs, "");
1660 else if (error_output)
1670 error_output->add_parse_error("t[...] needs an argument",
1680 tree_it->line_col.first);
16998499 q }
17098499 q return result;
174Evaluator_Value::Evaluator_Value
175 (int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)
17698499 q : Evaluator(line_number_), rhs(0)
17898499 q std::map< std::string, std::string > attributes;
17998499 q eval_attributes_array(get_name(), attributes, input_attributes);
183void Evaluator_Value::add_statement(Statement* statement, std::string text)
18598499 q Evaluator* tag_value_ = dynamic_cast< Evaluator* >(statement);
18698499 q if (!tag_value_)
1870 substatement_error(get_name(), statement);
18898499 q else if (!rhs)
18998499 q rhs = tag_value_;
1900 else
1910 add_static_error(get_name() + " must have exactly one evaluator substatement.");
195Requested_Context Evaluator_Value::request_context() const
19725795 q if (rhs)
19825795 q return rhs->request_context().add_usage(Set_Usage::TAGS);
1990 return Requested_Context().add_usage(Set_Usage::TAGS);
203Eval_Task* Evaluator_Value::get_string_task(Prepare_Task_Context& context, const std::string* key)
20525795 q Eval_Task* rhs_task = rhs ? rhs->get_string_task(context, key) : 0;
20625795 q return new Value_Eval_Task(rhs_task);
210std::string Value_Eval_Task::eval(const std::string* key) const
2110{
2120 return "";
2130}
216std::string Value_Eval_Task::eval(const Element_With_Context< Node_Skeleton >& data, const std::string* key) const
217146487631 q{
218146487631 q return find_value(data.tags, rhs ? rhs->eval(data, key) : "");
219146487631 q}
222std::string Value_Eval_Task::eval(const Element_With_Context< Attic< Node_Skeleton > >& data, const std::string* key) const
22345539 q{
22445539 q return find_value(data.tags, rhs ? rhs->eval(data, key) : "");
22545539 q}
228std::string Value_Eval_Task::eval(const Element_With_Context< Way_Skeleton >& data, const std::string* key) const
22917234243 q{
23017234243 q return find_value(data.tags, rhs ? rhs->eval(data, key) : "");
23117234243 q}
234std::string Value_Eval_Task::eval(const Element_With_Context< Attic< Way_Skeleton > >& data, const std::string* key) const
2358636 q{
2368636 q return find_value(data.tags, rhs ? rhs->eval(data, key) : "");
2378636 q}
240std::string Value_Eval_Task::eval(const Element_With_Context< Relation_Skeleton >& data, const std::string* key) const
24112095427 q{
24212095427 q return find_value(data.tags, rhs ? rhs->eval(data, key) : "");
24312095427 q}
246std::string Value_Eval_Task::eval(const Element_With_Context< Attic< Relation_Skeleton > >& data, const std::string* key) const
24764525 q{
24864525 q return find_value(data.tags, rhs ? rhs->eval(data, key) : "");
24964525 q}
252std::string Value_Eval_Task::eval(const Element_With_Context< Area_Skeleton >& data, const std::string* key) const
254414 q return find_value(data.tags, rhs ? rhs->eval(data, key) : "");
258std::string Value_Eval_Task::eval(const Element_With_Context< Derived_Skeleton >& data, const std::string* key) const
2593914610 q{
2603914610 q return find_value(data.tags, rhs ? rhs->eval(data, key) : "");
2613914610 q}
264//-----------------------------------------------------------------------------
267std::string exists_value(const std::vector< std::pair< std::string, std::string > >* tags, const std::string& key)
26821112413 q{
26921112413 q if (!tags)
2701229649 q return "0";
2728816013 q for (std::vector< std::pair< std::string, std::string > >::const_iterator it = tags->begin();
27351461213 q it != tags->end(); ++it)
27443219013 q {
27543219013 q if (it->first == key)
27657384 q return "1";
27743219013 q }
2798242213 q return "0";
2808816013 q}
283Evaluator_Is_Tag::Statement_Maker Evaluator_Is_Tag::statement_maker;
284Evaluator_Is_Tag::Evaluator_Maker Evaluator_Is_Tag::evaluator_maker;
287Statement* Evaluator_Is_Tag::Evaluator_Maker::create_evaluator(
288 const Token_Node_Ptr& tree_it, Statement::QL_Context tree_context,
289 Statement::Factory& stmt_factory, Parsed_Query& global_settings, Error_Output* error_output)
2919221 q if (!tree_it.assert_is_function(error_output) || !tree_it.assert_has_input_set(error_output, false)
2929221 q || !tree_it.assert_has_arguments(error_output, true)
2939221 q || !assert_element_in_context(error_output, tree_it, tree_context))
29441 q return 0;
2968820 q if (tree_it.rhs()->lhs || tree_it.rhs()->rhs)
2970 {
2980 if (error_output)
2990 error_output->add_parse_error("is_tag(key) needs a simple string as argument", tree_it->line_col.first);
3000 return 0;
3010 }
3028820 q std::map< std::string, std::string > attributes;
3038820 q attributes["k"] = decode_json(tree_it.rhs()->token, error_output);
3048820 q return new Evaluator_Is_Tag(tree_it->line_col.first, attributes, global_settings);
308Evaluator_Is_Tag::Evaluator_Is_Tag
309 (int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)
3108820 q : Evaluator(line_number_)
3128820 q std::map< std::string, std::string > attributes;
3148820 q attributes["k"] = "";
3168820 q eval_attributes_array(get_name(), attributes, input_attributes);
3188820 q key = attributes["k"];
322//-----------------------------------------------------------------------------
325Evaluator_All_Keys::Statement_Maker Evaluator_All_Keys::statement_maker;
326Element_Function_Maker< Evaluator_All_Keys > Evaluator_All_Keys::evaluator_maker;
329std::vector< std::string > all_keys(const std::vector< std::pair< std::string, std::string > >* tags)
33082035 q{
33182035 q std::vector< std::string > result;
33282035 q if (!tags)
33329562 q return result;
33552475 q for (std::vector< std::pair< std::string, std::string > >::const_iterator it = tags->begin();
336314285 q it != tags->end(); ++it)
337261815 q result.push_back(it->first);
33952475 q std::sort(result.begin(), result.end());
34052475 q result.erase(std::unique(result.begin(), result.end()), result.end());
34252475 q return result;
34382035 q}
346Evaluator_All_Keys::Evaluator_All_Keys
347 (int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)
348246 q : Evaluator(line_number_)
350246 q std::map< std::string, std::string > attributes;
351246 q eval_attributes_array(get_name(), attributes, input_attributes);
355//-----------------------------------------------------------------------------
358Evaluator_Version::Statement_Maker Evaluator_Version::statement_maker;
359Element_Function_Maker< Evaluator_Version > Evaluator_Version::evaluator_maker;
362Evaluator_Version::Evaluator_Version
363 (int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)
3648821 q : Evaluator(line_number_)
3668821 q std::map< std::string, std::string > attributes;
3678821 q eval_attributes_array(get_name(), attributes, input_attributes);
371Evaluator_Timestamp::Statement_Maker Evaluator_Timestamp::statement_maker;
372Element_Function_Maker< Evaluator_Timestamp > Evaluator_Timestamp::evaluator_maker;
375Evaluator_Timestamp::Evaluator_Timestamp
376 (int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)
37727250 q : Evaluator(line_number_)
37927250 q std::map< std::string, std::string > attributes;
38027250 q eval_attributes_array(get_name(), attributes, input_attributes);
384Evaluator_Changeset::Statement_Maker Evaluator_Changeset::statement_maker;
385Element_Function_Maker< Evaluator_Changeset > Evaluator_Changeset::evaluator_maker;
388Evaluator_Changeset::Evaluator_Changeset
389 (int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)
3907217 q : Evaluator(line_number_)
3927217 q std::map< std::string, std::string > attributes;
3937217 q eval_attributes_array(get_name(), attributes, input_attributes);
397Evaluator_Uid::Statement_Maker Evaluator_Uid::statement_maker;
398Element_Function_Maker< Evaluator_Uid > Evaluator_Uid::evaluator_maker;
401Evaluator_Uid::Evaluator_Uid
402 (int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)
40310023 q : Evaluator(line_number_)
40510023 q std::map< std::string, std::string > attributes;
40610023 q eval_attributes_array(get_name(), attributes, input_attributes);
410Evaluator_User::Statement_Maker Evaluator_User::statement_maker;
411Element_Function_Maker< Evaluator_User > Evaluator_User::evaluator_maker;
414Evaluator_User::Evaluator_User
415 (int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)
41621243 q : Evaluator(line_number_)
41821243 q std::map< std::string, std::string > attributes;
41921243 q eval_attributes_array(get_name(), attributes, input_attributes);
423//-----------------------------------------------------------------------------
426Evaluator_Generic::Statement_Maker Evaluator_Generic::statement_maker;
427Evaluator_Generic::Evaluator_Maker Evaluator_Generic::evaluator_maker;
430Statement* Evaluator_Generic::Evaluator_Maker::create_evaluator(
431 const Token_Node_Ptr& tree_it, Statement::QL_Context tree_context,
432 Statement::Factory& stmt_factory, Parsed_Query& global_settings, Error_Output* error_output)
4347619 q if (tree_it->lhs || tree_it->rhs)
4350 return 0;
4367619 q std::map< std::string, std::string > attributes;
4377619 q return new Evaluator_Generic(tree_it->line_col.first, attributes, global_settings);
441Evaluator_Generic::Evaluator_Generic
442 (int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)
4437619 q : Evaluator(line_number_)
4457619 q std::map< std::string, std::string > attributes;
4477619 q eval_attributes_array(get_name(), attributes, input_attributes);
451//-----------------------------------------------------------------------------
454Evaluator_Properties_Count::Statement_Maker Evaluator_Properties_Count::statement_maker;
455Evaluator_Properties_Count::Evaluator_Maker Evaluator_Properties_Count::evaluator_maker;
458Statement* Evaluator_Properties_Count::Evaluator_Maker::create_evaluator(
459 const Token_Node_Ptr& tree_it, Statement::QL_Context tree_context,
460 Statement::Factory& stmt_factory, Parsed_Query& global_settings, Error_Output* error_output)
46235672 q if (!tree_it.assert_is_function(error_output) || !tree_it.assert_has_input_set(error_output, false)
46335672 q || !assert_element_in_context(error_output, tree_it, tree_context))
4640 return 0;
46635672 q std::map< std::string, std::string > attributes;
46835672 q const std::string* func_name = tree_it.function_name();
46935672 q attributes["type"] = func_name->size() > 6 ? func_name->substr(6) : "";
47135672 q if (*func_name == "count_by_role" || *func_name == "count_distinct_by_role")
47213630 q {
47313630 q if (tree_it->rhs)
47413630 q {
47513630 q if (tree_it.rhs()->token == "," && tree_it.rhs()->lhs && tree_it.rhs()->rhs)
4760 {
4770 if (!tree_it.rhs().lhs()->lhs && !tree_it.rhs().lhs()->rhs)
4780 attributes["role"] = decode_json(tree_it.rhs().lhs()->token, error_output);
4790 else
4800 {
4810 if (error_output)
4820 error_output->add_parse_error(tree_it.lhs()->token
4830 + "() needs a single literal expression as argument for the wanted role", tree_it->line_col.first);
4840 return 0;
4850 }
4870 if (tree_it.rhs().rhs()->lhs || tree_it.rhs().rhs()->rhs
4880 || (tree_it.rhs().rhs()->token != "nodes" && tree_it.rhs().rhs()->token != "ways"
4890 && tree_it.rhs().rhs()->token != "relations" && tree_it.rhs().rhs()->token != "rels"))
4900 {
4910 if (error_output)
4920 error_output->add_parse_error(tree_it.lhs()->token
4930 + "(...) can only have one of the words nodes, ways, or relations as second argument",
4940 tree_it->line_col.first);
4950 return 0;
4960 }
4970 else
4980 attributes["members_type"] = tree_it.rhs().rhs()->token;
4990 }
50013630 q else if (!tree_it.rhs()->lhs && !tree_it.rhs()->rhs)
50113630 q attributes["role"] = decode_json(tree_it.rhs()->token, error_output);
5020 else
5030 {
5040 if (error_output)
5050 error_output->add_parse_error(tree_it.lhs()->token
5060 + "() needs a single literal expression as argument for the wanted role", tree_it->line_col.first);
5070 return 0;
5080 }
50913630 q }
5100 else
5110 {
5120 if (error_output)
5130 error_output->add_parse_error(tree_it.lhs()->token
5140 + "() must have the name of the wanted role as argument", tree_it->line_col.first);
5150 return 0;
5160 }
51713630 q }
51822050 q else if (*func_name == "count_members" || *func_name == "count_distinct_members")
5207618 q if (tree_it->rhs)
5210 {
5220 if (tree_it.rhs()->lhs || tree_it.rhs()->rhs
5230 || (tree_it.rhs()->token != "nodes" && tree_it.rhs()->token != "ways"
5240 && tree_it.rhs()->token != "relations" && tree_it.rhs()->token != "rels"))
5250 {
5260 if (error_output)
5270 error_output->add_parse_error(tree_it.lhs()->token
5280 + "(...) can only have one of the words nodes, ways, or relations as an argument",
5290 tree_it->line_col.first);
5300 return 0;
5310 }
5320 else
5330 attributes["members_type"] = tree_it.rhs()->token;
5340 }
53614434 q else
53714434 q {
53814434 q if (!tree_it.assert_has_arguments(error_output, false))
53941 q return 0;
54014434 q }
54235271 q return new Evaluator_Properties_Count(tree_it->line_col.first, attributes, global_settings);
546std::string Evaluator_Properties_Count::to_string(Evaluator_Properties_Count::Objects objects)
54826471 q if (objects == tags)
54910533 q return "tags";
55015943 q if (objects == members)
5514213 q return "members";
55211734 q if (objects == distinct_members)
553155 q return "distinct_members";
55410230 q if (objects == by_role)
5554214 q return "by_role";
5566017 q if (objects == distinct_by_role)
5576017 q return "distinct_by_role";
5590 return "nothing";
563std::string Evaluator_Properties_Count::to_string(Evaluator_Properties_Count::Members_Type type_to_count)
5640{
5650 if (type_to_count == nodes)
5660 return "nodes";
5670 if (type_to_count == ways)
5680 return "ways";
5690 if (type_to_count == relations)
5700 return "relations";
5720 return "all";
5730}
576Evaluator_Properties_Count::Evaluator_Properties_Count
577 (int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)
57835271 q : Evaluator(line_number_), to_count(nothing), type_to_count(all)
58035271 q std::map< std::string, std::string > attributes;
58235271 q attributes["type"] = "";
58335271 q attributes["role"] = "";
58435271 q attributes["members_type"] = "all";
58635271 q eval_attributes_array(get_name(), attributes, input_attributes);
58835271 q if (attributes["type"] == "tags")
58914033 q to_count = tags;
59021243 q else if (attributes["type"] == "members")
5915613 q to_count = members;
59215634 q else if (attributes["type"] == "distinct_members")
593205 q to_count = distinct_members;
59413630 q else if (attributes["type"] == "by_role")
5955614 q to_count = by_role;
5968017 q else if (attributes["type"] == "distinct_by_role")
5978017 q to_count = distinct_by_role;
5980 else
5990 {
6000 add_static_error("For the attribute \"type\" of the element \"eval-prop-count\""
6010 " the only allowed values are \"tags\", \"members\", \"distinct_members\","
6020 " \"by_role\", or \"distinct_by_role\" strings.");
6030 }
60535271 q if (attributes["members_type"] == "all")
60635271 q type_to_count = all;
6070 else if (attributes["members_type"] == "nodes")
6080 type_to_count = nodes;
6090 else if (attributes["members_type"] == "ways")
6100 type_to_count = ways;
6110 else if (attributes["members_type"] == "relations" || attributes["members_type"] == "rels")
6120 type_to_count = relations;
6130 else
6140 {
6150 add_static_error("For the attribute \"members_type\" of the element \"eval-prop-count\""
6160 " the only allowed values are \"all\", \"nodes\", \"ways\", or \"relations\" strings.");
6170 }
61935271 q role = attributes["role"];
623Requested_Context Evaluator_Properties_Count::request_context() const
6259969 q if (to_count == Evaluator_Properties_Count::tags)
6264431 q return Requested_Context().add_usage(Set_Usage::TAGS);
6275543 q else if (to_count == Evaluator_Properties_Count::members || to_count == Evaluator_Properties_Count::distinct_members)
6282018 q return Requested_Context().add_usage(Set_Usage::SKELETON);
6293530 q else if (to_count == Evaluator_Properties_Count::by_role || to_count == Evaluator_Properties_Count::distinct_by_role)
6303530 q return Requested_Context().add_usage(Set_Usage::SKELETON).add_role_names();
6320 return Requested_Context();
636Eval_Task* Evaluator_Properties_Count::get_string_task(Prepare_Task_Context& context, const std::string* key)
6389969 q if (to_count == Evaluator_Properties_Count::by_role || to_count == Evaluator_Properties_Count::distinct_by_role)
6393530 q return new Prop_Count_Eval_Task(to_count, type_to_count, context.get_role_id(role));
6416447 q return new Prop_Count_Eval_Task(to_count, type_to_count);
645std::string Prop_Count_Eval_Task::eval(const Element_With_Context< Node_Skeleton >& data, const std::string* key) const
64611257024 q{
64711257024 q if (to_count == Evaluator_Properties_Count::tags && data.tags)
648107411 q return to_string(data.tags->size());
64911149621 q return "0";
65011257024 q}
653std::string Prop_Count_Eval_Task::eval(const Element_With_Context< Attic< Node_Skeleton > >& data,
654 const std::string* key) const
65581317 q{
65681317 q if (to_count == Evaluator_Properties_Count::tags && data.tags)
657264 q return to_string(data.tags->size());
65881055 q return "0";
65981317 q}
662std::string Prop_Count_Eval_Task::eval(const Element_With_Context< Way_Skeleton >& data,
663 const std::string* key) const
66410979333 q{
66510979333 q if (to_count == Evaluator_Properties_Count::members
66610979333 q && type_to_count == Evaluator_Properties_Count::all && data.object)
667188995 q return to_string(data.object->nds.size());
6689089430 q else if (to_count == Evaluator_Properties_Count::distinct_members
6699089430 q && type_to_count == Evaluator_Properties_Count::all && data.object)
6706883 q {
6716883 q std::vector< Node::Id_Type > distinct = data.object->nds;
6726883 q std::sort(distinct.begin(), distinct.end());
6736883 q return to_string(std::distance(distinct.begin(), std::unique(distinct.begin(), distinct.end())));
6746883 q }
6759020629 q else if (to_count == Evaluator_Properties_Count::tags && data.tags)
676467117 q return to_string(data.tags->size());
6778553520 q return "0";
67810979333 q}
681std::string Prop_Count_Eval_Task::eval(const Element_With_Context< Attic< Way_Skeleton > >& data,
682 const std::string* key) const
6831137 q{
6841137 q if (to_count == Evaluator_Properties_Count::members
6851137 q && type_to_count == Evaluator_Properties_Count::all && data.object)
6860 return to_string(data.object->nds.size());
6871137 q else if (to_count == Evaluator_Properties_Count::distinct_members
6881137 q && type_to_count == Evaluator_Properties_Count::all && data.object)
6890 {
6900 std::vector< Node::Id_Type > distinct = data.object->nds;
6910 std::sort(distinct.begin(), distinct.end());
6920 return to_string(std::distance(distinct.begin(), std::unique(distinct.begin(), distinct.end())));
6930 }
6941137 q else if (to_count == Evaluator_Properties_Count::tags && data.tags)
695366 q return to_string(data.tags->size());
696774 q return "0";
6971137 q}
700bool matches_criterion(const Relation_Entry& member, Evaluator_Properties_Count::Objects to_count,
701 Evaluator_Properties_Count::Members_Type type_to_count, uint32 role_id)
7021302168 q{
7031302168 q if (type_to_count != Evaluator_Properties_Count::all)
7040 {
7050 if (type_to_count == Evaluator_Properties_Count::nodes && member.type != Relation_Entry::NODE)
7060 return false;
7070 if (type_to_count == Evaluator_Properties_Count::ways && member.type != Relation_Entry::WAY)
7080 return false;
7090 if (type_to_count == Evaluator_Properties_Count::relations && member.type != Relation_Entry::RELATION)
7100 return false;
7110 }
7131302168 q if (member.role != role_id &&
7141302168 q (to_count == Evaluator_Properties_Count::by_role || to_count == Evaluator_Properties_Count::distinct_by_role))
7151301978 q return false;
717192 q return true;
7181302168 q}
721struct Relation_Member_Comparer
723 bool operator()(const Relation_Entry& lhs, const Relation_Entry& rhs) const
72428403 q {
72528403 q if (lhs.type != rhs.type)
7260 return lhs.type < rhs.type;
72828403 q return lhs.ref < rhs.ref;
72928403 q }
730};
733std::string Prop_Count_Eval_Task::eval(const Element_With_Context< Relation_Skeleton >& data,
734 const std::string* key) const
7353216417 q{
7363216417 q if (to_count == Evaluator_Properties_Count::members || to_count == Evaluator_Properties_Count::by_role)
737786 q {
738786 q if (!data.object)
7390 return "0";
741786 q if (to_count == Evaluator_Properties_Count::members && type_to_count == Evaluator_Properties_Count::all)
742411 q return to_string(data.object->members.size());
744375 q uint counter = 0;
74542845 q for (std::vector< Relation_Entry >::const_iterator it = data.object->members.begin(); it != data.object->members.end(); ++it)
74642475 q {
74742475 q if (matches_criterion(*it, to_count, type_to_count, role_id))
7480 ++counter;
74942475 q }
750375 q return to_string(counter);
751786 q }
7523208613 q else if (to_count == Evaluator_Properties_Count::distinct_members
7533208613 q || to_count == Evaluator_Properties_Count::distinct_by_role)
75499495 q {
75599495 q if (!data.object)
7560 return "0";
75899495 q std::vector< Relation_Entry > distinct = data.object->members;
76099495 q if (to_count != Evaluator_Properties_Count::distinct_members || type_to_count != Evaluator_Properties_Count::all)
76197264 q {
76297264 q std::vector< Relation_Entry >::size_type from = 0;
76397264 q std::vector< Relation_Entry >::size_type to = 0;
7641356954 q for (; from < distinct.size(); ++from)
7651259694 q {
7661259694 q if (matches_criterion(distinct[from], to_count, type_to_count, role_id))
767192 q distinct[to++] = distinct[from];
7681259694 q }
76997264 q distinct.resize(to);
77097264 q }
77299495 q std::sort(distinct.begin(), distinct.end(), Relation_Member_Comparer());
77399495 q return to_string(std::distance(distinct.begin(), std::unique(distinct.begin(), distinct.end())));
77499495 q }
775221378 q else if (to_count == Evaluator_Properties_Count::tags && data.tags)
776221368 q return to_string(data.tags->size());
77711 q return "0";
7783216417 q}
781std::string Prop_Count_Eval_Task::eval(const Element_With_Context< Attic< Relation_Skeleton > >& data,
782 const std::string* key) const
784382 q if (to_count == Evaluator_Properties_Count::members || to_count == Evaluator_Properties_Count::by_role)
7850 {
7860 if (!data.object)
7870 return "0";
7890 if (to_count == Evaluator_Properties_Count::members && type_to_count == Evaluator_Properties_Count::all)
7900 return to_string(data.object->members.size());
7920 uint counter = 0;
7930 for (std::vector< Relation_Entry >::const_iterator it = data.object->members.begin(); it != data.object->members.end(); ++it)
7940 {
7950 if (matches_criterion(*it, to_count, type_to_count, role_id))
7960 ++counter;
7970 }
7980 return to_string(counter);
7990 }
800382 q else if (to_count == Evaluator_Properties_Count::distinct_members
801382 q || to_count == Evaluator_Properties_Count::distinct_by_role)
8020 {
8030 if (!data.object)
8040 return "0";
8060 std::vector< Relation_Entry > distinct = data.object->members;
8080 if (to_count != Evaluator_Properties_Count::distinct_members || type_to_count != Evaluator_Properties_Count::all)
8090 {
8100 std::vector< Relation_Entry >::size_type from = 0;
8110 std::vector< Relation_Entry >::size_type to = 0;
8120 for (; from < distinct.size(); ++from)
8130 {
8140 if (matches_criterion(distinct[from], to_count, type_to_count, role_id))
8150 distinct[to++] = distinct[from];
8160 }
8170 distinct.resize(to);
8180 }
8200 std::sort(distinct.begin(), distinct.end(), Relation_Member_Comparer());
8210 return to_string(std::distance(distinct.begin(), std::unique(distinct.begin(), distinct.end())));
8220 }
823382 q else if (to_count == Evaluator_Properties_Count::tags && data.tags)
824382 q return to_string(data.tags->size());
8250 return "0";
829std::string Prop_Count_Eval_Task::eval(const Element_With_Context< Area_Skeleton >& data, const std::string* key) const
831103 q if (to_count == Evaluator_Properties_Count::tags && data.tags)
83272 q return to_string(data.tags->size());
83331 q return "0";
837std::string Prop_Count_Eval_Task::eval(const Element_With_Context< Derived_Skeleton >& data, const std::string* key) const
839177 q if (to_count == Evaluator_Properties_Count::tags && data.tags)
840104 q return to_string(data.tags->size());
84175 q return "0";