PGROUTING  3.2
transitiveClosure_driver.cpp File Reference
#include "drivers/transitiveClosure/transitiveClosure_driver.h"
#include <string.h>
#include <sstream>
#include <deque>
#include <vector>
#include <algorithm>
#include "transitiveClosure/pgr_transitiveClosure.hpp"
#include "cpp_common/identifiers.hpp"
#include "cpp_common/pgr_alloc.hpp"
#include "cpp_common/basePath_SSEC.hpp"
#include "cpp_common/pgr_base_graph.hpp"
Include dependency graph for transitiveClosure_driver.cpp:

Go to the source code of this file.

Functions

void do_pgr_transitiveClosure (pgr_edge_t *data_edges, size_t total_edges, transitiveClosure_rt **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
 
template<typename G >
static void get_postgres_result (G &graph, transitiveClosure_rt **return_tuples, size_t *count)
 
template<class G >
static boost::adjacency_list pgr_transitiveClosure (G &graph)
 

Function Documentation

◆ do_pgr_transitiveClosure()

void do_pgr_transitiveClosure ( pgr_edge_t data_edges,
size_t  total_edges,
transitiveClosure_rt **  return_tuples,
size_t *  return_count,
char **  log_msg,
char **  notice_msg,
char **  err_msg 
)

Definition at line 94 of file transitiveClosure_driver.cpp.

101  {
102  std::ostringstream log;
103  std::ostringstream notice;
104  std::ostringstream err;
105  try {
106  pgassert(total_edges != 0);
107  pgassert(!(*log_msg));
108  pgassert(!(*notice_msg));
109  pgassert(!(*err_msg));
110  pgassert(!(*return_tuples));
111  pgassert(*return_count == 0);
112 
113  /*
114  * Converting to C++ structures
115  */
116  std::vector<pgr_edge_t> edges(data_edges, data_edges + total_edges);
117 
118 
119  graphType gType = DIRECTED;
120  pgrouting::DirectedGraph digraph(gType);
121  digraph.insert_edges(data_edges, total_edges);
122 
124  digraph,
125  return_tuples,
126  return_count);
127 
128  *log_msg = log.str().empty()?
129  *log_msg :
130  pgr_msg(log.str().c_str());
131  *notice_msg = notice.str().empty()?
132  *notice_msg :
133  pgr_msg(notice.str().c_str());
134  } catch (AssertFailedException &except) {
135  (*return_tuples) = pgr_free(*return_tuples);
136  (*return_count) = 0;
137  err << except.what();
138  *err_msg = pgr_msg(err.str().c_str());
139  *log_msg = pgr_msg(log.str().c_str());
140  } catch (std::exception &except) {
141  (*return_tuples) = pgr_free(*return_tuples);
142  (*return_count) = 0;
143  err << except.what();
144  *err_msg = pgr_msg(err.str().c_str());
145  *log_msg = pgr_msg(log.str().c_str());
146  } catch(...) {
147  (*return_tuples) = pgr_free(*return_tuples);
148  (*return_count) = 0;
149  err << "Caught unknown exception!";
150  *err_msg = pgr_msg(err.str().c_str());
151  *log_msg = pgr_msg(log.str().c_str());
152  }
153 }

References DIRECTED, get_postgres_result(), pgrouting::graph::Pgr_base_graph< G, T_V, T_E >::insert_edges(), pgassert, pgr_free(), pgr_msg(), and AssertFailedException::what().

Referenced by process().

◆ get_postgres_result()

template<typename G >
static void get_postgres_result ( G &  graph,
transitiveClosure_rt **  return_tuples,
size_t *  count 
)
static

Definition at line 52 of file transitiveClosure_driver.cpp.

55  {
56  boost::adjacency_list <> TC;
57  TC = pgr_transitiveClosure(graph);
58  (*count) = boost::num_vertices(TC);
59  (*return_tuples) = pgr_alloc((*count), (*return_tuples));
60  size_t sequence = 0;
61  boost::graph_traits < boost::adjacency_list <> >::vertex_iterator i, end;
62  boost::graph_traits < boost::adjacency_list <> >::adjacency_iterator ai, a_end;
63  int ii = 1;
64  for (boost::tie(i, end) = boost::vertices(TC); i != end; ++i) {
65  auto u = *i;
66  int64_t* target_array = nullptr;
67  auto uid = graph.graph[u].id;
68  boost::tie(ai, a_end) = adjacent_vertices(u, TC);
69  size_t adj_siz = static_cast<size_t>(a_end - ai);
70  target_array = pgr_alloc(adj_siz , target_array);
71  int number = 0;
72  for (; ai != a_end; ++ai) {
73  auto v = *ai;
74  int64_t vid = graph.graph[v].id;
75  target_array[number++] = vid;
76  }
77 
78  (*return_tuples)[sequence] = {
79  ii++,
80  uid,
81  target_array,
82  number};
83 
84  ++sequence;
85  }
86 }

References pgr_alloc(), and pgr_transitiveClosure().

Referenced by do_pgr_transitiveClosure().

◆ pgr_transitiveClosure()

template<class G >
static boost::adjacency_list pgr_transitiveClosure ( G &  graph)
static

Definition at line 43 of file transitiveClosure_driver.cpp.

44  {
45  Pgr_transitiveClosure< G > fn_transitiveClosure;
46  return fn_transitiveClosure.transitiveClosure(graph);
47 }

References Pgr_transitiveClosure< G >::transitiveClosure().

Referenced by get_postgres_result().

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
get_postgres_result
static void get_postgres_result(G &graph, transitiveClosure_rt **return_tuples, size_t *count)
Definition: transitiveClosure_driver.cpp:52
pgr_transitiveClosure
static boost::adjacency_list pgr_transitiveClosure(G &graph)
Definition: transitiveClosure_driver.cpp:43
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_transitiveClosure
Definition: pgr_transitiveClosure.hpp:43
pgr_free
T * pgr_free(T *ptr)
Definition: pgr_alloc.hpp:77
pgrouting::graph::Pgr_base_graph
Definition: pgr_base_graph.hpp:168
Pgr_transitiveClosure::transitiveClosure
boost::adjacency_list< boost::vecS, boost::vecS, boost::directedS, boost::no_property, boost::no_property, boost::no_property, boost::listS > transitiveClosure(G &graph)
Definition: pgr_transitiveClosure.hpp:67
AssertFailedException
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:139