Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
IP
elsa
Commits
476b1c97
Commit
476b1c97
authored
Jan 29, 2022
by
David Frank
Browse files
Add custom assertions macros
parent
d2a9be89
Changes
3
Hide whitespace changes
Inline
Side-by-side
elsa/core/CMakeLists.txt
View file @
476b1c97
...
...
@@ -3,6 +3,7 @@ set(MODULE_HEADERS
elsaDefines.h
Backtrace.h
Cloneable.h
Utilities/Assertions.h
Utilities/Badge.hpp
Utilities/CartesianIndices.h
Utilities/DataContainerFormatter.hpp
...
...
@@ -37,6 +38,7 @@ set(MODULE_SOURCES
elsaDefines.cpp
Backtrace.cpp
Utilities/CartesianIndices.cpp
Utilities/Assertions.cpp
Descriptors/DataDescriptor.cpp
Descriptors/VolumeDescriptor.cpp
Descriptors/PlanarDetectorDescriptor.cpp
...
...
elsa/core/Utilities/Assertions.cpp
0 → 100644
View file @
476b1c97
#include "Assertions.h"
namespace
elsa
::
detail
{
void
assert_nomsg
(
const
char
*
expr_str
,
bool
expr
,
const
char
*
file
,
int
line
)
{
if
(
!
expr
)
{
std
::
cerr
<<
"Assert failed:
\n
"
<<
"Expected:
\t
"
<<
expr_str
<<
"
\n
"
<<
"Source:
\t\t
"
<<
file
<<
", line "
<<
line
<<
"
\n
"
;
abort
();
}
}
void
assert_msg
(
const
char
*
expr_str
,
bool
expr
,
const
char
*
file
,
int
line
,
const
char
*
msg
)
{
if
(
!
expr
)
{
std
::
cerr
<<
"Assert failed:
\t
"
<<
msg
<<
"
\n
"
<<
"Expected:
\t
"
<<
expr_str
<<
"
\n
"
<<
"Source:
\t\t
"
<<
file
<<
", line "
<<
line
<<
"
\n
"
;
abort
();
}
}
}
// namespace elsa::detail
elsa/core/Utilities/Assertions.h
0 → 100644
View file @
476b1c97
#pragma once
#include <iostream>
// Based on the standard paper P0627r0 (see
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0627r0.pdf)
#if defined(_MSC_VER)
#define ELSA_UNREACHABLE() __assume(false);
#elif defined(__GNUC__) or defined(__clang__)
// All gcc/clang compilers supporting c++17 have __builtin_unreachable
#define ELSA_UNREACHABLE() __builtin_unreachable()
#else
#include <exception>
#define ELSA_UNREACHABLE() std::terminate()
#endif
namespace
elsa
::
detail
{
void
assert_nomsg
(
const
char
*
expr_str
,
bool
expr
,
const
char
*
file
,
int
line
);
void
assert_msg
(
const
char
*
expr_str
,
bool
expr
,
const
char
*
file
,
int
line
,
const
char
*
msg
);
}
// namespace elsa::detail
#define GET_MACRO(_1, _2, NAME, ...) NAME
#define ELSA_VERIFY_IMPL2(Expr, Msg) \
::elsa::detail::assert_msg(#Expr, Expr, __FILE__, __LINE__, Msg)
#define ELSA_VERIFY_IMPL1(Expr) ::elsa::detail::assert_nomsg(#Expr, Expr, __FILE__, __LINE__)
#define ELSA_VERIFY(...) GET_MACRO(__VA_ARGS__, ELSA_VERIFY_IMPL2, ELSA_VERIFY_IMPL1)(__VA_ARGS__)
#define ELSA_TODO() ELSA_VERIFY(false, "TODO")
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment