|
| 1 | +/**************************************************************************/ |
| 2 | +/* converter.hpp */ |
| 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 | +#pragma once |
| 32 | + |
| 33 | +#include <godot_cpp/core/defs.hpp> |
| 34 | +#include <godot_cpp/core/method_ptrcall.hpp> |
| 35 | +#include <godot_cpp/core/type_info.hpp> |
| 36 | +#include <godot_cpp/variant/variant.hpp> |
| 37 | + |
| 38 | +#include <gdextension_interface.h> |
| 39 | + |
| 40 | +#define GD_REGISTER_CONVERSION(m_type, m_conv, m_to, m_from, m_var_type) \ |
| 41 | + namespace godot { \ |
| 42 | + template<> \ |
| 43 | + struct VariantCaster<m_type> { \ |
| 44 | + _FORCE_INLINE_ static m_type cast(const Variant &p_variant) { \ |
| 45 | + return m_to(p_variant); \ |
| 46 | + } \ |
| 47 | + template<> \ |
| 48 | + struct VariantCaster<m_type &> { \ |
| 49 | + _FORCE_INLINE_ static m_type cast(const Variant &p_variant) { \ |
| 50 | + return m_to(p_variant); \ |
| 51 | + } \ |
| 52 | + template<> \ |
| 53 | + struct VariantCaster<const m_type &> { \ |
| 54 | + _FORCE_INLINE_ static m_type cast(const Variant &p_variant) { \ |
| 55 | + return m_to(p_variant); \ |
| 56 | + } \ |
| 57 | + MAKE_TYPE_INFO(m_type, m_var_type) \ |
| 58 | + MAKE_PTRARG_CONVERTER(m_type, m_conv, m_to, m_from); \ |
| 59 | + } |
| 60 | + |
| 61 | +#define GD_REGISTER_CONVERSION_BY_REFERENCE(m_type, m_conv, m_to, m_from, m_var_type) \ |
| 62 | + namespace godot { \ |
| 63 | + template<> \ |
| 64 | + struct VariantCaster<m_type> { \ |
| 65 | + _FORCE_INLINE_ static m_type cast(const Variant &p_variant) { \ |
| 66 | + return m_to(p_variant); \ |
| 67 | + } \ |
| 68 | + template<> \ |
| 69 | + struct VariantCaster<m_type &> { \ |
| 70 | + _FORCE_INLINE_ static m_type cast(const Variant &p_variant) { \ |
| 71 | + return m_to(p_variant); \ |
| 72 | + } \ |
| 73 | + template<> \ |
| 74 | + struct VariantCaster<const m_type &> { \ |
| 75 | + _FORCE_INLINE_ static m_type cast(const Variant &p_variant) { \ |
| 76 | + return m_to(p_variant); \ |
| 77 | + } \ |
| 78 | + MAKE_TYPE_INFO(m_type, m_var_type) \ |
| 79 | + MAKE_PTRARG_CONVERTER_BY_REFERENCE(m_type, m_conv, m_to, m_from); \ |
| 80 | + } |
| 81 | + |
0 commit comments