5#include <Foundation/Reflection/Implementation/AbstractProperty.h>
6#include <Foundation/Reflection/Implementation/StaticRTTI.h>
7#include <Foundation/Types/Variant.h>
18template <
typename Type>
26 m_Flags = plPropertyFlags::GetParameterFlags<Type>();
28 !std::is_pointer<Type>::value ||
30 "Pointer to standard types are not supported.");
37 return plGetStaticRTTI<typename plTypeTraits<Type>::NonConstReferencePointerType>();
41 virtual Type
GetValue(
const void* pInstance)
const = 0;
46 virtual void SetValue(
void* pInstance, Type value)
const = 0;
48 virtual void GetValuePtr(
const void* pInstance,
void* pObject)
const override { *
static_cast<Type*
>(pObject) =
GetValue(pInstance); };
49 virtual void SetValuePtr(
void* pInstance,
const void* pObject)
const override {
SetValue(pInstance, *
static_cast<const Type*
>(pObject)); };
64 m_Flags = plPropertyFlags::GetParameterFlags<const char*>();
69 return plGetStaticRTTI<const char*>();
72 virtual const char*
GetValue(
const void* pInstance)
const = 0;
73 virtual void SetValue(
void* pInstance,
const char* value)
const = 0;
74 virtual void GetValuePtr(
const void* pInstance,
void* pObject)
const override { *
static_cast<const char**
>(pObject) =
GetValue(pInstance); };
75 virtual void SetValuePtr(
void* pInstance,
const void* pObject)
const override {
SetValue(pInstance, *
static_cast<const char* const*
>(pObject)); };
83template <
typename Class,
typename Type>
88 using GetterFunc = Type (Class::*)()
const;
89 using SetterFunc = void (Class::*)(Type value);
95 PL_ASSERT_DEBUG(getter !=
nullptr,
"The getter of a property cannot be nullptr.");
100 if (m_Setter ==
nullptr)
113 virtual RealType
GetValue(
const void* pInstance)
const override
115 return (
static_cast<const Class*
>(pInstance)->*m_Getter)();
121 virtual void SetValue(
void* pInstance, RealType value)
const override
126 (
static_cast<Class*
>(pInstance)->*m_Setter)(value);
139template <
typename Class,
typename Type, Type Class::*Member>
142 static Type GetValue(
const Class* pInstance) {
return (*pInstance).*Member; }
144 static void SetValue(Class* pInstance, Type value) { (*pInstance).*Member = value; }
146 static void* GetPropertyPointer(
const Class* pInstance) {
return (
void*)&((*pInstance).*Member); }
151template <
typename Class,
typename Type>
155 using GetterFunc = Type (*)(
const Class* pInstance);
156 using SetterFunc = void (*)(Class* pInstance, Type value);
157 using PointerFunc =
void* (*)(
const Class* pInstance);
160 plMemberProperty(
const char* szPropertyName, GetterFunc getter, SetterFunc setter, PointerFunc pointer)
163 PL_ASSERT_DEBUG(getter !=
nullptr,
"The getter of a property cannot be nullptr.");
169 if (m_Setter ==
nullptr)
174 virtual void*
GetPropertyPointer(
const void* pInstance)
const override {
return m_Pointer(
static_cast<const Class*
>(pInstance)); }
177 virtual Type
GetValue(
const void* pInstance)
const override {
return m_Getter(
static_cast<const Class*
>(pInstance)); }
182 virtual void SetValue(
void* pInstance, Type value)
const override
187 m_Setter(
static_cast<Class*
>(pInstance), value);
193 PointerFunc m_Pointer;
This is the base class for all properties that are members of a class. It provides more information a...
Definition AbstractProperty.h:237
plAbstractMemberProperty(const char *szPropertyName)
Passes the property name through to plAbstractProperty.
Definition AbstractProperty.h:240
const char * GetPropertyName() const
Returns the name of the property.
Definition AbstractProperty.h:158
[internal] An implementation of plTypedMemberProperty that uses custom getter / setter functions to a...
Definition MemberProperty.h:85
virtual RealType GetValue(const void *pInstance) const override
Returns the value of the property. Pass the instance pointer to the surrounding class along.
Definition MemberProperty.h:113
virtual void * GetPropertyPointer(const void *pInstance) const override
Always returns nullptr; once a property is modified through accessors, there is no point in giving mo...
Definition MemberProperty.h:106
virtual void SetValue(void *pInstance, RealType value) const override
Modifies the value of the property. Pass the instance pointer to the surrounding class along.
Definition MemberProperty.h:121
plAccessorProperty(const char *szPropertyName, GetterFunc getter, SetterFunc setter)
Constructor.
Definition MemberProperty.h:92
[internal] An implementation of plTypedMemberProperty that accesses the property data directly.
Definition MemberProperty.h:153
virtual void * GetPropertyPointer(const void *pInstance) const override
Returns a pointer to the member property.
Definition MemberProperty.h:174
plMemberProperty(const char *szPropertyName, GetterFunc getter, SetterFunc setter, PointerFunc pointer)
Constructor.
Definition MemberProperty.h:160
virtual Type GetValue(const void *pInstance) const override
Returns the value of the property. Pass the instance pointer to the surrounding class along.
Definition MemberProperty.h:177
virtual void SetValue(void *pInstance, Type value) const override
Modifies the value of the property. Pass the instance pointer to the surrounding class along.
Definition MemberProperty.h:182
This class holds information about reflected types. Each instance represents one type that is known t...
Definition RTTI.h:30
virtual void GetValuePtr(const void *pInstance, void *pObject) const override
Writes the value of this property in pInstance to pObject. pObject needs to point to an instance of t...
Definition MemberProperty.h:74
virtual void SetValuePtr(void *pInstance, const void *pObject) const override
Sets the value of pObject to the property in pInstance. pObject needs to point to an instance of this...
Definition MemberProperty.h:75
virtual const plRTTI * GetSpecificType() const override
Returns the type information of the constant property. Use this to cast this property to a specific v...
Definition MemberProperty.h:67
The base class for all typed member properties. I.e. once the type of a property is determined,...
Definition MemberProperty.h:20
virtual Type GetValue(const void *pInstance) const =0
Returns the value of the property. Pass the instance pointer to the surrounding class along.
plTypedMemberProperty(const char *szPropertyName)
Passes the property name through to plAbstractMemberProperty.
Definition MemberProperty.h:23
virtual void SetValuePtr(void *pInstance, const void *pObject) const override
Sets the value of pObject to the property in pInstance. pObject needs to point to an instance of this...
Definition MemberProperty.h:49
virtual void GetValuePtr(const void *pInstance, void *pObject) const override
Writes the value of this property in pInstance to pObject. pObject needs to point to an instance of t...
Definition MemberProperty.h:48
virtual void SetValue(void *pInstance, Type value) const =0
Modifies the value of the property. Pass the instance pointer to the surrounding class along.
virtual const plRTTI * GetSpecificType() const override
Returns the actual type of the property. You can then compare that with known types,...
Definition MemberProperty.h:35
PL_ALWAYS_INLINE void Add(const plBitflags< T > &rhs)
Sets the given flag.
Definition Bitflags.h:151
[internal] Helper class to generate accessor functions for (private) members of another class
Definition MemberProperty.h:141
@ ReadOnly
Can only be read but not modified.
Definition AbstractProperty.h:63
typename std::remove_const< typename std::remove_reference< T >::type >::type NonConstReferenceType
removes reference and const qualifier
Definition TypeTraits.h:218
A helper struct to convert the C++ type, which is passed as the template argument,...
Definition VariantType.h:97
@ Invalid
The variant stores no (valid) data at the moment.
Definition VariantType.h:27