1 | /**************************************************************************/ |
2 | /* variant_op.h */ |
3 | /**************************************************************************/ |
4 | /* This file is part of: */ |
5 | /* GODOT ENGINE */ |
6 | /* https://godotengine.org */ |
7 | /**************************************************************************/ |
8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
10 | /* */ |
11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
12 | /* a copy of this software and associated documentation files (the */ |
13 | /* "Software"), to deal in the Software without restriction, including */ |
14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
17 | /* the following conditions: */ |
18 | /* */ |
19 | /* The above copyright notice and this permission notice shall be */ |
20 | /* included in all copies or substantial portions of the Software. */ |
21 | /* */ |
22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
29 | /**************************************************************************/ |
30 | |
31 | #ifndef VARIANT_OP_H |
32 | #define VARIANT_OP_H |
33 | |
34 | #include "variant.h" |
35 | |
36 | #include "core/core_string_names.h" |
37 | #include "core/debugger/engine_debugger.h" |
38 | #include "core/object/class_db.h" |
39 | |
40 | template <class R, class A, class B> |
41 | class OperatorEvaluatorAdd { |
42 | public: |
43 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
44 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
45 | const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); |
46 | *r_ret = a + b; |
47 | r_valid = true; |
48 | } |
49 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
50 | *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) + *VariantGetInternalPtr<B>::get_ptr(right); |
51 | } |
52 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
53 | PtrToArg<R>::encode(PtrToArg<A>::convert(left) + PtrToArg<B>::convert(right), r_ret); |
54 | } |
55 | static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } |
56 | }; |
57 | |
58 | template <class R, class A, class B> |
59 | class OperatorEvaluatorSub { |
60 | public: |
61 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
62 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
63 | const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); |
64 | *r_ret = a - b; |
65 | r_valid = true; |
66 | } |
67 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
68 | *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) - *VariantGetInternalPtr<B>::get_ptr(right); |
69 | } |
70 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
71 | PtrToArg<R>::encode(PtrToArg<A>::convert(left) - PtrToArg<B>::convert(right), r_ret); |
72 | } |
73 | static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } |
74 | }; |
75 | |
76 | template <class R, class A, class B> |
77 | class OperatorEvaluatorMul { |
78 | public: |
79 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
80 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
81 | const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); |
82 | *r_ret = a * b; |
83 | r_valid = true; |
84 | } |
85 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
86 | *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) * *VariantGetInternalPtr<B>::get_ptr(right); |
87 | } |
88 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
89 | PtrToArg<R>::encode(PtrToArg<A>::convert(left) * PtrToArg<B>::convert(right), r_ret); |
90 | } |
91 | static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } |
92 | }; |
93 | |
94 | template <class R, class A, class B> |
95 | class OperatorEvaluatorPow { |
96 | public: |
97 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
98 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
99 | const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); |
100 | *r_ret = R(Math::pow((double)a, (double)b)); |
101 | r_valid = true; |
102 | } |
103 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
104 | *VariantGetInternalPtr<R>::get_ptr(r_ret) = R(Math::pow((double)*VariantGetInternalPtr<A>::get_ptr(left), (double)*VariantGetInternalPtr<B>::get_ptr(right))); |
105 | } |
106 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
107 | PtrToArg<R>::encode(R(Math::pow((double)PtrToArg<A>::convert(left), (double)PtrToArg<B>::convert(right))), r_ret); |
108 | } |
109 | static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } |
110 | }; |
111 | |
112 | template <class R, class A, class B> |
113 | class OperatorEvaluatorXForm { |
114 | public: |
115 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
116 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
117 | const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); |
118 | *r_ret = a.xform(b); |
119 | r_valid = true; |
120 | } |
121 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
122 | *VariantGetInternalPtr<R>::get_ptr(r_ret) = VariantGetInternalPtr<A>::get_ptr(left)->xform(*VariantGetInternalPtr<B>::get_ptr(right)); |
123 | } |
124 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
125 | PtrToArg<R>::encode(PtrToArg<A>::convert(left).xform(PtrToArg<B>::convert(right)), r_ret); |
126 | } |
127 | static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } |
128 | }; |
129 | |
130 | template <class R, class A, class B> |
131 | class OperatorEvaluatorXFormInv { |
132 | public: |
133 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
134 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
135 | const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); |
136 | *r_ret = b.xform_inv(a); |
137 | r_valid = true; |
138 | } |
139 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
140 | *VariantGetInternalPtr<R>::get_ptr(r_ret) = VariantGetInternalPtr<B>::get_ptr(right)->xform_inv(*VariantGetInternalPtr<A>::get_ptr(left)); |
141 | } |
142 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
143 | PtrToArg<R>::encode(PtrToArg<B>::convert(right).xform_inv(PtrToArg<A>::convert(left)), r_ret); |
144 | } |
145 | static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } |
146 | }; |
147 | |
148 | template <class R, class A, class B> |
149 | class OperatorEvaluatorDiv { |
150 | public: |
151 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
152 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
153 | const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); |
154 | *r_ret = a / b; |
155 | r_valid = true; |
156 | } |
157 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
158 | *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) / *VariantGetInternalPtr<B>::get_ptr(right); |
159 | } |
160 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
161 | PtrToArg<R>::encode(PtrToArg<A>::convert(left) / PtrToArg<B>::convert(right), r_ret); |
162 | } |
163 | static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } |
164 | }; |
165 | |
166 | template <class R, class A, class B> |
167 | class OperatorEvaluatorDivNZ { |
168 | public: |
169 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
170 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
171 | const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); |
172 | if (b == 0) { |
173 | r_valid = false; |
174 | *r_ret = "Division by zero error" ; |
175 | return; |
176 | } |
177 | *r_ret = a / b; |
178 | r_valid = true; |
179 | } |
180 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
181 | *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) / *VariantGetInternalPtr<B>::get_ptr(right); |
182 | } |
183 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
184 | PtrToArg<R>::encode(PtrToArg<A>::convert(left) / PtrToArg<B>::convert(right), r_ret); |
185 | } |
186 | static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } |
187 | }; |
188 | |
189 | template <> |
190 | class OperatorEvaluatorDivNZ<Vector2i, Vector2i, Vector2i> { |
191 | public: |
192 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
193 | const Vector2i &a = *VariantGetInternalPtr<Vector2i>::get_ptr(&p_left); |
194 | const Vector2i &b = *VariantGetInternalPtr<Vector2i>::get_ptr(&p_right); |
195 | if (unlikely(b.x == 0 || b.y == 0)) { |
196 | r_valid = false; |
197 | *r_ret = "Division by zero error" ; |
198 | return; |
199 | } |
200 | *r_ret = a / b; |
201 | r_valid = true; |
202 | } |
203 | static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
204 | VariantTypeChanger<Vector2i>::change(r_ret); |
205 | *VariantGetInternalPtr<Vector2i>::get_ptr(r_ret) = *VariantGetInternalPtr<Vector2i>::get_ptr(left) / *VariantGetInternalPtr<Vector2i>::get_ptr(right); |
206 | } |
207 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
208 | PtrToArg<Vector2i>::encode(PtrToArg<Vector2i>::convert(left) / PtrToArg<Vector2i>::convert(right), r_ret); |
209 | } |
210 | static Variant::Type get_return_type() { return GetTypeInfo<Vector2i>::VARIANT_TYPE; } |
211 | }; |
212 | |
213 | template <> |
214 | class OperatorEvaluatorDivNZ<Vector3i, Vector3i, Vector3i> { |
215 | public: |
216 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
217 | const Vector3i &a = *VariantGetInternalPtr<Vector3i>::get_ptr(&p_left); |
218 | const Vector3i &b = *VariantGetInternalPtr<Vector3i>::get_ptr(&p_right); |
219 | if (unlikely(b.x == 0 || b.y == 0 || b.z == 0)) { |
220 | r_valid = false; |
221 | *r_ret = "Division by zero error" ; |
222 | return; |
223 | } |
224 | *r_ret = a / b; |
225 | r_valid = true; |
226 | } |
227 | static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
228 | VariantTypeChanger<Vector3i>::change(r_ret); |
229 | *VariantGetInternalPtr<Vector3i>::get_ptr(r_ret) = *VariantGetInternalPtr<Vector3i>::get_ptr(left) / *VariantGetInternalPtr<Vector3i>::get_ptr(right); |
230 | } |
231 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
232 | PtrToArg<Vector3i>::encode(PtrToArg<Vector3i>::convert(left) / PtrToArg<Vector3i>::convert(right), r_ret); |
233 | } |
234 | static Variant::Type get_return_type() { return GetTypeInfo<Vector3i>::VARIANT_TYPE; } |
235 | }; |
236 | |
237 | template <> |
238 | class OperatorEvaluatorDivNZ<Vector4i, Vector4i, Vector4i> { |
239 | public: |
240 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
241 | const Vector4i &a = *VariantGetInternalPtr<Vector4i>::get_ptr(&p_left); |
242 | const Vector4i &b = *VariantGetInternalPtr<Vector4i>::get_ptr(&p_right); |
243 | if (unlikely(b.x == 0 || b.y == 0 || b.z == 0 || b.w == 0)) { |
244 | r_valid = false; |
245 | *r_ret = "Division by zero error" ; |
246 | return; |
247 | } |
248 | *r_ret = a / b; |
249 | r_valid = true; |
250 | } |
251 | static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
252 | VariantTypeChanger<Vector4i>::change(r_ret); |
253 | *VariantGetInternalPtr<Vector4i>::get_ptr(r_ret) = *VariantGetInternalPtr<Vector4i>::get_ptr(left) / *VariantGetInternalPtr<Vector4i>::get_ptr(right); |
254 | } |
255 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
256 | PtrToArg<Vector4i>::encode(PtrToArg<Vector4i>::convert(left) / PtrToArg<Vector4i>::convert(right), r_ret); |
257 | } |
258 | static Variant::Type get_return_type() { return GetTypeInfo<Vector4i>::VARIANT_TYPE; } |
259 | }; |
260 | |
261 | template <class R, class A, class B> |
262 | class OperatorEvaluatorMod { |
263 | public: |
264 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
265 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
266 | const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); |
267 | *r_ret = a % b; |
268 | r_valid = true; |
269 | } |
270 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
271 | *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) % *VariantGetInternalPtr<B>::get_ptr(right); |
272 | } |
273 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
274 | PtrToArg<R>::encode(PtrToArg<A>::convert(left) % PtrToArg<B>::convert(right), r_ret); |
275 | } |
276 | static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } |
277 | }; |
278 | |
279 | template <class R, class A, class B> |
280 | class OperatorEvaluatorModNZ { |
281 | public: |
282 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
283 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
284 | const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); |
285 | if (b == 0) { |
286 | r_valid = false; |
287 | *r_ret = "Modulo by zero error" ; |
288 | return; |
289 | } |
290 | *r_ret = a % b; |
291 | r_valid = true; |
292 | } |
293 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
294 | *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) % *VariantGetInternalPtr<B>::get_ptr(right); |
295 | } |
296 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
297 | PtrToArg<R>::encode(PtrToArg<A>::convert(left) % PtrToArg<B>::convert(right), r_ret); |
298 | } |
299 | static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } |
300 | }; |
301 | |
302 | template <> |
303 | class OperatorEvaluatorModNZ<Vector2i, Vector2i, Vector2i> { |
304 | public: |
305 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
306 | const Vector2i &a = *VariantGetInternalPtr<Vector2i>::get_ptr(&p_left); |
307 | const Vector2i &b = *VariantGetInternalPtr<Vector2i>::get_ptr(&p_right); |
308 | if (unlikely(b.x == 0 || b.y == 0)) { |
309 | r_valid = false; |
310 | *r_ret = "Modulo by zero error" ; |
311 | return; |
312 | } |
313 | *r_ret = a % b; |
314 | r_valid = true; |
315 | } |
316 | static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
317 | VariantTypeChanger<Vector2i>::change(r_ret); |
318 | *VariantGetInternalPtr<Vector2i>::get_ptr(r_ret) = *VariantGetInternalPtr<Vector2i>::get_ptr(left) % *VariantGetInternalPtr<Vector2i>::get_ptr(right); |
319 | } |
320 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
321 | PtrToArg<Vector2i>::encode(PtrToArg<Vector2i>::convert(left) / PtrToArg<Vector2i>::convert(right), r_ret); |
322 | } |
323 | static Variant::Type get_return_type() { return GetTypeInfo<Vector2i>::VARIANT_TYPE; } |
324 | }; |
325 | |
326 | template <> |
327 | class OperatorEvaluatorModNZ<Vector3i, Vector3i, Vector3i> { |
328 | public: |
329 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
330 | const Vector3i &a = *VariantGetInternalPtr<Vector3i>::get_ptr(&p_left); |
331 | const Vector3i &b = *VariantGetInternalPtr<Vector3i>::get_ptr(&p_right); |
332 | if (unlikely(b.x == 0 || b.y == 0 || b.z == 0)) { |
333 | r_valid = false; |
334 | *r_ret = "Modulo by zero error" ; |
335 | return; |
336 | } |
337 | *r_ret = a % b; |
338 | r_valid = true; |
339 | } |
340 | static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
341 | VariantTypeChanger<Vector3i>::change(r_ret); |
342 | *VariantGetInternalPtr<Vector3i>::get_ptr(r_ret) = *VariantGetInternalPtr<Vector3i>::get_ptr(left) % *VariantGetInternalPtr<Vector3i>::get_ptr(right); |
343 | } |
344 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
345 | PtrToArg<Vector3i>::encode(PtrToArg<Vector3i>::convert(left) % PtrToArg<Vector3i>::convert(right), r_ret); |
346 | } |
347 | static Variant::Type get_return_type() { return GetTypeInfo<Vector3i>::VARIANT_TYPE; } |
348 | }; |
349 | |
350 | template <> |
351 | class OperatorEvaluatorModNZ<Vector4i, Vector4i, Vector4i> { |
352 | public: |
353 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
354 | const Vector4i &a = *VariantGetInternalPtr<Vector4i>::get_ptr(&p_left); |
355 | const Vector4i &b = *VariantGetInternalPtr<Vector4i>::get_ptr(&p_right); |
356 | if (unlikely(b.x == 0 || b.y == 0 || b.z == 0 || b.w == 0)) { |
357 | r_valid = false; |
358 | *r_ret = "Modulo by zero error" ; |
359 | return; |
360 | } |
361 | *r_ret = a % b; |
362 | r_valid = true; |
363 | } |
364 | static void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
365 | VariantTypeChanger<Vector4i>::change(r_ret); |
366 | *VariantGetInternalPtr<Vector4i>::get_ptr(r_ret) = *VariantGetInternalPtr<Vector4i>::get_ptr(left) % *VariantGetInternalPtr<Vector4i>::get_ptr(right); |
367 | } |
368 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
369 | PtrToArg<Vector4i>::encode(PtrToArg<Vector4i>::convert(left) % PtrToArg<Vector4i>::convert(right), r_ret); |
370 | } |
371 | static Variant::Type get_return_type() { return GetTypeInfo<Vector4i>::VARIANT_TYPE; } |
372 | }; |
373 | |
374 | template <class R, class A> |
375 | class OperatorEvaluatorNeg { |
376 | public: |
377 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
378 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
379 | *r_ret = -a; |
380 | r_valid = true; |
381 | } |
382 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
383 | *VariantGetInternalPtr<R>::get_ptr(r_ret) = -*VariantGetInternalPtr<A>::get_ptr(left); |
384 | } |
385 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
386 | PtrToArg<R>::encode(-PtrToArg<A>::convert(left), r_ret); |
387 | } |
388 | static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } |
389 | }; |
390 | |
391 | template <class R, class A> |
392 | class OperatorEvaluatorPos { |
393 | public: |
394 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
395 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
396 | *r_ret = a; |
397 | r_valid = true; |
398 | } |
399 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
400 | *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left); |
401 | } |
402 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
403 | PtrToArg<R>::encode(PtrToArg<A>::convert(left), r_ret); |
404 | } |
405 | static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } |
406 | }; |
407 | |
408 | template <class R, class A, class B> |
409 | class OperatorEvaluatorShiftLeft { |
410 | public: |
411 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
412 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
413 | const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); |
414 | |
415 | #if defined(DEBUG_ENABLED) |
416 | if (b < 0 || a < 0) { |
417 | *r_ret = "Invalid operands for bit shifting. Only positive operands are supported." ; |
418 | r_valid = false; |
419 | return; |
420 | } |
421 | #endif |
422 | *r_ret = a << b; |
423 | r_valid = true; |
424 | } |
425 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
426 | *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) << *VariantGetInternalPtr<B>::get_ptr(right); |
427 | } |
428 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
429 | PtrToArg<R>::encode(PtrToArg<A>::convert(left) << PtrToArg<B>::convert(right), r_ret); |
430 | } |
431 | static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } |
432 | }; |
433 | |
434 | template <class R, class A, class B> |
435 | class OperatorEvaluatorShiftRight { |
436 | public: |
437 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
438 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
439 | const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); |
440 | |
441 | #if defined(DEBUG_ENABLED) |
442 | if (b < 0 || a < 0) { |
443 | *r_ret = "Invalid operands for bit shifting. Only positive operands are supported." ; |
444 | r_valid = false; |
445 | return; |
446 | } |
447 | #endif |
448 | *r_ret = a >> b; |
449 | r_valid = true; |
450 | } |
451 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
452 | *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) >> *VariantGetInternalPtr<B>::get_ptr(right); |
453 | } |
454 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
455 | PtrToArg<R>::encode(PtrToArg<A>::convert(left) >> PtrToArg<B>::convert(right), r_ret); |
456 | } |
457 | static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } |
458 | }; |
459 | |
460 | template <class R, class A, class B> |
461 | class OperatorEvaluatorBitOr { |
462 | public: |
463 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
464 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
465 | const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); |
466 | *r_ret = a | b; |
467 | r_valid = true; |
468 | } |
469 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
470 | *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) | *VariantGetInternalPtr<B>::get_ptr(right); |
471 | } |
472 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
473 | PtrToArg<R>::encode(PtrToArg<A>::convert(left) | PtrToArg<B>::convert(right), r_ret); |
474 | } |
475 | static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } |
476 | }; |
477 | |
478 | template <class R, class A, class B> |
479 | class OperatorEvaluatorBitAnd { |
480 | public: |
481 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
482 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
483 | const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); |
484 | *r_ret = a & b; |
485 | r_valid = true; |
486 | } |
487 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
488 | *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) & *VariantGetInternalPtr<B>::get_ptr(right); |
489 | } |
490 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
491 | PtrToArg<R>::encode(PtrToArg<A>::convert(left) & PtrToArg<B>::convert(right), r_ret); |
492 | } |
493 | static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } |
494 | }; |
495 | |
496 | template <class R, class A, class B> |
497 | class OperatorEvaluatorBitXor { |
498 | public: |
499 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
500 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
501 | const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); |
502 | *r_ret = a ^ b; |
503 | r_valid = true; |
504 | } |
505 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
506 | *VariantGetInternalPtr<R>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) ^ *VariantGetInternalPtr<B>::get_ptr(right); |
507 | } |
508 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
509 | PtrToArg<R>::encode(PtrToArg<A>::convert(left) ^ PtrToArg<B>::convert(right), r_ret); |
510 | } |
511 | static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } |
512 | }; |
513 | |
514 | template <class R, class A> |
515 | class OperatorEvaluatorBitNeg { |
516 | public: |
517 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
518 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
519 | *r_ret = ~a; |
520 | r_valid = true; |
521 | } |
522 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
523 | *VariantGetInternalPtr<R>::get_ptr(r_ret) = ~*VariantGetInternalPtr<A>::get_ptr(left); |
524 | } |
525 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
526 | PtrToArg<R>::encode(~PtrToArg<A>::convert(left), r_ret); |
527 | } |
528 | static Variant::Type get_return_type() { return GetTypeInfo<R>::VARIANT_TYPE; } |
529 | }; |
530 | |
531 | template <class A, class B> |
532 | class OperatorEvaluatorEqual { |
533 | public: |
534 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
535 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
536 | const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); |
537 | *r_ret = a == b; |
538 | r_valid = true; |
539 | } |
540 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
541 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) == *VariantGetInternalPtr<B>::get_ptr(right); |
542 | } |
543 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
544 | PtrToArg<bool>::encode(PtrToArg<A>::convert(left) == PtrToArg<B>::convert(right), r_ret); |
545 | } |
546 | static Variant::Type get_return_type() { return Variant::BOOL; } |
547 | }; |
548 | |
549 | class OperatorEvaluatorEqualObject { |
550 | public: |
551 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
552 | const Object *a = p_left.get_validated_object(); |
553 | const Object *b = p_right.get_validated_object(); |
554 | *r_ret = a == b; |
555 | r_valid = true; |
556 | } |
557 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
558 | const Object *a = left->get_validated_object(); |
559 | const Object *b = right->get_validated_object(); |
560 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = a == b; |
561 | } |
562 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
563 | PtrToArg<bool>::encode(PtrToArg<Object *>::convert(left) == PtrToArg<Object *>::convert(right), r_ret); |
564 | } |
565 | static Variant::Type get_return_type() { return Variant::BOOL; } |
566 | }; |
567 | |
568 | class OperatorEvaluatorEqualObjectNil { |
569 | public: |
570 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
571 | const Object *a = p_left.get_validated_object(); |
572 | *r_ret = a == nullptr; |
573 | r_valid = true; |
574 | } |
575 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
576 | const Object *a = left->get_validated_object(); |
577 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = a == nullptr; |
578 | } |
579 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
580 | PtrToArg<bool>::encode(PtrToArg<Object *>::convert(left) == nullptr, r_ret); |
581 | } |
582 | static Variant::Type get_return_type() { return Variant::BOOL; } |
583 | }; |
584 | |
585 | class OperatorEvaluatorEqualNilObject { |
586 | public: |
587 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
588 | const Object *b = p_right.get_validated_object(); |
589 | *r_ret = nullptr == b; |
590 | r_valid = true; |
591 | } |
592 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
593 | const Object *b = right->get_validated_object(); |
594 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = nullptr == b; |
595 | } |
596 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
597 | PtrToArg<bool>::encode(nullptr == PtrToArg<Object *>::convert(right), r_ret); |
598 | } |
599 | static Variant::Type get_return_type() { return Variant::BOOL; } |
600 | }; |
601 | |
602 | template <class A, class B> |
603 | class OperatorEvaluatorNotEqual { |
604 | public: |
605 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
606 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
607 | const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); |
608 | *r_ret = a != b; |
609 | r_valid = true; |
610 | } |
611 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
612 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) != *VariantGetInternalPtr<B>::get_ptr(right); |
613 | } |
614 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
615 | PtrToArg<bool>::encode(PtrToArg<A>::convert(left) != PtrToArg<B>::convert(right), r_ret); |
616 | } |
617 | static Variant::Type get_return_type() { return Variant::BOOL; } |
618 | }; |
619 | |
620 | class OperatorEvaluatorNotEqualObject { |
621 | public: |
622 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
623 | Object *a = p_left.get_validated_object(); |
624 | Object *b = p_right.get_validated_object(); |
625 | *r_ret = a != b; |
626 | r_valid = true; |
627 | } |
628 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
629 | Object *a = left->get_validated_object(); |
630 | Object *b = right->get_validated_object(); |
631 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = a != b; |
632 | } |
633 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
634 | PtrToArg<bool>::encode(PtrToArg<Object *>::convert(left) != PtrToArg<Object *>::convert(right), r_ret); |
635 | } |
636 | static Variant::Type get_return_type() { return Variant::BOOL; } |
637 | }; |
638 | |
639 | class OperatorEvaluatorNotEqualObjectNil { |
640 | public: |
641 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
642 | Object *a = p_left.get_validated_object(); |
643 | *r_ret = a != nullptr; |
644 | r_valid = true; |
645 | } |
646 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
647 | Object *a = left->get_validated_object(); |
648 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = a != nullptr; |
649 | } |
650 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
651 | PtrToArg<bool>::encode(PtrToArg<Object *>::convert(left) != nullptr, r_ret); |
652 | } |
653 | static Variant::Type get_return_type() { return Variant::BOOL; } |
654 | }; |
655 | |
656 | class OperatorEvaluatorNotEqualNilObject { |
657 | public: |
658 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
659 | Object *b = p_right.get_validated_object(); |
660 | *r_ret = nullptr != b; |
661 | r_valid = true; |
662 | } |
663 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
664 | Object *b = right->get_validated_object(); |
665 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = nullptr != b; |
666 | } |
667 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
668 | PtrToArg<bool>::encode(nullptr != PtrToArg<Object *>::convert(right), r_ret); |
669 | } |
670 | static Variant::Type get_return_type() { return Variant::BOOL; } |
671 | }; |
672 | |
673 | template <class A, class B> |
674 | class OperatorEvaluatorLess { |
675 | public: |
676 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
677 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
678 | const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); |
679 | *r_ret = a < b; |
680 | r_valid = true; |
681 | } |
682 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
683 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) < *VariantGetInternalPtr<B>::get_ptr(right); |
684 | } |
685 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
686 | PtrToArg<bool>::encode(PtrToArg<A>::convert(left) < PtrToArg<B>::convert(right), r_ret); |
687 | } |
688 | static Variant::Type get_return_type() { return Variant::BOOL; } |
689 | }; |
690 | |
691 | template <class A, class B> |
692 | class OperatorEvaluatorLessEqual { |
693 | public: |
694 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
695 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
696 | const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); |
697 | *r_ret = a <= b; |
698 | r_valid = true; |
699 | } |
700 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
701 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) <= *VariantGetInternalPtr<B>::get_ptr(right); |
702 | } |
703 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
704 | PtrToArg<bool>::encode(PtrToArg<A>::convert(left) <= PtrToArg<B>::convert(right), r_ret); |
705 | } |
706 | static Variant::Type get_return_type() { return Variant::BOOL; } |
707 | }; |
708 | |
709 | template <class A, class B> |
710 | class OperatorEvaluatorGreater { |
711 | public: |
712 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
713 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
714 | const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); |
715 | *r_ret = a > b; |
716 | r_valid = true; |
717 | } |
718 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
719 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) > *VariantGetInternalPtr<B>::get_ptr(right); |
720 | } |
721 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
722 | PtrToArg<bool>::encode(PtrToArg<A>::convert(left) > PtrToArg<B>::convert(right), r_ret); |
723 | } |
724 | static Variant::Type get_return_type() { return Variant::BOOL; } |
725 | }; |
726 | |
727 | template <class A, class B> |
728 | class OperatorEvaluatorGreaterEqual { |
729 | public: |
730 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
731 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
732 | const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); |
733 | *r_ret = a >= b; |
734 | r_valid = true; |
735 | } |
736 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
737 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) >= *VariantGetInternalPtr<B>::get_ptr(right); |
738 | } |
739 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
740 | PtrToArg<bool>::encode(PtrToArg<A>::convert(left) >= PtrToArg<B>::convert(right), r_ret); |
741 | } |
742 | static Variant::Type get_return_type() { return Variant::BOOL; } |
743 | }; |
744 | |
745 | template <class A, class B> |
746 | class OperatorEvaluatorAnd { |
747 | public: |
748 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
749 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
750 | const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); |
751 | *r_ret = a && b; |
752 | r_valid = true; |
753 | } |
754 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
755 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) && *VariantGetInternalPtr<B>::get_ptr(right); |
756 | } |
757 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
758 | PtrToArg<bool>::encode(PtrToArg<A>::convert(left) && PtrToArg<B>::convert(right), r_ret); |
759 | } |
760 | static Variant::Type get_return_type() { return Variant::BOOL; } |
761 | }; |
762 | |
763 | template <class A, class B> |
764 | class OperatorEvaluatorOr { |
765 | public: |
766 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
767 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
768 | const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); |
769 | *r_ret = a || b; |
770 | r_valid = true; |
771 | } |
772 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
773 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) || *VariantGetInternalPtr<B>::get_ptr(right); |
774 | } |
775 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
776 | PtrToArg<bool>::encode(PtrToArg<A>::convert(left) || PtrToArg<B>::convert(right), r_ret); |
777 | } |
778 | static Variant::Type get_return_type() { return Variant::BOOL; } |
779 | }; |
780 | |
781 | #define XOR_OP(m_a, m_b) (((m_a) || (m_b)) && !((m_a) && (m_b))) |
782 | template <class A, class B> |
783 | class OperatorEvaluatorXor { |
784 | public: |
785 | _FORCE_INLINE_ static bool xor_op(const A &a, const B &b) { |
786 | return ((a) || (b)) && !((a) && (b)); |
787 | } |
788 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
789 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
790 | const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); |
791 | *r_ret = xor_op(a, b); |
792 | r_valid = true; |
793 | } |
794 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
795 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = xor_op(*VariantGetInternalPtr<A>::get_ptr(left), *VariantGetInternalPtr<B>::get_ptr(right)); |
796 | } |
797 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
798 | PtrToArg<bool>::encode(xor_op(PtrToArg<A>::convert(left), PtrToArg<B>::convert(right)), r_ret); |
799 | } |
800 | static Variant::Type get_return_type() { return Variant::BOOL; } |
801 | }; |
802 | |
803 | template <class A> |
804 | class OperatorEvaluatorNot { |
805 | public: |
806 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
807 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
808 | *r_ret = a == A(); |
809 | r_valid = true; |
810 | } |
811 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
812 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = *VariantGetInternalPtr<A>::get_ptr(left) == A(); |
813 | } |
814 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
815 | PtrToArg<bool>::encode(PtrToArg<A>::convert(left) == A(), r_ret); |
816 | } |
817 | static Variant::Type get_return_type() { return Variant::BOOL; } |
818 | }; |
819 | |
820 | //// CUSTOM //// |
821 | |
822 | class OperatorEvaluatorAddArray { |
823 | public: |
824 | _FORCE_INLINE_ static void _add_arrays(Array &sum, const Array &array_a, const Array &array_b) { |
825 | int asize = array_a.size(); |
826 | int bsize = array_b.size(); |
827 | |
828 | if (array_a.is_typed() && array_a.is_same_typed(array_b)) { |
829 | sum.set_typed(array_a.get_typed_builtin(), array_a.get_typed_class_name(), array_a.get_typed_script()); |
830 | } |
831 | |
832 | sum.resize(asize + bsize); |
833 | for (int i = 0; i < asize; i++) { |
834 | sum[i] = array_a[i]; |
835 | } |
836 | for (int i = 0; i < bsize; i++) { |
837 | sum[i + asize] = array_b[i]; |
838 | } |
839 | } |
840 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
841 | const Array &array_a = *VariantGetInternalPtr<Array>::get_ptr(&p_left); |
842 | const Array &array_b = *VariantGetInternalPtr<Array>::get_ptr(&p_right); |
843 | Array sum; |
844 | _add_arrays(sum, array_a, array_b); |
845 | *r_ret = sum; |
846 | r_valid = true; |
847 | } |
848 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
849 | *r_ret = Array(); |
850 | _add_arrays(*VariantGetInternalPtr<Array>::get_ptr(r_ret), *VariantGetInternalPtr<Array>::get_ptr(left), *VariantGetInternalPtr<Array>::get_ptr(right)); |
851 | } |
852 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
853 | Array ret; |
854 | _add_arrays(ret, PtrToArg<Array>::convert(left), PtrToArg<Array>::convert(right)); |
855 | PtrToArg<Array>::encode(ret, r_ret); |
856 | } |
857 | static Variant::Type get_return_type() { return Variant::ARRAY; } |
858 | }; |
859 | |
860 | template <class T> |
861 | class OperatorEvaluatorAppendArray { |
862 | public: |
863 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
864 | const Vector<T> &array_a = *VariantGetInternalPtr<Vector<T>>::get_ptr(&p_left); |
865 | const Vector<T> &array_b = *VariantGetInternalPtr<Vector<T>>::get_ptr(&p_right); |
866 | Vector<T> sum = array_a; |
867 | sum.append_array(array_b); |
868 | *r_ret = sum; |
869 | r_valid = true; |
870 | } |
871 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
872 | *VariantGetInternalPtr<Vector<T>>::get_ptr(r_ret) = *VariantGetInternalPtr<Vector<T>>::get_ptr(left); |
873 | VariantGetInternalPtr<Vector<T>>::get_ptr(r_ret)->append_array(*VariantGetInternalPtr<Vector<T>>::get_ptr(right)); |
874 | } |
875 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
876 | Vector<T> sum = PtrToArg<Vector<T>>::convert(left); |
877 | sum.append_array(PtrToArg<Vector<T>>::convert(right)); |
878 | PtrToArg<Vector<T>>::encode(sum, r_ret); |
879 | } |
880 | static Variant::Type get_return_type() { return GetTypeInfo<Vector<T>>::VARIANT_TYPE; } |
881 | }; |
882 | |
883 | template <class Left, class Right> |
884 | class OperatorEvaluatorStringConcat { |
885 | public: |
886 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
887 | const String a(*VariantGetInternalPtr<Left>::get_ptr(&p_left)); |
888 | const String b(*VariantGetInternalPtr<Right>::get_ptr(&p_right)); |
889 | *r_ret = a + b; |
890 | r_valid = true; |
891 | } |
892 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
893 | const String a(*VariantGetInternalPtr<Left>::get_ptr(left)); |
894 | const String b(*VariantGetInternalPtr<Right>::get_ptr(right)); |
895 | *VariantGetInternalPtr<String>::get_ptr(r_ret) = a + b; |
896 | } |
897 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
898 | const String a(PtrToArg<Left>::convert(left)); |
899 | const String b(PtrToArg<Right>::convert(right)); |
900 | PtrToArg<String>::encode(a + b, r_ret); |
901 | } |
902 | static Variant::Type get_return_type() { return Variant::STRING; } |
903 | }; |
904 | |
905 | template <class S, class T> |
906 | class OperatorEvaluatorStringFormat; |
907 | |
908 | template <class S> |
909 | class OperatorEvaluatorStringFormat<S, void> { |
910 | public: |
911 | _FORCE_INLINE_ static String do_mod(const String &s, bool *r_valid) { |
912 | Array values; |
913 | values.push_back(Variant()); |
914 | |
915 | String a = s.sprintf(values, r_valid); |
916 | if (r_valid) { |
917 | *r_valid = !*r_valid; |
918 | } |
919 | return a; |
920 | } |
921 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
922 | *r_ret = do_mod(*VariantGetInternalPtr<S>::get_ptr(&p_left), &r_valid); |
923 | } |
924 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
925 | bool valid = true; |
926 | String result = do_mod(*VariantGetInternalPtr<S>::get_ptr(left), &valid); |
927 | ERR_FAIL_COND_MSG(!valid, result); |
928 | *VariantGetInternalPtr<String>::get_ptr(r_ret) = result; |
929 | } |
930 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
931 | PtrToArg<String>::encode(do_mod(PtrToArg<S>::convert(left), nullptr), r_ret); |
932 | } |
933 | static Variant::Type get_return_type() { return Variant::STRING; } |
934 | }; |
935 | |
936 | template <class S> |
937 | class OperatorEvaluatorStringFormat<S, Array> { |
938 | public: |
939 | _FORCE_INLINE_ static String do_mod(const String &s, const Array &p_values, bool *r_valid) { |
940 | String a = s.sprintf(p_values, r_valid); |
941 | if (r_valid) { |
942 | *r_valid = !*r_valid; |
943 | } |
944 | return a; |
945 | } |
946 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
947 | *r_ret = do_mod(*VariantGetInternalPtr<S>::get_ptr(&p_left), *VariantGetInternalPtr<Array>::get_ptr(&p_right), &r_valid); |
948 | } |
949 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
950 | bool valid = true; |
951 | String result = do_mod(*VariantGetInternalPtr<S>::get_ptr(left), *VariantGetInternalPtr<Array>::get_ptr(right), &valid); |
952 | ERR_FAIL_COND_MSG(!valid, result); |
953 | *VariantGetInternalPtr<String>::get_ptr(r_ret) = result; |
954 | } |
955 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
956 | PtrToArg<String>::encode(do_mod(PtrToArg<S>::convert(left), PtrToArg<Array>::convert(right), nullptr), r_ret); |
957 | } |
958 | static Variant::Type get_return_type() { return Variant::STRING; } |
959 | }; |
960 | |
961 | template <class S> |
962 | class OperatorEvaluatorStringFormat<S, Object> { |
963 | public: |
964 | _FORCE_INLINE_ static String do_mod(const String &s, const Object *p_object, bool *r_valid) { |
965 | Array values; |
966 | values.push_back(p_object); |
967 | String a = s.sprintf(values, r_valid); |
968 | if (r_valid) { |
969 | *r_valid = !*r_valid; |
970 | } |
971 | |
972 | return a; |
973 | } |
974 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
975 | *r_ret = do_mod(*VariantGetInternalPtr<S>::get_ptr(&p_left), p_right.get_validated_object(), &r_valid); |
976 | } |
977 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
978 | bool valid = true; |
979 | String result = do_mod(*VariantGetInternalPtr<S>::get_ptr(left), right->get_validated_object(), &valid); |
980 | ERR_FAIL_COND_MSG(!valid, result); |
981 | *VariantGetInternalPtr<String>::get_ptr(r_ret) = result; |
982 | } |
983 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
984 | PtrToArg<String>::encode(do_mod(PtrToArg<S>::convert(left), PtrToArg<Object *>::convert(right), nullptr), r_ret); |
985 | } |
986 | static Variant::Type get_return_type() { return Variant::STRING; } |
987 | }; |
988 | |
989 | template <class S, class T> |
990 | class OperatorEvaluatorStringFormat { |
991 | public: |
992 | _FORCE_INLINE_ static String do_mod(const String &s, const T &p_value, bool *r_valid) { |
993 | Array values; |
994 | values.push_back(p_value); |
995 | String a = s.sprintf(values, r_valid); |
996 | if (r_valid) { |
997 | *r_valid = !*r_valid; |
998 | } |
999 | return a; |
1000 | } |
1001 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
1002 | *r_ret = do_mod(*VariantGetInternalPtr<S>::get_ptr(&p_left), *VariantGetInternalPtr<T>::get_ptr(&p_right), &r_valid); |
1003 | } |
1004 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
1005 | bool valid = true; |
1006 | String result = do_mod(*VariantGetInternalPtr<S>::get_ptr(left), *VariantGetInternalPtr<T>::get_ptr(right), &valid); |
1007 | ERR_FAIL_COND_MSG(!valid, result); |
1008 | *VariantGetInternalPtr<String>::get_ptr(r_ret) = result; |
1009 | } |
1010 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
1011 | PtrToArg<String>::encode(do_mod(PtrToArg<S>::convert(left), PtrToArg<T>::convert(right), nullptr), r_ret); |
1012 | } |
1013 | static Variant::Type get_return_type() { return Variant::STRING; } |
1014 | }; |
1015 | |
1016 | template <Variant::Operator op, Variant::Type type_left, Variant::Type type_right> |
1017 | class OperatorEvaluatorAlwaysTrue { |
1018 | public: |
1019 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
1020 | *r_ret = true; |
1021 | r_valid = true; |
1022 | } |
1023 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
1024 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = true; |
1025 | } |
1026 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
1027 | PtrToArg<bool>::encode(true, r_ret); |
1028 | } |
1029 | static Variant::Type get_return_type() { return Variant::BOOL; } |
1030 | }; |
1031 | |
1032 | template <Variant::Operator op, Variant::Type type_left, Variant::Type type_right> |
1033 | class OperatorEvaluatorAlwaysFalse { |
1034 | public: |
1035 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
1036 | *r_ret = false; |
1037 | r_valid = true; |
1038 | } |
1039 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
1040 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = false; |
1041 | } |
1042 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
1043 | PtrToArg<bool>::encode(false, r_ret); |
1044 | } |
1045 | static Variant::Type get_return_type() { return Variant::BOOL; } |
1046 | }; |
1047 | |
1048 | ///// OR /////// |
1049 | |
1050 | _FORCE_INLINE_ static bool _operate_or(bool p_left, bool p_right) { |
1051 | return p_left || p_right; |
1052 | } |
1053 | |
1054 | _FORCE_INLINE_ static bool _operate_and(bool p_left, bool p_right) { |
1055 | return p_left && p_right; |
1056 | } |
1057 | |
1058 | _FORCE_INLINE_ static bool _operate_xor(bool p_left, bool p_right) { |
1059 | return (p_left || p_right) && !(p_left && p_right); |
1060 | } |
1061 | |
1062 | _FORCE_INLINE_ static bool _operate_get_nil(const Variant *p_ptr) { |
1063 | return p_ptr->get_validated_object() != nullptr; |
1064 | } |
1065 | |
1066 | _FORCE_INLINE_ static bool _operate_get_bool(const Variant *p_ptr) { |
1067 | return *VariantGetInternalPtr<bool>::get_ptr(p_ptr); |
1068 | } |
1069 | |
1070 | _FORCE_INLINE_ static bool _operate_get_int(const Variant *p_ptr) { |
1071 | return *VariantGetInternalPtr<int64_t>::get_ptr(p_ptr) != 0; |
1072 | } |
1073 | |
1074 | _FORCE_INLINE_ static bool _operate_get_float(const Variant *p_ptr) { |
1075 | return *VariantGetInternalPtr<double>::get_ptr(p_ptr) != 0.0; |
1076 | } |
1077 | |
1078 | _FORCE_INLINE_ static bool _operate_get_object(const Variant *p_ptr) { |
1079 | return p_ptr->get_validated_object() != nullptr; |
1080 | } |
1081 | |
1082 | _FORCE_INLINE_ static bool _operate_get_ptr_nil(const void *p_ptr) { |
1083 | return false; |
1084 | } |
1085 | |
1086 | _FORCE_INLINE_ static bool _operate_get_ptr_bool(const void *p_ptr) { |
1087 | return PtrToArg<bool>::convert(p_ptr); |
1088 | } |
1089 | |
1090 | _FORCE_INLINE_ static bool _operate_get_ptr_int(const void *p_ptr) { |
1091 | return PtrToArg<int64_t>::convert(p_ptr) != 0; |
1092 | } |
1093 | |
1094 | _FORCE_INLINE_ static bool _operate_get_ptr_float(const void *p_ptr) { |
1095 | return PtrToArg<double>::convert(p_ptr) != 0.0; |
1096 | } |
1097 | |
1098 | _FORCE_INLINE_ static bool _operate_get_ptr_object(const void *p_ptr) { |
1099 | return PtrToArg<Object *>::convert(p_ptr) != nullptr; |
1100 | } |
1101 | |
1102 | #define OP_EVALUATOR(m_class_name, m_left, m_right, m_op) \ |
1103 | class m_class_name { \ |
1104 | public: \ |
1105 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { \ |
1106 | *r_ret = m_op(_operate_get_##m_left(&p_left), _operate_get_##m_right(&p_right)); \ |
1107 | r_valid = true; \ |
1108 | } \ |
1109 | \ |
1110 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { \ |
1111 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = m_op(_operate_get_##m_left(left), _operate_get_##m_right(right)); \ |
1112 | } \ |
1113 | \ |
1114 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { \ |
1115 | PtrToArg<bool>::encode(m_op(_operate_get_ptr_##m_left(left), _operate_get_ptr_##m_right(right)), r_ret); \ |
1116 | } \ |
1117 | \ |
1118 | static Variant::Type get_return_type() { \ |
1119 | return Variant::BOOL; \ |
1120 | } \ |
1121 | }; |
1122 | |
1123 | // OR |
1124 | |
1125 | // nil |
1126 | OP_EVALUATOR(OperatorEvaluatorNilXBoolOr, nil, bool, _operate_or) |
1127 | OP_EVALUATOR(OperatorEvaluatorBoolXNilOr, bool, nil, _operate_or) |
1128 | |
1129 | OP_EVALUATOR(OperatorEvaluatorNilXIntOr, nil, int, _operate_or) |
1130 | OP_EVALUATOR(OperatorEvaluatorIntXNilOr, int, nil, _operate_or) |
1131 | |
1132 | OP_EVALUATOR(OperatorEvaluatorNilXFloatOr, nil, float, _operate_or) |
1133 | OP_EVALUATOR(OperatorEvaluatorFloatXNilOr, float, nil, _operate_or) |
1134 | |
1135 | OP_EVALUATOR(OperatorEvaluatorObjectXNilOr, object, nil, _operate_or) |
1136 | OP_EVALUATOR(OperatorEvaluatorNilXObjectOr, nil, object, _operate_or) |
1137 | |
1138 | // bool |
1139 | OP_EVALUATOR(OperatorEvaluatorBoolXBoolOr, bool, bool, _operate_or) |
1140 | |
1141 | OP_EVALUATOR(OperatorEvaluatorBoolXIntOr, bool, int, _operate_or) |
1142 | OP_EVALUATOR(OperatorEvaluatorIntXBoolOr, int, bool, _operate_or) |
1143 | |
1144 | OP_EVALUATOR(OperatorEvaluatorBoolXFloatOr, bool, float, _operate_or) |
1145 | OP_EVALUATOR(OperatorEvaluatorFloatXBoolOr, float, bool, _operate_or) |
1146 | |
1147 | OP_EVALUATOR(OperatorEvaluatorBoolXObjectOr, bool, object, _operate_or) |
1148 | OP_EVALUATOR(OperatorEvaluatorObjectXBoolOr, object, bool, _operate_or) |
1149 | |
1150 | // int |
1151 | OP_EVALUATOR(OperatorEvaluatorIntXIntOr, int, int, _operate_or) |
1152 | |
1153 | OP_EVALUATOR(OperatorEvaluatorIntXFloatOr, int, float, _operate_or) |
1154 | OP_EVALUATOR(OperatorEvaluatorFloatXIntOr, float, int, _operate_or) |
1155 | |
1156 | OP_EVALUATOR(OperatorEvaluatorIntXObjectOr, int, object, _operate_or) |
1157 | OP_EVALUATOR(OperatorEvaluatorObjectXIntOr, object, int, _operate_or) |
1158 | |
1159 | // float |
1160 | OP_EVALUATOR(OperatorEvaluatorFloatXFloatOr, float, float, _operate_or) |
1161 | |
1162 | OP_EVALUATOR(OperatorEvaluatorFloatXObjectOr, float, object, _operate_or) |
1163 | OP_EVALUATOR(OperatorEvaluatorObjectXFloatOr, object, float, _operate_or) |
1164 | |
1165 | // object |
1166 | OP_EVALUATOR(OperatorEvaluatorObjectXObjectOr, object, object, _operate_or) |
1167 | |
1168 | // AND |
1169 | |
1170 | // nil |
1171 | OP_EVALUATOR(OperatorEvaluatorNilXBoolAnd, nil, bool, _operate_and) |
1172 | OP_EVALUATOR(OperatorEvaluatorBoolXNilAnd, bool, nil, _operate_and) |
1173 | |
1174 | OP_EVALUATOR(OperatorEvaluatorNilXIntAnd, nil, int, _operate_and) |
1175 | OP_EVALUATOR(OperatorEvaluatorIntXNilAnd, int, nil, _operate_and) |
1176 | |
1177 | OP_EVALUATOR(OperatorEvaluatorNilXFloatAnd, nil, float, _operate_and) |
1178 | OP_EVALUATOR(OperatorEvaluatorFloatXNilAnd, float, nil, _operate_and) |
1179 | |
1180 | OP_EVALUATOR(OperatorEvaluatorObjectXNilAnd, object, nil, _operate_and) |
1181 | OP_EVALUATOR(OperatorEvaluatorNilXObjectAnd, nil, object, _operate_and) |
1182 | |
1183 | // bool |
1184 | OP_EVALUATOR(OperatorEvaluatorBoolXBoolAnd, bool, bool, _operate_and) |
1185 | |
1186 | OP_EVALUATOR(OperatorEvaluatorBoolXIntAnd, bool, int, _operate_and) |
1187 | OP_EVALUATOR(OperatorEvaluatorIntXBoolAnd, int, bool, _operate_and) |
1188 | |
1189 | OP_EVALUATOR(OperatorEvaluatorBoolXFloatAnd, bool, float, _operate_and) |
1190 | OP_EVALUATOR(OperatorEvaluatorFloatXBoolAnd, float, bool, _operate_and) |
1191 | |
1192 | OP_EVALUATOR(OperatorEvaluatorBoolXObjectAnd, bool, object, _operate_and) |
1193 | OP_EVALUATOR(OperatorEvaluatorObjectXBoolAnd, object, bool, _operate_and) |
1194 | |
1195 | // int |
1196 | OP_EVALUATOR(OperatorEvaluatorIntXIntAnd, int, int, _operate_and) |
1197 | |
1198 | OP_EVALUATOR(OperatorEvaluatorIntXFloatAnd, int, float, _operate_and) |
1199 | OP_EVALUATOR(OperatorEvaluatorFloatXIntAnd, float, int, _operate_and) |
1200 | |
1201 | OP_EVALUATOR(OperatorEvaluatorIntXObjectAnd, int, object, _operate_and) |
1202 | OP_EVALUATOR(OperatorEvaluatorObjectXIntAnd, object, int, _operate_and) |
1203 | |
1204 | // float |
1205 | OP_EVALUATOR(OperatorEvaluatorFloatXFloatAnd, float, float, _operate_and) |
1206 | |
1207 | OP_EVALUATOR(OperatorEvaluatorFloatXObjectAnd, float, object, _operate_and) |
1208 | OP_EVALUATOR(OperatorEvaluatorObjectXFloatAnd, object, float, _operate_and) |
1209 | |
1210 | // object |
1211 | OP_EVALUATOR(OperatorEvaluatorObjectXObjectAnd, object, object, _operate_and) |
1212 | |
1213 | // XOR |
1214 | |
1215 | // nil |
1216 | OP_EVALUATOR(OperatorEvaluatorNilXBoolXor, nil, bool, _operate_xor) |
1217 | OP_EVALUATOR(OperatorEvaluatorBoolXNilXor, bool, nil, _operate_xor) |
1218 | |
1219 | OP_EVALUATOR(OperatorEvaluatorNilXIntXor, nil, int, _operate_xor) |
1220 | OP_EVALUATOR(OperatorEvaluatorIntXNilXor, int, nil, _operate_xor) |
1221 | |
1222 | OP_EVALUATOR(OperatorEvaluatorNilXFloatXor, nil, float, _operate_xor) |
1223 | OP_EVALUATOR(OperatorEvaluatorFloatXNilXor, float, nil, _operate_xor) |
1224 | |
1225 | OP_EVALUATOR(OperatorEvaluatorObjectXNilXor, object, nil, _operate_xor) |
1226 | OP_EVALUATOR(OperatorEvaluatorNilXObjectXor, nil, object, _operate_xor) |
1227 | |
1228 | // bool |
1229 | OP_EVALUATOR(OperatorEvaluatorBoolXBoolXor, bool, bool, _operate_xor) |
1230 | |
1231 | OP_EVALUATOR(OperatorEvaluatorBoolXIntXor, bool, int, _operate_xor) |
1232 | OP_EVALUATOR(OperatorEvaluatorIntXBoolXor, int, bool, _operate_xor) |
1233 | |
1234 | OP_EVALUATOR(OperatorEvaluatorBoolXFloatXor, bool, float, _operate_xor) |
1235 | OP_EVALUATOR(OperatorEvaluatorFloatXBoolXor, float, bool, _operate_xor) |
1236 | |
1237 | OP_EVALUATOR(OperatorEvaluatorBoolXObjectXor, bool, object, _operate_xor) |
1238 | OP_EVALUATOR(OperatorEvaluatorObjectXBoolXor, object, bool, _operate_xor) |
1239 | |
1240 | // int |
1241 | OP_EVALUATOR(OperatorEvaluatorIntXIntXor, int, int, _operate_xor) |
1242 | |
1243 | OP_EVALUATOR(OperatorEvaluatorIntXFloatXor, int, float, _operate_xor) |
1244 | OP_EVALUATOR(OperatorEvaluatorFloatXIntXor, float, int, _operate_xor) |
1245 | |
1246 | OP_EVALUATOR(OperatorEvaluatorIntXObjectXor, int, object, _operate_xor) |
1247 | OP_EVALUATOR(OperatorEvaluatorObjectXIntXor, object, int, _operate_xor) |
1248 | |
1249 | // float |
1250 | OP_EVALUATOR(OperatorEvaluatorFloatXFloatXor, float, float, _operate_xor) |
1251 | |
1252 | OP_EVALUATOR(OperatorEvaluatorFloatXObjectXor, float, object, _operate_xor) |
1253 | OP_EVALUATOR(OperatorEvaluatorObjectXFloatXor, object, float, _operate_xor) |
1254 | |
1255 | // object |
1256 | OP_EVALUATOR(OperatorEvaluatorObjectXObjectXor, object, object, _operate_xor) |
1257 | |
1258 | class OperatorEvaluatorNotBool { |
1259 | public: |
1260 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
1261 | *r_ret = !*VariantGetInternalPtr<bool>::get_ptr(&p_left); |
1262 | r_valid = true; |
1263 | } |
1264 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
1265 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = !*VariantGetInternalPtr<bool>::get_ptr(left); |
1266 | } |
1267 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
1268 | PtrToArg<bool>::encode(!PtrToArg<bool>::convert(left), r_ret); |
1269 | } |
1270 | static Variant::Type get_return_type() { return Variant::BOOL; } |
1271 | }; |
1272 | |
1273 | class OperatorEvaluatorNotInt { |
1274 | public: |
1275 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
1276 | *r_ret = !*VariantGetInternalPtr<int64_t>::get_ptr(&p_left); |
1277 | r_valid = true; |
1278 | } |
1279 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
1280 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = !*VariantGetInternalPtr<int64_t>::get_ptr(left); |
1281 | } |
1282 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
1283 | PtrToArg<bool>::encode(!PtrToArg<int64_t>::convert(left), r_ret); |
1284 | } |
1285 | static Variant::Type get_return_type() { return Variant::BOOL; } |
1286 | }; |
1287 | |
1288 | class OperatorEvaluatorNotFloat { |
1289 | public: |
1290 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
1291 | *r_ret = !*VariantGetInternalPtr<double>::get_ptr(&p_left); |
1292 | r_valid = true; |
1293 | } |
1294 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
1295 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = !*VariantGetInternalPtr<double>::get_ptr(left); |
1296 | } |
1297 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
1298 | PtrToArg<bool>::encode(!PtrToArg<double>::convert(left), r_ret); |
1299 | } |
1300 | static Variant::Type get_return_type() { return Variant::BOOL; } |
1301 | }; |
1302 | |
1303 | class OperatorEvaluatorNotObject { |
1304 | public: |
1305 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
1306 | *r_ret = p_left.get_validated_object() == nullptr; |
1307 | r_valid = true; |
1308 | } |
1309 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
1310 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = left->get_validated_object() == nullptr; |
1311 | } |
1312 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
1313 | PtrToArg<bool>::encode(PtrToArg<Object *>::convert(left) == nullptr, r_ret); |
1314 | } |
1315 | static Variant::Type get_return_type() { return Variant::BOOL; } |
1316 | }; |
1317 | |
1318 | //// |
1319 | |
1320 | template <class Left, class Right> |
1321 | class OperatorEvaluatorInStringFind; |
1322 | |
1323 | template <class Left> |
1324 | class OperatorEvaluatorInStringFind<Left, String> { |
1325 | public: |
1326 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
1327 | const Left &str_a = *VariantGetInternalPtr<Left>::get_ptr(&p_left); |
1328 | const String &str_b = *VariantGetInternalPtr<String>::get_ptr(&p_right); |
1329 | |
1330 | *r_ret = str_b.find(str_a) != -1; |
1331 | r_valid = true; |
1332 | } |
1333 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
1334 | const Left &str_a = *VariantGetInternalPtr<Left>::get_ptr(left); |
1335 | const String &str_b = *VariantGetInternalPtr<String>::get_ptr(right); |
1336 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = str_b.find(str_a) != -1; |
1337 | } |
1338 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
1339 | PtrToArg<bool>::encode(PtrToArg<String>::convert(right).find(PtrToArg<Left>::convert(left)) != -1, r_ret); |
1340 | } |
1341 | static Variant::Type get_return_type() { return Variant::BOOL; } |
1342 | }; |
1343 | |
1344 | template <class Left> |
1345 | class OperatorEvaluatorInStringFind<Left, StringName> { |
1346 | public: |
1347 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
1348 | const Left &str_a = *VariantGetInternalPtr<Left>::get_ptr(&p_left); |
1349 | const String str_b = VariantGetInternalPtr<StringName>::get_ptr(&p_right)->operator String(); |
1350 | |
1351 | *r_ret = str_b.find(str_a) != -1; |
1352 | r_valid = true; |
1353 | } |
1354 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
1355 | const Left &str_a = *VariantGetInternalPtr<Left>::get_ptr(left); |
1356 | const String str_b = VariantGetInternalPtr<StringName>::get_ptr(right)->operator String(); |
1357 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = str_b.find(str_a) != -1; |
1358 | } |
1359 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
1360 | PtrToArg<bool>::encode(PtrToArg<StringName>::convert(right).operator String().find(PtrToArg<Left>::convert(left)) != -1, r_ret); |
1361 | } |
1362 | static Variant::Type get_return_type() { return Variant::BOOL; } |
1363 | }; |
1364 | |
1365 | template <class A, class B> |
1366 | class OperatorEvaluatorInArrayFind { |
1367 | public: |
1368 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
1369 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
1370 | const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); |
1371 | |
1372 | *r_ret = b.find(a) != -1; |
1373 | r_valid = true; |
1374 | } |
1375 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
1376 | const A &a = *VariantGetInternalPtr<A>::get_ptr(left); |
1377 | const B &b = *VariantGetInternalPtr<B>::get_ptr(right); |
1378 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.find(a) != -1; |
1379 | } |
1380 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
1381 | PtrToArg<bool>::encode(PtrToArg<B>::convert(right).find(PtrToArg<A>::convert(left)) != -1, r_ret); |
1382 | } |
1383 | static Variant::Type get_return_type() { return Variant::BOOL; } |
1384 | }; |
1385 | |
1386 | class OperatorEvaluatorInArrayFindNil { |
1387 | public: |
1388 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
1389 | const Array &b = *VariantGetInternalPtr<Array>::get_ptr(&p_right); |
1390 | *r_ret = b.find(Variant()) != -1; |
1391 | r_valid = true; |
1392 | } |
1393 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
1394 | const Array &b = *VariantGetInternalPtr<Array>::get_ptr(right); |
1395 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.find(Variant()) != -1; |
1396 | } |
1397 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
1398 | PtrToArg<bool>::encode(PtrToArg<Array>::convert(right).find(Variant()) != -1, r_ret); |
1399 | } |
1400 | static Variant::Type get_return_type() { return Variant::BOOL; } |
1401 | }; |
1402 | |
1403 | class OperatorEvaluatorInArrayFindObject { |
1404 | public: |
1405 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
1406 | const Array &b = *VariantGetInternalPtr<Array>::get_ptr(&p_right); |
1407 | *r_ret = b.find(p_left) != -1; |
1408 | r_valid = true; |
1409 | } |
1410 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
1411 | const Array &b = *VariantGetInternalPtr<Array>::get_ptr(right); |
1412 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.find(*left) != -1; |
1413 | } |
1414 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
1415 | PtrToArg<bool>::encode(PtrToArg<Array>::convert(right).find(PtrToArg<Object *>::convert(left)) != -1, r_ret); |
1416 | } |
1417 | static Variant::Type get_return_type() { return Variant::BOOL; } |
1418 | }; |
1419 | |
1420 | template <class A> |
1421 | class OperatorEvaluatorInDictionaryHas { |
1422 | public: |
1423 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
1424 | const Dictionary &b = *VariantGetInternalPtr<Dictionary>::get_ptr(&p_right); |
1425 | const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); |
1426 | |
1427 | *r_ret = b.has(a); |
1428 | r_valid = true; |
1429 | } |
1430 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
1431 | const Dictionary &b = *VariantGetInternalPtr<Dictionary>::get_ptr(right); |
1432 | const A &a = *VariantGetInternalPtr<A>::get_ptr(left); |
1433 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.has(a); |
1434 | } |
1435 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
1436 | PtrToArg<bool>::encode(PtrToArg<Dictionary>::convert(right).has(PtrToArg<A>::convert(left)), r_ret); |
1437 | } |
1438 | static Variant::Type get_return_type() { return Variant::BOOL; } |
1439 | }; |
1440 | |
1441 | class OperatorEvaluatorInDictionaryHasNil { |
1442 | public: |
1443 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
1444 | const Dictionary &b = *VariantGetInternalPtr<Dictionary>::get_ptr(&p_right); |
1445 | |
1446 | *r_ret = b.has(Variant()); |
1447 | r_valid = true; |
1448 | } |
1449 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
1450 | const Dictionary &b = *VariantGetInternalPtr<Dictionary>::get_ptr(right); |
1451 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.has(Variant()); |
1452 | } |
1453 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
1454 | PtrToArg<bool>::encode(PtrToArg<Dictionary>::convert(right).has(Variant()), r_ret); |
1455 | } |
1456 | static Variant::Type get_return_type() { return Variant::BOOL; } |
1457 | }; |
1458 | |
1459 | class OperatorEvaluatorInDictionaryHasObject { |
1460 | public: |
1461 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
1462 | const Dictionary &b = *VariantGetInternalPtr<Dictionary>::get_ptr(&p_right); |
1463 | |
1464 | *r_ret = b.has(p_left); |
1465 | r_valid = true; |
1466 | } |
1467 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
1468 | const Dictionary &b = *VariantGetInternalPtr<Dictionary>::get_ptr(right); |
1469 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = b.has(*left); |
1470 | } |
1471 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
1472 | PtrToArg<bool>::encode(PtrToArg<Dictionary>::convert(right).has(PtrToArg<Object *>::convert(left)), r_ret); |
1473 | } |
1474 | static Variant::Type get_return_type() { return Variant::BOOL; } |
1475 | }; |
1476 | |
1477 | class OperatorEvaluatorObjectHasPropertyString { |
1478 | public: |
1479 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
1480 | Object *b = p_right.get_validated_object(); |
1481 | if (!b) { |
1482 | *r_ret = "Invalid base object for 'in'" ; |
1483 | r_valid = false; |
1484 | return; |
1485 | } |
1486 | |
1487 | const String &a = *VariantGetInternalPtr<String>::get_ptr(&p_left); |
1488 | |
1489 | bool exist; |
1490 | b->get(a, &exist); |
1491 | *r_ret = exist; |
1492 | r_valid = true; |
1493 | } |
1494 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
1495 | Object *l = right->get_validated_object(); |
1496 | ERR_FAIL_NULL(l); |
1497 | const String &a = *VariantGetInternalPtr<String>::get_ptr(left); |
1498 | |
1499 | bool valid; |
1500 | l->get(a, &valid); |
1501 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = valid; |
1502 | } |
1503 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
1504 | bool valid; |
1505 | PtrToArg<Object *>::convert(right)->get(PtrToArg<String>::convert(left), &valid); |
1506 | PtrToArg<bool>::encode(valid, r_ret); |
1507 | } |
1508 | static Variant::Type get_return_type() { return Variant::BOOL; } |
1509 | }; |
1510 | |
1511 | class OperatorEvaluatorObjectHasPropertyStringName { |
1512 | public: |
1513 | static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { |
1514 | Object *b = p_right.get_validated_object(); |
1515 | if (!b) { |
1516 | *r_ret = "Invalid base object for 'in'" ; |
1517 | r_valid = false; |
1518 | return; |
1519 | } |
1520 | |
1521 | const StringName &a = *VariantGetInternalPtr<StringName>::get_ptr(&p_left); |
1522 | |
1523 | bool exist; |
1524 | b->get(a, &exist); |
1525 | *r_ret = exist; |
1526 | r_valid = true; |
1527 | } |
1528 | static inline void validated_evaluate(const Variant *left, const Variant *right, Variant *r_ret) { |
1529 | Object *l = right->get_validated_object(); |
1530 | ERR_FAIL_NULL(l); |
1531 | const StringName &a = *VariantGetInternalPtr<StringName>::get_ptr(left); |
1532 | |
1533 | bool valid; |
1534 | l->get(a, &valid); |
1535 | *VariantGetInternalPtr<bool>::get_ptr(r_ret) = valid; |
1536 | } |
1537 | static void ptr_evaluate(const void *left, const void *right, void *r_ret) { |
1538 | bool valid; |
1539 | PtrToArg<Object *>::convert(right)->get(PtrToArg<StringName>::convert(left), &valid); |
1540 | PtrToArg<bool>::encode(valid, r_ret); |
1541 | } |
1542 | static Variant::Type get_return_type() { return Variant::BOOL; } |
1543 | }; |
1544 | |
1545 | #endif // VARIANT_OP_H |
1546 | |