Botan  1.10.9
assert.h
Go to the documentation of this file.
1 /*
2 * Runtime assertion checking
3 * (C) 2010 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7 
8 #ifndef BOTAN_ASSERTION_CHECKING_H__
9 #define BOTAN_ASSERTION_CHECKING_H__
10 
11 namespace Botan {
12 
13 void assertion_failure(const char* expr_str,
14  const char* msg,
15  const char* func,
16  const char* file,
17  int line);
18 
19 #define BOTAN_ASSERT(expr, msg) \
20  do { \
21  if(!(expr)) \
22  Botan::assertion_failure(#expr, \
23  msg, \
24  BOTAN_ASSERT_FUNCTION, \
25  __FILE__, \
26  __LINE__); \
27  } while(0)
28 
29 #define BOTAN_ASSERT_EQUAL(value1, value2, msg) \
30  do { \
31  if(value1 != value2) \
32  Botan::assertion_failure(#value1 " == " #value2, \
33  msg, \
34  BOTAN_ASSERT_FUNCTION, \
35  __FILE__, \
36  __LINE__); \
37  } while(0)
38 
39 /*
40 * Unfortunately getting the function name from the preprocessor
41 * isn't standard in C++98 (C++0x uses C99's __func__)
42 */
43 #if defined(BOTAN_BUILD_COMPILER_IS_GCC) || \
44  defined(BOTAN_BUILD_COMPILER_IS_CLANG) || \
45  defined(BOTAN_BUILD_COMPILER_IS_INTEL)
46 
47  #define BOTAN_ASSERT_FUNCTION __PRETTY_FUNCTION__
48 
49 #elif defined(BOTAN_BUILD_COMPILER_IS_MSVC)
50 
51  #define BOTAN_ASSERT_FUNCTION __FUNCTION__
52 
53 #else
54  #define BOTAN_ASSERT_FUNCTION ((const char*)0)
55 #endif
56 
57 }
58 
59 #endif
void assertion_failure(const char *expr_str, const char *msg, const char *func, const char *file, int line)
Definition: assert.cpp:14