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

overpass_api/output_formats/output_popup.cc

166 of 176 instrumented lines run by the suite (94.3%) 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
28681719 q{
29681719 q if (!tags)
30574499 q return false;
31795298 q for (std::vector< std::pair< std::string, std::string > >::const_iterator it = tags->begin(); it != tags->end(); ++it)
32688148 q {
33688148 q if (it->first == key && condition.matches(it->second))
3472 q return straight;
35688148 q }
36107157 q return !straight;
37107228 q}
40std::string link_if_any(const std::vector< std::pair< std::string, std::string > >& tags)
4161996 q{
4261996 q std::string link;
44280506 q for (std::vector< std::pair< std::string, std::string > >::const_iterator it = tags.begin(); it != tags.end(); ++it)
45218516 q {
46218516 q if (it->second.find("www.") != std::string::npos)
47853 q link = "http://" + it->second;
48218516 q }
49280506 q for (std::vector< std::pair< std::string, std::string > >::const_iterator it = tags.begin(); it != tags.end(); ++it)
50218516 q {
51218516 q if (it->second.find("http://") != std::string::npos)
52304 q link = it->second;
53218516 q }
54280506 q for (std::vector< std::pair< std::string, std::string > >::const_iterator it = tags.begin(); it != tags.end(); ++it)
55218516 q {
56218516 q if (it->second.find("https://") != std::string::npos)
57733 q link = it->second;
58218516 q }
6061996 q return link;
6161996 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)
6661996 q{
6761996 q std::string title;
69280266 q for (std::vector< std::pair< std::string, std::string > >::const_iterator it = tags.begin(); it != tags.end(); ++it)
70218386 q {
71218386 q if (it->first == title_key)
72111 q {
73111 q if (link != "")
740 title += "<a href=\"" + link + "\" target=\"_blank\">";
75111 q title += "<strong>" + it->second + "</strong>";
76111 q if (link != "")
770 title += "</a>";
78111 q title += "<br/>\n";
80111 q break;
81111 q }
82218386 q }
8461996 q return title;
8561996 q}
88void Category_Filter::set_title(const std::string& title)
8910821 q{
9010821 q output = "\n<h2>" + title + "</h2>";
9110821 q}
94void Category_Filter::set_title_key(const std::string& title_key_)
96205 q title_key = title_key_;
100template< typename TSkel > std::string elem_type() { return ""; }
10115253 qtemplate< > std::string elem_type< Node_Skeleton >() { return "Node"; }
10246214 qtemplate< > std::string elem_type< Way_Skeleton >() { return "Way"; }
103421 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)
10961996 q{
11061996 q std::string link = tags ? link_if_any(*tags) : "";
11161996 q std::string result = "\n<p>" + (tags ? title_if_any(link, title_key, *tags) : "");
11361996 q if (result == "\n<p>")
11461886 q {
11561886 q if (link != "")
116894 q result += "<a href=\"" + link + "\" target=\"_blank\">";
11761886 q std::ostringstream out;
11861886 q out<<skel.id.val();
11961886 q result += "<strong>" + elem_type< TSkel >() + " " + out.str() + "</strong>";
12061886 q if (link != "")
121894 q result += "</a>";
12261886 q result += "<br/>\n";
12361886 q }
12561996 q if (tags)
12661996 q {
12761996 q for (std::vector< std::pair< std::string, std::string > >::const_iterator it = tags->begin();
128280506 q it != tags->end(); ++it)
129218516 q result += it->first + ": " + it->second + "<br/>\n";
13061996 q }
13161996 q return result + "<p/>\n";
13261996 q}
135bool Category_Filter::consider(const Node_Skeleton& skel,
136 const std::vector< std::pair< std::string, std::string > >* tags)
137526635 q{
138526635 q std::vector< std::vector< Tag_Filter* > >::const_iterator it_conj = filter_disjunction.begin();
1391042165 q for (; it_conj != filter_disjunction.end(); ++it_conj)
140530865 q {
141530865 q std::vector< Tag_Filter* >::const_iterator it = it_conj->begin();
1421083275 q for (; it != it_conj->end(); ++it)
143567745 q {
144567745 q if ((*it)->matches(tags))
14515333 q break;
146567745 q }
147530865 q if (it != it_conj->end())
14815333 q break;
149530865 q }
151526635 q if (it_conj != filter_disjunction.end())
15215333 q output += print(title_key, skel, tags);
154526635 q return it_conj != filter_disjunction.end();
155526635 q}
158bool Category_Filter::consider(const Way_Skeleton& skel,
159 const std::vector< std::pair< std::string, std::string > >* tags)
16066786 q{
16166786 q std::vector< std::vector< Tag_Filter* > >::const_iterator it_conj = filter_disjunction.begin();
16277226 q for (; it_conj != filter_disjunction.end(); ++it_conj)
16356685 q {
16456685 q std::vector< Tag_Filter* >::const_iterator it = it_conj->begin();
16567185 q for (; it != it_conj->end(); ++it)
16656745 q {
16756745 q if ((*it)->matches(tags))
16846244 q break;
16956745 q }
17056685 q if (it != it_conj->end())
17146244 q break;
17256685 q }
17466786 q if (it_conj != filter_disjunction.end())
17546244 q output += print(title_key, skel, tags);
17766786 q return it_conj != filter_disjunction.end();
17866786 q}
181bool Category_Filter::consider(const Relation_Skeleton& skel,
182 const std::vector< std::pair< std::string, std::string > >* tags)
183119454 q{
184119454 q std::vector< std::vector< Tag_Filter* > >::const_iterator it_conj = filter_disjunction.begin();
185175424 q for (; it_conj != filter_disjunction.end(); ++it_conj)
18656392 q {
18756392 q std::vector< Tag_Filter* >::const_iterator it = it_conj->begin();
188113202 q for (; it != it_conj->end(); ++it)
18957232 q {
19057232 q if ((*it)->matches(tags))
191421 q break;
19257232 q }
19356392 q if (it != it_conj->end())
194421 q break;
19556392 q }
197119454 q if (it_conj != filter_disjunction.end())
198421 q output += print(title_key, skel, tags);
200119454 q return it_conj != filter_disjunction.end();
201119454 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_)
2142121 q std::cout<<
2152121 q "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
2162121 q "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"
2172121 q " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
2182121 q "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n"
2192121 q "<head>\n"
2202121 q " <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" lang=\"en\"/>\n"
2212121 q " <title>OSM3S Response</title>\n"
2222121 q "</head>\n"
2232121 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()
2414821 q for (std::vector< Category_Filter* >::iterator it = categories.begin(); it != categories.end(); ++it)
2422721 q std::cout<<(*it)->result();
2442121 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)
259489755 q{
2601001055 q for (std::vector< Category_Filter* >::iterator it = categories.begin(); it != categories.end(); ++it)
261526635 q {
262526635 q if ((*it)->consider(skel, tags))
26315333 q return;
264526635 q }
265489755 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)
27956706 q{
28077246 q for (std::vector< Category_Filter* >::iterator it = categories.begin(); it != categories.end(); ++it)
28166786 q {
28266786 q if ((*it)->consider(skel, tags))
28346244 q return;
28466786 q }
28556706 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)
30064744 q{
301183774 q for (std::vector< Category_Filter* >::iterator it = categories.begin(); it != categories.end(); ++it)
302119454 q {
303119454 q if ((*it)->consider(skel, tags))
304421 q return;
305119454 q }
30664744 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)
314105321 q{
315 // Intentionally empty
316105321 q}