mal-packet-weaver
C++20 packet serialization/deserialization library.
Loading...
Searching...
No Matches
debug_without_source_location.hpp
Go to the documentation of this file.
1#pragma once
2#include "../debug.hpp"
7namespace mal_toolkit
8{
17 inline std::string CurrentSourceLocation() { return ""; }
18
46 inline void Assert(bool value, std::string_view message = "Assert failed")
47 {
48 if constexpr (!MAL_TOOLKIT_ASSERT_ENABLED)
49 {
50 return;
51 }
52
53 if (value) [[likely]]
54 {
55 return;
56 }
57
58 if constexpr (MAL_TOOLKIT_ASSERT_LOGS)
59 {
60 spdlog::critical(std::basic_string(message));
61 }
62
63 assert(value);
64 }
65
94 inline void AlwaysAssert(bool value, std::string_view message = "Assert failed")
95 {
96 if (value) [[likely]]
97 {
98 return;
99 }
100
101 if constexpr (MAL_TOOLKIT_ASSERT_LOGS)
102 {
103 spdlog::critical(std::basic_string(message));
104 }
105
106 if constexpr (MAL_TOOLKIT_ASSERT_ENABLED)
107 {
108 assert(value);
109 }
110 else
111 {
112 if constexpr (MAL_TOOLKIT_ASSERT_ABORTS)
113 {
114 std::abort();
115 }
116 else
117 {
118 throw std::runtime_error(std::basic_string(message));
119 }
120 }
121 }
122} // namespace mal_toolkit
Contains debugging-related macros and utilities for assisting with debugging tasks.
#define MAL_TOOLKIT_ASSERT_ABORTS
Controls whether assertions should result in program abortion.
Definition debug.hpp:35
#define MAL_TOOLKIT_ASSERT_ENABLED
Definition debug.hpp:75
#define MAL_TOOLKIT_ASSERT_LOGS
Indicates whether assertion logs are enabled (1) or disabled (0).
Definition debug.hpp:18
Contains a collection of tools and utilities provided by the MAL Toolkit library.
Definition backoffs.hpp:7
void Assert(bool value, std::string_view message="Assert failed", std::source_location location=std::source_location::current())
Asserts a condition with customizable behavior based on debug mode.
std::string CurrentSourceLocation()
Returns an empty string representing the current source location.
void AlwaysAssert(bool value, std::string_view message="Assert failed", std::source_location location=std::source_location::current())
Always asserts a condition with customizable behavior.