Nix (Dev) 3.5.10
dev - 3.5.10 - 1af9301
Loading...
Searching...
No Matches
assert.hpp File Reference
#include <string>
Include dependency graph for assert.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  iv
 
namespace  iv::assert
 

Macros

#define ASSERT_FUNCTION_   __extension__ __PRETTY_FUNCTION__
 
#define IV_ARG_CHECK(expr, msg, ...)
 
#define IV_STATE_CHECK(expr)
 
#define IV_ASSERT(expr, assertion_made, ...)
 
#define IV_ASSERT_NOMSG(expr, ...)
 
#define IV_ASSERT_IMPLICATION(expr1, expr2, msg, ...)
 
#define IV_ASSERT_NULL_POINTER(ptr)
 
#define IV_UNUSED   iv::assert::ignoreParams
 
#define IV_ASSERT_UNREACHABLE()
 
#define IV_ASSERT_MSG(msg, ...)
 
#define IV_MISSING_CASE_CHECK(msg, ...)
 
#define IV_ASSERT_EQUAL(expr1, expr2, assertion_made)
 

Functions

void iv::assert::assertionFailure (const char *exprString, const char *assertionMade, const char *func, const char *file, int line)
 
void iv::assert::throwInvalidArgument (const char *message, const char *func, const char *file)
 
void iv::assert::throwInvalidState (const char *expr, const char *func, const char *file)
 
template<typename T >
void iv::assert::ignoreParam (T &&)
 
template<typename... T>
void iv::assert::ignoreParams (T &&...args)
 
void iv::assert::assertUnreachable (const char *file, int line)
 
void iv::assert::assertionMessage (const char *message, const char *func, const char *file, int line)
 
void iv::assert::debugInfo (std::string_view message)
 
void iv::assert::debugMessage (std::string_view message)
 
void iv::assert::debugError (std::string_view message)
 
void throwMissingCase (const char *message, const char *func, const char *file)
 

Variables

template<class... >
constexpr bool iv::assert::always_false = false
 

Macro Definition Documentation

◆ ASSERT_FUNCTION_

#define ASSERT_FUNCTION_   __extension__ __PRETTY_FUNCTION__

◆ IV_ARG_CHECK

#define IV_ARG_CHECK ( expr,
msg,
... )
Value:
do \
{ \
if (not(expr)) \
iv::assert::throwInvalidArgument(msg, ASSERT_FUNCTION_, __FILE__); \
} while (0)
#define ASSERT_FUNCTION_
Definition assert.hpp:68

Called when an invalid state is encountered Throws Invalid_State

◆ IV_ASSERT

#define IV_ASSERT ( expr,
assertion_made,
... )
Value:
do \
{ \
if (not(expr)) \
iv::assert::assertionFailure(#expr, assertion_made, ASSERT_FUNCTION_, __FILE__, __LINE__); \
} while (0)

Make an assertion

◆ IV_ASSERT_EQUAL

#define IV_ASSERT_EQUAL ( expr1,
expr2,
assertion_made )
Value:
do \
{ \
if ((expr1) != (expr2)) \
iv::assert::assertionFailure(#expr1 " == " #expr2, assertion_made, __func__, __FILE__, __LINE__); \
} while (0)

Assert that value1 == value2

◆ IV_ASSERT_IMPLICATION

#define IV_ASSERT_IMPLICATION ( expr1,
expr2,
msg,
... )
Value:
do \
{ \
if ((expr1) && not(expr2)) \
iv::assert::assertionFailure(#expr1 " implies " #expr2, msg, ASSERT_FUNCTION_, __FILE__, __LINE__); \
} while (0)

Assert that expr1 (if true) implies expr2 is also true

◆ IV_ASSERT_MSG

#define IV_ASSERT_MSG ( msg,
... )
Value:
do \
{ \
iv::assert::assertionMessage(msg, ASSERT_FUNCTION_, __FILE__, __LINE__); \
} while (0)

Make an message assertion

Deprecated

◆ IV_ASSERT_NOMSG

#define IV_ASSERT_NOMSG ( expr,
... )
Value:
do \
{ \
if (not(expr)) \
iv::assert::assertionFailure(#expr, "", ASSERT_FUNCTION_, __FILE__, __LINE__); \
} while (0)

Make an assertion

◆ IV_ASSERT_NULL_POINTER

#define IV_ASSERT_NULL_POINTER ( ptr)
Value:
do \
{ \
if ((ptr) == nullptr) \
iv::assert::assertionFailure(#ptr " is null", "", ASSERT_FUNCTION_, __FILE__, __LINE__); \
} while (0)

Assert that a pointer is not null

◆ IV_ASSERT_UNREACHABLE

#define IV_ASSERT_UNREACHABLE ( )
Value:
iv::assert::assertUnreachable(__FILE__, __LINE__)
void assertUnreachable(const char *file, int line)
Definition assert.cpp:69

Define assertUnreachable and IV_ASSERT_UNREACHABLE

◆ IV_MISSING_CASE_CHECK

#define IV_MISSING_CASE_CHECK ( msg,
... )
Value:
do \
{ \
throwMissingCase(#msg, __func__, __FILE__); \
} while (0)

◆ IV_STATE_CHECK

#define IV_STATE_CHECK ( expr)
Value:
do \
{ \
if (not(expr)) \
iv::assert::throwInvalidState(#expr, ASSERT_FUNCTION_, __FILE__); \
} while (0)

Called when an invalid state is encountered Throws InvalidState

◆ IV_UNUSED

#define IV_UNUSED   iv::assert::ignoreParams

Mark variable as unused.

Takes any number of arguments and marks all as unused, for instance IV_UNUSED(a); or IV_UNUSED(x, y, z);

Function Documentation

◆ throwMissingCase()

void throwMissingCase ( const char * message,
const char * func,
const char * file )

Called when switch-case not has a valid default value Throws InvalidArgument