pgRouting
pgRouting extends the PostGIS / PostgreSQL geospatial database to provide geospatial routing functionality.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pgr_assert.cpp
Go to the documentation of this file.
1 /*PGR-MIT******************************************************************
2  *
3  * file pgr_assert.cpp
4  *
5  * Copyright 2014 Stephen Woodbridge <woodbri@imaptools.com>
6  * Copyright 2014 Vicky Vergara <vicky_vergara@hotmail.com>
7  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the MIT License. Please file MIT-LICENSE for details.
10  *
11  *****************************************************************PGR-MIT*/
12 #include "./pgr_assert.h"
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <stddef.h>
16 
17 #ifdef __linux__
18 #include <execinfo.h>
19 #endif
20 #include <string>
21 #include <exception>
22 
23 #if 0
24 #ifdef assert
25 #undef assert
26 #endif
27 
28 #ifndef __STRING
29 #define __STRING(x) #x
30 #endif
31 
32 #define __TOSTRING(x) __STRING(x)
33 #endif
34 
35 std::string get_backtrace() {
36 #ifdef __linux__
37  void *trace[16];
38  int i, trace_size = 0;
39 
40  trace_size = backtrace(trace, 16);
41  char** funcNames = backtrace_symbols(trace, trace_size);
42 
43 
44  std::string message = "\n*** Execution path***\n";
45  for (i = 0; i < trace_size; ++i) {
46  message += "[bt]" + static_cast<std::string>(funcNames[i]) + "\n";
47  }
48 
49  free(funcNames);
50  return message;
51 #else
52  return "";
53 #endif
54 }
55 
56 std::string get_backtrace(const std::string &msg) {
57  return std::string("\n") + msg + "\n" + get_backtrace();
58 }
59 
60 
61 
62 const char* AssertFailedException::what() const throw() {
63  return str.c_str();
64 }
65 
67  str(msg) {}
68 
std::string get_backtrace()
returns the execution path of the trace
Definition: pgr_assert.cpp:35
AssertFailedException(std::string msg)
Definition: pgr_assert.cpp:66
const std::string str
Holds what() we got as message.
Definition: pgr_assert.h:128
Assertions Handling.
virtual const char * what() const
Definition: pgr_assert.cpp:62