MRMD 0.4.0
Multi Resolution Molecular Dynamics
Loading...
Searching...
No Matches
normal.hpp
Go to the documentation of this file.
1// Copyright 2024 Sebastian Eibl
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
37
38#pragma once
39
40#include <cassert>
41
42// macro overloading (-> https://stackoverflow.com/a/24028231)
43
44#define GLUE(x, y) x y
45
46#define RETURN_ARG_COUNT(_1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, _9_, _10_, count, ...) count
47#define EXPAND_ARGS(args) RETURN_ARG_COUNT args
48#define COUNT_ARGS_MAX10(...) EXPAND_ARGS((__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0))
49
50#define OVERLOAD_MACRO2(name, count) name##count
51#define OVERLOAD_MACRO1(name, count) OVERLOAD_MACRO2(name, count)
52#define OVERLOAD_MACRO(name, count) OVERLOAD_MACRO1(name, count)
53
54#define MACRO_OVERLOAD(name, ...) \
55 GLUE(OVERLOAD_MACRO(name, COUNT_ARGS_MAX10(__VA_ARGS__)), (__VA_ARGS__))
56
57#define MRMD_NORMAL_CHECK_1(X) \
58 { \
59 assert(X); \
60 }
61#define MRMD_NORMAL_CHECK_2(X, MSG) \
62 { \
63 assert(X); \
64 }
65
66#define MRMD_NORMAL_CHECK_NULLPTR_1(X) \
67 { \
68 assert(X == nullptr); \
69 }
70#define MRMD_NORMAL_CHECK_NULLPTR_2(X, MSG) \
71 { \
72 assert(X == nullptr); \
73 }
74
75#define MRMD_NORMAL_CHECK_NOT_NULLPTR_1(X) \
76 { \
77 assert(X != nullptr); \
78 }
79#define MRMD_NORMAL_CHECK_NOT_NULLPTR_2(X, MSG) \
80 { \
81 assert(X != nullptr); \
82 }
83
84#define MRMD_NORMAL_CHECK_EQUAL_2(X, Y) \
85 { \
86 assert(X == Y); \
87 }
88#define MRMD_NORMAL_CHECK_EQUAL_3(X, Y, MSG) \
89 { \
90 assert(X == Y); \
91 }
92
93#define MRMD_NORMAL_CHECK_FLOAT_EQUAL_2(X, Y) \
94 { \
95 assert(X == Y); \
96 }
97#define MRMD_NORMAL_CHECK_FLOAT_EQUAL_3(X, Y, MSG) \
98 { \
99 assert(X == Y); \
100 }
101
102#define MRMD_NORMAL_CHECK_NOT_EQUAL_2(X, Y) \
103 { \
104 assert(X != Y); \
105 }
106#define MRMD_NORMAL_CHECK_NOT_EQUAL_3(X, Y, MSG) \
107 { \
108 assert(X != Y); \
109 }
110
111#define MRMD_NORMAL_CHECK_GREATER_2(X, Y) \
112 { \
113 assert(X > Y); \
114 }
115#define MRMD_NORMAL_CHECK_GREATER_3(X, Y, MSG) \
116 { \
117 assert(X > Y); \
118 }
119
120#define MRMD_NORMAL_CHECK_LESS_2(X, Y) \
121 { \
122 assert(X < Y); \
123 }
124#define MRMD_NORMAL_CHECK_LESS_3(X, Y, MSG) \
125 { \
126 assert(X < Y); \
127 }
128
129#define MRMD_NORMAL_CHECK_GREATEREQUAL_2(X, Y) \
130 { \
131 assert(X >= Y); \
132 }
133#define MRMD_NORMAL_CHECK_GREATEREQUAL_3(X, Y, MSG) \
134 { \
135 assert(X >= Y); \
136 }
137
138#define MRMD_NORMAL_CHECK_LESSEQUAL_2(X, Y) \
139 { \
140 assert(X <= Y); \
141 }
142#define MRMD_NORMAL_CHECK_LESSEQUAL_3(X, Y, MSG) \
143 { \
144 assert(X <= Y); \
145 }
146
147#define MRMD_NORMAL_CHECK(...) MACRO_OVERLOAD(MRMD_NORMAL_CHECK_, __VA_ARGS__)
148#define MRMD_NORMAL_CHECK_NULLPTR(...) MACRO_OVERLOAD(MRMD_NORMAL_CHECK_EQUAL_, __VA_ARGS__)
149#define MRMD_NORMAL_CHECK_NOT_NULLPTR(...) \
150 MACRO_OVERLOAD(MRMD_NORMAL_CHECK_NOT_NULLPTR_, __VA_ARGS__)
151#define MRMD_NORMAL_CHECK_EQUAL(...) MACRO_OVERLOAD(MRMD_NORMAL_CHECK_EQUAL_, __VA_ARGS__)
152#define MRMD_NORMAL_CHECK_FLOAT_EQUAL(...) MACRO_OVERLOAD(MRMD_NORMAL_CHECK_EQUAL_, __VA_ARGS__)
153#define MRMD_NORMAL_CHECK_NOT_EQUAL(...) MACRO_OVERLOAD(MRMD_NORMAL_CHECK_NOT_EQUAL_, __VA_ARGS__)
154#define MRMD_NORMAL_CHECK_GREATER(...) MACRO_OVERLOAD(MRMD_NORMAL_CHECK_GREATER_, __VA_ARGS__)
155#define MRMD_NORMAL_CHECK_LESS(...) MACRO_OVERLOAD(MRMD_NORMAL_CHECK_LESS_, __VA_ARGS__)
156#define MRMD_NORMAL_CHECK_GREATEREQUAL(...) \
157 MACRO_OVERLOAD(MRMD_NORMAL_CHECK_GREATEREQUAL_, __VA_ARGS__)
158#define MRMD_NORMAL_CHECK_LESSEQUAL(...) MACRO_OVERLOAD(MRMD_NORMAL_CHECK_LESSEQUAL_, __VA_ARGS__)