Overpass API regression suite coverage (Saxony) / 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) 371384692 q int64 result = strtoll(&arg[0], &pos, 0); 401384692 q auto offset = std::distance(&arg[0], (const char*)pos); 411384692 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) 62692692 q : Statement(line_number_), 63692692 q desired_timestamp(NOW), comparison_timestamp(0), add_deletion_information(false), 64692692 q max_allowed_time(0), max_allowed_space(0), 67692692 q std::map< std::string, std::string > attributes; 69692692 q attributes["bbox"] = ""; 70692692 q attributes["timeout"] = "180"; 71692692 q attributes["element-limit"] = "536870912"; 72692692 q attributes["output"] = "xml"; 73692692 q attributes["output-config"] = ""; 74692692 q attributes["date"] = ""; 75692692 q attributes["from"] = ""; 76692692 q attributes["augmented"] = ""; 78692692 q eval_attributes_array(get_name(), attributes, input_attributes); 80692692 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()); 88692692 q max_allowed_time = timeout; 90692692 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\"."); 95692692 q max_allowed_space = max_space; 98692692 q if (!global_settings.get_output_handler()) 100563563 q Output_Handler_Parser* format_parser = Output_Handler_Parser::get_format_parser(attributes["output"]); 1020 add_static_error("Unknown output format: " + attributes["output"]); 105563563 q if (attributes["output-config"] == "") 106563563 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); 117692692 q if (attributes["bbox"] != "") 1192323 q std::map< std::string, std::string > bbox_attributes; 1212323 q std::string& bbox_s = attributes["bbox"]; 1222323 q std::string::size_type pos = bbox_s.find(","); 1232323 q std::string::size_type from = 0; 1242323 q if (pos != std::string::npos) 1262323 q bbox_attributes["s"] = bbox_s.substr(0, pos); 1282323 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()); 1362323 q if (pos != std::string::npos) 1382323 q bbox_attributes["w"] = bbox_s.substr(from, pos-from); 1402323 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()); 1482323 q if (pos != std::string::npos) 1502323 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()); 1592323 q bbox_attributes["e"] = bbox_s.substr(from); 1612323 q double south = atof(bbox_attributes["s"].c_str()); 1622323 q double north = atof(bbox_attributes["n"].c_str()); 1632323 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()); 1702323 q double west = atof(bbox_attributes["w"].c_str()); 1712323 q double east = atof(bbox_attributes["e"].c_str()); 1722323 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()); 1792323 q if (south >= -90.0 && south <= 90.0 && north >= -90.0 && north <= 90.0 1802323 q && west >= -180.0 && west <= 180.0 && east >= -180.0 && east <= 180.0) 1812323 q global_settings.set_global_bbox(Bbox_Double(south, west, north, east)); 184692692 q if (attributes["date"] != "") 186223223 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\"."); 191692692 q if (attributes["from"] != "") 1938181 q comparison_timestamp = Timestamp(attributes["from"]).timestamp; 1948181 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\"."); 1968181 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."); 200692692 q if (attributes["augmented"] != "") 2023333 q if (attributes["augmented"] == "deletions" && attributes["from"] != "") 2033333 q add_deletion_information = true; 2053333 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()); 2113333 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) 2225689689 q assure_no_text(text, this->get_name()); 2265689689 q if (statement->get_name() != "newer") 2275689689 q substatements.push_back(statement); 2290 add_static_error("\"newer\" can appear only inside \"query\" statements."); 234void Osm_Script_Statement::execute(Resource_Manager& rman) 236673673 q rman.set_limits(max_allowed_time, max_allowed_space); 237673673 q rman.get_global_settings().trigger_print_bounds(); 239673673 q if (comparison_timestamp > 0) 2418181 q rman.start_diff(comparison_timestamp, desired_timestamp); 2438181 q for (std::vector< Statement* >::iterator it(substatements.begin()); 24477881 q it != substatements.end(); ++it) 2478181 q rman.switch_diff_rhs(add_deletion_information); 250673673 q for (std::vector< Statement* >::iterator it(substatements.begin()); 2516228673 q it != substatements.end(); ++it) 2550 rman.area_updater()->flush();