Loading...
Searching...
No Matches
Go to the documentation of this file.
23#if !defined(SPARROW_CONTRACTS_THROW_ON_FAILURE)
24# define SPARROW_CONTRACTS_THROW_ON_FAILURE 0
28#if SPARROW_CONTRACTS_THROW_ON_FAILURE == 1
40#if not defined(SPARROW_CONTRACTS_USE_STD_PRINT) and not defined(SPARROW_CONTRACTS_USE_STD_FORMAT)
41# if __cplusplus >= 202002L
43# ifdef __cpp_lib_print
44# define SPARROW_CONTRACTS_USE_STD_PRINT 1
49# if defined(SPARROW_CONTRACTS_USE_STD_PRINT) and not defined(__cpp_lib_print)
50# error "std::print usage is requested but not available"
55#if not defined(SPARROW_CONTRACTS_USE_STD_FORMAT) and not defined(SPARROW_CONTRACTS_USE_STD_PRINT)
56# if __cplusplus >= 202002L
58# ifdef __cpp_lib_format
59# define SPARROW_CONTRACTS_USE_STD_FORMAT 1
63# if defined(SPARROW_CONTRACTS_USE_STD_FORMAT) and not defined(__cpp_lib_format)
64# error "std::format usage is requested but not available"
69#if defined(SPARROW_CONTRACTS_USE_CFORMAT) && SPARROW_CONTRACTS_USE_CFORMAT == 1
70# ifdef SPARROW_CONTRACTS_USE_STD_FORMAT
71# undef SPARROW_CONTRACTS_USE_STD_FORMAT
73# ifdef SPARROW_CONTRACTS_USE_STD_PRINT
74# undef SPARROW_CONTRACTS_USE_STD_PRINT
80# define SPARROW_CONTRACTS_IGNORE_WARNINGS \
81 _Pragma("GCC diagnostic push") \
82 _Pragma("GCC diagnostic ignored \"-Wall\"") \
83 _Pragma("GCC diagnostic ignored \"-Wformat-security\"")
84# define SPARROW_CONTRACTS_RESTORE_WARNINGS \
85 _Pragma("GCC diagnostic pop")
86#elif defined(__clang__)
87# define SPARROW_CONTRACTS_IGNORE_WARNINGS \
88 _Pragma("clang diagnostic push") \
89 _Pragma("clang diagnostic ignored \"-Weverything\"")
90# define SPARROW_CONTRACTS_RESTORE_WARNINGS \
91 _Pragma("clang diagnostic pop")
92#elif defined(_MSC_VER)
93# define SPARROW_CONTRACTS_IGNORE_WARNINGS \
94 _Pragma("warning(push)") \
95 _Pragma("warning(disable : 4774)")
96# define SPARROW_CONTRACTS_RESTORE_WARNINGS \
97 _Pragma("warning(pop)")
99# define SPARROW_CONTRACTS_IGNORE_WARNINGS
100# define SPARROW_CONTRACTS_RESTORE_WARNINGS
104#ifndef SPARROW_CONTRACTS_LOG_FAILURE
105# if defined(SPARROW_CONTRACTS_USE_STD_PRINT) && SPARROW_CONTRACTS_USE_STD_PRINT == 1
109# define SPARROW_CONTRACTS_LOG_FAILURE(expr__, message__) \
110 ::std::print(stderr, "Assertion Failed ({}:{}): {} - ({} is wrong)\n", __FILE__, __LINE__, message__, #expr__)
112# elif defined(SPARROW_CONTRACTS_USE_STD_FORMAT) && SPARROW_CONTRACTS_USE_STD_FORMAT == 1
116# define SPARROW_CONTRACTS_LOG_FAILURE( expr__, message__ ) \
118 auto msg = ::std::format("Assertion Failed ({}:{}): {} - ({} is wrong)\n", __FILE__, __LINE__, message__, #expr__); \
119 ::fprintf(stderr, "%s", msg.c_str()); \
126# define SPARROW_CONTRACTS_LOG_FAILURE(expr__, message__) \
127 ::fprintf(stderr, "Assertion Failed (%s:%i): %s - (%s is wrong)\n", __FILE__, __LINE__, message__, #expr__);
132#ifndef SPARROW_CONTRACTS_ABORT
133# if SPARROW_CONTRACTS_THROW_ON_FAILURE == 1
134# if defined(SPARROW_CONTRACTS_USE_STD_FORMAT) && SPARROW_CONTRACTS_USE_STD_FORMAT == 1
135# define SPARROW_CONTRACTS_ABORT(expr__, message__) \
136 throw ::sparrow::contract_assertion_error( \
137 ::std::format("Assertion Failed ({}:{}): {} - ({} is wrong)", __FILE__, __LINE__, message__, #expr__) \
140# define SPARROW_CONTRACTS_ABORT(expr__, message__) \
141 throw ::sparrow::contract_assertion_error( \
142 ::std::string("Assertion Failed (") + __FILE__ + ":" + ::std::to_string(__LINE__) \
143 + "): " + message__ + " - (" + #expr__ + " is wrong)" \
147# define SPARROW_CONTRACTS_ABORT(expr__, message__) std::abort()
152#if defined(SPARROW_CONTRACTS_CONTINUE_ON_FAILURE) and SPARROW_CONTRACTS_CONTINUE_ON_FAILURE == 1
153# undef SPARROW_CONTRACTS_ABORT
154# if SPARROW_CONTRACTS_THROW_ON_FAILURE == 1
155# define SPARROW_CONTRACTS_ABORT(expr__, message__)
157# define SPARROW_CONTRACTS_ABORT
161#ifndef SPARROW_CONTRACTS_DEBUGBREAK
163# define SPARROW_CONTRACTS_DEBUGBREAK() __debugbreak();
165# define SPARROW_CONTRACTS_DEBUGBREAK() std::raise(SIGTRAP);
172#define SPARROW_CONTRACTS_DEFAULT_CHECKS_ENABLED 1
173#define SPARROW_CONTRACTS_DEFAULT_ABORT_ON_FAILURE 1
175#define SPARROW_CONTRACTS_DEFAULT_ON_FAILURE(expr__, message__) \
176 SPARROW_CONTRACTS_LOG_FAILURE(expr__, message__); \
177 SPARROW_CONTRACTS_DEBUGBREAK(); \
178 SPARROW_CONTRACTS_ABORT(expr__, message__);
184#ifndef SPARROW_CONTRACTS_CHECKS_ENABLED
185# define SPARROW_CONTRACTS_CHECKS_ENABLED SPARROW_CONTRACTS_DEFAULT_CHECKS_ENABLED
188#if SPARROW_CONTRACTS_CHECKS_ENABLED == 1
190# ifndef SPARROW_CONTRACTS_ON_FAILURE
191# define SPARROW_CONTRACTS_ON_FAILURE(expr__, message__) \
192 SPARROW_CONTRACTS_DEFAULT_ON_FAILURE(expr__, message__)
195# ifndef SPARROW_ASSERT
196# define SPARROW_ASSERT(expr__, message__) \
199 SPARROW_CONTRACTS_ON_FAILURE(expr__, message__); \
203# define SPARROW_ASSERT_TRUE(expr__) SPARROW_ASSERT(expr__, #expr__)
204# define SPARROW_ASSERT_FALSE(expr__) SPARROW_ASSERT(!(expr__), "!(" #expr__ ")")
207# define SPARROW_CONTRACTS_ON_FAILURE(expr__)
208# define SPARROW_ASSERT(expr__, message__)
209# define SPARROW_ASSERT_TRUE(expr__)
210# define SPARROW_ASSERT_FALSE(expr__)