CppELib 1.7.0
Loading...
Searching...
No Matches
Assertion.h File Reference
#include <cstddef>

Go to the source code of this file.

Classes

class  Assertion::AssertHandler
 Interface for handling assertion failure by CHECK_ASSERT() macro. More...
 
class  Assertion::Failure
 Class used when CHECK_ASSERT() macro fails. More...
 

Namespaces

namespace  Assertion
 

Macros

#define CPPELIB_ASSERTION_FAILURE_BUFSIZE   (512)
 Buffer size of Assertion::Failure object.
 
#define CHECK_ASSERT(x)    ((x) ? (void)0 : Assertion::Failure::assertFail(__FILE__, __LINE__, #x))
 Used instead of standard assert() macro for implementing Design by Contract.
 
#define DEBUG_ASSERT(x)   CHECK_ASSERT(x)
 The same as CHECK_ASSERT() macro.
 

Functions

void Assertion::setHandler (AssertHandler *handler)
 Set AssertHandler.
 

Macro Definition Documentation

◆ CHECK_ASSERT

#define CHECK_ASSERT (   x)     ((x) ? (void)0 : Assertion::Failure::assertFail(__FILE__, __LINE__, #x))

Used instead of standard assert() macro for implementing Design by Contract.

Note
This macro is always enabled.

If an assertion fails, you must handle to do shutdown your application safely. In the assertion failure function, the Assertion::AssertHandler that is set by Assertion::setHandler() is called. If Assertion::AssertHandler is not set, the exception Assertion::Failure is thrown.

Attention
If CPPELIB_NO_EXCEPTIONS macro is defined, the exception is not thrown, therefore you must surely set Assertion::AssertHandler.

◆ CPPELIB_ASSERTION_FAILURE_BUFSIZE

#define CPPELIB_ASSERTION_FAILURE_BUFSIZE   (512)

Buffer size of Assertion::Failure object.

This buffer is used as assertion failure message when an assertion fails. That time, Assertion::Failure object is allocated on the stack. If the stack size of the thread is small, you can define this macro by preprocessor according as the stack size. If you define this buffer size smaller than the default value, assertion failure message might be cut off.

◆ DEBUG_ASSERT

#define DEBUG_ASSERT (   x)    CHECK_ASSERT(x)

The same as CHECK_ASSERT() macro.

Note
When NDEBUG macro is defined, calls of this macro is disabled by preprocessor.