PGROUTING  3.2
johnson_driver.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: johnson_driver.cpp
3 
4 Generated with Template by:
5 Copyright (c) 2015 pgRouting developers
7 
8 Function's developer:
9 Copyright (c) 2015 Celia Virginia Vergara Castillo
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_assert.h"
39 
40 
41 void
43  pgr_edge_t *data_edges,
44  size_t total_tuples,
45  bool directed,
46  Matrix_cell_t **return_tuples,
47  size_t *return_count,
48  char ** log_msg,
49  char ** err_msg) {
50  std::ostringstream log;
51  std::ostringstream err;
52 
53  try {
54  pgassert(!(*log_msg));
55  pgassert(!(*err_msg));
56  pgassert(!(*return_tuples));
57  pgassert(*return_count == 0);
58 
59  graphType gType = directed? DIRECTED: UNDIRECTED;
60 
61  if (directed) {
62  log << "Processing Directed graph\n";
63  pgrouting::DirectedGraph digraph(gType);
64  digraph.insert_edges(data_edges, total_tuples);
65  pgr_johnson(digraph, *return_count, return_tuples);
66  } else {
67  log << "Processing Undirected graph\n";
68  pgrouting::UndirectedGraph undigraph(gType);
69  undigraph.insert_edges(data_edges, total_tuples);
70  pgr_johnson(undigraph, *return_count, return_tuples);
71  }
72 
73 
74  if (*return_count == 0) {
75  log << "No result generated, report this error\n";
76  *log_msg = pgr_msg(err.str().c_str());
77  *return_tuples = NULL;
78  *return_count = 0;
79  return;
80  }
81 
82 
83  *log_msg = log.str().empty()?
84  *log_msg :
85  pgr_msg(log.str().c_str());
86  } catch (AssertFailedException &except) {
87  (*return_tuples) = pgr_free(*return_tuples);
88  (*return_count) = 0;
89  err << except.what();
90  *err_msg = pgr_msg(err.str().c_str());
91  *log_msg = pgr_msg(log.str().c_str());
92  } catch (std::exception &except) {
93  (*return_tuples) = pgr_free(*return_tuples);
94  (*return_count) = 0;
95  err << except.what();
96  *err_msg = pgr_msg(err.str().c_str());
97  *log_msg = pgr_msg(log.str().c_str());
98  } catch(...) {
99  (*return_tuples) = pgr_free(*return_tuples);
100  (*return_count) = 0;
101  err << "Caught unknown exception!";
102  *err_msg = pgr_msg(err.str().c_str());
103  *log_msg = pgr_msg(log.str().c_str());
104  }
105 }
johnson_driver.h
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
pgr_allpairs.hpp
do_pgr_johnson
void do_pgr_johnson(pgr_edge_t *data_edges, size_t total_tuples, bool directed, Matrix_cell_t **return_tuples, size_t *return_count, char **log_msg, char **err_msg)
Definition: johnson_driver.cpp:42
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
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
graphType
graphType
Definition: graph_enum.h:30
pgr_assert.h
An assert functionality that uses C++ throw().
pgr_johnson
void pgr_johnson(G &graph, std::vector< Matrix_cell_t > &rows)
Definition: pgr_allpairs.hpp:57
DIRECTED
@ DIRECTED
Definition: graph_enum.h:30
pgr_free
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:77
pgrouting::graph::Pgr_base_graph
Definition: pgr_base_graph.hpp:168
matrix_cell
Definition: matrix_cell_t.h:37
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139