Newer
Older
#ifndef DUNE_STUFF_DEBUG_HH
#define DUNE_STUFF_DEBUG_HH
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#define SEGFAULT \
{ \
int* J = 0; \
*J = 9; \
}
//! from right/bottom limiter for file paths
const char* rightPathLimiter(const char* path, int depth = 2)
{
char* c = new char[255];
strcpy(c, path);
const char* p = strtok(c, "/");
int i = 0;
while (p && i < depth) {
p = strtok(NULL, "/");
}
p = strtok(NULL, "\0");
return p;
}
#ifndef NDEBUG
#ifndef LOGIC_ERROR
#include <stdexcept>
#include <sstream>
#define LOGIC_ERROR \
{ \
std::stringstream ss; \
ss << __FILE__ << ":" << __LINE__ << " should never be called"; \
throw std::logic_error(ss.str()); \
}
#endif
#else
#define LOGIC_ERROR
#endif
char* copy(const char* s)
{
int l = strlen(s) + 1;
char* t = new char[l];
for (int i = 0; i < l; i++) {
t[i] = s[i];
}
return t;
}
#define __CLASS__ strtok(copy(__PRETTY_FUNCTION__), "<(")
#ifndef NDEBUG
#define NEEDS_IMPLEMENTATION \
{ \
std::stringstream ss; \
ss << " implementation missing: " << __CLASS__ << " -- " << rightPathLimiter(__FILE__) << ":" << __LINE__; \
std::cerr << ss.str() << std::endl; \
}
#else
#define NEEDS_IMPLEMENTATION
#endif // NDEBUG
class assert_exception : public std::runtime_error
{
public:
assert_exception(std::string msg)
namespace Stuff {
class singlerun_abort_exception : public std::runtime_error
{
public:
singlerun_abort_exception(std::string msg)
#ifndef NDEBUG
#define ASSERT_EXCEPTION(cond, msg) \
if (!(cond)) { \
std::string rmsg(std::string(__FILE__) + std::string(":") + Stuff::toString(__LINE__) + std::string("\n") \
+ std::string(msg)); \
throw assert_exception(rmsg); \
}
#else
#define ASSERT_EXCEPTION(cond, msg)
#endif
#if 1 /* there should be no more any compilers needing the "#else" version */
#define UNUSED(identifier) /* identifier */
#else /* stupid, broken compiler */
#define UNUSED(identifier) identifier
#endif
/* some arguments are only used in debug mode, but unused in release one */
#ifndef NDEBUG
#define UNUSED_UNLESS_DEBUG(param) param
#else
#define UNUSED_UNLESS_DEBUG(param) UNUSED(param)
#endif