PGROUTING  3.2
connectedComponents_driver.cpp File Reference
#include "drivers/components/connectedComponents_driver.h"
#include <sstream>
#include <deque>
#include <vector>
#include "cpp_common/pgr_alloc.hpp"
#include "cpp_common/pgr_assert.h"
#include "cpp_common/pgr_base_graph.hpp"
#include "components/pgr_components.hpp"
Include dependency graph for connectedComponents_driver.cpp:

Go to the source code of this file.

Functions

void do_pgr_connectedComponents (pgr_edge_t *data_edges, size_t total_edges, pgr_components_rt **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
 

Function Documentation

◆ do_pgr_connectedComponents()

void do_pgr_connectedComponents ( pgr_edge_t data_edges,
size_t  total_edges,
pgr_components_rt **  return_tuples,
size_t *  return_count,
char **  log_msg,
char **  notice_msg,
char **  err_msg 
)

Definition at line 47 of file connectedComponents_driver.cpp.

54  {
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  graphType gType = UNDIRECTED;
67 
68  log << "Working with Undirected Graph\n";
69  pgrouting::UndirectedGraph undigraph(gType);
70  undigraph.insert_edges(data_edges, total_edges);
71  auto results(pgrouting::algorithms::pgr_connectedComponents(undigraph));
72 
73  auto count = results.size();
74 
75  if (count == 0) {
76  (*return_tuples) = NULL;
77  (*return_count) = 0;
78  notice <<
79  "No paths found between start_vid and end_vid vertices";
80  return;
81  }
82 
83  (*return_tuples) = pgr_alloc(count, (*return_tuples));
84  for (size_t i = 0; i < count; i++) {
85  *((*return_tuples) + i) = results[i];
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 }

References pgrouting::graph::Pgr_base_graph< G, T_V, T_E >::insert_edges(), pgassert, pgr_alloc(), pgrouting::algorithms::pgr_connectedComponents(), pgr_free(), pgr_msg(), UNDIRECTED, and AssertFailedException::what().

Referenced by process().

pgr_alloc
T * pgr_alloc(std::size_t size, T *ptr)
allocates memory
Definition: pgr_alloc.hpp:66
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
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
UNDIRECTED
@ UNDIRECTED
Definition: graph_enum.h:30
graphType
graphType
Definition: graph_enum.h:30
pgrouting::algorithms::pgr_connectedComponents
std::vector< pgr_components_rt > pgr_connectedComponents(pgrouting::UndirectedGraph &graph)
works for undirected graph
Definition: pgr_components.cpp:47
pgr_free
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:77
pgrouting::graph::Pgr_base_graph
Definition: pgr_base_graph.hpp:168
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139