RavEngine
Loading...
Searching...
No Matches
Debug.hpp
1#pragma once
2#include "SpinLock.hpp"
3#include "PhysXDefines.h"
4#include "Format.hpp"
5
6namespace RavEngine {
7
8class Debug{
9private:
10 Debug() = delete;
11 static SpinLock mtx;
12 constexpr static uint16_t bufsize = 512;
13
14 static void LogHelper(FILE* output, const std::string_view, const char* type);
15
16 static void InvokeUserHandler(const std::string_view msg);
17
18public:
19
24 static inline void LogTemp(const std::string_view message){
25#ifndef NDEBUG
26 LogHelper(stdout, message, "LOGTEMP");
27#endif
28 }
29
35 template <typename ... T>
36 static inline void LogTemp(const std::string_view formatstr, T&& ... values){
37#ifndef NDEBUG
38 LogHelper(stdout, Format(formatstr,values...),"LOGTEMP");
39#endif
40 }
41
46 static inline void Log(const std::string_view message){
47 LogHelper(stdout, message, "LOG");
48 }
49
55 template <typename ... T>
56 static constexpr inline void Log(const std::string_view formatstr, T&& ... values){
57 LogHelper(stdout, VFormat(formatstr, values...),"LOG");
58 }
59
64 static inline void Warning(const char* message){
65 LogHelper(stderr, message, "WARN");
66 }
67
73 template <typename ... T>
74 static inline void Warning(const std::string_view formatstr, T&& ... values){
75 LogHelper(stderr, VFormat(formatstr, values...), "WARN");
76 }
77
78 static inline void PrintStacktraceHere(){
79 //TODO: get stack trace and print
80 }
81
86 static inline void Error(const std::string_view message){
87 LogHelper(stderr, message, "ERROR");
88 PrintStacktraceHere();
89 }
90
96 template <typename ... T>
97 static inline void Error(const std::string_view formatstr, T&& ... values){
98 LogHelper(stderr, VFormat(formatstr, values...), "ERROR");
99 PrintStacktraceHere();
100 }
101
106 static inline void Fatal(const std::string_view message){
107 Debug::Error(message);
108 InvokeUserHandler(message);
109 throw std::runtime_error(std::string(message));
110 }
111
117 template <typename ... T>
118 static inline void Fatal(const std::string_view formatstr, T&& ... values){
119 Debug::Error(formatstr,values...);
120 auto formattedMsg = VFormat(formatstr, values...);
121 InvokeUserHandler(formattedMsg);
122 throw std::runtime_error(formattedMsg);
123 }
124
131 template <typename ... T>
132 static inline void Assert(bool condition, const char* formatstr, T&& ... values){
133 if (!condition){
134 Fatal(formatstr,values...);
135 }
136 }
137
143 static inline void Assert(bool condition, const char* msg){
144 if (!condition){
145 Fatal(msg);
146 }
147 }
148
152 template<typename U,typename T>
153 static inline U AssertSize(T val, const char* name = ""){
154 Debug::Assert(val <= std::numeric_limits<U>::max(), "Size ({}) is greater than maximum allowed ({})",val, std::numeric_limits<U>::max());
155 return static_cast<U>(val);
156 }
157};
158
159}
Definition Debug.hpp:8
static void Assert(bool condition, const char *formatstr, T &&... values)
Definition Debug.hpp:132
static constexpr void Log(const std::string_view formatstr, T &&... values)
Definition Debug.hpp:56
static void Fatal(const std::string_view message)
Definition Debug.hpp:106
static void Error(const std::string_view formatstr, T &&... values)
Definition Debug.hpp:97
static void Warning(const std::string_view formatstr, T &&... values)
Definition Debug.hpp:74
static void LogTemp(const std::string_view message)
Definition Debug.hpp:24
static void Warning(const char *message)
Definition Debug.hpp:64
static void LogTemp(const std::string_view formatstr, T &&... values)
Definition Debug.hpp:36
static void Assert(bool condition, const char *msg)
Definition Debug.hpp:143
static void Log(const std::string_view message)
Definition Debug.hpp:46
static void Fatal(const std::string_view formatstr, T &&... values)
Definition Debug.hpp:118
static void Error(const std::string_view message)
Definition Debug.hpp:86
static U AssertSize(T val, const char *name="")
Definition Debug.hpp:153
Definition SpinLock.hpp:9
Definition concurrentqueue.h:747
Definition Animation.hpp:6