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

overpass_api/statements/compare.h

31 of 45 instrumented lines run by the suite (68.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__COMPARE_H
20#define DE__OSM3S___OVERPASS_API__STATEMENTS__COMPARE_H
23#include "statement.h"
26class Set_Comparison;
29/* === The block statement <em>compare</em> ===
31''since v0.7.55''
33The statement <em>compare</em> computes the diff of the data of two timestamps.
34That diff can consist of any elements as well as only those with specific properties.
36The statement can have a block of substatements.
37The block of substatements is executed after computing the diff in the second run,
38once for the old timestamp and then again for the new timestamp.
39This allows to do extra computations based on the diff results.
41The statement can only be used in diff mode.
42In other modes its behaviour is undefined,
43and in future versions it might be a syntax error to have it elsewhere.
45In the first run of a diff query it returns an empty set.
46In the second run of a diff query it returns the difference of the elements.
47If the statement gets an evaluator as argument
48then only those elements that have different values on both timestamps are returned.
49If the element does not exist on one of the timstamps
50then its value is regarded as the empty string.
51Currently, the only purpose of such a difference is to feed it into an output statement.
53The base syntax is
55 compare();
57In addition, an input and/or output set can be specified:
59 .<Set> compare()->.<Set>;
61With the evaluator, the syntax becomes
63 compare(delta:<Evaluator>);
65resp.
67 .<Set> compare->.<Set>(delta:<Evaluator>);
69In all syntax variants a block of substatements can be attached:
71 compare()
72 {
73 <List of Substatements>
74 };
76resp.
78 .<Set> compare(delta:<Evaluator>)->.<Set>;
79 {
80 <List of Substatements>
81 };
83*/
85class Compare_Statement : public Output_Statement
87public:
88 Compare_Statement(int line_number_, const std::map< std::string, std::string >& attributes,
89 Parsed_Query& global_settings);
90 virtual ~Compare_Statement();
9117421 q virtual std::string get_name() const { return "compare"; }
92 virtual void add_statement(Statement* statement, std::string text);
93 virtual void execute(Resource_Manager& rman);
95 static Generic_Statement_Maker< Compare_Statement > statement_maker;
97 virtual std::string dump_xml(const std::string& indent) const
980 {
990 std::string result = indent + "<compare"
1000 + (input != "_" ? std::string(" from=\"") + input + "\"" : "")
1010 + dump_xml_result_name();
1020 if (criterion || !substatements.empty())
1030 result += ">\n";
1050 if (criterion)
1060 result += criterion->dump_xml(indent + " ");
1080 for (std::vector< Statement* >::const_iterator it = substatements.begin(); it != substatements.end(); ++it)
1090 result += *it ? (*it)->dump_xml(indent + " ") : "";
1110 if (criterion || !substatements.empty())
1120 return result + indent + "</criterion>\n";
1130 return result + "/>\n";
1140 }
116 virtual std::string dump_compact_ql(const std::string& indent) const
1182121 q std::string result = (input != "_" ? std::string(".") + input + " " : "")
1192121 q + "compare" + dump_ql_result_name()
1202121 q + (criterion ? "(delta:" + criterion->dump_compact_ql(indent) + ")" : "()");
1222121 q if (!substatements.empty())
1241111 q result += "{";
1252311 q for (std::vector< Statement* >::const_iterator it = substatements.begin(); it != substatements.end(); ++it)
1261211 q result += (*it)->dump_compact_ql(indent) + ";";
1271111 q result += "}";
1291010 q else
1301010 q result += ";";
1322121 q return result;
135 virtual std::string dump_pretty_ql(const std::string& indent) const
1372121 q std::string result = (input != "_" ? std::string(".") + input + " " : "")
1382121 q + "compare" + dump_ql_result_name()
1392121 q + (criterion ? "(delta:" + criterion->dump_compact_ql(indent) + ")" : "()");
1412121 q if (!substatements.empty())
1431111 q result += indent + "{";
1442311 q for (std::vector< Statement* >::const_iterator it = substatements.begin(); it != substatements.end(); ++it)
1451211 q result += "\n" + (*it)->dump_pretty_ql(indent + " ") + ";";
1461111 q result += "\n" + indent + "}";
1481010 q else
1491010 q result += ";";
1512121 q return result;
154private:
155 Evaluator* criterion;
156 std::vector< Statement* > substatements;
157 std::string input;
158 Set_Comparison* set_comparison;
159};
162#endif