PGROUTING  2.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pgr_assert.h
Go to the documentation of this file.
1 /*PGR-MIT******************************************************************
2  *
3  * file pgr_assert.h
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 
13 #ifndef SRC_COMMON_SRC_PGR_ASSERT_H_
14 #define SRC_COMMON_SRC_PGR_ASSERT_H_
15 #pragma once
16 
17 #include <string>
18 #include <exception>
19 
20 #ifdef assert
21 #undef assert
22 #endif
23 
24 
41 #ifndef __STRING
42 #define __STRING(x) #x
43 #endif
44 
45 #define __TOSTRING(x) __STRING(x)
46 
47 
78 #ifdef NDEBUG
79 #define pgassert(expr) ((void)0)
80 #else
81 #define pgassert(expr) \
82  ((expr) \
83  ? static_cast<void>(0) \
84  : throw AssertFailedException( \
85  "AssertFailedException: " __STRING(expr) \
86  " at " __FILE__ ":" __TOSTRING(__LINE__) + get_backtrace() ) )
87 #endif
88 
101 #ifdef NDEBUG
102 #define pgassertwm(expr, msg) ((void)0)
103 #else
104 #define pgassertwm(expr, msg) \
105  ((expr) \
106  ? static_cast<void>(0) \
107  : throw AssertFailedException( \
108  "AssertFailedException: " __STRING(expr) \
109  " at " __FILE__ ":" __TOSTRING(__LINE__) + get_backtrace(msg) ) )
110 #endif
111 
120 std::string get_backtrace();
121 std::string get_backtrace(const std::string &);
122 
126 class AssertFailedException : public std::exception {
127  private:
128  const std::string str;
129 
130  public:
131  virtual const char *what() const throw();
132  explicit AssertFailedException(std::string msg);
133  virtual ~AssertFailedException() throw() {}
134 };
135 
136 #endif // SRC_COMMON_SRC_PGR_ASSERT_H_
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:126
std::string get_backtrace()
returns the execution path of the trace
Definition: pgr_assert.cpp:26
const std::string str
Holds what() we got as message.
Definition: pgr_assert.h:128
virtual const char * what() const
Definition: pgr_assert.cpp:53