PGROUTING  3.2
topologicalSort_driver.cpp File Reference
#include "drivers/topologicalSort/topologicalSort_driver.h"
#include <sstream>
#include <deque>
#include <vector>
#include <algorithm>
#include <limits>
#include "topologicalSort/pgr_topologicalSort.hpp"
#include "cpp_common/pgr_alloc.hpp"
#include "cpp_common/pgr_assert.h"
Include dependency graph for topologicalSort_driver.cpp:

Go to the source code of this file.

Functions

void do_pgr_topologicalSort (pgr_edge_t *data_edges, size_t total_edges, pgr_topologicalSort_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
 
template<class G >
static std::vector< pgr_topologicalSort_tpgr_topologicalSort (G &graph)
 

Function Documentation

◆ do_pgr_topologicalSort()

void do_pgr_topologicalSort ( pgr_edge_t data_edges,
size_t  total_edges,
pgr_topologicalSort_t **  return_tuples,
size_t *  return_count,
char **  log_msg,
char **  notice_msg,
char **  err_msg 
)

Definition at line 57 of file topologicalSort_driver.cpp.

66  {
67  std::ostringstream log;
68  std::ostringstream err;
69  std::ostringstream notice;
70 
71  try {
72  pgassert(total_edges != 0);
73  pgassert(!(*log_msg));
74  pgassert(!(*notice_msg));
75  pgassert(!(*err_msg));
76  pgassert(!(*return_tuples));
77  pgassert(*return_count == 0);
78 
79  graphType gType = DIRECTED;
80 
81  std::vector<pgr_topologicalSort_t> results;
82 
83  log << "Working with Directed Graph\n";
84  pgrouting::DirectedGraph digraph(gType);
85  digraph.insert_edges(data_edges, total_edges);
86  results = pgr_topologicalSort(
87  digraph);
88 
89  auto count = results.size();
90 
91  if (count == 0) {
92  (*return_tuples) = NULL;
93  (*return_count) = 0;
94  notice <<
95  "No vertices";
96  return;
97  }
98 
99  (*return_tuples) = pgr_alloc(count, (*return_tuples));
100  for (size_t i = 0; i < count; i++) {
101  *((*return_tuples) + i) = results[i];
102  }
103  (*return_count) = count;
104 
105  pgassert(*err_msg == NULL);
106  *log_msg = log.str().empty()?
107  *log_msg :
108  pgr_msg(log.str().c_str());
109  *notice_msg = notice.str().empty()?
110  *notice_msg :
111  pgr_msg(notice.str().c_str());
112  } catch (AssertFailedException &except) {
113  (*return_tuples) = pgr_free(*return_tuples);
114  (*return_count) = 0;
115  err << except.what();
116  *err_msg = pgr_msg(err.str().c_str());
117  *log_msg = pgr_msg(log.str().c_str());
118  } catch (std::exception &except) {
119  (*return_tuples) = pgr_free(*return_tuples);
120  (*return_count) = 0;
121  err << except.what();
122  *err_msg = pgr_msg(err.str().c_str());
123  *log_msg = pgr_msg(log.str().c_str());
124  } catch(...) {
125  (*return_tuples) = pgr_free(*return_tuples);
126  (*return_count) = 0;
127  err << "Caught unknown exception!";
128  *err_msg = pgr_msg(err.str().c_str());
129  *log_msg = pgr_msg(log.str().c_str());
130  }
131 }

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

Referenced by process().

◆ pgr_topologicalSort()

template<class G >
static std::vector<pgr_topologicalSort_t> pgr_topologicalSort ( G &  graph)
static

Definition at line 47 of file topologicalSort_driver.cpp.

48  {
49  Pgr_topologicalSort< G > fn_topologicalSort;
50  return fn_topologicalSort.topologicalSort(graph);
51 }

References Pgr_topologicalSort< G >::topologicalSort().

Referenced by do_pgr_topologicalSort().

Pgr_topologicalSort
Definition: pgr_topologicalSort.hpp:47
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
pgr_topologicalSort
static std::vector< pgr_topologicalSort_t > pgr_topologicalSort(G &graph)
Definition: topologicalSort_driver.cpp:47
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
Pgr_topologicalSort::topologicalSort
std::vector< pgr_topologicalSort_t > topologicalSort(G &graph)
Definition: pgr_topologicalSort.hpp:89
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