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

overpass_api/statements/tag_value.cc

369 of 520 instrumented lines run by the suite (71.0%) 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)
312536173 q{
322536173 q if (tree_it->lhs || tree_it->rhs)
33286 q return 0;
352508169 q int64 value_l = 0;
362508169 q double value_d = 0;
372508169 q if (tree_it->token.empty() ||
382508169 q (tree_it->token[0] != '\'' && tree_it->token[0] != '\"'
392508169 q && !try_int64(tree_it->token, value_l) && !try_double(tree_it->token, value_d)))
4182 q if (error_output)
4282 q error_output->add_parse_error(std::string("Put quotation marks around \"") + tree_it->token
4382 q + "\" if it should be a constant and not a tag evaluation.", tree_it->line_col.first);
4482 q return 0;
472500167 q std::map< std::string, std::string > attributes;
482500167 q attributes["v"] = decode_json(tree_it->token, error_output);
492500167 q return new Evaluator_Fixed(tree_it->line_col.first, attributes, global_settings);
502508169 q}
53Evaluator_Fixed::Evaluator_Fixed
54 (int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)
552500167 q : Evaluator(line_number_)
562500167 q{
572500167 q std::map< std::string, std::string > attributes;
592500167 q attributes["v"] = "";
612500167 q eval_attributes_array(get_name(), attributes, input_attributes);
632500167 q value = attributes["v"];
642500167 q}
67std::string Evaluator_Fixed::dump_compact_ql(const std::string&) const
681250167 q{
691250167 q int64 value_l = 0;
701250167 q if (try_int64(value, value_l))
7122685 q return to_string(value_l);
731024138 q double value_d = 0;
741024138 q if (try_double(value, value_d))
7510021 q return to_string(value_d);
77924134 q return std::string("\"") + escape_cstr(value) + "\"";
781024138 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)
9051288 q : Evaluator(line_number_)
9151288 q{
9251288 q std::map< std::string, std::string > attributes;
9351288 q eval_attributes_array(get_name(), attributes, input_attributes);
9451288 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)
10626045 q : Evaluator(line_number_)
10826045 q std::map< std::string, std::string > attributes;
11026045 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)
118366997988 q{
119366997988 q if (!tags)
120145578835 q return "";
122221419183 q for (std::vector< std::pair< std::string, std::string > >::const_iterator it = tags->begin();
1231043480083 q it != tags->end(); ++it)
124868687583 q {
125868687583 q if (it->first == key)
12646626648 q return it->second;
127868687583 q }
129174792579 q return "";
130221419183 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)
1411032103 q if (!assert_element_in_context(error_output, tree_it, tree_context))
1420 return 0;
1441032103 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 }
1511032103 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 }
1581032103 q std::map< std::string, std::string > attributes;
1591032103 q Statement* result = new Evaluator_Value(tree_it->line_col.first, attributes, global_settings);
1601032103 q if (result)
1611032103 q {
1621032103 q Statement* rhs = stmt_factory.create_evaluator(
1631032103 q tree_it.rhs(), tree_context, Statement::Single_Return_Type_Checker(Statement::string));
1641032103 q if (rhs)
1651032103 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);
1691032103 q }
1701032103 q return result;
174Evaluator_Value::Evaluator_Value
175 (int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)
1761032103 q : Evaluator(line_number_), rhs(0)
1781032103 q std::map< std::string, std::string > attributes;
1791032103 q eval_attributes_array(get_name(), attributes, input_attributes);
183void Evaluator_Value::add_statement(Statement* statement, std::string text)
1851032103 q Evaluator* tag_value_ = dynamic_cast< Evaluator* >(statement);
1861032103 q if (!tag_value_)
1870 substatement_error(get_name(), statement);
1881032103 q else if (!rhs)
1891032103 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
197265101 q if (rhs)
198265101 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)
205265101 q Eval_Task* rhs_task = rhs ? rhs->get_string_task(context, key) : 0;
206265101 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
217173509226 q{
218173509226 q return find_value(data.tags, rhs ? rhs->eval(data, key) : "");
219173509226 q}
222std::string Value_Eval_Task::eval(const Element_With_Context< Attic< Node_Skeleton > >& data, const std::string* key) const
22369688 q{
22469688 q return find_value(data.tags, rhs ? rhs->eval(data, key) : "");
22569688 q}
228std::string Value_Eval_Task::eval(const Element_With_Context< Way_Skeleton >& data, const std::string* key) const
22962123734 q{
23062123734 q return find_value(data.tags, rhs ? rhs->eval(data, key) : "");
23162123734 q}
234std::string Value_Eval_Task::eval(const Element_With_Context< Attic< Way_Skeleton > >& data, const std::string* key) const
235285529 q{
236285529 q return find_value(data.tags, rhs ? rhs->eval(data, key) : "");
237285529 q}
240std::string Value_Eval_Task::eval(const Element_With_Context< Relation_Skeleton >& data, const std::string* key) const
24149217823 q{
24249217823 q return find_value(data.tags, rhs ? rhs->eval(data, key) : "");
24349217823 q}
246std::string Value_Eval_Task::eval(const Element_With_Context< Attic< Relation_Skeleton > >& data, const std::string* key) const
248483 q return find_value(data.tags, rhs ? rhs->eval(data, key) : "");
252std::string Value_Eval_Task::eval(const Element_With_Context< Area_Skeleton >& data, const std::string* key) const
2533734 q{
2543734 q return find_value(data.tags, rhs ? rhs->eval(data, key) : "");
2553734 q}
258std::string Value_Eval_Task::eval(const Element_With_Context< Derived_Skeleton >& data, const std::string* key) const
25938939012 q{
26038939012 q return find_value(data.tags, rhs ? rhs->eval(data, key) : "");
26138939012 q}
264//-----------------------------------------------------------------------------
267std::string exists_value(const std::vector< std::pair< std::string, std::string > >* tags, const std::string& key)
26864498717 q{
26964498717 q if (!tags)
27043518010 q return "0";
27220980717 q for (std::vector< std::pair< std::string, std::string > >::const_iterator it = tags->begin();
273114110517 q it != tags->end(); ++it)
27493188517 q {
27593188517 q if (it->first == key)
2765877 q return "1";
27793188517 q }
27920922017 q return "0";
28020980717 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)
29110826 q if (!tree_it.assert_is_function(error_output) || !tree_it.assert_has_input_set(error_output, false)
29210826 q || !tree_it.assert_has_arguments(error_output, true)
29310826 q || !assert_element_in_context(error_output, tree_it, tree_context))
29441 q return 0;
29610425 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 }
30210425 q std::map< std::string, std::string > attributes;
30310425 q attributes["k"] = decode_json(tree_it.rhs()->token, error_output);
30410425 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)
31010425 q : Evaluator(line_number_)
31210425 q std::map< std::string, std::string > attributes;
31410425 q attributes["k"] = "";
31610425 q eval_attributes_array(get_name(), attributes, input_attributes);
31810425 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)
3305975 q{
3315975 q std::vector< std::string > result;
3325975 q if (!tags)
333952 q return result;
3355025 q for (std::vector< std::pair< std::string, std::string > >::const_iterator it = tags->begin();
33622035 q it != tags->end(); ++it)
33717015 q result.push_back(it->first);
3395025 q std::sort(result.begin(), result.end());
3405025 q result.erase(std::unique(result.begin(), result.end()), result.end());
3425025 q return result;
3435975 q}
346Evaluator_All_Keys::Evaluator_All_Keys
347 (int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)
348328 q : Evaluator(line_number_)
350328 q std::map< std::string, std::string > attributes;
351328 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)
3647217 q : Evaluator(line_number_)
3667217 q std::map< std::string, std::string > attributes;
3677217 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)
37727654 q : Evaluator(line_number_)
37927654 q std::map< std::string, std::string > attributes;
38027654 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)
3906415 q : Evaluator(line_number_)
3926415 q std::map< std::string, std::string > attributes;
3936415 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)
40310425 q : Evaluator(line_number_)
40510425 q std::map< std::string, std::string > attributes;
40610425 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)
41620439 q : Evaluator(line_number_)
41820439 q std::map< std::string, std::string > attributes;
41920439 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)
4349624 q if (tree_it->lhs || tree_it->rhs)
4350 return 0;
4369624 q std::map< std::string, std::string > attributes;
4379624 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)
4439624 q : Evaluator(line_number_)
4459624 q std::map< std::string, std::string > attributes;
4479624 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)
46243283 q if (!tree_it.assert_is_function(error_output) || !tree_it.assert_has_input_set(error_output, false)
46343283 q || !assert_element_in_context(error_output, tree_it, tree_context))
4640 return 0;
46643283 q std::map< std::string, std::string > attributes;
46843283 q const std::string* func_name = tree_it.function_name();
46943283 q attributes["type"] = func_name->size() > 6 ? func_name->substr(6) : "";
47143283 q if (*func_name == "count_by_role" || *func_name == "count_distinct_by_role")
47216435 q {
47316435 q if (tree_it->rhs)
47416435 q {
47516435 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 }
50016435 q else if (!tree_it.rhs()->lhs && !tree_it.rhs()->rhs)
50116435 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 }
50916435 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 }
51716435 q }
51826858 q else if (*func_name == "count_members" || *func_name == "count_distinct_members")
51912825 q {
52012825 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 }
53512825 q }
53614035 q else
53714035 q {
53814035 q if (!tree_it.assert_has_arguments(error_output, false))
53941 q return 0;
54014035 q }
54242882 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)
54832182 q if (objects == tags)
54910234 q return "tags";
55021953 q if (objects == members)
5514815 q return "members";
55217144 q if (objects == distinct_members)
5534813 q return "distinct_members";
55412335 q if (objects == by_role)
5555117 q return "by_role";
5567221 q if (objects == distinct_by_role)
5577221 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)
57842882 q : Evaluator(line_number_), to_count(nothing), type_to_count(all)
58042882 q std::map< std::string, std::string > attributes;
58242882 q attributes["type"] = "";
58342882 q attributes["role"] = "";
58442882 q attributes["members_type"] = "all";
58642882 q eval_attributes_array(get_name(), attributes, input_attributes);
58842882 q if (attributes["type"] == "tags")
58913634 q to_count = tags;
59029253 q else if (attributes["type"] == "members")
5916415 q to_count = members;
59222844 q else if (attributes["type"] == "distinct_members")
5936413 q to_count = distinct_members;
59416435 q else if (attributes["type"] == "by_role")
5956817 q to_count = by_role;
5969621 q else if (attributes["type"] == "distinct_by_role")
5979621 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 }
60542882 q if (attributes["members_type"] == "all")
60642882 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 }
61942882 q role = attributes["role"];
623Requested_Context Evaluator_Properties_Count::request_context() const
62511879 q if (to_count == Evaluator_Properties_Count::tags)
6264532 q return Requested_Context().add_usage(Set_Usage::TAGS);
6277352 q else if (to_count == Evaluator_Properties_Count::members || to_count == Evaluator_Properties_Count::distinct_members)
6283325 q return Requested_Context().add_usage(Set_Usage::SKELETON);
6294034 q else if (to_count == Evaluator_Properties_Count::by_role || to_count == Evaluator_Properties_Count::distinct_by_role)
6304034 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)
63811879 q if (to_count == Evaluator_Properties_Count::by_role || to_count == Evaluator_Properties_Count::distinct_by_role)
6394034 q return new Prop_Count_Eval_Task(to_count, type_to_count, context.get_role_id(role));
6417855 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
64691137622 q{
64791137622 q if (to_count == Evaluator_Properties_Count::tags && data.tags)
64865009 q return to_string(data.tags->size());
64990487619 q return "0";
65091137622 q}
653std::string Prop_Count_Eval_Task::eval(const Element_With_Context< Attic< Node_Skeleton > >& data,
654 const std::string* key) const
655255546 q{
656255546 q if (to_count == Evaluator_Properties_Count::tags && data.tags)
65717903 q return to_string(data.tags->size());
658237646 q return "0";
659255546 q}
662std::string Prop_Count_Eval_Task::eval(const Element_With_Context< Way_Skeleton >& data,
663 const std::string* key) const
66415371624 q{
66515371624 q if (to_count == Evaluator_Properties_Count::members
66615371624 q && type_to_count == Evaluator_Properties_Count::all && data.object)
66776743 q return to_string(data.object->nds.size());
66814604222 q else if (to_count == Evaluator_Properties_Count::distinct_members
66914604222 q && type_to_count == Evaluator_Properties_Count::all && data.object)
67093192 q {
67193192 q std::vector< Node::Id_Type > distinct = data.object->nds;
67293192 q std::sort(distinct.begin(), distinct.end());
67393192 q return to_string(std::distance(distinct.begin(), std::unique(distinct.begin(), distinct.end())));
67493192 q }
67513672320 q else if (to_count == Evaluator_Properties_Count::tags && data.tags)
6765393911 q return to_string(data.tags->size());
6778278414 q return "0";
67815371624 q}
681std::string Prop_Count_Eval_Task::eval(const Element_With_Context< Attic< Way_Skeleton > >& data,
682 const std::string* key) const
683162919 q{
684162919 q if (to_count == Evaluator_Properties_Count::members
685162919 q && type_to_count == Evaluator_Properties_Count::all && data.object)
6860 return to_string(data.object->nds.size());
687162919 q else if (to_count == Evaluator_Properties_Count::distinct_members
688162919 q && type_to_count == Evaluator_Properties_Count::all && data.object)
68949671 q {
69049671 q std::vector< Node::Id_Type > distinct = data.object->nds;
69149671 q std::sort(distinct.begin(), distinct.end());
69249671 q return to_string(std::distance(distinct.begin(), std::unique(distinct.begin(), distinct.end())));
69349671 q }
694113248 q else if (to_count == Evaluator_Properties_Count::tags && data.tags)
69540807 q return to_string(data.tags->size());
69672446 q return "0";
697162919 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)
7024101828 q{
7034101828 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 }
7134101828 q if (member.role != role_id &&
7144101828 q (to_count == Evaluator_Properties_Count::by_role || to_count == Evaluator_Properties_Count::distinct_by_role))
7153833158 q return false;
717268674 q return true;
7184101828 q}
721struct Relation_Member_Comparer
723 bool operator()(const Relation_Entry& lhs, const Relation_Entry& rhs) const
724212583026 q {
725212583026 q if (lhs.type != rhs.type)
7265962624 q return lhs.type < rhs.type;
728206620406 q return lhs.ref < rhs.ref;
729212583026 q }
730};
733std::string Prop_Count_Eval_Task::eval(const Element_With_Context< Relation_Skeleton >& data,
734 const std::string* key) const
73517925618 q{
73617925618 q if (to_count == Evaluator_Properties_Count::members || to_count == Evaluator_Properties_Count::by_role)
7375990110 q {
7385990110 q if (!data.object)
7390 return "0";
7415990110 q if (to_count == Evaluator_Properties_Count::members && type_to_count == Evaluator_Properties_Count::all)
742588265 q return to_string(data.object->members.size());
74410755 q uint counter = 0;
7451971995 q for (std::vector< Relation_Entry >::const_iterator it = data.object->members.begin(); it != data.object->members.end(); ++it)
7461961245 q {
7471961245 q if (matches_criterion(*it, to_count, type_to_count, role_id))
748192 q ++counter;
7491961245 q }
75010755 q return to_string(counter);
7515990110 q }
75211935513 q else if (to_count == Evaluator_Properties_Count::distinct_members
75311935513 q || to_count == Evaluator_Properties_Count::distinct_by_role)
754601908 q {
755601908 q if (!data.object)
7560 return "0";
758601908 q std::vector< Relation_Entry > distinct = data.object->members;
760601908 q if (to_count != Evaluator_Properties_Count::distinct_members || type_to_count != Evaluator_Properties_Count::all)
76113624 q {
76213624 q std::vector< Relation_Entry >::size_type from = 0;
76313624 q std::vector< Relation_Entry >::size_type to = 0;
7642154204 q for (; from < distinct.size(); ++from)
7652140584 q {
7662140584 q if (matches_criterion(distinct[from], to_count, type_to_count, role_id))
767268483 q distinct[to++] = distinct[from];
7682140584 q }
76913624 q distinct.resize(to);
77013624 q }
772601908 q std::sort(distinct.begin(), distinct.end(), Relation_Member_Comparer());
773601908 q return to_string(std::distance(distinct.begin(), std::unique(distinct.begin(), distinct.end())));
774601908 q }
775591655 q else if (to_count == Evaluator_Properties_Count::tags && data.tags)
776591645 q return to_string(data.tags->size());
77711 q return "0";
77817925618 q}
781std::string Prop_Count_Eval_Task::eval(const Element_With_Context< Attic< Relation_Skeleton > >& data,
782 const std::string* key) const
7834692 q{
7844692 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 }
8004692 q else if (to_count == Evaluator_Properties_Count::distinct_members
8014692 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 }
8234692 q else if (to_count == Evaluator_Properties_Count::tags && data.tags)
8244692 q return to_string(data.tags->size());
8250 return "0";
8264692 q}
829std::string Prop_Count_Eval_Task::eval(const Element_With_Context< Area_Skeleton >& data, const std::string* key) const
831175 q if (to_count == Evaluator_Properties_Count::tags && data.tags)
832123 q return to_string(data.tags->size());
83352 q return "0";
837std::string Prop_Count_Eval_Task::eval(const Element_With_Context< Derived_Skeleton >& data, const std::string* key) const
839668 q if (to_count == Evaluator_Properties_Count::tags && data.tags)
84022 q return to_string(data.tags->size());
841647 q return "0";