26#define KASSERT_ASSERTION_LEVEL_KTHROW 10
32#define KASSERT_ASSERTION_LEVEL_NORMAL 30
40#ifndef KASSERT_ASSERTION_LEVEL
41 #warning "Assertion level was not set explicitly; using default assertion level."
43 #define KASSERT_ASSERTION_LEVEL KASSERT_ASSERTION_LEVEL_NORMAL
61 KASSERT_KASSERT_HPP_VARARG_HELPER_3( \
64 KASSERT_3(__VA_ARGS__), \
65 KASSERT_2(__VA_ARGS__), \
66 KASSERT_1(__VA_ARGS__), \
82#define THROWING_KASSERT(...) \
83 KASSERT_KASSERT_HPP_VARARG_HELPER_2( \
86 THROWING_KASSERT_2(__VA_ARGS__), \
87 THROWING_KASSERT_1(__VA_ARGS__), \
104#define THROWING_KASSERT_SPECIFIED(expression, message, exception_type, ...) \
105 KASSERT_KASSERT_HPP_THROWING_KASSERT_CUSTOM_IMPL(expression, exception_type, message, ##__VA_ARGS__)
107namespace kassert::internal {
123[[maybe_unused]]
inline std::string
125 using namespace std::string_literals;
126 return "\n"s + where.
file +
": In function '" + where.
function +
"':\n" + where.
file +
": "
127 + std::to_string(where.
row) +
": FAILED ASSERTION\n" +
"\t" + expression +
"\n" + message +
"\n";
142 [[nodiscard]]
char const*
what() const noexcept final {
143 return _what.c_str();
152namespace kassert::internal {
165#define KASSERT_ENABLED(level) level <= KASSERT_ASSERTION_LEVEL
179 << where.
file <<
":" << where.
row <<
": FAILED " << type <<
"\n"
180 <<
"\t" << expr_str <<
"\n";
194 if (!expr.result()) {
196 << where.
file <<
":" << where.
row <<
": FAILED " << type <<
"\n"
197 <<
"\t" << expr_str <<
"\n"
198 <<
"with expansion:\n"
199 <<
"\t" << expr <<
"\n";
201 return expr.result();
Provides macros to implement the KASSERT, THROWING_KASSERT and THROWING_KASSERT_SPECIFIED macros.
The default exception type used together with THROWING_KASSERT. Reports the erroneous expression toge...
Definition: kassert.hpp:134
KassertException(std::string message)
Constructs the exception.
Definition: kassert.hpp:138
char const * what() const noexcept final
Gets a description of this exception.
Definition: kassert.hpp:142
Interface for decomposed unary and binary expressions.
Definition: expression_decomposition.hpp:55
Expression decomposition.
constexpr int kthrow
Assertion level for exceptions if exception mode is disabled.
Definition: kassert.hpp:29
#define KASSERT_ASSERTION_LEVEL_KTHROW
Assertion level for exceptions if exception mode is disabled.
Definition: kassert.hpp:26
#define KASSERT_ASSERTION_LEVEL_NORMAL
Default assertion level. This level is used if no assertion level is specified.
Definition: kassert.hpp:32
constexpr int normal
Default assertion level. This level is used if no assertion level is specified.
Definition: kassert.hpp:35
Logger< std::ostream & > OStreamLogger
Logger writing all output to a std::ostream. This specialization is used to generate the KASSERT erro...
Definition: logger.hpp:113
std::string build_what(std::string const &expression, SourceLocation const where, std::string const &message)
Builds the description for an exception.
Definition: kassert.hpp:124
bool evaluate_and_print_assertion(char const *type, bool result, SourceLocation const &where, char const *expr_str)
Evaluates an assertion that could not be decomposed (i.e., expressions that use && or ||)....
Definition: kassert.hpp:176
constexpr bool assertion_enabled(int level)
Checks if a assertion of the given level is enabled. This is controlled by the CMake option KASSERT_A...
Definition: kassert.hpp:157
#define KASSERT_ASSERTION_LEVEL
Default assertion level to kassert::assert::normal if not set explicitly.
Definition: kassert.hpp:43
Logger utility class to build error messages for failed assertins.
Assertion levels.
Definition: kassert.hpp:21
Describes a source code location.
Definition: kassert.hpp:109
char const * function
Function name.
Definition: kassert.hpp:115
unsigned row
Line number.
Definition: kassert.hpp:113
char const * file
Filename.
Definition: kassert.hpp:111