PGROUTING  3.2
boyerMyrvold_driver.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: boyerMyrvold_driver.cpp
3 
4 Generated with Template by:
5 Copyright (c) 2020 pgRouting developers
7 
8 Function's developer:
9 Copyright (c) 2020 Himanshu Raj
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 <vector>
33 #include <algorithm>
34 #include <string>
35 
36 #include "cpp_common/pgr_alloc.hpp"
37 #include "cpp_common/pgr_assert.h"
38 #include "c_types/pgr_boyer_t.h"
39 
42 
43 
44 
45 void
47  pgr_edge_t *data_edges,
48  size_t total_edges,
49 
50  pgr_boyer_t **return_tuples,
51  size_t *return_count,
52  char ** log_msg,
53  char ** notice_msg,
54  char ** err_msg) {
55  std::ostringstream log;
56  std::ostringstream err;
57  std::ostringstream notice;
58  try {
59  pgassert(!(*log_msg));
60  pgassert(!(*notice_msg));
61  pgassert(!(*err_msg));
62  pgassert(!(*return_tuples));
63  pgassert(*return_count == 0);
64  pgassert(total_edges != 0);
65 
66  std::vector<pgr_boyer_t> results;
67  std::string logstr;
68 
69  graphType gType = UNDIRECTED;
70  log << "Working with Undirected Graph\n";
71  pgrouting::UndirectedGraph undigraph(gType);
72  undigraph.insert_edges(data_edges, total_edges);
74  results = fn_boyerMyrvold.boyerMyrvold(undigraph);
75  logstr += fn_boyerMyrvold.get_log();
76  log << logstr;
77 
78 
79  auto count = results.size();
80 
81  if (count == 0) {
82  (*return_tuples) = NULL;
83  (*return_count) = 0;
84  notice <<
85  "No Vertices";
86  *log_msg = pgr_msg(notice.str().c_str());
87  return;
88  }
89 
90  (*return_tuples) = pgr_alloc(count, (*return_tuples));
91  log << "\nConverting a set of traversals into the tuples";
92  for (size_t i = 0; i < count; i++) {
93  *((*return_tuples) + i) = results[i];
94  }
95  (*return_count) = count;
96 
97  pgassert(*err_msg == NULL);
98  *log_msg = log.str().empty()?
99  *log_msg :
100  pgr_msg(log.str().c_str());
101  *notice_msg = notice.str().empty()?
102  *notice_msg :
103  pgr_msg(notice.str().c_str());
104  } catch (AssertFailedException &except) {
105  (*return_tuples) = pgr_free(*return_tuples);
106  (*return_count) = 0;
107  err << except.what();
108  *err_msg = pgr_msg(err.str().c_str());
109  *log_msg = pgr_msg(log.str().c_str());
110  } catch (std::exception &except) {
111  (*return_tuples) = pgr_free(*return_tuples);
112  (*return_count) = 0;
113  err << except.what();
114  *err_msg = pgr_msg(err.str().c_str());
115  *log_msg = pgr_msg(log.str().c_str());
116  } catch(...) {
117  (*return_tuples) = pgr_free(*return_tuples);
118  (*return_count) = 0;
119  err << "Caught unknown exception!";
120  *err_msg = pgr_msg(err.str().c_str());
121  *log_msg = pgr_msg(log.str().c_str());
122  }
123 }
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
boyerMyrvold_driver.h
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
pgr_alloc.hpp
do_pgr_boyerMyrvold
void do_pgr_boyerMyrvold(pgr_edge_t *data_edges, size_t total_edges, pgr_boyer_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
Definition: boyerMyrvold_driver.cpp:46
pgrouting::Pgr_messages::get_log
std::string get_log() const
get_log
Definition: pgr_messages.cpp:36
pgr_boyer_t
Definition: pgr_boyer_t.h:37
graphType
graphType
Definition: graph_enum.h:30
pgr_assert.h
An assert functionality that uses C++ throw().
pgr_boyer_t.h
pgr_free
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:77
pgrouting::graph::Pgr_base_graph
Definition: pgr_base_graph.hpp:168
pgrouting::functions::Pgr_boyerMyrvold
Definition: pgr_boyerMyrvold.hpp:47
pgrouting::functions::Pgr_boyerMyrvold::boyerMyrvold
std::vector< pgr_boyer_t > boyerMyrvold(G &graph)
Definition: pgr_boyerMyrvold.hpp:52
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139
pgr_boyerMyrvold.hpp