Overpass API regression suite coverage (Nova Scotia) / overpass_api/statements/osm_script.cc
overpass_api/statements/osm_script.cc
117 of 192 instrumented lines run by the suite (60.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. 3 * This file is part of Overpass_API. 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. 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. 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/>. 23#include "../core/settings.h" 24#include "../frontend/output_handler_parser.h" 25#include "bbox_query.h" 26#include "osm_script.h" 30Generic_Statement_Maker< Osm_Script_Statement > Osm_Script_Statement::statement_maker("osm-script"); 33int64 eval_number_with_suffix(const std::string& arg) 371224612 q int64 result = strtoll(&arg[0], &pos, 0); 401224612 q auto offset = std::distance(&arg[0], (const char*)pos); 411224612 q if ((decltype(offset))arg.size() <= offset) 430 std::string suffix = arg.substr(offset); 440 if (suffix == "ki" || suffix == " ki") 460 if (suffix == "Mi" || suffix == " Mi") 480 if (suffix == "Gi" || suffix == " Gi") 500 if (suffix == "k" || suffix == " k") 510 return result * 1000; 520 if (suffix == "M" || suffix == " M") 530 return result * 1000000; 540 if (suffix == "G" || suffix == " G") 550 return result * 1000000000; 60Osm_Script_Statement::Osm_Script_Statement 61 (int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings) 62612612 q : Statement(line_number_), 63612612 q desired_timestamp(NOW), comparison_timestamp(0), add_deletion_information(false), 64612612 q max_allowed_time(0), max_allowed_space(0), 67612612 q std::map< std::string, std::string > attributes; 69612612 q attributes["bbox"] = ""; 70612612 q attributes["timeout"] = "180"; 71612612 q attributes["element-limit"] = "536870912"; 72612612 q attributes["output"] = "xml"; 73612612 q attributes["output-config"] = ""; 74612612 q attributes["date"] = ""; 75612612 q attributes["from"] = ""; 76612612 q attributes["augmented"] = ""; 78612612 q eval_attributes_array(get_name(), attributes, input_attributes); 80612612 q int64 timeout = eval_number_with_suffix(attributes["timeout"]); 830 std::ostringstream temp; 840 temp<<"For the attribute \"timeout\" of the element \"osm-script\"" 850 <<" the only allowed values are positive integers optionally with suffix \"ki\", \"Mi\", or \"Gi\"."; 860 add_static_error(temp.str()); 88612612 q max_allowed_time = timeout; 90612612 q int64 max_space = eval_number_with_suffix(attributes["element-limit"]); 920 add_static_error("For the attribute \"element-limit\" of the element \"osm-script\"" 930 " the only allowed values are positive integers optionally with suffix \"ki\", \"Mi\", or \"Gi\"."); 95612612 q max_allowed_space = max_space; 98612612 q if (!global_settings.get_output_handler()) 100500500 q Output_Handler_Parser* format_parser = Output_Handler_Parser::get_format_parser(attributes["output"]); 1020 add_static_error("Unknown output format: " + attributes["output"]); 105500500 q if (attributes["output-config"] == "") 106500500 q global_settings.set_output_handler(format_parser, 0, 0); 1090 std::istringstream in(attributes["output-config"]); 1100 Tokenizer_Wrapper token(in); 1110 global_settings.set_output_handler(format_parser, &token, 0); 117612612 q if (attributes["bbox"] != "") 1192020 q std::map< std::string, std::string > bbox_attributes; 1212020 q std::string& bbox_s = attributes["bbox"]; 1222020 q std::string::size_type pos = bbox_s.find(","); 1232020 q std::string::size_type from = 0; 1242020 q if (pos != std::string::npos) 1262020 q bbox_attributes["s"] = bbox_s.substr(0, pos); 1282020 q pos = bbox_s.find(",", from); 1320 std::ostringstream temp; 1330 temp<<"A bounding box needs four comma-separated values."; 1340 add_static_error(temp.str()); 1362020 q if (pos != std::string::npos) 1382020 q bbox_attributes["w"] = bbox_s.substr(from, pos-from); 1402020 q pos = bbox_s.find(",", from); 1440 std::ostringstream temp; 1450 temp<<"A bounding box needs four comma-separated values."; 1460 add_static_error(temp.str()); 1482020 q if (pos != std::string::npos) 1502020 q bbox_attributes["n"] = bbox_s.substr(from, pos-from); 1550 std::ostringstream temp; 1560 temp<<"A bounding box needs four comma-separated values."; 1570 add_static_error(temp.str()); 1592020 q bbox_attributes["e"] = bbox_s.substr(from); 1612020 q double south = atof(bbox_attributes["s"].c_str()); 1622020 q double north = atof(bbox_attributes["n"].c_str()); 1632020 q if (south < -90.0 || south > 90.0 || north < -90.0 || north > 90.0) 1650 std::ostringstream temp; 1660 temp<<"Latitudes in bounding boxes must be between -90.0 and 90.0."; 1670 add_static_error(temp.str()); 1702020 q double west = atof(bbox_attributes["w"].c_str()); 1712020 q double east = atof(bbox_attributes["e"].c_str()); 1722020 q if (west < -180.0 || west > 180.0 || east < -180.0 || east > 180.0) 1740 std::ostringstream temp; 1750 temp<<"Longitudes in bounding boxes must be between -180.0 and 180.0."; 1760 add_static_error(temp.str()); 1792020 q if (south >= -90.0 && south <= 90.0 && north >= -90.0 && north <= 90.0 1802020 q && west >= -180.0 && west <= 180.0 && east >= -180.0 && east <= 180.0) 1812020 q global_settings.set_global_bbox(Bbox_Double(south, west, north, east)); 184612612 q if (attributes["date"] != "") 186191191 q desired_timestamp = Timestamp(attributes["date"]).timestamp; 1880 add_static_error("The attribute \"date\" must be empty or contain a timestamp exactly in the form \"yyyy-mm-ddThh:mm:ssZ\"."); 191612612 q if (attributes["from"] != "") 1937676 q comparison_timestamp = Timestamp(attributes["from"]).timestamp; 1947676 q if (comparison_timestamp == 0) 1950 add_static_error("The attribute \"from\" must be empty or contain a timestamp exactly in the form \"yyyy-mm-ddThh:mm:ssZ\"."); 1967676 q else if (global_settings.get_output_handler() && !global_settings.get_output_handler()->supports_diff()) 1970 add_static_error("The selected output format does not support the diff or adiff mode."); 200612612 q if (attributes["augmented"] != "") 2023232 q if (attributes["augmented"] == "deletions" && attributes["from"] != "") 2033232 q add_deletion_information = true; 2053232 q if (attributes["augmented"] != "deletions") 2070 std::ostringstream temp; 2080 temp<<"The only allowed values for \"augmented\" are an empty value or \"deletions\"."; 2090 add_static_error(temp.str()); 2113232 q if (attributes["from"] == "") 2130 std::ostringstream temp; 2140 temp<<"The attribute \"augmented\" can only be set if the attribute \"from\" is set."; 2150 add_static_error(temp.str()); 220void Osm_Script_Statement::add_statement(Statement* statement, std::string text) 2225084608 q assure_no_text(text, this->get_name()); 2265084608 q if (statement->get_name() != "newer") 2275084608 q substatements.push_back(statement); 2290 add_static_error("\"newer\" can appear only inside \"query\" statements."); 234void Osm_Script_Statement::execute(Resource_Manager& rman) 236595595 q rman.set_limits(max_allowed_time, max_allowed_space); 237595595 q rman.get_global_settings().trigger_print_bounds(); 239595595 q if (comparison_timestamp > 0) 2417676 q rman.start_diff(comparison_timestamp, desired_timestamp); 2437676 q for (std::vector< Statement* >::iterator it(substatements.begin()); 24473876 q it != substatements.end(); ++it) 2477676 q rman.switch_diff_rhs(add_deletion_information); 250595595 q for (std::vector< Statement* >::iterator it(substatements.begin()); 2515553595 q it != substatements.end(); ++it) 2550 rman.area_updater()->flush();