Euphoria
assert.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <vector>
5 
6 #ifdef _MSC_VER
7 #define __PRETTY_FUNCTION__ __FUNCSIG__
8 #define BREAK_IN_DEBUG() __debugbreak()
9 #else
10 #define BREAK_IN_DEBUG() \
11  do \
12  { \
13  } while(false)
14 #endif
15 
16 #ifdef RELEASE
17 
18 // todo(Gustav): implement assert for windows...
19 
20 #define ASSERT(x)
21 #define ASSERTX(x, ...)
22 #define DIE(message)
23 
24 #else
25 
26 #define IMPLEMENT_ASSERT_LIB
27 
28 // todo(Gustav): stb libraries and rapidjson aren't using our assert
29 #define ASSERT(x) \
30  do \
31  { \
32  if(x) \
33  { \
34  } \
35  else \
36  { \
37  if(::eu::assertlib::is_throwing() == false) { BREAK_IN_DEBUG(); } \
38  ::eu::assertlib::on_assert( \
39  #x, \
40  __LINE__, \
41  __FILE__, \
42  "", \
43  {}, \
44  __PRETTY_FUNCTION__); \
45  } \
46  } while(false)
47 
48 #define ASSERTX(x, ...) \
49  do \
50  { \
51  if(x) \
52  { \
53  } \
54  else \
55  { \
56  if(::eu::assertlib::is_throwing() == false) { BREAK_IN_DEBUG(); } \
57  ::eu::assertlib::on_assert( \
58  #x, \
59  __LINE__, \
60  __FILE__, \
61  #__VA_ARGS__, \
62  {__VA_ARGS__}, \
63  __PRETTY_FUNCTION__); \
64  } \
65  } while(false)
66 
67 #define DIE(message) \
68  ::eu::assertlib::on_assert( \
69  message, \
70  __LINE__, \
71  __FILE__, \
72  "", \
73  {}, \
74  __PRETTY_FUNCTION__)
75 
76 #define DIEX(message, ...) \
77  ::eu::assertlib::on_assert( \
78  message, \
79  __LINE__, \
80  __FILE__, \
81  #__VA_ARGS__, \
82  {__VA_ARGS__}, \
83  __PRETTY_FUNCTION__)
84 
85 #endif // _MSC_VER
86 
87 #ifdef IMPLEMENT_ASSERT_LIB
88 
89 namespace eu::assertlib
90 {
92  {
93  std::string value;
94 
95  template <typename T>
96  AssertArgumentValue(const T& t)
97  : value(fmt::to_string(t))
98  {}
99  };
100 
101  void
103 
104  bool
106 
107  void
109  (
110  const char* expression,
111  int line,
112  const char* file,
113  const char* argstr,
114  const std::vector<AssertArgumentValue>& arguments,
115  const char* function
116  );
117 }
118 #endif // IMPLEMENT_ASSERT_LIB
119 
bool is_throwing()
void begin_throwing()
void on_assert(const char *expression, int line, const char *file, const char *argstr, const std::vector< AssertArgumentValue > &arguments, const char *function)
std::string to_string(const Aabb &a)
Definition: aabb.cc:110
int line
Definition: nlp_sentence.cc:91