15 #include <type_traits>
41 const char*
function) = 0;
51 static AssertManager& instance()
53 static AssertManager mgr;
57 AssertManager(
const AssertManager&) =
delete;
59 AssertManager& operator=(
const AssertManager&) =
delete;
61 Assert* reset(Assert* newAssert =
nullptr)
63 auto prevAssert = assert_;
73 bool hasAssertRegistered()
const
75 return (assert_ !=
nullptr);
78 static void infiniteLoop()
84 AssertManager() : assert_(nullptr) {}
98 template <
typename TAssert>
101 static_assert(std::is_base_of<Assert, TAssert>::value,
102 "TAssert class must be derived class of Assert");
112 template<
typename... TParams>
114 : assert_(std::forward<TParams>(args)...),
115 prevAssert_(AssertManager::instance().reset(&assert_))
124 AssertManager::instance().reset(prevAssert_);
145 #if defined(NOSTDLIB) && !defined(COMMS_NOSTDLIB)
146 #define COMMS_NOSTDLIB
150 #ifndef __ASSERT_FUNCTION
151 #define COMMS_ASSERT_FUNCTION_STR __FUNCTION__
153 #define COMMS_ASSERT_FUNCTION_STR __ASSERT_FUNCTION
156 #ifndef COMMS_NOSTDLIB
157 #define COMMS_ASSERT_FAIL_FUNC(expr) assert(expr)
159 #define COMMS_ASSERT_FAIL_FUNC(expr) comms::AssertManager::instance().infiniteLoop()
170 #define COMMS_ASSERT(expr) \
172 ? static_cast<void>(0) \
173 : (comms::AssertManager::instance().hasAssertRegistered() \
174 ? comms::AssertManager::instance().getAssert()->fail( \
175 #expr, __FILE__, __LINE__, COMMS_ASSERT_FUNCTION_STR) \
176 : COMMS_ASSERT_FAIL_FUNC(expr)))
180 #define COMMS_ASSERT(expr) static_cast<void>(0)
188 #define GASSERT(expr) COMMS_ASSERT(expr)
Base class for any custom assertion behaviour.
Definition: Assert.h:27
virtual void fail(const char *expr, const char *file, unsigned int line, const char *function)=0
Pure virtual function to be called when assertion fails.
virtual ~Assert() noexcept
Destructor.
Definition: Assert.h:30
Enable new assertion behaviour.
Definition: Assert.h:100
AssertType & getAssert()
Provides reference to internal Assert object.
Definition: Assert.h:130
EnableAssert(TParams &&... args)
Constructor.
Definition: Assert.h:113
TAssert AssertType
Type of assert object.
Definition: Assert.h:105
~EnableAssert() noexcept
Destructor.
Definition: Assert.h:122
Main namespace for all classes / functions of COMMS library.