added iOS source code
[wl-app.git] / iOS / Pods / Realm / include / core / realm / util / assert.hpp
1 /*************************************************************************
2  *
3  * Copyright 2016 Realm Inc.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  **************************************************************************/
18
19 #ifndef REALM_UTIL_ASSERT_HPP
20 #define REALM_UTIL_ASSERT_HPP
21
22 #include <realm/util/features.h>
23 #include <realm/util/terminate.hpp>
24
25 #if REALM_ENABLE_ASSERTIONS || defined(REALM_DEBUG)
26 #define REALM_ASSERTIONS_ENABLED 1
27 #else
28 #define REALM_ASSERTIONS_ENABLED 0
29 #endif
30
31 #define REALM_ASSERT_RELEASE(condition)                                                                              \
32     (REALM_LIKELY(condition) ? static_cast<void>(0)                                                                  \
33                              : realm::util::terminate("Assertion failed: " #condition, __FILE__, __LINE__))
34
35 #if REALM_ASSERTIONS_ENABLED
36 #define REALM_ASSERT(condition) REALM_ASSERT_RELEASE(condition)
37 #else
38 #define REALM_ASSERT(condition) static_cast<void>(sizeof bool(condition))
39 #endif
40
41 #ifdef REALM_DEBUG
42 #define REALM_ASSERT_DEBUG(condition) REALM_ASSERT_RELEASE(condition)
43 #else
44 #define REALM_ASSERT_DEBUG(condition) static_cast<void>(sizeof bool(condition))
45 #endif
46
47 #define REALM_STRINGIFY(X) #X
48
49 #define REALM_ASSERT_RELEASE_EX(condition, ...)                                                                      \
50     (REALM_LIKELY(condition) ? static_cast<void>(0)                                                                  \
51                              : realm::util::terminate_with_info("Assertion failed: " #condition, __LINE__, __FILE__, \
52                                                                 REALM_STRINGIFY((__VA_ARGS__)), __VA_ARGS__))
53
54 #ifdef REALM_DEBUG
55 #define REALM_ASSERT_DEBUG_EX REALM_ASSERT_RELEASE_EX
56 #else
57 #define REALM_ASSERT_DEBUG_EX(condition, ...) static_cast<void>(sizeof bool(condition))
58 #endif
59
60 // Becase the assert is used in noexcept methods, it's a bad idea to allocate
61 // buffer space for the message so therefore we must pass it to terminate which
62 // will 'cerr' it for us without needing any buffer
63 #if REALM_ENABLE_ASSERTIONS || defined(REALM_DEBUG)
64
65 #define REALM_ASSERT_EX REALM_ASSERT_RELEASE_EX
66
67 #define REALM_ASSERT_3(left, cmp, right)                                                                             \
68     (REALM_LIKELY((left)cmp(right)) ? static_cast<void>(0)                                                           \
69                                     : realm::util::terminate("Assertion failed: "                                    \
70                                                              "" #left " " #cmp " " #right,                           \
71                                                              __FILE__, __LINE__, left, right))
72
73 #define REALM_ASSERT_7(left1, cmp1, right1, logical, left2, cmp2, right2)                                            \
74     (REALM_LIKELY(((left1)cmp1(right1))logical((left2)cmp2(right2)))                                                 \
75          ? static_cast<void>(0)                                                                                      \
76          : realm::util::terminate("Assertion failed: "                                                               \
77                                   "" #left1 " " #cmp1 " " #right1 " " #logical " "                                   \
78                                   "" #left2 " " #cmp2 " " #right2,                                                   \
79                                   __FILE__, __LINE__, left1, right1, left2, right2))
80
81 #define REALM_ASSERT_11(left1, cmp1, right1, logical1, left2, cmp2, right2, logical2, left3, cmp3, right3)           \
82     (REALM_LIKELY(((left1)cmp1(right1))logical1((left2)cmp2(right2)) logical2((left3)cmp3(right3)))                  \
83          ? static_cast<void>(0)                                                                                      \
84          : realm::util::terminate("Assertion failed: "                                                               \
85                                   "" #left1 " " #cmp1 " " #right1 " " #logical1 " "                                  \
86                                   "" #left2 " " #cmp2 " " #right2 " " #logical2 " "                                  \
87                                   "" #left3 " " #cmp3 " " #right3,                                                   \
88                                   __FILE__, __LINE__, left1, right1, left2, right2, left3, right3))
89 #else
90 #define REALM_ASSERT_EX(condition, ...) static_cast<void>(sizeof bool(condition))
91 #define REALM_ASSERT_3(left, cmp, right) static_cast<void>(sizeof bool((left)cmp(right)))
92 #define REALM_ASSERT_7(left1, cmp1, right1, logical, left2, cmp2, right2)                                            \
93     static_cast<void>(sizeof bool(((left1)cmp1(right1))logical((left2)cmp2(right2))))
94 #define REALM_ASSERT_11(left1, cmp1, right1, logical1, left2, cmp2, right2, logical2, left3, cmp3, right3)           \
95     static_cast<void>(sizeof bool(((left1)cmp1(right1))logical1((left2)cmp2(right2)) logical2((left3)cmp3(right3))))
96 #endif
97
98 #define REALM_UNREACHABLE() realm::util::terminate("Unreachable code", __FILE__, __LINE__)
99 #ifdef REALM_COVER
100 #define REALM_COVER_NEVER(x) false
101 #define REALM_COVER_ALWAYS(x) true
102 #else
103 #define REALM_COVER_NEVER(x) (x)
104 #define REALM_COVER_ALWAYS(x) (x)
105 #endif
106
107 #endif // REALM_UTIL_ASSERT_HPP