Loading...
Searching...
No Matches
Go to the documentation of this file.
28#if not defined(SPARROW_CONTRACTS_USE_STD_PRINT) and not defined(SPARROW_CONTRACTS_USE_STD_FORMAT)
29# if __cplusplus >= 202002L
31# ifdef __cpp_lib_print
32# define SPARROW_CONTRACTS_USE_STD_PRINT 1
37# if defined(SPARROW_CONTRACTS_USE_STD_PRINT) and not defined(__cpp_lib_print)
38# error "std::print usage is requested but not available"
43#if not defined(SPARROW_CONTRACTS_USE_STD_FORMAT) and not defined(SPARROW_CONTRACTS_USE_STD_PRINT)
44# if __cplusplus >= 202002L
46# ifdef __cpp_lib_format
47# define SPARROW_CONTRACTS_USE_STD_FORMAT 1
51# if defined(SPARROW_CONTRACTS_USE_STD_FORMAT) and not defined(__cpp_lib_format)
52# error "std::format usage is requested but not available"
57#if defined(SPARROW_CONTRACTS_USE_CFORMAT) && SPARROW_CONTRACTS_USE_CFORMAT == 1
58# ifdef SPARROW_CONTRACTS_USE_STD_FORMAT
59# undef SPARROW_CONTRACTS_USE_STD_FORMAT
61# ifdef SPARROW_CONTRACTS_USE_STD_PRINT
62# undef SPARROW_CONTRACTS_USE_STD_PRINT
68# define SPARROW_CONTRACTS_IGNORE_WARNINGS \
69 _Pragma("GCC diagnostic push") \
70 _Pragma("GCC diagnostic ignored \"-Wall\"") \
71 _Pragma("GCC diagnostic ignored \"-Wformat-security\"")
72# define SPARROW_CONTRACTS_RESTORE_WARNINGS \
73 _Pragma("GCC diagnostic pop")
74#elif defined(__clang__)
75# define SPARROW_CONTRACTS_IGNORE_WARNINGS \
76 _Pragma("clang diagnostic push") \
77 _Pragma("clang diagnostic ignored \"-Weverything\"")
78# define SPARROW_CONTRACTS_RESTORE_WARNINGS \
79 _Pragma("clang diagnostic pop")
80#elif defined(_MSC_VER)
81# define SPARROW_CONTRACTS_IGNORE_WARNINGS \
82 _Pragma("warning(push)") \
83 _Pragma("warning(disable : 4774)")
84# define SPARROW_CONTRACTS_RESTORE_WARNINGS \
85 _Pragma("warning(pop)")
87# define SPARROW_CONTRACTS_IGNORE_WARNINGS
88# define SPARROW_CONTRACTS_RESTORE_WARNINGS
92#ifndef SPARROW_CONTRACTS_LOG_FAILURE
93# if defined(SPARROW_CONTRACTS_USE_STD_PRINT) && SPARROW_CONTRACTS_USE_STD_PRINT == 1
97# define SPARROW_CONTRACTS_LOG_FAILURE(expr__, message__) \
98 ::std::print(stderr, "Assertion Failed ({}:{}): {} - ({} is wrong)\n", __FILE__, __LINE__, message__, #expr__)
100# elif defined(SPARROW_CONTRACTS_USE_STD_FORMAT) && SPARROW_CONTRACTS_USE_STD_FORMAT == 1
104# define SPARROW_CONTRACTS_LOG_FAILURE( expr__, message__ ) \
106 SPARROW_CONTRACTS_IGNORE_WARNINGS; \
107 ::fprintf(stderr, ::std::format("Assertion Failed ({}:{}): {} - ({} is wrong)\n", __FILE__, __LINE__, message__, #expr__ ).c_str()); \
108 SPARROW_CONTRACTS_RESTORE_WARNINGS; \
115# define SPARROW_CONTRACTS_LOG_FAILURE(expr__, message__) \
116 ::fprintf(stderr, "Assertion Failed (%s:%i): %s - (%s is wrong)\n", __FILE__, __LINE__, message__, #expr__);
121#ifndef SPARROW_CONTRACTS_ABORT
122# define SPARROW_CONTRACTS_ABORT() std::abort()
126#if defined(SPARROW_CONTRACTS_CONTINUE_ON_FAILURE) and SPARROW_CONTRACTS_CONTINUE_ON_FAILURE == 1
127# undef SPARROW_CONTRACTS_ABORT
128# define SPARROW_CONTRACTS_ABORT
131#ifndef SPARROW_CONTRACTS_DEBUGBREAK
133# define SPARROW_CONTRACTS_DEBUGBREAK() __debugbreak();
135# define SPARROW_CONTRACTS_DEBUGBREAK() std::raise(SIGTRAP);
142#define SPARROW_CONTRACTS_DEFAULT_CHECKS_ENABLED 1
143#define SPARROW_CONTRACTS_DEFAULT_ABORT_ON_FAILURE 1
145#define SPARROW_CONTRACTS_DEFAULT_ON_FAILURE(expr__, message__) \
146 SPARROW_CONTRACTS_LOG_FAILURE(expr__, message__); \
147 SPARROW_CONTRACTS_DEBUGBREAK(); \
148 SPARROW_CONTRACTS_ABORT();
154#ifndef SPARROW_CONTRACTS_CHECKS_ENABLED
155# define SPARROW_CONTRACTS_CHECKS_ENABLED SPARROW_CONTRACTS_DEFAULT_CHECKS_ENABLED
158#if SPARROW_CONTRACTS_CHECKS_ENABLED == 1
160# ifndef SPARROW_CONTRACTS_ON_FAILURE
161# define SPARROW_CONTRACTS_ON_FAILURE(expr__, message__) \
162 SPARROW_CONTRACTS_DEFAULT_ON_FAILURE(expr__, message__)
165# ifndef SPARROW_ASSERT
166# define SPARROW_ASSERT(expr__, message__) \
169 SPARROW_CONTRACTS_ON_FAILURE(expr__, message__); \
173# define SPARROW_ASSERT_TRUE(expr__) SPARROW_ASSERT(expr__, #expr__)
174# define SPARROW_ASSERT_FALSE(expr__) SPARROW_ASSERT(!(expr__), "!(" #expr__ ")")
177# define SPARROW_CONTRACTS_ON_FAILURE(expr__)
178# define SPARROW_ASSERT(expr__, message__)
179# define SPARROW_ASSERT_TRUE(expr__)
180# define SPARROW_ASSERT_FALSE(expr__)