5#include <Foundation/Reflection/Implementation/AbstractProperty.h>
10template <
typename Type>
17 m_Flags = plPropertyFlags::GetParameterFlags<Type>();
18 static_assert(!std::is_pointer<Type>::value ||
21 "Pointer to standard types are not supported.");
24 virtual const plRTTI*
GetSpecificType()
const override {
return plGetStaticRTTI<typename plTypeTraits<Type>::NonConstReferencePointerType>(); }
35 m_Flags = plPropertyFlags::GetParameterFlags<const char*>();
42template <
typename Class,
typename Type>
47 using GetCountFunc = plUInt32 (Class::*)()
const;
48 using GetValueFunc = Type (Class::*)(plUInt32 uiIndex)
const;
49 using SetValueFunc = void (Class::*)(plUInt32 uiIndex, Type value);
50 using InsertFunc = void (Class::*)(plUInt32 uiIndex, Type value);
51 using RemoveFunc = void (Class::*)(plUInt32 uiIndex);
55 const char* szPropertyName, GetCountFunc getCount, GetValueFunc getter, SetValueFunc setter, InsertFunc insert, RemoveFunc remove)
58 PL_ASSERT_DEBUG(getCount !=
nullptr,
"The get count function of an array property cannot be nullptr.");
59 PL_ASSERT_DEBUG(getter !=
nullptr,
"The get value function of an array property cannot be nullptr.");
61 m_GetCount = getCount;
67 if (m_Setter ==
nullptr)
72 virtual plUInt32
GetCount(
const void* pInstance)
const override {
return (
static_cast<const Class*
>(pInstance)->*m_GetCount)(); }
74 virtual void GetValue(
const void* pInstance, plUInt32 uiIndex,
void* pObject)
const override
76 PL_ASSERT_DEBUG(uiIndex <
GetCount(pInstance),
"GetValue: uiIndex ('{0}') is out of range ('{1}')", uiIndex,
GetCount(pInstance));
77 *
static_cast<RealType*
>(pObject) = (
static_cast<const Class*
>(pInstance)->*m_Getter)(uiIndex);
80 virtual void SetValue(
void* pInstance, plUInt32 uiIndex,
const void* pObject)
const override
82 PL_ASSERT_DEBUG(uiIndex <
GetCount(pInstance),
"SetValue: uiIndex ('{0}') is out of range ('{1}')", uiIndex,
GetCount(pInstance));
84 (
static_cast<Class*
>(pInstance)->*m_Setter)(uiIndex, *
static_cast<const RealType*
>(pObject));
87 virtual void Insert(
void* pInstance, plUInt32 uiIndex,
const void* pObject)
const override
89 PL_ASSERT_DEBUG(uiIndex <=
GetCount(pInstance),
"Insert: uiIndex ('{0}') is out of range ('{1}')", uiIndex,
GetCount(pInstance));
91 (
static_cast<Class*
>(pInstance)->*m_Insert)(uiIndex, *
static_cast<const RealType*
>(pObject));
94 virtual void Remove(
void* pInstance, plUInt32 uiIndex)
const override
96 PL_ASSERT_DEBUG(uiIndex <
GetCount(pInstance),
"Remove: uiIndex ('{0}') is out of range ('{1}')", uiIndex,
GetCount(pInstance));
98 (
static_cast<Class*
>(pInstance)->*m_Remove)(uiIndex);
101 virtual void Clear(
void* pInstance)
const override {
SetCount(pInstance, 0); }
103 virtual void SetCount(
void* pInstance, plUInt32 uiCount)
const override
105 PL_ASSERT_DEBUG(m_Insert !=
nullptr && m_Remove !=
nullptr,
"The property '{0}' has no remove and insert function, thus it is fixed-size.",
107 while (uiCount <
GetCount(pInstance))
111 while (uiCount >
GetCount(pInstance))
113 RealType elem = RealType();
119 GetCountFunc m_GetCount;
120 GetValueFunc m_Getter;
121 SetValueFunc m_Setter;
128template <
typename Class,
typename Container, Container Class::*Member>
134 static const ContainerType& GetConstContainer(
const Class* pInstance) {
return (*pInstance).*Member; }
136 static ContainerType& GetContainer(Class* pInstance) {
return (*pInstance).*Member; }
140template <
typename Class,
typename Container,
typename Type>
145 using GetConstContainerFunc =
const Container& (*)(
const Class* pInstance);
146 using GetContainerFunc = Container& (*)(Class* pInstance);
148 plMemberArrayProperty(
const char* szPropertyName, GetConstContainerFunc constGetter, GetContainerFunc getter)
151 PL_ASSERT_DEBUG(constGetter !=
nullptr,
"The const get count function of an array property cannot be nullptr.");
153 m_ConstGetter = constGetter;
156 if (m_Getter ==
nullptr)
160 virtual plUInt32
GetCount(
const void* pInstance)
const override {
return m_ConstGetter(
static_cast<const Class*
>(pInstance)).GetCount(); }
162 virtual void GetValue(
const void* pInstance, plUInt32 uiIndex,
void* pObject)
const override
164 PL_ASSERT_DEBUG(uiIndex <
GetCount(pInstance),
"GetValue: uiIndex ('{0}') is out of range ('{1}')", uiIndex,
GetCount(pInstance));
165 *
static_cast<RealType*
>(pObject) = m_ConstGetter(
static_cast<const Class*
>(pInstance))[uiIndex];
168 virtual void SetValue(
void* pInstance, plUInt32 uiIndex,
const void* pObject)
const override
170 PL_ASSERT_DEBUG(uiIndex <
GetCount(pInstance),
"SetValue: uiIndex ('{0}') is out of range ('{1}')", uiIndex,
GetCount(pInstance));
171 PL_ASSERT_DEBUG(m_Getter !=
nullptr,
"The property '{0}' has no non-const array accessor function, thus it is read-only.",
173 m_Getter(
static_cast<Class*
>(pInstance))[uiIndex] = *
static_cast<const RealType*
>(pObject);
176 virtual void Insert(
void* pInstance, plUInt32 uiIndex,
const void* pObject)
const override
178 PL_ASSERT_DEBUG(uiIndex <=
GetCount(pInstance),
"Insert: uiIndex ('{0}') is out of range ('{1}')", uiIndex,
GetCount(pInstance));
179 PL_ASSERT_DEBUG(m_Getter !=
nullptr,
"The property '{0}' has no non-const array accessor function, thus it is read-only.",
181 m_Getter(
static_cast<Class*
>(pInstance)).InsertAt(uiIndex, *
static_cast<const RealType*
>(pObject));
184 virtual void Remove(
void* pInstance, plUInt32 uiIndex)
const override
186 PL_ASSERT_DEBUG(uiIndex <
GetCount(pInstance),
"Remove: uiIndex ('{0}') is out of range ('{1}')", uiIndex,
GetCount(pInstance));
187 PL_ASSERT_DEBUG(m_Getter !=
nullptr,
"The property '{0}' has no non-const array accessor function, thus it is read-only.",
189 m_Getter(
static_cast<Class*
>(pInstance)).RemoveAtAndCopy(uiIndex);
192 virtual void Clear(
void* pInstance)
const override
194 PL_ASSERT_DEBUG(m_Getter !=
nullptr,
"The property '{0}' has no non-const array accessor function, thus it is read-only.",
196 m_Getter(
static_cast<Class*
>(pInstance)).Clear();
199 virtual void SetCount(
void* pInstance, plUInt32 uiCount)
const override
201 PL_ASSERT_DEBUG(m_Getter !=
nullptr,
"The property '{0}' has no non-const array accessor function, thus it is read-only.",
203 m_Getter(
static_cast<Class*
>(pInstance)).SetCount(uiCount);
206 virtual void* GetValuePointer(
void* pInstance, plUInt32 uiIndex)
const override
208 PL_ASSERT_DEBUG(uiIndex <
GetCount(pInstance),
"GetValue: uiIndex ('{0}') is out of range ('{1}')", uiIndex,
GetCount(pInstance));
209 return &(m_Getter(
static_cast<Class*
>(pInstance))[uiIndex]);
213 GetConstContainerFunc m_ConstGetter;
214 GetContainerFunc m_Getter;
218template <
typename Class,
typename Container,
typename Type>
223 using GetConstContainerFunc =
const Container& (*)(
const Class* pInstance);
228 PL_ASSERT_DEBUG(constGetter !=
nullptr,
"The const get count function of an array property cannot be nullptr.");
230 m_ConstGetter = constGetter;
234 virtual plUInt32
GetCount(
const void* pInstance)
const override {
return m_ConstGetter(
static_cast<const Class*
>(pInstance)).GetCount(); }
236 virtual void GetValue(
const void* pInstance, plUInt32 uiIndex,
void* pObject)
const override
238 PL_ASSERT_DEBUG(uiIndex <
GetCount(pInstance),
"GetValue: uiIndex ('{0}') is out of range ('{1}')", uiIndex,
GetCount(pInstance));
239 *
static_cast<RealType*
>(pObject) = m_ConstGetter(
static_cast<const Class*
>(pInstance))[uiIndex];
242 virtual void SetValue(
void* pInstance, plUInt32 uiIndex,
const void* pObject)
const override
247 virtual void Insert(
void* pInstance, plUInt32 uiIndex,
const void* pObject)
const override
252 virtual void Remove(
void* pInstance, plUInt32 uiIndex)
const override
257 virtual void Clear(
void* pInstance)
const override
262 virtual void SetCount(
void* pInstance, plUInt32 uiCount)
const override
268 GetConstContainerFunc m_ConstGetter;
The base class for a property that represents an array of values.
Definition AbstractProperty.h:273
plAbstractArrayProperty(const char *szPropertyName)
Passes the property name through to plAbstractProperty.
Definition AbstractProperty.h:276
const char * GetPropertyName() const
Returns the name of the property.
Definition AbstractProperty.h:158
Definition ArrayProperty.h:44
virtual void Insert(void *pInstance, plUInt32 uiIndex, const void *pObject) const override
Inserts the target of pObject into the array at index uiIndex.
Definition ArrayProperty.h:87
virtual void Clear(void *pInstance) const override
Clears the array.
Definition ArrayProperty.h:101
virtual void SetCount(void *pInstance, plUInt32 uiCount) const override
Resizes the array to uiCount.
Definition ArrayProperty.h:103
virtual plUInt32 GetCount(const void *pInstance) const override
Returns number of elements.
Definition ArrayProperty.h:72
virtual void Remove(void *pInstance, plUInt32 uiIndex) const override
Removes the element in the array at index uiIndex.
Definition ArrayProperty.h:94
virtual void SetValue(void *pInstance, plUInt32 uiIndex, const void *pObject) const override
Writes the target of pObject to the element at index uiIndex.
Definition ArrayProperty.h:80
virtual void GetValue(const void *pInstance, plUInt32 uiIndex, void *pObject) const override
Writes element at index uiIndex to the target of pObject.
Definition ArrayProperty.h:74
Definition ArrayProperty.h:142
virtual void SetCount(void *pInstance, plUInt32 uiCount) const override
Resizes the array to uiCount.
Definition ArrayProperty.h:199
virtual void SetValue(void *pInstance, plUInt32 uiIndex, const void *pObject) const override
Writes the target of pObject to the element at index uiIndex.
Definition ArrayProperty.h:168
virtual void GetValue(const void *pInstance, plUInt32 uiIndex, void *pObject) const override
Writes element at index uiIndex to the target of pObject.
Definition ArrayProperty.h:162
virtual void Remove(void *pInstance, plUInt32 uiIndex) const override
Removes the element in the array at index uiIndex.
Definition ArrayProperty.h:184
virtual void Clear(void *pInstance) const override
Clears the array.
Definition ArrayProperty.h:192
virtual plUInt32 GetCount(const void *pInstance) const override
Returns number of elements.
Definition ArrayProperty.h:160
virtual void Insert(void *pInstance, plUInt32 uiIndex, const void *pObject) const override
Inserts the target of pObject into the array at index uiIndex.
Definition ArrayProperty.h:176
Read only version of plMemberArrayProperty that does not call any functions that modify the array....
Definition ArrayProperty.h:220
virtual void SetCount(void *pInstance, plUInt32 uiCount) const override
Resizes the array to uiCount.
Definition ArrayProperty.h:262
virtual void Insert(void *pInstance, plUInt32 uiIndex, const void *pObject) const override
Inserts the target of pObject into the array at index uiIndex.
Definition ArrayProperty.h:247
virtual void Clear(void *pInstance) const override
Clears the array.
Definition ArrayProperty.h:257
virtual void Remove(void *pInstance, plUInt32 uiIndex) const override
Removes the element in the array at index uiIndex.
Definition ArrayProperty.h:252
virtual void SetValue(void *pInstance, plUInt32 uiIndex, const void *pObject) const override
Writes the target of pObject to the element at index uiIndex.
Definition ArrayProperty.h:242
virtual plUInt32 GetCount(const void *pInstance) const override
Returns number of elements.
Definition ArrayProperty.h:234
virtual void GetValue(const void *pInstance, plUInt32 uiIndex, void *pObject) const override
Writes element at index uiIndex to the target of pObject.
Definition ArrayProperty.h:236
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 ArrayProperty.h:38
Do not cast into this class or any of its derived classes, use plTypedArrayProperty instead.
Definition ArrayProperty.h:12
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 ArrayProperty.h:24
Definition ArrayProperty.h:130
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 TypeTraits.h:207
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