JPL Spatial
Sound spatialization and propagation library
Loading...
Searching...
No Matches
ErrorReporting.h
Go to the documentation of this file.
1//
2// ██╗██████╗ ██╗ ██╗██████╗ ███████╗
3// ██║██╔══██╗ ██║ ██║██╔══██╗██╔════╝ ** JPLSpatialziation **
4// ██║██████╔╝ ██║ ██║██████╔╝███████╗
5// ██ ██║██╔═══╝ ██║ ██║██╔══██╗╚════██║ https://github.com/Jaytheway/JPLSpatialziation
6// ╚█████╔╝██║ ███████╗██║██████╔╝███████║
7// ╚════╝ ╚═╝ ╚══════╝╚═╝╚═════╝ ╚══════╝
8//
9// Copyright 2024 Jaroslav Pevno, JPLSpatialziation is offered under the terms of the ISC license:
10//
11// Permission to use, copy, modify, and/or distribute this software for any purpose with or
12// without fee is hereby granted, provided that the above copyright notice and this permission
13// notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
14// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
16// CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
17// WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
18// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
20#pragma once
21
22// Thanks Jorrit Rouwe and his JoltPhysics library for the boilerplate below
23// https://github.com/jrouwe/JoltPhysics
24
25#ifndef JPL_ERROR_REPORTING_DEFINED
26#define JPL_ERROR_REPORTING_DEFINED
27
28#include "Core.h"
29
30#include <format>
31#include <source_location>
32
33namespace JPL
34{
36#ifdef JPL_TAGGED_LOGGING
37 using TaggedTraceFunction = void (*)(std::string_view tag, std::string_view message);
42#else
43 using TraceFunction = void (*)(const char* message);
45#endif
46
47// Always turn on asserts in Debug mode
48#if defined(JPL_DEBUG)
49#ifndef JPL_ENABLE_ASSERTS
50#define JPL_ENABLE_ASSERTS
51#endif
52#if !defined (JPL_TEST) && !defined(JPL_ENABLE_ENSURE)
53#define JPL_ENABLE_ENSURE
54#endif
55#endif
56
57#if defined(JPL_ENABLE_ASSERTS) || defined(JPL_ENABLE_ENSURE)
59using AssertFailedFunction = bool(*)(const char* inExpression, const char* inMessage, const std::source_location);
61
62// Helper functions to pass message on to failed function
63inline bool AssertFailedParamHelper(const char* inExpression, const std::source_location location)
64{
65 return AssertFailed(inExpression, nullptr, location);
66}
67
68inline bool AssertFailedParamHelper(const char* inExpression, const std::source_location location, const char* inMessage)
69{
71}
72#endif
73
74#ifdef JPL_ENABLE_ASSERTS
76#define JPL_ASSERT(inExpression, ...) do { if (!(inExpression) && ::JPL::AssertFailedParamHelper(#inExpression, std::source_location::current(), ##__VA_ARGS__)) JPL_BREAKPOINT; } while (false)
77
78#define JPL_IF_ENABLE_ASSERTS(...) __VA_ARGS__
79#else
80#define JPL_ASSERT(...) ((void)0)
81
82#define JPL_IF_ENABLE_ASSERTS(...)
83#endif // JPL_ENABLE_ASSERTS
84
85
87#ifndef JPL_ENSURE
88#ifdef JPL_ENABLE_ENSURE
89
90#define JPL_ENSURE(inExpression, ...) [&]{ if(!(inExpression) && ::JPL::AssertFailedParamHelper(#inExpression, std::source_location::current(), ##__VA_ARGS__)) { JPL_BREAKPOINT; } return (inExpression); }()
91#else
92#define JPL_ENSURE(inExpression, ...) (inExpression)
93#endif
94#endif // !JPL_ENSURE
95
96#ifndef JPL_TRACE_TAG
97 #ifdef JPL_TAGGED_LOGGING
98 #define JPL_TRACE_TAG(tag, message) JPLTraceTaggedTrace(tag, message)
99 #else
100 #define JPL_TRACE_TAG(tag, message) SpatialTrace(std::format("[{}]: Trace: {}", tag, message).c_str())
101 #endif
102#endif // !JPL_TRACE_TAG
103
104#ifndef JPL_INFO_TAG
105 #ifdef JPL_TAGGED_LOGGING
106 #define JPL_INFO_TAG(tag, message) JPLTraceTaggedInfo(tag, message)
107 #else
108 #define JPL_INFO_TAG(tag, message) SpatialTrace(std::format("[{}]: Info: {}", tag, message).c_str())
109 #endif
110#endif // !JPL_INFO_TAG
111
112#ifndef JPL_WARN_TAG
113 #ifdef JPL_TAGGED_LOGGING
114 #define JPL_WARN_TAG(tag, message) JPLTraceTaggedWarn(tag, message)
115 #else
116 #define JPL_WARN_TAG(tag, message) SpatialTrace(std::format("[{}]: Warning: {}", tag, message).c_str())
117 #endif
118#endif // !JPL_WARN_TAG
119
120#ifndef JPL_ERROR_TAG
121 #ifdef JPL_TAGGED_LOGGING
122 #define JPL_ERROR_TAG(tag, message) JPLTraceTaggedError(tag, message)
123 #else
124 #define JPL_ERROR_TAG(tag, message) SpatialTrace(std::format("[{}]: Error: {}", tag, message).c_str())
125 #endif
126#endif // !JPL_ERROR_TAG
127
128} // namespace JPL
129
130#endif // JPL_ERROR_REPORTING_DEFINED
#define JPL_EXPORT
Definition Core.h:235
Definition AcousticMaterial.h:36
bool AssertFailedParamHelper(const char *inExpression, const std::source_location location)
Definition ErrorReporting.h:63
JPL_INLINE simd min(const simd &a, const simd &b) noexcept
Element-wise min.
Definition SIMD.h:1813
void(*)(const char *message) TraceFunction
Trace function, needs to be overridden by application. This should output a line of text to the log /...
Definition ErrorReporting.h:43
JPL_EXPORT TraceFunction SpatialTrace
bool(*)(const char *inExpression, const char *inMessage, const std::source_location) AssertFailedFunction
Function called when an assertion fails. This function should return true if a breakpoint needs to be...
Definition ErrorReporting.h:59
JPL_EXPORT AssertFailedFunction AssertFailed