PGROUTING  3.2
mst_common.cpp
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: mst_common.c
3 
4 Copyright (c) 2018 Vicky Vergara
5 Mail: vicky at georepublic dot de
6 
7 ------
8 
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 
23  ********************************************************************PGR-GNU*/
24 
26 
27 #include <string>
28 #include <sstream>
29 
30 #include "cpp_common/pgr_assert.h"
31 #include "cpp_common/pgr_alloc.hpp"
32 
33 int
34 get_order(char * fn_suffix, char ** err_msg) {
35  std::ostringstream err;
36  try {
37  pgassert(!(*err_msg));
38  std::string suffix(fn_suffix);
39  if (suffix.empty()) return 0;
40  if (suffix == "DFS") return 1;
41  if (suffix == "BFS") return 2;
42  if (suffix == "DD") return 1;
43  err << "Unknown function suffix" << suffix;
44  *err_msg = pgr_msg(err.str().c_str());
45  } catch (std::exception &except) {
46  err << except.what();
47  *err_msg = pgr_msg(err.str().c_str());
48  }
49  return -1;
50 }
51 
52 
53 char *
54 get_name(int fn_id, char * fn_suffix, char ** err_msg) {
55  std::ostringstream err;
56  try {
57  pgassert(!(*err_msg));
58  std::string name;
59  switch (fn_id) {
60  case 0: name = "pgr_kruskal";
61  break;
62  case 1: name = "pgr_prim";
63  break;
64  default : name = "unknown";
65  err << "Unknown function name";
66  *err_msg = pgr_msg(err.str().c_str());
67  }
68  std::string suffix(fn_suffix);
69  name += suffix;
70  char * full_name = pgr_msg(name.c_str());
71  return full_name;
72  } catch (std::exception &except) {
73  err << except.what();
74  *err_msg = pgr_msg(err.str().c_str());
75  }
76  return nullptr;
77 }
mst_common.h
pgr_msg
char * pgr_msg(const std::string &msg)
Definition: pgr_alloc.cpp:30
get_order
int get_order(char *fn_suffix, char **err_msg)
defines ordering
Definition: mst_common.cpp:34
pgassert
#define pgassert(expr)
Uses the standard assert syntax.
Definition: pgr_assert.h:94
pgr_alloc.hpp
pgr_assert.h
An assert functionality that uses C++ throw().
get_name
char * get_name(int fn_id, char *fn_suffix, char **err_msg)
Definition: mst_common.cpp:54