COMMS
Template library intended to help with implementation of communication protocols.
Custom Assertion Failure Behaviour

First of all, there is a need to define a custom assertion failure report class which inherits from comms::Assert and overrides pure virtual member function fail():

#include "comms/comms.h"
class MyAssert : public comms::Assert
{
public:
MyAssert(...) {...} // The constructor may receive any parameters needed
protected:
virtual void fail(
const char* expr,
const char* file,
unsigned int line,
const char* function) override
{
... // Do the failure report
}
private:
... // Any data members
}
Base class for any custom assertion behaviour.
Definition: Assert.h:27
virtual void fail(const char *expr, const char *file, unsigned int line, const char *function)=0
Pure virtual function to be called when assertion fails.
Aggregates all the includes of the COMMS library interface.

The second stage is to enable/register the the custom assertion failure behaviour:

int main(int argc, const char* argv[])
{
// From this point custom assertion failure bahaviour takes place.
...
}
Enable new assertion behaviour.
Definition: Assert.h:100

It is also possible to override custom assertion failure behavior several times:

int main(int argc, const char* argv[])
{
// From this point custom assertion failure bahaviour takes place.
...
{
// From this point different custom assertion failure bahaviour
// defined in SomeOtherMyAssert class takes place.
...
} // assert2 is out of scope, the custom assertion failure behavior
// registered with assert1 is restored.
...
}