File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66
77#pragma once
88
9+ #include < source_location>
910#include < string>
1011
11-
12- #define OVASSERT (condition, message ) OvDebug::Assertion::Assert(condition, message)
12+ #ifdef NDEBUG
13+ #define OVASSERT (condition, message ) static_cast <void >(0 )
14+ #else
15+ #define OVASSERT (condition, message ) \
16+ static_cast <bool >(condition) ? \
17+ static_cast <void >(0 ) : \
18+ OvDebug::_Assert (#condition, message, std::source_location::current());
19+ #endif
1320
1421namespace OvDebug
1522{
16- /* *
17- * Wrapper for C++ assert
18- */
19- class Assertion
20- {
21- public:
22-
23- /* *
24- * Disabled constructor
25- */
26- Assertion () = delete ;
27-
28- /* *
29- * C++ assertion wrapped call
30- * @param p_condition
31- * @param p_message
32- */
33- static void Assert (bool p_condition, const std::string& p_message = " " );
34- };
23+ void _Assert (
24+ const char * p_expression,
25+ const std::string_view p_message,
26+ const std::source_location& p_location
27+ );
3528}
Original file line number Diff line number Diff line change 44* @licence: MIT
55*/
66
7- #include " OvDebug/Assertion.h"
7+ #include < OvDebug/Assertion.h>
8+ #include < OvDebug/Logger.h>
89
910#include < cassert>
11+ #include < format>
1012
11- void OvDebug::Assertion::Assert (bool p_condition, const std::string& p_message)
13+ #if defined(_MSC_VER)
14+ # define OV_DEBUG_BREAK () __debugbreak()
15+ #elif defined(__clang__) || defined(__GNUC__)
16+ # define OV_DEBUG_BREAK () __builtin_trap()
17+ #else
18+ # define OV_DEBUG_BREAK () std::abort()
19+ #endif
20+
21+ void OvDebug::_Assert (const char * p_expression, const std::string_view p_message, const std::source_location& p_location)
1222{
13- assert (p_condition && p_message.c_str ());
14- }
23+ OVLOG_ERROR (std::format (
24+ " Assertion failed: {}\n "
25+ " Expression: {}\n "
26+ " Function: {}\n "
27+ " Location: {}:{}" ,
28+ p_message, p_expression, p_location.function_name (),
29+ p_location.file_name (), p_location.line ()));
30+ OV_DEBUG_BREAK ();
31+ }
You can’t perform that action at this time.
0 commit comments