skullc-peripherals/Utility/Src/utility_assert.cpp
Erki c0a622c5e4
All checks were successful
continuous-integration/drone/push Build is passing
gitea/skullc-peripherals/pipeline/head This commit looks good
Utility: add mini-assert library
2022-06-29 01:00:45 +03:00

46 lines
538 B
C++

//
// Created by erki on 29.06.22.
//
#include "utility_assert.hpp"
#include <exception>
namespace
{
Utility::Assert::assert_cb INSTALLED_HANDLER = nullptr;
}
namespace Utility::Assert
{
namespace Detail
{
void assertImpl(const bool expr, const char* file, const int line)
{
if (!expr)
{
if (INSTALLED_HANDLER)
INSTALLED_HANDLER(file, line);
else
std::terminate();
}
}
}
void setHandler(assert_cb callback)
{
INSTALLED_HANDLER = callback;
}
assert_cb getHandler()
{
return INSTALLED_HANDLER;
}
}