Workspace 6.21.5
|
#include <functional>
#include <stdexcept>
#include <QFileInfo>
#include <QString>
#include "Workspace/api_workspace.h"
#include <csignal>
Classes | |
class | Assert |
Namespaces | |
namespace | CSIRO |
Top level namespace for all Workspace code. | |
Macros | |
#define | WS_ASSERT_FAIL(msg) |
#define | WS_ASSERT_LOGIC(cond) |
#define | WS_ASSERT_LOGIC_MSG(cond, msg) |
#define | WS_ASSERT_RUNTIME(cond) |
#define | WS_ASSERT_RUNTIME_MSG(cond, msg) |
#define | WS_HALT() std::raise(SIGTRAP) |
#define | WS_VERIFY_RUNTIME(cond) |
#define | WS_VERIFY_RUNTIME_MSG(cond, msg) |
Functions | |
template<typename T > | |
std::enable_if_t< std::is_convertible< T, bool >::value > | validateExpression () |
template<typename T > | |
std::enable_if_t< std::is_convertible< T, QString >::value > | validateString () |
#define WS_ASSERT_FAIL | ( | msg | ) |
Use this macro to protect sections of the code that should not be entered.
This macro is only active in debug (i.e. when NDEBUG is not defined). In release, the macro evaluates to nothing.
#define WS_ASSERT_LOGIC | ( | cond | ) |
Use this macro to assert behaviour related to the internal logic of a program. Errors of this type are assumed to be "detectable" before the program executes.
This macro is only active in debug (i.e. when NDEBUG is not defined). In release, the macro evaluates to nothing.
#define WS_ASSERT_LOGIC_MSG | ( | cond, | |
msg | |||
) |
Identical to WS_ASSERT_LOGIC but with a message that will be printed if the assert fails.
This macro is only active in debug (i.e. when NDEBUG is not defined). In release, the macro evaluates to nothing.
The msg passed in has to be of the type const char*.
#define WS_ASSERT_RUNTIME | ( | cond | ) |
Use this macro to assert conditions that can only be validated at runtime. Assertions of this type are usually used to guard against impossible user input or data variations.
This macro is only active in debug (i.e. when NDEBUG is not defined). In release, the macro evaluates to nothing.
#define WS_ASSERT_RUNTIME_MSG | ( | cond, | |
msg | |||
) |
Identical to WS_ASSERT_RUNTIME but with a message that will be printed if the assert fails.
This macro is only active in debug (i.e. when NDEBUG is not defined). In release, the macro evaluates to nothing.
The msg passed in has to be of the type const char*.
#define WS_HALT | ( | ) | std::raise(SIGTRAP) |
#define WS_VERIFY_RUNTIME | ( | cond | ) |
This macro is identical to WS_ASSERT_RUNTIME except that it is evaluated even in release mode.
#define WS_VERIFY_RUNTIME_MSG | ( | cond, | |
msg | |||
) |
This macro is identical to WS_VERIFY_RUNTIME except that it is prints the specified message when the verification fails. It is evaluated even in release mode. The msg passed in could be formatted QString or anything QString::arg accept, be aware that formatting a QString may throw std::bad_alloc if memory allocation fails.
Sample usages:
WS_VERIFY_RUNTIME_MSG(ptr != nullptr, "A pointer that is not expected to be null."); // exception thrown when ptr is nullptr. ptr->foo(); // ptr is guaranteed to be not nullptr.
WS_VERIFY_RUNTIME_MSG(value > 0, QString("A value expected to be positive, but turned out to be %1.").arg(value));