Function meta_getter

Synopsis

#include <src/entt/meta/utility.hpp>

template <typename Type, auto Data, typename Policy = as_is_t>
meta_any meta_getter([[maybe_unused]] meta_handle instance)

Description

Gets the value of a given variable.

Template Parameters

Type - Reflected type to which the variable is associated.

Data - The actual variable to get.

Policy - Optional policy (no policy set by default).

Parameters

instance - An opaque instance of the underlying type, if required.

Returns
A meta any containing the value of the underlying variable.

Source

Lines 239-266 in src/entt/meta/utility.hpp.

template<typename Type, auto Data, typename Policy = as_is_t>
[[nodiscard]] meta_any meta_getter([[maybe_unused]] meta_handle instance) {
    if constexpr(std::is_member_pointer_v<decltype(Data)> || std::is_function_v<std::remove_reference_t<std::remove_pointer_t<decltype(Data)>>>) {
        if constexpr(!std::is_array_v<std::remove_cv_t<std::remove_reference_t<std::invoke_result_t<decltype(Data), Type &>>>>) {
            if constexpr(std::is_invocable_v<decltype(Data), Type &>) {
                if(auto *clazz = instance->try_cast<Type>(); clazz) {
                    return meta_dispatch<Policy>(std::invoke(Data, *clazz));
                }
            }

            if constexpr(std::is_invocable_v<decltype(Data), const Type &>) {
                if(auto *fallback = instance->try_cast<const Type>(); fallback) {
                    return meta_dispatch<Policy>(std::invoke(Data, *fallback));
                }
            }
        }

        return meta_any{};
    } else if constexpr(std::is_pointer_v<decltype(Data)>) {
        if constexpr(std::is_array_v<std::remove_pointer_t<decltype(Data)>>) {
            return meta_any{};
        } else {
            return meta_dispatch<Policy>(*Data);
        }
    } else {
        return meta_dispatch<Policy>(Data);
    }
}





Add Discussion

Log in to comment