World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
ErrorHandling.cpp
См. документацию.
1 #include "Engine/ErrorHandling.h"
2 
3 #include <cstdarg>
4 #include <cstdio>
5 #include <cstring>
6 
7 #include <sstream>
8 
9 void Error_impl_(const char *filename, const char *functionname,
10  int line, const char *format, ...) {
11  char msg_body[8192] = { 0 };
12  if (format != nullptr) {
13  va_list va;
14  va_start(va, format);
15  vsnprintf(msg_body, 8192, format, va);
16  va_end(va);
17  }
18 
19  std::stringstream out;
20  out << "Error in " << filename << ": ";
21  out << line << "\n\t" << functionname << "\n\n";
22  if (strlen(msg_body) > 0) {
23  out << "\n\n" << msg_body;
24  }
25 
26  extern void OS_MsgBox(const char *, const char *);
27  OS_MsgBox(out.str().c_str(), "Error");
28 }
29 
30 void Assert_impl_(const char *filename, const char *functionname,
31  int line, bool condition, const char *condition_string,
32  const char *format, ...) {
33  if (condition) return;
34 
35  char msg_body[8192] = { 0 };
36  if (format != nullptr) {
37  va_list va;
38  va_start(va, format);
39  vsnprintf(msg_body, 8192, format, va);
40  va_end(va);
41  }
42 
43  std::stringstream out;
44  out << "Assertion in " << filename << ": ";
45  out << line << "\n\t" << functionname << "\n\n";
46  if (strlen(msg_body) > 0) {
47  out << "\n\n" << msg_body;
48  }
49 
50  extern void OS_MsgBox(const char *, const char *);
51  OS_MsgBox(out.str().c_str(), "Assertion");
52 
53  assert(false);
54 }
condition
EGLenum condition
Definition: SDL_egl.h:1629
format
SDL_AudioFormat format
Definition: SDL_audio.h:194
ErrorHandling.h
OS_MsgBox
void OS_MsgBox(const char *msg, const char *title)
Definition: Lin.cpp:8
Assert_impl_
void Assert_impl_(const char *filename, const char *functionname, int line, bool condition, const char *condition_string, const char *format,...)
Definition: ErrorHandling.cpp:30
Error_impl_
void Error_impl_(const char *filename, const char *functionname, int line, const char *format,...)
Definition: ErrorHandling.cpp:9