/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Code/Engine/Foundation/Reflection/Implementation/BitflagsProperty.h
100 строк
4 KB
C-Core
Various fixes and improvements (#1031)
07 сен 2023, 11:12
Не верифицирован
07 сен 2023, 11:12
cc77144
Код
Авторство
О чём код?
#pragma once /// \file #include <Foundation/Reflection/Implementation/EnumProperty.h> #include <Foundation/Reflection/Implementation/StaticRTTI.h> /// \brief [internal] An implementation of ezTypedEnumProperty that uses custom getter / setter functions to access a bitflags property. template <typename Class, typename EnumType, typename Type> class ezBitflagsAccessorProperty : public ezTypedEnumProperty<EnumType> { public: using RealType = typename ezTypeTraits<Type>::NonConstReferenceType; using GetterFunc = Type (Class::*)() const; using SetterFunc = void (Class::*)(Type value); /// \brief Constructor. ezBitflagsAccessorProperty(const char* szPropertyName, GetterFunc getter, SetterFunc setter) : ezTypedEnumProperty<EnumType>(szPropertyName) { EZ_ASSERT_DEBUG(getter != nullptr, "The getter of a property cannot be nullptr."); ezAbstractMemberProperty::m_Flags.Add(ezPropertyFlags::Bitflags); m_Getter = getter; m_Setter = setter; if (m_Setter == nullptr) ezAbstractMemberProperty::m_Flags.Add(ezPropertyFlags::ReadOnly); } virtual void* GetPropertyPointer(const void* pInstance) const override { // No access to sub-properties, if we have accessors for this property return nullptr; } virtual ezInt64 GetValue(const void* pInstance) const override // [tested] { typename EnumType::StorageType enumTemp = (static_cast<const Class*>(pInstance)->*m_Getter)().GetValue(); return (ezInt64)enumTemp; } virtual void SetValue(void* pInstance, ezInt64 value) const override // [tested] { EZ_ASSERT_DEV(m_Setter != nullptr, "The property '{0}' has no setter function, thus it is read-only.", ezAbstractProperty::GetPropertyName()); if (m_Setter) (static_cast<Class*>(pInstance)->*m_Setter)((typename EnumType::Enum)value); } private: GetterFunc m_Getter; SetterFunc m_Setter; }; /// \brief [internal] An implementation of ezTypedEnumProperty that accesses the bitflags property data directly. template <typename Class, typename EnumType, typename Type> class ezBitflagsMemberProperty : public ezTypedEnumProperty<EnumType> { public: using GetterFunc = Type (*)(const Class* pInstance); using SetterFunc = void (*)(Class* pInstance, Type value); using PointerFunc = void* (*)(const Class* pInstance); /// \brief Constructor. ezBitflagsMemberProperty(const char* szPropertyName, GetterFunc getter, SetterFunc setter, PointerFunc pointer) : ezTypedEnumProperty<EnumType>(szPropertyName) { EZ_ASSERT_DEBUG(getter != nullptr, "The getter of a property cannot be nullptr."); ezAbstractMemberProperty::m_Flags.Add(ezPropertyFlags::Bitflags); m_Getter = getter; m_Setter = setter; m_Pointer = pointer; if (m_Setter == nullptr) ezAbstractMemberProperty::m_Flags.Add(ezPropertyFlags::ReadOnly); } virtual void* GetPropertyPointer(const void* pInstance) const override { return m_Pointer(static_cast<const Class*>(pInstance)); } virtual ezInt64 GetValue(const void* pInstance) const override // [tested] { typename EnumType::StorageType enumTemp = m_Getter(static_cast<const Class*>(pInstance)).GetValue(); return (ezInt64)enumTemp; } virtual void SetValue(void* pInstance, ezInt64 value) const override // [tested] { EZ_ASSERT_DEV(m_Setter != nullptr, "The property '{0}' has no setter function, thus it is read-only.", ezAbstractProperty::GetPropertyName()); if (m_Setter) m_Setter(static_cast<Class*>(pInstance), (typename EnumType::Enum)value); } private: GetterFunc m_Getter; SetterFunc m_Setter; PointerFunc m_Pointer; };