PGROUTING  3.2
articulationPoints_driver.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: articulationPoints_driver.cpp
3 
4 Generated with Template by:
5 Copyright (c) 2015 pgRouting developers
7 
8 Function's developer:
9 Copyright (c) 2017 Maoguang Wang
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 
31 
32 #include <sstream>
33 #include <deque>
34 #include <vector>
35 
37 
38 #include "cpp_common/pgr_alloc.hpp"
39 #include "cpp_common/pgr_assert.h"
41 
42 
43 void
45  pgr_edge_t *data_edges,
46  size_t total_edges,
47  int64_t **return_tuples,
48  size_t *return_count,
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  try {
56  pgassert(!(*log_msg));
57  pgassert(!(*notice_msg));
58  pgassert(!(*err_msg));
59  pgassert(!(*return_tuples));
60  pgassert(*return_count == 0);
61  pgassert(total_edges != 0);
62 
63  graphType gType = UNDIRECTED;
64 
65  log << "Working with Undirected Graph\n";
66  pgrouting::UndirectedGraph undigraph(gType);
67  undigraph.insert_edges(data_edges, total_edges);
68  auto results(pgrouting::algorithms::articulationPoints(undigraph));
69 
70  auto count = results.size();
71 
72  if (count == 0) {
73  (*return_tuples) = NULL;
74  (*return_count) = 0;
75  notice <<
76  "No paths found between start_vid and end_vid vertices";
77  return;
78  }
79 
80  (*return_tuples) = pgr_alloc(count, (*return_tuples));
81  size_t i = 0;
82  for (const auto vertex : results) {
83  *((*return_tuples) + i) = vertex;
84  ++i;
85  }
86 
87  (*return_count) = count;
88 
89  pgassert(*err_msg == NULL);
90  *log_msg = log.str().empty()?
91  *log_msg :
92  pgr_msg(log.str().c_str());
93  *notice_msg = notice.str().empty()?
94  *notice_msg :
95  pgr_msg(notice.str().c_str());
96  } catch (AssertFailedException &except) {
97  (*return_tuples) = pgr_free(*return_tuples);
98  (*return_count) = 0;
99  err << except.what();
100  *err_msg = pgr_msg(err.str().c_str());
101  *log_msg = pgr_msg(log.str().c_str());
102  } catch (std::exception &except) {
103  (*return_tuples) = pgr_free(*return_tuples);
104  (*return_count) = 0;
105  err << except.what();
106  *err_msg = pgr_msg(err.str().c_str());
107  *log_msg = pgr_msg(log.str().c_str());
108  } catch(...) {
109  (*return_tuples) = pgr_free(*return_tuples);
110  (*return_count) = 0;
111  err << "Caught unknown exception!";
112  *err_msg = pgr_msg(err.str().c_str());
113  *log_msg = pgr_msg(log.str().c_str());
114  }
115 }
116 
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
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
pgrouting::algorithms::articulationPoints
Identifiers< int64_t > articulationPoints(pgrouting::UndirectedGraph &graph)
Articulation Points.
Definition: pgr_components.cpp:126
articulationPoints_driver.h
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
pgr_components.hpp
UNDIRECTED
@ UNDIRECTED
Definition: graph_enum.h:30
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
graphType
graphType
Definition: graph_enum.h:30
pgr_assert.h
An assert functionality that uses C++ throw().
pgr_free
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:77
pgrouting::graph::Pgr_base_graph
Definition: pgr_base_graph.hpp:168
do_pgr_articulationPoints
void do_pgr_articulationPoints(pgr_edge_t *data_edges, size_t total_edges, int64_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
Definition: articulationPoints_driver.cpp:44
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139