Asserts module

Butano assert system.

It can be enabled or disabled by overloading the definition of BN_CFG_ASSERT_ENABLED.

Note that these asserts can be used in constexpr contexts (is_constant_evaluated() returns true).

Files

file bn_assert.h
file bn_assert_callback_type.h
file bn_config_assert.h

Namespaces

namespace bn
Main Butano namespace.
namespace bn::assert
Assert related functions.

Defines

#define BN_ASSERT(condition, ...)
#define BN_BASIC_ASSERT
#define BN_ERROR(...)
#define BN_ASSERT_FILE
#define BN_CFG_ASSERT_ENABLED
#define BN_CFG_ASSERT_SHOW_DIAGNOSTIC
#define BN_CFG_ASSERT_BUFFER_SIZE
#define BN_CFG_ASSERT_STACKTRACE_DEMANGLE

Define documentation

#define BN_ASSERT(condition, ...)
#include <bn_assert.h>

Checks if the specified condition is true.

If it doesn't, the execution is stopped and diagnostic information is shown on the screen.

More information can be shown by passing it by argument.

Example:

BN_ASSERT(integer > 0, "Invalid integer: ", integer);

Custom parameter types are supported by overloading bn::ostringstream::operator<<.

Example:

bn::ostringstream& operator<<(bn::ostringstream& stream, const custom_type& custom_value)
{
    stream.append("custom_type: ");
    stream.append(custom_value.data);
    return stream;
}

Note that it can be used in constexpr contexts (is_constant_evaluated() returns true).

#define BN_BASIC_ASSERT
#include <bn_assert.h>

Checks if the specified condition is true.

If it doesn't, the execution is stopped and basic diagnostic information is shown on the screen.

More information can be shown by passing it by argument.

Example:

BN_BASIC_ASSERT(integer > 0, "Invalid integer: ", integer);

Custom parameter types are supported by overloading bn::ostringstream::operator<<.

Example:

bn::ostringstream& operator<<(bn::ostringstream& stream, const custom_type& custom_value)
{
    stream.append("custom_type: ");
    stream.append(custom_value.data);
    return stream;
}

Note that it can be used in constexpr contexts (is_constant_evaluated() returns true).

#define BN_ERROR(...)
#include <bn_assert.h>

If this is called, the execution is stopped and diagnostic information is shown on the screen.

More information can be shown by passing it by argument.

Example:

BN_ERROR("Invalid integer: ", integer);

Custom parameter types are supported by overloading bn::ostringstream::operator<<.

Example:

bn::ostringstream& operator<<(bn::ostringstream& stream, const custom_type& custom_value)
{
    stream.append("custom_type: ");
    stream.append(custom_value.data);
    return stream;
}

Note that it can be used in constexpr contexts (is_constant_evaluated() returns true).

#define BN_ASSERT_FILE
#include <bn_assert.h>

Current input file name if available; otherwise an empty string.

#define BN_CFG_ASSERT_ENABLED

Specifies if asserts must be enabled or not.

#define BN_CFG_ASSERT_SHOW_DIAGNOSTIC

Specifies if asserts diagnostic information must be shown or not.

Disabling diagnostic information reduces ROM size.

#define BN_CFG_ASSERT_BUFFER_SIZE

Specifies the maximum size of the messages that can be displayed by an assert.

#define BN_CFG_ASSERT_STACKTRACE_DEMANGLE

Indicates if the stack trace logged in error messages must be demangled or not.

Stack trace demangle requires to link standard system libraries (DEFAULTLIBS makefile variable).

Expect a crash after logging the stack trace.