Overpass API regression suite coverage (Nova Scotia) / overpass_api/output_formats/output_popup.cc

overpass_api/output_formats/output_popup.cc

165 of 176 instrumented lines run by the suite (93.8%) 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 "../../expat/escape_xml.h"
20#include "../frontend/basic_formats.h"
21#include "output_popup.h"
23#include <cmath>
24#include <fstream>
27bool Tag_Filter::matches(const std::vector< std::pair< std::string, std::string > >* tags) const
28247229 q{
29247229 q if (!tags)
30237409 q return false;
3139329 q for (std::vector< std::pair< std::string, std::string > >::const_iterator it = tags->begin(); it != tags->end(); ++it)
3229529 q {
3329529 q if (it->first == key && condition.matches(it->second))
3421 q return straight;
3529529 q }
369809 q return !straight;
379829 q}
40std::string link_if_any(const std::vector< std::pair< std::string, std::string > >& tags)
413716 q{
423716 q std::string link;
4416546 q for (std::vector< std::pair< std::string, std::string > >::const_iterator it = tags.begin(); it != tags.end(); ++it)
4512836 q {
4612836 q if (it->second.find("www.") != std::string::npos)
4711 q link = "http://" + it->second;
4812836 q }
4916546 q for (std::vector< std::pair< std::string, std::string > >::const_iterator it = tags.begin(); it != tags.end(); ++it)
5012836 q {
5112836 q if (it->second.find("http://") != std::string::npos)
520 link = it->second;
5312836 q }
5416546 q for (std::vector< std::pair< std::string, std::string > >::const_iterator it = tags.begin(); it != tags.end(); ++it)
5512836 q {
5612836 q if (it->second.find("https://") != std::string::npos)
5711 q link = it->second;
5812836 q }
603716 q return link;
613716 q}
64std::string title_if_any(const std::string& link, const std::string& title_key,
65 const std::vector< std::pair< std::string, std::string > >& tags)
663716 q{
673716 q std::string title;
6916376 q for (std::vector< std::pair< std::string, std::string > >::const_iterator it = tags.begin(); it != tags.end(); ++it)
7012686 q {
7112686 q if (it->first == title_key)
7321 q if (link != "")
740 title += "<a href=\"" + link + "\" target=\"_blank\">";
7521 q title += "<strong>" + it->second + "</strong>";
7621 q if (link != "")
770 title += "</a>";
7821 q title += "<br/>\n";
8021 q break;
8212686 q }
843716 q return title;
853716 q}
88void Category_Filter::set_title(const std::string& title)
908818 q output = "\n<h2>" + title + "</h2>";
94void Category_Filter::set_title_key(const std::string& title_key_)
96123 q title_key = title_key_;
100template< typename TSkel > std::string elem_type() { return ""; }
1012422 qtemplate< > std::string elem_type< Node_Skeleton >() { return "Node"; }
1021164 qtemplate< > std::string elem_type< Way_Skeleton >() { return "Way"; }
103112 qtemplate< > std::string elem_type< Relation_Skeleton >() { return "Relation"; }
106template< typename TSkel >
107std::string print(const std::string& title_key,
108 const TSkel& skel, const std::vector< std::pair< std::string, std::string > >* tags)
1093716 q{
1103716 q std::string link = tags ? link_if_any(*tags) : "";
1113716 q std::string result = "\n<p>" + (tags ? title_if_any(link, title_key, *tags) : "");
1133716 q if (result == "\n<p>")
1143696 q {
1153696 q if (link != "")
11611 q result += "<a href=\"" + link + "\" target=\"_blank\">";
1173696 q std::ostringstream out;
1183696 q out<<skel.id.val();
1193696 q result += "<strong>" + elem_type< TSkel >() + " " + out.str() + "</strong>";
1203696 q if (link != "")
12111 q result += "</a>";
1223696 q result += "<br/>\n";
1233696 q }
1253716 q if (tags)
1263716 q {
1273716 q for (std::vector< std::pair< std::string, std::string > >::const_iterator it = tags->begin();
12816546 q it != tags->end(); ++it)
12912836 q result += it->first + ": " + it->second + "<br/>\n";
1303716 q }
1313716 q return result + "<p/>\n";
1323716 q}
135bool Category_Filter::consider(const Node_Skeleton& skel,
136 const std::vector< std::pair< std::string, std::string > >* tags)
137187886 q{
138187886 q std::vector< std::vector< Tag_Filter* > >::const_iterator it_conj = filter_disjunction.begin();
139394766 q for (; it_conj != filter_disjunction.end(); ++it_conj)
140209304 q {
141209304 q std::vector< Tag_Filter* >::const_iterator it = it_conj->begin();
142447654 q for (; it != it_conj->end(); ++it)
143240774 q {
144240774 q if ((*it)->matches(tags))
1452422 q break;
146240774 q }
147209304 q if (it != it_conj->end())
1482422 q break;
149209304 q }
151187886 q if (it_conj != filter_disjunction.end())
1522422 q output += print(title_key, skel, tags);
154187886 q return it_conj != filter_disjunction.end();
155187886 q}
158bool Category_Filter::consider(const Way_Skeleton& skel,
159 const std::vector< std::pair< std::string, std::string > >* tags)
1604509 q{
1614509 q std::vector< std::vector< Tag_Filter* > >::const_iterator it_conj = filter_disjunction.begin();
1628599 q for (; it_conj != filter_disjunction.end(); ++it_conj)
1635277 q {
1645277 q std::vector< Tag_Filter* >::const_iterator it = it_conj->begin();
1659947 q for (; it != it_conj->end(); ++it)
1665857 q {
1675857 q if ((*it)->matches(tags))
1681184 q break;
1695857 q }
1705277 q if (it != it_conj->end())
1711184 q break;
1725277 q }
1744509 q if (it_conj != filter_disjunction.end())
1751184 q output += print(title_key, skel, tags);
1774509 q return it_conj != filter_disjunction.end();
1784509 q}
181bool Category_Filter::consider(const Relation_Skeleton& skel,
182 const std::vector< std::pair< std::string, std::string > >* tags)
18310484 q{
18410484 q std::vector< std::vector< Tag_Filter* > >::const_iterator it_conj = filter_disjunction.begin();
18510814 q for (; it_conj != filter_disjunction.end(); ++it_conj)
186443 q {
187443 q std::vector< Tag_Filter* >::const_iterator it = it_conj->begin();
188933 q for (; it != it_conj->end(); ++it)
189603 q {
190603 q if ((*it)->matches(tags))
191112 q break;
192603 q }
193443 q if (it != it_conj->end())
194112 q break;
195443 q }
19710484 q if (it_conj != filter_disjunction.end())
198112 q output += print(title_key, skel, tags);
20010484 q return it_conj != filter_disjunction.end();
20110484 q}
204bool Output_Popup::write_http_headers()
2050{
2060 std::cout<<"Content-type: text/html; charset=utf-8\n";
2070 return true;
2080}
211void Output_Popup::write_payload_header
212 (const std::string& db_dir_, const std::string& timestamp_, const std::string& area_timestamp_)
2141818 q std::cout<<
2151818 q "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
2161818 q "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
2171818 q " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
2181818 q "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n"
2191818 q "<head>\n"
2201818 q " <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" lang=\"en\"/>\n"
2211818 q " <title>OSM3S Response</title>\n"
2221818 q "</head>\n"
2231818 q "<body>\n";
227void Output_Popup::display_remark(const std::string& text)
2280{
229 //TODO
2300}
233void Output_Popup::display_error(const std::string& text)
2340{
235 //TODO
2360}
239void Output_Popup::write_footer()
2414018 q for (std::vector< Category_Filter* >::iterator it = categories.begin(); it != categories.end(); ++it)
2422218 q std::cout<<(*it)->result();
2441818 q std::cout<<"\n</body>\n</html>\n";
248void Output_Popup::print_item(const Node_Skeleton& skel,
249 const Opaque_Geometry& geometry,
250 const std::vector< std::pair< std::string, std::string > >* tags,
251 const OSM_Element_Metadata_Skeleton< Node::Id_Type >* meta,
252 const std::map< uint32, std::string >* users,
253 Output_Mode mode,
254 const Feature_Action& action,
255 const Node_Skeleton* new_skel,
256 const Opaque_Geometry* new_geometry,
257 const std::vector< std::pair< std::string, std::string > >* new_tags,
258 const OSM_Element_Metadata_Skeleton< Node::Id_Type >* new_meta)
259123296 q{
260308756 q for (std::vector< Category_Filter* >::iterator it = categories.begin(); it != categories.end(); ++it)
261187886 q {
262187886 q if ((*it)->consider(skel, tags))
2632422 q return;
264187886 q }
265123296 q}
268void Output_Popup::print_item(const Way_Skeleton& skel,
269 const Opaque_Geometry& geometry,
270 const std::vector< std::pair< std::string, std::string > >* tags,
271 const OSM_Element_Metadata_Skeleton< Way::Id_Type >* meta,
272 const std::map< uint32, std::string >* users,
273 Output_Mode mode,
274 const Feature_Action& action,
275 const Way_Skeleton* new_skel,
276 const Opaque_Geometry* new_geometry,
277 const std::vector< std::pair< std::string, std::string > >* new_tags,
278 const OSM_Element_Metadata_Skeleton< Way::Id_Type >* new_meta)
2792719 q{
2806039 q for (std::vector< Category_Filter* >::iterator it = categories.begin(); it != categories.end(); ++it)
2814509 q {
2824509 q if ((*it)->consider(skel, tags))
2831184 q return;
2844509 q }
2852719 q}
288void Output_Popup::print_item(const Relation_Skeleton& skel,
289 const Opaque_Geometry& geometry,
290 const std::vector< std::pair< std::string, std::string > >* tags,
291 const OSM_Element_Metadata_Skeleton< Relation::Id_Type >* meta,
292 const std::map< uint32, std::string >* roles,
293 const std::map< uint32, std::string >* users,
294 Output_Mode mode,
295 const Feature_Action& action,
296 const Relation_Skeleton* new_skel,
297 const Opaque_Geometry* new_geometry,
298 const std::vector< std::pair< std::string, std::string > >* new_tags,
299 const OSM_Element_Metadata_Skeleton< Relation::Id_Type >* new_meta)
30010324 q{
30120694 q for (std::vector< Category_Filter* >::iterator it = categories.begin(); it != categories.end(); ++it)
30210484 q {
30310484 q if ((*it)->consider(skel, tags))
304112 q return;
30510484 q }
30610324 q}
309void Output_Popup::print_item(const Derived_Skeleton& skel,
310 const Opaque_Geometry& geometry,
311 const std::vector< std::pair< std::string, std::string > >* tags,
312 Output_Mode mode,
313 const Feature_Action& action)
314275017 q{
315 // Intentionally empty
316275017 q}