preCICE v3.1.2
Loading...
Searching...
No Matches
Namespaces | Macros | Variables
assertion.hpp File Reference
#include <cstdlib>
#include <iostream>
#include <string_view>
#include "utils/fmt.hpp"
#include <boost/current_function.hpp>
#include <boost/preprocessor/comparison/greater.hpp>
#include <boost/preprocessor/control/if.hpp>
#include <boost/preprocessor/stringize.hpp>
#include <boost/preprocessor/variadic/size.hpp>
#include "utils/ArgumentFormatter.hpp"
#include "utils/Parallel.hpp"
#include "utils/stacktrace.hpp"
#include <cassert>
Include dependency graph for assertion.hpp:

Go to the source code of this file.

Namespaces

namespace  precice
 Main namespace of the precice library.
 
namespace  precice::utils
 contains precice-related utilities.
 

Macros

#define PRECICE_ASSERT_WRAPPER()   assert(false)
 
#define PRECICE_ASSERT_IMPL(check, args)
 
#define PRECICE_ASSERT_IMPL_N(check, ...)    PRECICE_ASSERT_IMPL(check, PRECICE_LOG_ARGUMENTS(__VA_ARGS__))
 
#define PRECICE_ASSERT_IMPL_1(check)    PRECICE_ASSERT_IMPL(check, "none")
 
#define PRECICE_ASSERT(...)
 
#define PRECICE_UNREACHABLE(...)
 

Variables

static constexpr std::string_view precice::utils::ASSERT_FMT
 

Macro Definition Documentation

◆ PRECICE_ASSERT

#define PRECICE_ASSERT ( ...)
Value:
BOOST_PP_CAT(PRECICE_ASSERT_IMPL_, BOOST_PP_IF(BOOST_PP_GREATER(BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), 1), N, 1)) \
(__VA_ARGS__)

Asserts either a single statement or a statement followed by multiple arguments.

This dispatches to PRECICE_ASSERT_IMPL_1 if only a check is provided, otherwise to PRECICE_ASSERT_IMPL_N

Definition at line 87 of file assertion.hpp.

◆ PRECICE_ASSERT_IMPL

#define PRECICE_ASSERT_IMPL ( check,
args )
Value:
do { \
if (!(check)) { \
BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, \
BOOST_PP_STRINGIZE(check), \
args, \
<< std::flush; \
std::cout.flush(); \
PRECICE_ASSERT_WRAPPER(); \
} \
} while (false)
static Rank getProcessRank()
Definition Parallel.cpp:299
T flush(T... args)
static constexpr std::string_view ASSERT_FMT
Definition assertion.hpp:38
std::string format_or_error(std::string_view str)
Definition fmt.hpp:19
std::string getStacktrace()
Returns a demangled stack backtrace of the caller function.
Definition stacktrace.cpp:7

Main implementation of the assertion

Parameters
[in]checkthe expression which needs to evaluate to true for the assertion to pass
[in]argsthe expression which evaluates to the formatted arguments

Definition at line 61 of file assertion.hpp.

◆ PRECICE_ASSERT_IMPL_1

#define PRECICE_ASSERT_IMPL_1 ( check)     PRECICE_ASSERT_IMPL(check, "none")

Definition at line 80 of file assertion.hpp.

◆ PRECICE_ASSERT_IMPL_N

#define PRECICE_ASSERT_IMPL_N ( check,
... )    PRECICE_ASSERT_IMPL(check, PRECICE_LOG_ARGUMENTS(__VA_ARGS__))

Definition at line 77 of file assertion.hpp.

◆ PRECICE_ASSERT_WRAPPER

#define PRECICE_ASSERT_WRAPPER ( )    assert(false)

Definition at line 52 of file assertion.hpp.

◆ PRECICE_UNREACHABLE

#define PRECICE_UNREACHABLE ( ...)
Value:
{ \
std::abort(); \
}
T endl(T... args)

Displays an error message and aborts the program independent of the build type. Use to mark unreachable statements under switch or if blocks.

Definition at line 95 of file assertion.hpp.