Doxygen Samurai Engine 0.0.1
Doxygen Samurai Engine Documentation
Loading...
Searching...
No Matches
assert.cpp
Go to the documentation of this file.
1#include <Config.h>
2#include <cstdlib>
3#include <cstdio>
4#include <assert.h>
5
6#include "settings/log.h"
7
8namespace samurai
9{
10
11 namespace assert
12 {
13 inline void terminate(...)
14 {
15 std::abort();
16 }
17
18
19 #ifdef SAMURAI_WINDOWS
20
21 #include <Windows.h>
22
23 void assertFunctionDevelopment(const char *expression, const char *file,
24 int line, const char *comment)
25 {
26 char buffer[1024] = {};
27
28 std::snprintf(buffer, sizeof(buffer),
29 "Assertion failed\n\n"
30
31 "Expression: \n%s\n\n"
32
33 "File: %s\n"
34 "Line: %d\n\n"
35
36 "Comment: \n%s\n\n"
37
38 "Press retry to debug."
39 , expression
40 , file
41 , line
42 , comment
43 );
44
45 int const action = MessageBoxA(0, buffer, "Pika error", MB_TASKMODAL
46 | MB_ICONHAND | MB_ABORTRETRYIGNORE | MB_SETFOREGROUND);
47
48 switch (action)
49 {
50 case IDABORT: //Abort the program
51 {
52 terminate();
53 return;
54 }
55 case IDRETRY: //Break execution (debug)
56 {
57 #ifdef _MSC_VER
58 __debugbreak();
59 #endif
60 terminate();
61
62 return;
63 }
64 case IDIGNORE: //Ignore assert
65 {
66 return;
67 }
68
69 }
70
71 };
72
73
74 void assertFunctionProduction(const char *expression, const char *file,
75 int line, const char *comment)
76 {
77
78 char buffer[1024] = {};
79
80 std::snprintf(buffer, sizeof(buffer),
81 "Assertion failed\n\n"
82
83 "Expression: \n%s\n\n"
84
85 "File: %s\n"
86 "Line: %d\n\n"
87
88 "Comment: \n%s\n\n"
89
90 "Please report this error to the developer."
91 , expression
92 , file
93 , line
94 , comment
95 );
96
97
98 int const action = MessageBoxA(0,
99 buffer, "Pika error", MB_TASKMODAL
100 | MB_ICONHAND | MB_OK | MB_SETFOREGROUND);
101
102 terminate();
103 }
104
105
106 void assertFunctionToLog(const char *expression, const char *file, int line, const char *comment)
107 {
108
109 char buffer[1024] = {};
110
111 std::snprintf(buffer, sizeof(buffer),
112 "Assertion failed\n"
113 "Expression: \n%s\n"
114 "File: %s\n"
115 "Line: %d\n"
116 "Comment: \n%s\n"
117 , expression
118 , file
119 , line
120 , comment
121 );
122
124
125 }
126
127 }
128
129#endif
130
131
132};
void terminate(...)
void assertFunctionDevelopment(const char *expression, const char *file, int line, const char *comment=nullptr)
void assertFunctionProduction(const char *expression, const char *file, int line, const char *comment=nullptr)
void assertFunctionToLog(const char *expression, const char *file, int line, const char *comment=nullptr)
void logToFile(const char *fileName, const char *l, int type=samurai::logNormal)
Definition log.cpp:69
static constexpr const char * DefaultLogFile
Definition log.h:18