PGROUTING  3.2
lengauerTarjanDominatorTree_driver.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: lengauerTarjanDominatorTree_driver.pp
3 
4 Generated with Template by:
5 Copyright (c) 2015 pgRouting developers
7 
8 Function's developer:
9 Copyright (c) 2020 Prakash Tiwari
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 
31 
32 
33 #include <string>
34 #include <sstream>
35 #include <deque>
36 #include <vector>
37 #include <algorithm>
39 #include "cpp_common/pgr_alloc.hpp"
42 #include "c_types/pgr_ltdtree_rt.h"
45 
46 
47 /************************************************************
48  edges_sql TEXT
49  ***********************************************************/
50 void
52  pgr_edge_t *data_edges,
53  size_t total_edges,
54  int64_t root_vertex,
55  pgr_ltdtree_rt **return_tuples,
56  size_t *return_count,
57  char **log_msg,
58  char **notice_msg,
59  char **err_msg) {
60  std::ostringstream log;
61  std::ostringstream notice;
62  std::ostringstream err;
63 
64 
65  try {
66  pgassert(total_edges != 0);
67  pgassert(!(*log_msg));
68  pgassert(!(*notice_msg));
69  pgassert(!(*err_msg));
70  pgassert(!(*return_tuples));
71  pgassert(*return_count == 0);
72 
73  std::string logstr;
74 
75 /***********************Working with graph**************************/
76 
77  graphType gType = DIRECTED;
78  pgrouting::DirectedGraph digraph(gType);
79  digraph.insert_edges(data_edges, total_edges);
80  std::vector<pgr_ltdtree_rt> results;
82  results = fn_LTDTree.pgr_ltdtree(digraph, root_vertex);
83 
84  logstr += fn_LTDTree.get_log();
85  log << logstr;
86 
87  auto count = results.size();
88 
89  if (count == 0) {
90  (*return_tuples) = NULL;
91  (*return_count) = 0;
92  notice << "No result found";
93  *log_msg = log.str().empty()?
94  *log_msg :
95  pgr_msg(log.str().c_str());
96  *notice_msg = notice.str().empty()?
97  *notice_msg :
98  pgr_msg(notice.str().c_str());
99  return;
100  }
101  (*return_tuples) = pgr_alloc(count, (*return_tuples));
102  for (size_t i = 0; i < count; i++) {
103  *((*return_tuples) + i) = results[i];
104  }
105  (*return_count) = count;
106 
107  pgassert(*err_msg == NULL);
108  *log_msg = log.str().empty()?
109  *log_msg :
110  pgr_msg(log.str().c_str());
111  *notice_msg = notice.str().empty()?
112  *notice_msg :
113  pgr_msg(notice.str().c_str());
114  } catch (AssertFailedException &except) {
115  (*return_tuples) = pgr_free(*return_tuples);
116  (*return_count) = 0;
117  err << except.what();
118  *err_msg = pgr_msg(err.str().c_str());
119  *log_msg = pgr_msg(log.str().c_str());
120  } catch (std::exception &except) {
121  (*return_tuples) = pgr_free(*return_tuples);
122  (*return_count) = 0;
123  err << except.what();
124  *err_msg = pgr_msg(err.str().c_str());
125  *log_msg = pgr_msg(log.str().c_str());
126  } catch(...) {
127  (*return_tuples) = pgr_free(*return_tuples);
128  (*return_count) = 0;
129  err << "Caught unknown exception!";
130  *err_msg = pgr_msg(err.str().c_str());
131  *log_msg = pgr_msg(log.str().c_str());
132  }
133 }
pgr_lengauerTarjanDominatorTree_driver.hpp
pgrouting::functions::Pgr_LTDTree
Definition: pgr_lengauerTarjanDominatorTree_driver.hpp:53
pgr_alloc
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:66
pgr_base_graph.hpp
pgr_edge_t
Definition: pgr_edge_t.h:37
pgrouting::functions::Pgr_LTDTree::pgr_ltdtree
std::vector< pgr_ltdtree_rt > pgr_ltdtree(G &graph, int64_t root)
Definition: pgr_lengauerTarjanDominatorTree_driver.hpp:58
pgr_msg
char * pgr_msg(const std::string &msg)
Definition: pgr_alloc.cpp:30
AssertFailedException::what
virtual const char * what() const
Definition: pgr_assert.cpp:67
pgr_ltdtree_rt.h
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
do_pgr_LTDTree
void do_pgr_LTDTree(pgr_edge_t *data_edges, size_t total_edges, int64_t root_vertex, pgr_ltdtree_rt **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
Definition: lengauerTarjanDominatorTree_driver.cpp:51
pgrouting::graph::Pgr_base_graph::insert_edges
void insert_edges(const T *edges, size_t count)
Inserts count edges of type T into the graph.
Definition: pgr_base_graph.hpp:357
pgr_alloc.hpp
pgrouting::Pgr_messages::get_log
std::string get_log() const
get_log
Definition: pgr_messages.cpp:36
graphType
graphType
Definition: graph_enum.h:30
DIRECTED
@ DIRECTED
Definition: graph_enum.h:30
lengauerTarjanDominatorTree_driver.h
pgr_free
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:77
pgr_ltdtree_rt
Definition: pgr_ltdtree_rt.h:35
pgrouting::graph::Pgr_base_graph
Definition: pgr_base_graph.hpp:168
identifiers.hpp
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139
basePath_SSEC.hpp