5#include <Foundation/Reflection/Implementation/AbstractProperty.h>
8template <
typename Type>
15 m_Flags = plPropertyFlags::GetParameterFlags<Type>();
18 virtual const plRTTI*
GetSpecificType()
const override {
return plGetStaticRTTI<typename plTypeTraits<Type>::NonConstReferencePointerType>(); }
29 m_Flags = plPropertyFlags::GetParameterFlags<const char*>();
36template <
typename Class,
typename Type,
typename Container>
43 using InsertFunc = void (Class::*)(Type value);
44 using RemoveFunc = void (Class::*)(Type value);
45 using GetValuesFunc = Container (Class::*)()
const;
47 plAccessorSetProperty(
const char* szPropertyName, GetValuesFunc getValues, InsertFunc insert, RemoveFunc remove)
50 PL_ASSERT_DEBUG(getValues !=
nullptr,
"The get values function of an set property cannot be nullptr.");
52 m_GetValues = getValues;
56 if (m_Insert ==
nullptr || m_Remove ==
nullptr)
61 virtual bool IsEmpty(
const void* pInstance)
const override {
return (
static_cast<const Class*
>(pInstance)->*m_GetValues)().
IsEmpty(); }
63 virtual void Clear(
void* pInstance)
const override
65 PL_ASSERT_DEBUG(m_Insert !=
nullptr && m_Remove !=
nullptr,
"The property '{0}' has no remove and insert function, thus it is read-only",
73 decltype((
static_cast<const Class*
>(pInstance)->*m_GetValues)()) c = (
static_cast<const Class*
>(pInstance)->*m_GetValues)();
80 virtual void Insert(
void* pInstance,
const void* pObject)
const override
83 (
static_cast<Class*
>(pInstance)->*m_Insert)(*
static_cast<const RealType*
>(pObject));
86 virtual void Remove(
void* pInstance,
const void* pObject)
const override
89 (
static_cast<Class*
>(pInstance)->*m_Remove)(*
static_cast<const RealType*
>(pObject));
92 virtual bool Contains(
const void* pInstance,
const void* pObject)
const override
94 for (
const auto& value : (
static_cast<const Class*
>(pInstance)->*m_GetValues)())
96 if (value == *
static_cast<const RealType*
>(pObject))
105 for (
const auto& value : (
static_cast<const Class*
>(pInstance)->*m_GetValues)())
112 GetValuesFunc m_GetValues;
119template <
typename Class,
typename Container, Container Class::*Member>
125 static const ContainerType& GetConstContainer(
const Class* pInstance) {
return (*pInstance).*Member; }
127 static ContainerType& GetContainer(Class* pInstance) {
return (*pInstance).*Member; }
131template <
typename Class,
typename Container,
typename Type>
136 using GetConstContainerFunc =
const Container& (*)(
const Class* pInstance);
137 using GetContainerFunc = Container& (*)(Class* pInstance);
139 plMemberSetProperty(
const char* szPropertyName, GetConstContainerFunc constGetter, GetContainerFunc getter)
142 PL_ASSERT_DEBUG(constGetter !=
nullptr,
"The const get count function of an set property cannot be nullptr.");
144 m_ConstGetter = constGetter;
147 if (m_Getter ==
nullptr)
151 virtual bool IsEmpty(
const void* pInstance)
const override {
return m_ConstGetter(
static_cast<const Class*
>(pInstance)).IsEmpty(); }
153 virtual void Clear(
void* pInstance)
const override
157 m_Getter(
static_cast<Class*
>(pInstance)).Clear();
160 virtual void Insert(
void* pInstance,
const void* pObject)
const override
164 m_Getter(
static_cast<Class*
>(pInstance)).Insert(*
static_cast<const RealType*
>(pObject));
167 virtual void Remove(
void* pInstance,
const void* pObject)
const override
171 m_Getter(
static_cast<Class*
>(pInstance)).Remove(*
static_cast<const RealType*
>(pObject));
174 virtual bool Contains(
const void* pInstance,
const void* pObject)
const override
176 return m_ConstGetter(
static_cast<const Class*
>(pInstance)).Contains(*
static_cast<const RealType*
>(pObject));
182 for (
const auto& value : m_ConstGetter(
static_cast<const Class*
>(pInstance)))
189 GetConstContainerFunc m_ConstGetter;
190 GetContainerFunc m_Getter;
const char * GetPropertyName() const
Returns the name of the property.
Definition AbstractProperty.h:158
The base class for a property that represents a set of values.
Definition AbstractProperty.h:313
plAbstractSetProperty(const char *szPropertyName)
Passes the property name through to plAbstractProperty.
Definition AbstractProperty.h:316
Definition SetProperty.h:38
virtual void Clear(void *pInstance) const override
Clears the set.
Definition SetProperty.h:63
virtual bool Contains(const void *pInstance, const void *pObject) const override
Returns whether the target of pObject is in the set.
Definition SetProperty.h:92
virtual void Remove(void *pInstance, const void *pObject) const override
Removes the target of pObject from the set.
Definition SetProperty.h:86
virtual void GetValues(const void *pInstance, plDynamicArray< plVariant > &out_keys) const override
Writes the content of the set to out_keys.
Definition SetProperty.h:102
virtual bool IsEmpty(const void *pInstance) const override
Returns whether the set is empty.
Definition SetProperty.h:61
virtual void Insert(void *pInstance, const void *pObject) const override
Inserts the target of pObject into the set.
Definition SetProperty.h:80
void PushBack(const T &value)
Pushes value at the end of the array.
Definition ArrayBase_inl.h:333
void Clear()
Clears the array.
Definition ArrayBase_inl.h:184
Definition DynamicArray.h:81
Definition SetProperty.h:133
virtual void Insert(void *pInstance, const void *pObject) const override
Inserts the target of pObject into the set.
Definition SetProperty.h:160
virtual void Clear(void *pInstance) const override
Clears the set.
Definition SetProperty.h:153
virtual bool Contains(const void *pInstance, const void *pObject) const override
Returns whether the target of pObject is in the set.
Definition SetProperty.h:174
virtual void Remove(void *pInstance, const void *pObject) const override
Removes the target of pObject from the set.
Definition SetProperty.h:167
virtual bool IsEmpty(const void *pInstance) const override
Returns whether the set is empty.
Definition SetProperty.h:151
virtual void GetValues(const void *pInstance, plDynamicArray< plVariant > &out_keys) const override
Writes the content of the set to out_keys.
Definition SetProperty.h:179
This class holds information about reflected types. Each instance represents one type that is known t...
Definition RTTI.h:30
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 SetProperty.h:32
Do not cast into this class or any of its derived classes, use plAbstractSetProperty instead.
Definition SetProperty.h:10
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 SetProperty.h:18
plVariant is a class that can store different types of variables, which is useful in situations where...
Definition Variant.h:44
PL_ALWAYS_INLINE void Add(const plBitflags< T > &rhs)
Sets the given flag.
Definition Bitflags.h:151
@ ReadOnly
Can only be read but not modified.
Definition AbstractProperty.h:63
Definition SetProperty.h:121
Definition TypeTraits.h:207
typename std::remove_const< typename std::remove_reference< T >::type >::type NonConstReferenceType
removes reference and const qualifier
Definition TypeTraits.h:218