PGROUTING  3.2
depthFirstSearch_driver.h File Reference
#include <stddef.h>
#include "c_types/pgr_edge_t.h"
#include "c_types/pgr_mst_rt.h"
Include dependency graph for depthFirstSearch_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_depthFirstSearch (pgr_edge_t *data_edges, size_t total_edges, int64_t *rootsArr, size_t size_rootsArr, bool directed, int64_t max_depth, pgr_mst_rt **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
 Performs exception handling and converts the results to postgres. More...
 

Function Documentation

◆ do_pgr_depthFirstSearch()

void do_pgr_depthFirstSearch ( pgr_edge_t data_edges,
size_t  total_edges,
int64_t *  rootsArr,
size_t  size_rootsArr,
bool  directed,
int64_t  max_depth,
pgr_mst_rt **  return_tuples,
size_t *  return_count,
char **  log_msg,
char **  notice_msg,
char **  err_msg 
)

Performs exception handling and converts the results to postgres.

Precondition
log_msg is empty
notice_msg is empty
err_msg is empty
return_tuples is empty
return_count is 0

It builds the graph using the data_edges, depending on whether the graph is directed or undirected. It also converts the C types to the C++ types, such as the rootsArr to roots vector and passes these variables to the template function pgr_depthFirstSearch which calls the main function defined in the C++ Header file. It also does exception handling.

Parameters
data_edgesthe set of edges from the SQL query
total_edgesthe total number of edges in the SQL query
rootsArrthe array containing the root vertices
size_rootsArrthe size of the array containing the root vertices
directedwhether the graph is directed or undirected
max_depththe maximum depth of traversal
return_tuplesthe rows in the result
return_countthe count of rows in the result
log_msgstores the log message
notice_msgstores the notice message
err_msgstores the error message
Returns
void

Definition at line 118 of file depthFirstSearch_driver.cpp.

133  {
134  std::ostringstream log;
135  std::ostringstream err;
136  std::ostringstream notice;
137  try {
138  pgassert(!(*log_msg));
139  pgassert(!(*notice_msg));
140  pgassert(!(*err_msg));
141  pgassert(!(*return_tuples));
142  pgassert(*return_count == 0);
143 
144  std::vector < int64_t > roots(rootsArr, rootsArr + size_rootsArr);
145 
146  std::vector < pgr_mst_rt > results;
147 
148  graphType gType = directed ? DIRECTED : UNDIRECTED;
149 
150  if (directed) {
151  pgrouting::DirectedGraph digraph(gType);
152  digraph.insert_edges(data_edges, total_edges);
153 
154  results = pgr_depthFirstSearch(
155  digraph,
156  roots,
157  directed,
158  max_depth);
159  } else {
160  pgrouting::UndirectedGraph undigraph(gType);
161  undigraph.insert_edges(data_edges, total_edges);
162 
163  results = pgr_depthFirstSearch(
164  undigraph,
165  roots,
166  directed,
167  max_depth);
168  }
169 
170  auto count = results.size();
171 
172  if (count == 0) {
173  (*return_tuples) = NULL;
174  (*return_count) = 0;
175  notice << "No traversal found";
176  *log_msg = pgr_msg(notice.str().c_str());
177  return;
178  }
179 
180  (*return_tuples) = pgr_alloc(count, (*return_tuples));
181  for (size_t i = 0; i < count; i++) {
182  *((*return_tuples) + i) = results[i];
183  }
184  (*return_count) = count;
185 
186  pgassert(*err_msg == NULL);
187  *log_msg = log.str().empty()?
188  *log_msg :
189  pgr_msg(log.str().c_str());
190  *notice_msg = notice.str().empty()?
191  *notice_msg :
192  pgr_msg(notice.str().c_str());
193  } catch (AssertFailedException &except) {
194  (*return_tuples) = pgr_free(*return_tuples);
195  (*return_count) = 0;
196  err << except.what();
197  *err_msg = pgr_msg(err.str().c_str());
198  *log_msg = pgr_msg(log.str().c_str());
199  } catch (std::exception &except) {
200  (*return_tuples) = pgr_free(*return_tuples);
201  (*return_count) = 0;
202  err << except.what();
203  *err_msg = pgr_msg(err.str().c_str());
204  *log_msg = pgr_msg(log.str().c_str());
205  } catch(...) {
206  (*return_tuples) = pgr_free(*return_tuples);
207  (*return_count) = 0;
208  err << "Caught unknown exception!";
209  *err_msg = pgr_msg(err.str().c_str());
210  *log_msg = pgr_msg(log.str().c_str());
211  }
212 }

References DIRECTED, pgrouting::graph::Pgr_base_graph< G, T_V, T_E >::insert_edges(), pgassert, pgr_alloc(), pgr_depthFirstSearch(), 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
pgr_depthFirstSearch
std::vector< pgr_mst_rt > pgr_depthFirstSearch(G &graph, std::vector< int64_t > roots, bool directed, int64_t max_depth)
Calls the main function defined in the C++ Header file.
Definition: depthFirstSearch_driver.cpp:73
UNDIRECTED
@ UNDIRECTED
Definition: graph_enum.h:30
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
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139