The Sparta Modeling Framework
Loading...
Searching...
No Matches
SpartaAssert.hpp File Reference

Set of macros for Sparta assertions. Caught by the framework. More...

#include <exception>
#include <string>
#include <iostream>
#include <sstream>
#include "sparta/utils/SpartaException.hpp"

Go to the source code of this file.

Macros

#define SPARTA_EXPECT_FALSE(x)   __builtin_expect(!!(x), false)
 A macro for hinting to the compiler a particular condition should be considered most likely false.
 
#define SPARTA_EXPECT_TRUE(x)   __builtin_expect(!!(x), true)
 A macro for hinting to the compiler a particular condition should be considered most likely true.
 
#define sparta_assert(...)   sparta_assert_impl(VA_NARGS(__VA_ARGS__), __VA_ARGS__)
 Simple variadic assertion that will throw a sparta_exception if the condition fails.
 
#define sparta_assert_errno(_cond)    sparta_assert(_cond, std::string(std::strerror(errno)))
 Simple assert macro that throws a sparta_exception with a string representation of errno.
 
#define sparta_abort(...)   sparta_abort_impl(VA_NARGS(__VA_ARGS__), __VA_ARGS__)
 Simple variatic assertion that will print a message to std::cerr and call std::terminate()
 

Detailed Description

Set of macros for Sparta assertions. Caught by the framework.

Definition in file SpartaAssert.hpp.

Macro Definition Documentation

◆ sparta_abort

#define sparta_abort (   ...)    sparta_abort_impl(VA_NARGS(__VA_ARGS__), __VA_ARGS__)

Simple variatic assertion that will print a message to std::cerr and call std::terminate()

Use instead of sparta_assert() whenever you need an assertion in a noexcept(true) function (commonly destructors).

Note
This assertion remains even if compiling with NDEBUG

How to use:

sparta_abort(condition);
sparta_abort(condition, "My nasty gram");
sparta_abort(condition, "ostream supported message with a value: " << value);
#define sparta_abort(...)
Simple variatic assertion that will print a message to std::cerr and call std::terminate()

Mental thought "Make sure that condition is true. If not print message and abort"

Definition at line 145 of file SpartaAssert.hpp.

◆ sparta_assert

#define sparta_assert (   ...)    sparta_assert_impl(VA_NARGS(__VA_ARGS__), __VA_ARGS__)

Simple variadic assertion that will throw a sparta_exception if the condition fails.

Exceptions
SpartaExceptionincluding file and line information if e evaluates to false
Note
This assertion remains even if compiling with NDEBUG

How to use:

sparta_assert(condition);
sparta_assert(condition, "My nasty gram");
sparta_assert(condition, "ostream supported message with a value: " << value);
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.

Mental thought "Make sure that condition is true. If not send message"

Examples
/github/workspace/sparta/sparta/pevents/PEventHelper.hpp.

Definition at line 114 of file SpartaAssert.hpp.

◆ sparta_assert_errno

#define sparta_assert_errno (   _cond)     sparta_assert(_cond, std::string(std::strerror(errno)))

Simple assert macro that throws a sparta_exception with a string representation of errno.

Definition at line 123 of file SpartaAssert.hpp.

◆ SPARTA_EXPECT_FALSE

#define SPARTA_EXPECT_FALSE (   x)    __builtin_expect(!!(x), false)

A macro for hinting to the compiler a particular condition should be considered most likely false.

if(SPARTA_EXPECT_FALSE(my_usually_false_condition)) {}
#define SPARTA_EXPECT_FALSE(x)
A macro for hinting to the compiler a particular condition should be considered most likely false.
Examples
/github/workspace/sparta/sparta/pevents/PEventHelper.hpp.

Definition at line 27 of file SpartaAssert.hpp.

◆ SPARTA_EXPECT_TRUE

#define SPARTA_EXPECT_TRUE (   x)    __builtin_expect(!!(x), true)

A macro for hinting to the compiler a particular condition should be considered most likely true.

if(SPARTA_EXPECT_TRUE(my_usually_true_condition)) {}
#define SPARTA_EXPECT_TRUE(x)
A macro for hinting to the compiler a particular condition should be considered most likely true.

Definition at line 38 of file SpartaAssert.hpp.