PGROUTING  3.2
strongComponents_driver.h File Reference
#include <stddef.h>
#include "c_types/pgr_edge_t.h"
#include "c_types/pgr_components_rt.h"
Include dependency graph for strongComponents_driver.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void do_pgr_strongComponents (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_strongComponents()

void do_pgr_strongComponents ( 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 45 of file strongComponents_driver.cpp.

52  {
53  std::ostringstream log;
54  std::ostringstream err;
55  std::ostringstream notice;
56  try {
57  pgassert(!(*log_msg));
58  pgassert(!(*notice_msg));
59  pgassert(!(*err_msg));
60  pgassert(!(*return_tuples));
61  pgassert(*return_count == 0);
62  pgassert(total_edges != 0);
63 
64  graphType gType = DIRECTED;
65 
66  pgrouting::DirectedGraph digraph(gType);
67  digraph.insert_edges(data_edges, total_edges);
68  auto results(pgrouting::algorithms::strongComponents(digraph));
69 
70  auto count = results.size();
71 
72  if (count == 0) {
73  (*return_tuples) = NULL;
74  (*return_count) = 0;
75  notice <<
76  "No components found";
77  return;
78  }
79 
80  (*return_tuples) = pgr_alloc(count, (*return_tuples));
81  for (size_t i = 0; i < count; i++) {
82  *((*return_tuples) + i) = results[i];
83  }
84  (*return_count) = count;
85 
86  pgassert(*err_msg == NULL);
87  *log_msg = log.str().empty()?
88  *log_msg :
89  pgr_msg(log.str().c_str());
90  *notice_msg = notice.str().empty()?
91  *notice_msg :
92  pgr_msg(notice.str().c_str());
93  } catch (AssertFailedException &except) {
94  (*return_tuples) = pgr_free(*return_tuples);
95  (*return_count) = 0;
96  err << except.what();
97  *err_msg = pgr_msg(err.str().c_str());
98  *log_msg = pgr_msg(log.str().c_str());
99  } catch (std::exception &except) {
100  (*return_tuples) = pgr_free(*return_tuples);
101  (*return_count) = 0;
102  err << except.what();
103  *err_msg = pgr_msg(err.str().c_str());
104  *log_msg = pgr_msg(log.str().c_str());
105  } catch(...) {
106  (*return_tuples) = pgr_free(*return_tuples);
107  (*return_count) = 0;
108  err << "Caught unknown exception!";
109  *err_msg = pgr_msg(err.str().c_str());
110  *log_msg = pgr_msg(log.str().c_str());
111  }
112 }

References DIRECTED, pgrouting::graph::Pgr_base_graph< G, T_V, T_E >::insert_edges(), pgassert, pgr_alloc(), pgr_free(), pgr_msg(), pgrouting::algorithms::strongComponents(), 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
graphType
graphType
Definition: graph_enum.h:30
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
pgrouting::algorithms::strongComponents
std::vector< pgr_components_rt > strongComponents(pgrouting::DirectedGraph &graph)
Strongly Connected Components Vertex Version.
Definition: pgr_components.cpp:71
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139