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

overpass_api/statements/set_list_operators.cc

162 of 163 instrumented lines run by the suite (99.4%) 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 "set_list_operators.h"
24std::string trim(const std::string& input)
25439190360 q{
26439190360 q std::string::size_type from = 0;
27439192260 q while (from < input.size() && isspace(input[from]))
28192 q ++from;
30439190360 q if (from == input.size())
31401304 q return " ";
33435177360 q std::string::size_type to = input.size()-1;
34435177360 q while (isspace(input[to]))
350 --to;
37435177360 q return input.substr(from, to+1);
38439190360 q}
41std::vector< std::string > members(const std::string& lrs)
42538494243 q{
43538494243 q std::vector< std::string > result;
45538494243 q if (lrs.empty())
46242261637 q return result;
48296232642 q std::string::size_type from = 0;
49333707442 q while (from < lrs.size())
50333707442 q {
51333707442 q std::string::size_type to = lrs.find(';', from);
52333707442 q if (to == std::string::npos)
53296232642 q break;
5537474826 q result.push_back(trim(lrs.substr(from, to - from)));
5737474826 q from = to + 1;
5837474826 q }
59296232642 q result.push_back(trim(lrs.substr(from)));
61296232642 q std::sort(result.begin(), result.end());
62296232642 q result.erase(std::unique(result.begin(), result.end()), result.end());
63296232642 q return result;
64538494243 q}
67//-----------------------------------------------------------------------------
70Binary_Set_List_Operator_Statement_Maker< Evaluator_Lrs_In > Evaluator_Lrs_In::statement_maker;
71Binary_Set_List_Operator_Evaluator_Maker< Evaluator_Lrs_In > Evaluator_Lrs_In::evaluator_maker;
74std::string Evaluator_Lrs_In::process(const std::string& first_s, const std::string& second_s) const
757110416 q{
767110416 q if (second_s.empty())
772576 q return "0";
797084710 q std::string first = trim(first_s);
817084710 q std::string::size_type from = 0;
8210039010 q while (from < second_s.size())
8310039010 q {
8410039010 q std::string::size_type to = second_s.find(';', from);
8510039010 q if (to == std::string::npos)
866935910 q break;
88310316 q if (first == trim(second_s.substr(from, to - from)))
8914881 q return "1";
91295436 q from = to + 1;
92295436 q }
946935910 q if (first == trim(second_s.substr(from)))
9512661 q return "1";
976809310 q return "0";
986935910 q}
101//-----------------------------------------------------------------------------
104Binary_Set_List_Operator_Statement_Maker< Evaluator_Lrs_Isect > Evaluator_Lrs_Isect::statement_maker;
105Binary_Set_List_Operator_Evaluator_Maker< Evaluator_Lrs_Isect > Evaluator_Lrs_Isect::evaluator_maker;
108std::string Evaluator_Lrs_Isect::process(const std::string& first_s, const std::string& second_s) const
109128750622 q{
110128750622 q std::vector< std::string > first;
111128750622 q members(first_s).swap(first);
112128750622 q std::vector< std::string > second;
113128750622 q members(second_s).swap(second);
114128750622 q std::vector< std::string > result(std::min(first.size(), second.size()));
116128750622 q result.erase(std::set_intersection(first.begin(), first.end(), second.begin(), second.end(), result.begin()),
117128750622 q result.end());
119128750622 q std::string result_s;
120128750622 q if (!result.empty())
121271517 q result_s = result[0];
122129206422 q for (unsigned int i = 1; i < result.size(); ++i)
12345582 q result_s += ";" + result[i];
125128750622 q return result_s;
126128750622 q}
129//-----------------------------------------------------------------------------
132Binary_Set_List_Operator_Statement_Maker< Evaluator_Lrs_Union > Evaluator_Lrs_Union::statement_maker;
133Binary_Set_List_Operator_Evaluator_Maker< Evaluator_Lrs_Union > Evaluator_Lrs_Union::evaluator_maker;
136std::string Evaluator_Lrs_Union::process(const std::string& first_s, const std::string& second_s) const
137140496538 q{
138140496538 q std::vector< std::string > first;
139140496538 q members(first_s).swap(first);
140140496538 q std::vector< std::string > second;
141140496538 q members(second_s).swap(second);
142140496538 q std::vector< std::string > result(first.size() + second.size());
144140496538 q result.erase(std::set_union(first.begin(), first.end(), second.begin(), second.end(), result.begin()),
145140496538 q result.end());
147140496538 q std::string result_s;
148140496538 q if (!result.empty())
149140491137 q result_s = result[0];
150185408138 q for (unsigned int i = 1; i < result.size(); ++i)
15144911627 q result_s += ";" + result[i];
153140496538 q return result_s;
154140496538 q}
157//-----------------------------------------------------------------------------
160enum Type_Indicator { type_void = 0, type_int64 = 1, type_double = 2, type_string = 3 };
163Unary_Set_List_Operator_Statement_Maker< Evaluator_Lrs_Max > Evaluator_Lrs_Max::statement_maker;
164Unary_Set_List_Operator_Evaluator_Maker< Evaluator_Lrs_Max > Evaluator_Lrs_Max::evaluator_maker;
167void update_maximum(const std::string& elem, Type_Indicator& relevant_type,
168 int64& result_l, double& result_d, std::string& result_s)
16929836112 q{
17029836112 q if (relevant_type <= type_int64)
17129829812 q {
17229829812 q int64 rhs_l = 0;
17329829812 q if (try_int64(elem, rhs_l))
1741494626 q result_l = std::max(result_l, rhs_l);
1751488368 q else
1761488368 q relevant_type = type_double;
17729829812 q }
17929836112 q if (relevant_type <= type_double)
18029829812 q {
18129829812 q double rhs_d = 0;
18229829812 q if (try_double(elem, rhs_d))
1832201166 q result_d = std::max(result_d, rhs_d);
184781828 q else
185781828 q relevant_type = type_string;
18629829812 q }
18829836112 q if (!elem.empty())
18929836112 q result_s = (result_s.empty() ? elem : std::max(result_s, elem));
19029836112 q}
193std::string Evaluator_Lrs_Max::process(const std::string& rhs_s) const
19420796114 q{
19520796114 q if (rhs_s.empty())
196550723 q return "";
19815288912 q Type_Indicator relevant_type = type_int64;
19915288912 q int64 result_l = std::numeric_limits< int64 >::min();
20015288912 q double result_d = -std::numeric_limits< double >::max();
20115288912 q std::string result_s;
20315288912 q std::string::size_type from = 0;
20429836112 q while (from < rhs_s.size())
20529836112 q {
20629836112 q std::string::size_type to = rhs_s.find(';', from);
20729836112 q if (to == std::string::npos)
20815288912 q break;
2101454728 q update_maximum(trim(rhs_s.substr(from, to - from)), relevant_type, result_l, result_d, result_s);
2121454728 q from = to + 1;
2131454728 q }
21515288912 q update_maximum(trim(rhs_s.substr(from)), relevant_type, result_l, result_d, result_s);
21715288912 q if (relevant_type == type_int64)
21840534 q return to_string(result_l);
2191488368 q else if (relevant_type == type_double)
220706541 q return to_string(result_d);
222781828 q return result_s;
22315288912 q}
226//-----------------------------------------------------------------------------
229Unary_Set_List_Operator_Statement_Maker< Evaluator_Lrs_Min > Evaluator_Lrs_Min::statement_maker;
230Unary_Set_List_Operator_Evaluator_Maker< Evaluator_Lrs_Min > Evaluator_Lrs_Min::evaluator_maker;
233void update_minimum(const std::string& elem, Type_Indicator& relevant_type,
234 int64& result_l, double& result_d, std::string& result_s)
23558523131 q{
23658523131 q if (relevant_type <= type_int64)
23757420831 q {
23857420831 q int64 rhs_l = 0;
23957420831 q if (try_int64(elem, rhs_l))
24036769815 q result_l = std::min(result_l, rhs_l);
24120651020 q else
24220651020 q relevant_type = type_double;
24357420831 q }
24558523131 q if (relevant_type <= type_double)
24657420831 q {
24757420831 q double rhs_d = 0;
24857420831 q if (try_double(elem, rhs_d))
24936773215 q result_d = std::min(result_d, rhs_d);
25020647619 q else
25120647619 q relevant_type = type_string;
25257420831 q }
25458523131 q if (!elem.empty())
25558523131 q result_s = (result_s.empty() ? elem : std::min(result_s, elem));
25658523131 q}
259std::string Evaluator_Lrs_Min::process(const std::string& rhs_s) const
26039889345 q{
26139889345 q if (rhs_s.empty())
26212924721 q return "";
26426964631 q Type_Indicator relevant_type = type_int64;
26526964631 q int64 result_l = std::numeric_limits< int64 >::max();
26626964631 q double result_d = std::numeric_limits< double >::max();
26726964631 q std::string result_s;
26926964631 q std::string::size_type from = 0;
27058523131 q while (from < rhs_s.size())
27158523131 q {
27258523131 q std::string::size_type to = rhs_s.find(';', from);
27358523131 q if (to == std::string::npos)
27426964631 q break;
27631558517 q update_minimum(trim(rhs_s.substr(from, to - from)), relevant_type, result_l, result_d, result_s);
27831558517 q from = to + 1;
27931558517 q }
28126964631 q update_minimum(trim(rhs_s.substr(from)), relevant_type, result_l, result_d, result_s);
28326964631 q if (relevant_type == type_int64)
2846313614 q return to_string(result_l);
28520651020 q else if (relevant_type == type_double)
286342 q return to_string(result_d);
28820647619 q return result_s;
28926964631 q}