Nebula
Loading...
Searching...
No Matches
debug.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
16#include "core/config.h"
17
18void n_printf(const char *, ...) __attribute__((format(printf,1,2)));
19void n_error(const char*, ...) __attribute__((format(printf,1,2)));
20void n_dbgout(const char*, ...) __attribute__((format(printf,1,2)));
21void n_warning(const char*, ...) __attribute__((format(printf,1,2)));
22void n_confirm(const char*, ...) __attribute__((format(printf,1,2)));
23void n_sleep(double);
24void n_barf(const char *, const char *, int);
25void n_barf2(const char*, const char*, const char*, int);
26void n_barf_fmt(const char *, const char *, const char *, int, ...);
27void n_cough(const char*, const char*, int);
28void n_cough2(const char*, const char*, const char*, int);
29void n_cough_fmt(const char*, const char*, const char*, int, ...);
30void n_break();
31
32namespace IO
33{
34void Log(const char* logGroup, const char* fmt, ...) __attribute__((format(printf, 2, 3)));
35void LogWarning(const char* logGroup, const char* fmt, ...) __attribute__((format(printf, 2, 3)));
36void LogError(const char* logGroup, const char* fmt, ...) __attribute__((format(printf, 2, 3)));
37void LogSource(const char* logGroup, const char* file, const int line, const char* fmt, ...) __attribute__((format(printf, 4, 5)));
38}
39
40// backward compatibility
41#define n_message n_confirm
42
43#if __NEBULA_NO_ASSERT__
44#define n_assert(exp) if(!(exp)){}
45#define n_assert2(exp, msg) if(!(exp)){}
46#define n_assert_msg(exp, msg) n_assert2(exp, msg)
47#define n_assert_fmt(exp, msg, ...) if(!(exp)){}
48#define n_verify(exp) (exp)
49#define n_verify2(exp,imsg) (exp)
50#define n_warn(exp) if (!(exp)) {}
51#define n_warn2(exp, msg) if (!(exp)) {}
52#define n_warn_fmt(exp, msg, ...) if (!(exp)) {}
53#if __WIN32__
54#define n_dxtrace(hr, msg)
55#endif
56#define n_static_assert(exp)
57#else
58#define n_assert(exp) { if (!(exp)) n_barf(#exp, __FILE__, __LINE__); }
59#define n_assert2(exp, msg) { if (!(exp)) n_barf2(#exp, msg, __FILE__, __LINE__); }
60#define n_assert_msg(exp, msg) n_assert2(exp, msg)
61#define n_assert_fmt(exp, msg, ...) { if (!(exp)) n_barf_fmt(#exp, msg, __FILE__, __LINE__, __VA_ARGS__); }
62#define n_warn(exp) { if (!(exp)) n_cough(#exp, __FILE__, __LINE__); }
63#define n_warn2(exp, msg) { if (!(exp)) n_cough2(#exp, msg, __FILE__, __LINE__); }
64#define n_warn_fmt(exp, msg, ...) { if (!(exp)) n_cough_fmt(#exp, msg, __FILE__, __LINE__, __VA_ARGS__); }
65#define n_crash(msg) { n_error("*** NEBULA CRASH ***\n%s(%d)\nmessage: %s\n", __FILE__, __LINE__, msg); }
66#define n_static_assert(exp) { int _x[ 2*((exp) != 0)-1 ]; (void)(_x[0]=0);}
67#if __WIN32__
68// dx9 specific: check HRESULT and display DX9 specific message box
69#define n_dxtrace(hr, msg) { if (FAILED(hr)) DXTrace(__FILE__,__LINE__,hr,msg,true); }
70#endif
71#endif
72
73#define n_log(group, fmt, ...) IO::Log(#group, fmt, ##__VA_ARGS__)
74#define n_log_warn(group, fmt, ...) IO::LogWarning(#group, fmt, ##__VA_ARGS__)
75#define n_log_err(group, fmt, ...) IO::LogError(#group, fmt, ##__VA_ARGS__)
76#define n_log_source(group, fmt, ...) IO::LogSource(#group, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
77
78
79//------------------------------------------------------------------------------
void n_barf(const char *exp, const char *file, int line)
This function is called by n_assert() when the assertion fails.
Definition debug.cc:17
void n_barf_fmt(const char *exp, const char *fmt, const char *file, int line,...)
Definition debug.cc:54
void n_cough2(const char *exp, const char *msg, const char *file, int line)
This function is called by n_assert2() when the assertion fails.
Definition debug.cc:96
void n_sleep(double sec)
Put process to sleep.
Definition debug.cc:239
void n_barf2(const char *exp, const char *msg, const char *file, int line)
This function is called by n_assert2() when the assertion fails.
Definition debug.cc:36
void __cdecl n_error(const char *msg,...)
This function is called when a serious situation is encountered which requires abortion of the applic...
Definition debug.cc:138
void __cdecl n_confirm(const char *msg,...)
This function is called when a message should be displayed to the user which requires a confirmation ...
Definition debug.cc:184
void __cdecl n_warning(const char *msg,...)
This function is called when a warning should be issued which doesn't require abortion of the applica...
Definition debug.cc:161
void n_break()
Definition debug.cc:248
void n_cough_fmt(const char *exp, const char *fmt, const char *file, int line,...)
Definition debug.cc:114
void n_cough(const char *exp, const char *file, int line)
This function is called by n_assert() when the assertion fails.
Definition debug.cc:77
void __cdecl n_dbgout(const char *msg,...)
Put the message to the debug window.
Definition debug.cc:224
void n_printf(const char *,...) __attribute__((format(printf
Nebula compiler specific defines and configuration.
#define __attribute__(x)
Definition config.h:161
Instances of wrapped stream classes.
Definition multiplayerfeatureunit.cc:324