PGROUTING  3.2
sequentialVertexColoring_driver.cpp File Reference

Handles actual calling of function in the pgr_sequentialVertexColoring.hpp file. More...

#include "drivers/coloring/sequentialVertexColoring_driver.h"
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
#include "cpp_common/pgr_alloc.hpp"
#include "cpp_common/pgr_assert.h"
#include "coloring/pgr_sequentialVertexColoring.hpp"
Include dependency graph for sequentialVertexColoring_driver.cpp:

Go to the source code of this file.

Functions

void do_pgr_sequentialVertexColoring (pgr_edge_t *data_edges, size_t total_edges, pgr_vertex_color_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...
 
template<class G >
std::vector< pgr_vertex_color_rtpgr_sequentialVertexColoring (G &graph)
 Calls the main function defined in the C++ Header file. More...
 

Detailed Description

Handles actual calling of function in the pgr_sequentialVertexColoring.hpp file.

Definition in file sequentialVertexColoring_driver.cpp.

Function Documentation

◆ do_pgr_sequentialVertexColoring()

void do_pgr_sequentialVertexColoring ( pgr_edge_t data_edges,
size_t  total_edges,
pgr_vertex_color_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 undirected graph using the data_edges variable. Then, it passes the required variables to the template function pgr_sequentialVertexColoring 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
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 93 of file sequentialVertexColoring_driver.cpp.

102  {
103  std::ostringstream log;
104  std::ostringstream err;
105  std::ostringstream notice;
106  try {
107  pgassert(!(*log_msg));
108  pgassert(!(*notice_msg));
109  pgassert(!(*err_msg));
110  pgassert(!(*return_tuples));
111  pgassert(*return_count == 0);
112 
113  std::vector < pgr_vertex_color_rt > results;
114 
115  graphType gType = UNDIRECTED;
116  pgrouting::UndirectedGraph undigraph(gType);
117 
118  undigraph.insert_edges(data_edges, total_edges);
119 
120  results = pgr_sequentialVertexColoring(undigraph);
121 
122  auto count = results.size();
123 
124  if (count == 0) {
125  (*return_tuples) = NULL;
126  (*return_count) = 0;
127  notice << "No traversal found";
128  *log_msg = pgr_msg(notice.str().c_str());
129  return;
130  }
131 
132  (*return_tuples) = pgr_alloc(count, (*return_tuples));
133  for (size_t i = 0; i < count; i++) {
134  *((*return_tuples) + i) = results[i];
135  }
136  (*return_count) = count;
137 
138  pgassert(*err_msg == NULL);
139  *log_msg = log.str().empty()?
140  *log_msg :
141  pgr_msg(log.str().c_str());
142  *notice_msg = notice.str().empty()?
143  *notice_msg :
144  pgr_msg(notice.str().c_str());
145  } catch (AssertFailedException &except) {
146  (*return_tuples) = pgr_free(*return_tuples);
147  (*return_count) = 0;
148  err << except.what();
149  *err_msg = pgr_msg(err.str().c_str());
150  *log_msg = pgr_msg(log.str().c_str());
151  } catch (std::exception &except) {
152  (*return_tuples) = pgr_free(*return_tuples);
153  (*return_count) = 0;
154  err << except.what();
155  *err_msg = pgr_msg(err.str().c_str());
156  *log_msg = pgr_msg(log.str().c_str());
157  } catch(...) {
158  (*return_tuples) = pgr_free(*return_tuples);
159  (*return_count) = 0;
160  err << "Caught unknown exception!";
161  *err_msg = pgr_msg(err.str().c_str());
162  *log_msg = pgr_msg(log.str().c_str());
163  }
164 }

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

Referenced by process().

◆ pgr_sequentialVertexColoring()

template<class G >
std::vector< pgr_vertex_color_rt > pgr_sequentialVertexColoring ( G &  graph)

Calls the main function defined in the C++ Header file.

Parameters
graphthe graph containing the edges
logstores the log message
Returns
results, when results are found

Definition at line 62 of file sequentialVertexColoring_driver.cpp.

62  {
64  auto results = fn_sequentialVertexColoring.sequentialVertexColoring(graph);
65  return results;
66 }

References pgrouting::functions::Pgr_sequentialVertexColoring< G >::sequentialVertexColoring().

Referenced by do_pgr_sequentialVertexColoring().

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_sequentialVertexColoring
std::vector< pgr_vertex_color_rt > pgr_sequentialVertexColoring(G &graph)
Calls the main function defined in the C++ Header file.
Definition: sequentialVertexColoring_driver.cpp:62
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
UNDIRECTED
@ UNDIRECTED
Definition: graph_enum.h:30
pgrouting::functions::Pgr_sequentialVertexColoring
Definition: pgr_sequentialVertexColoring.hpp:58
graphType
graphType
Definition: graph_enum.h:30
pgrouting::functions::Pgr_sequentialVertexColoring::sequentialVertexColoring
std::vector< pgr_vertex_color_rt > sequentialVertexColoring(G &graph)
sequentialVertexColoring function
Definition: pgr_sequentialVertexColoring.hpp:81
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