1 /*PGR-GNU*****************************************************************
2 File: isPlanar_driver.cpp
3 
4 Generated with Template by:
5 Copyright (c) 2020 pgRouting developers
6 Mail: project@pgrouting.org
7 
8 Function's developer:
9 Copyright (c) 2020 Himanshu Raj
10 Mail: raj.himanshu2@gmail.com
11 
12 ------
13 
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18 
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23 
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 
28 ********************************************************************PGR-GNU*/
29 
30 #include "drivers/planar/isPlanar_driver.h"
31 
32 #include <vector>
33 #include <algorithm>
34 #include <string>
35 
36 #include "cpp_common/pgr_alloc.hpp"
37 #include "cpp_common/pgr_assert.h"
38 
39 #include "planar/pgr_boyerMyrvold.hpp"
40 #include "cpp_common/pgr_base_graph.hpp"
41 
42 
43 
44 bool
do_pgr_isPlanar(pgr_edge_t * data_edges,size_t total_edges,char ** log_msg,char ** notice_msg,char ** err_msg)45 do_pgr_isPlanar(
46                 pgr_edge_t  *data_edges,
47                 size_t total_edges,
48 
49                 char ** log_msg,
50                 char ** notice_msg,
51                 char ** err_msg) {
52     std::ostringstream log;
53     std::ostringstream err;
54     std::ostringstream notice;
55     bool result = false;
56     try {
57         pgassert(!(*log_msg));
58         pgassert(!(*notice_msg));
59         pgassert(!(*err_msg));
60         pgassert(total_edges != 0);
61 
62         graphType gType = UNDIRECTED;
63         log << "Working with Undirected Graph\n";
64         pgrouting::UndirectedGraph undigraph(gType);
65         undigraph.insert_edges(data_edges, total_edges);
66         pgrouting::functions::Pgr_boyerMyrvold<pgrouting::UndirectedGraph> fn_isPlanar;
67         result = fn_isPlanar.isPlanar(undigraph);
68         return result;
69 
70         pgassert(*err_msg == NULL);
71         *log_msg = log.str().empty()?
72             *log_msg :
73             pgr_msg(log.str().c_str());
74         *notice_msg = notice.str().empty()?
75             *notice_msg :
76             pgr_msg(notice.str().c_str());
77     } catch (AssertFailedException &except) {
78         err << except.what();
79         *err_msg = pgr_msg(err.str().c_str());
80         *log_msg = pgr_msg(log.str().c_str());
81     } catch (std::exception &except) {
82         err << except.what();
83         *err_msg = pgr_msg(err.str().c_str());
84         *log_msg = pgr_msg(log.str().c_str());
85     } catch(...) {
86         err << "Caught unknown exception!";
87         *err_msg = pgr_msg(err.str().c_str());
88         *log_msg = pgr_msg(log.str().c_str());
89     }
90       return result;
91 }
92