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 216-243 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_function_v<std::remove_reference_t<std::remove_pointer_t<decltype(Data)>>>) {
        auto * const clazz = instance->try_cast<std::conditional_t<std::is_invocable_v<decltype(Data), const Type &>, const Type, Type>>();
        return clazz ? meta_dispatch<Policy>(Data(*clazz)) : meta_any{};
    } else if constexpr(std::is_member_function_pointer_v<decltype(Data)>) {
        auto * const clazz = instance->try_cast<std::conditional_t<std::is_invocable_v<decltype(Data), const Type &>, const Type, Type>>();
        return clazz ? meta_dispatch<Policy>((clazz->*Data)()) : meta_any{};
    } else if constexpr(std::is_member_object_pointer_v<decltype(Data)>) {
        if constexpr(!std::is_array_v<std::remove_cv_t<std::remove_reference_t<decltype(std::declval<Type>().*Data)>>>) {
            if(auto * clazz = instance->try_cast<Type>(); clazz) {
                return meta_dispatch<Policy>(clazz->*Data);
            } else if(auto * fallback = instance->try_cast<const Type>(); fallback) {
                return meta_dispatch<Policy>(fallback->*Data);
            }
        }

        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