5#include <Foundation/Reflection/Implementation/AbstractProperty.h>
9template <
typename Type>
16 m_Flags = plPropertyFlags::GetParameterFlags<Type>();
18 !std::is_pointer<Type>::value ||
20 "Pointer to standard types are not supported.");
23 virtual const plRTTI*
GetSpecificType()
const override {
return plGetStaticRTTI<typename plTypeTraits<Type>::NonConstReferencePointerType>(); }
27template <
typename Class,
typename Type,
typename Container>
34 using InsertFunc = void (Class::*)(
const char* szKey, Type value);
35 using RemoveFunc = void (Class::*)(
const char* szKey);
36 using GetValueFunc = bool (Class::*)(
const char* szKey, RealType& value)
const;
37 using GetKeyRangeFunc = Container (Class::*)()
const;
39 plAccessorMapProperty(
const char* szPropertyName, GetKeyRangeFunc getKeys, GetValueFunc getValue, InsertFunc insert, RemoveFunc remove)
42 PL_ASSERT_DEBUG(getKeys !=
nullptr,
"The getKeys function of a map property cannot be nullptr.");
43 PL_ASSERT_DEBUG(getValue !=
nullptr,
"The GetValueFunc function of a map property cannot be nullptr.");
45 m_GetKeyRange = getKeys;
46 m_GetValue = getValue;
50 if (m_Insert ==
nullptr || remove ==
nullptr)
54 virtual bool IsEmpty(
const void* pInstance)
const override
57 decltype((
static_cast<const Class*
>(pInstance)->*m_GetKeyRange)()) c = (
static_cast<const Class*
>(pInstance)->*m_GetKeyRange)();
59 return begin(c) == end(c);
62 virtual void Clear(
void* pInstance)
const override
67 decltype((
static_cast<const Class*
>(pInstance)->*m_GetKeyRange)()) c = (
static_cast<const Class*
>(pInstance)->*m_GetKeyRange)();
77 virtual void Insert(
void* pInstance,
const char* szKey,
const void* pObject)
const override
80 (
static_cast<Class*
>(pInstance)->*m_Insert)(szKey, *
static_cast<const RealType*
>(pObject));
83 virtual void Remove(
void* pInstance,
const char* szKey)
const override
86 (
static_cast<Class*
>(pInstance)->*m_Remove)(szKey);
89 virtual bool Contains(
const void* pInstance,
const char* szKey)
const override
92 return (
static_cast<const Class*
>(pInstance)->*m_GetValue)(szKey, value);
95 virtual bool GetValue(
const void* pInstance,
const char* szKey,
void* pObject)
const override
97 return (
static_cast<const Class*
>(pInstance)->*m_GetValue)(szKey, *
static_cast<RealType*
>(pObject));
103 decltype(
auto) c = (
static_cast<const Class*
>(pInstance)->*m_GetKeyRange)();
104 for (
const auto& key : c)
111 GetKeyRangeFunc m_GetKeyRange;
112 GetValueFunc m_GetValue;
118template <
typename Class,
typename Type,
typename Container>
126 using InsertFunc = void (Class::*)(
const char* szKey, Type value);
127 using RemoveFunc = void (Class::*)(
const char* szKey);
128 using GetContainerFunc = Container (Class::*)()
const;
133 PL_ASSERT_DEBUG(getContainer !=
nullptr,
"The get count function of a map property cannot be nullptr.");
135 m_GetContainer = getContainer;
139 if (m_Insert ==
nullptr)
143 virtual bool IsEmpty(
const void* pInstance)
const override {
return (
static_cast<const Class*
>(pInstance)->*m_GetContainer)().
IsEmpty(); }
145 virtual void Clear(
void* pInstance)
const override
147 decltype(
auto) c = (
static_cast<const Class*
>(pInstance)->*m_GetContainer)();
150 auto it = c.GetIterator();
151 Remove(pInstance, it.Key());
155 virtual void Insert(
void* pInstance,
const char* szKey,
const void* pObject)
const override
158 (
static_cast<Class*
>(pInstance)->*m_Insert)(szKey, *
static_cast<const RealType*
>(pObject));
161 virtual void Remove(
void* pInstance,
const char* szKey)
const override
164 (
static_cast<Class*
>(pInstance)->*m_Remove)(szKey);
167 virtual bool Contains(
const void* pInstance,
const char* szKey)
const override
169 return (
static_cast<const Class*
>(pInstance)->*m_GetContainer)().
Contains(szKey);
172 virtual bool GetValue(
const void* pInstance,
const char* szKey,
void* pObject)
const override
174 decltype(
auto) c = (
static_cast<const Class*
>(pInstance)->*m_GetContainer)();
175 const RealType* value = c.GetValue(szKey);
178 *
static_cast<RealType*
>(pObject) = *value;
180 return value !=
nullptr;
185 decltype(
auto) c = (
static_cast<const Class*
>(pInstance)->*m_GetContainer)();
187 for (
auto it = c.GetIterator(); it.IsValid(); ++it)
194 GetContainerFunc m_GetContainer;
201template <
typename Class,
typename Container, Container Class::*Member>
207 static const ContainerType& GetConstContainer(
const Class* pInstance) {
return (*pInstance).*Member; }
209 static ContainerType& GetContainer(Class* pInstance) {
return (*pInstance).*Member; }
213template <
typename Class,
typename Container,
typename Type>
218 using GetConstContainerFunc =
const Container& (*)(
const Class* pInstance);
219 using GetContainerFunc = Container& (*)(Class* pInstance);
221 plMemberMapProperty(
const char* szPropertyName, GetConstContainerFunc constGetter, GetContainerFunc getter)
224 PL_ASSERT_DEBUG(constGetter !=
nullptr,
"The const get count function of an array property cannot be nullptr.");
226 m_ConstGetter = constGetter;
229 if (m_Getter ==
nullptr)
233 virtual bool IsEmpty(
const void* pInstance)
const override {
return m_ConstGetter(
static_cast<const Class*
>(pInstance)).IsEmpty(); }
235 virtual void Clear(
void* pInstance)
const override
239 m_Getter(
static_cast<Class*
>(pInstance)).Clear();
242 virtual void Insert(
void* pInstance,
const char* szKey,
const void* pObject)
const override
246 m_Getter(
static_cast<Class*
>(pInstance)).Insert(szKey, *
static_cast<const RealType*
>(pObject));
249 virtual void Remove(
void* pInstance,
const char* szKey)
const override
253 m_Getter(
static_cast<Class*
>(pInstance)).Remove(szKey);
256 virtual bool Contains(
const void* pInstance,
const char* szKey)
const override
258 return m_ConstGetter(
static_cast<const Class*
>(pInstance)).Contains(szKey);
261 virtual bool GetValue(
const void* pInstance,
const char* szKey,
void* pObject)
const override
263 const RealType* value = m_ConstGetter(
static_cast<const Class*
>(pInstance)).GetValue(szKey);
266 *
static_cast<RealType*
>(pObject) = *value;
268 return value !=
nullptr;
273 decltype(
auto) c = m_ConstGetter(
static_cast<const Class*
>(pInstance));
275 for (
auto it = c.GetIterator(); it.IsValid(); ++it)
282 GetConstContainerFunc m_ConstGetter;
283 GetContainerFunc m_Getter;
The base class for a property that represents a set of values.
Definition AbstractProperty.h:348
plAbstractMapProperty(const char *szPropertyName)
Passes the property name through to plAbstractProperty.
Definition AbstractProperty.h:351
const char * GetPropertyName() const
Returns the name of the property.
Definition AbstractProperty.h:158
Definition MapProperty.h:29
virtual bool GetValue(const void *pInstance, const char *szKey, void *pObject) const override
Writes element at index uiIndex to the target of pObject.
Definition MapProperty.h:95
virtual void Clear(void *pInstance) const override
Clears the set.
Definition MapProperty.h:62
virtual bool Contains(const void *pInstance, const char *szKey) const override
Returns whether the target of pObject is in the set.
Definition MapProperty.h:89
virtual void Insert(void *pInstance, const char *szKey, const void *pObject) const override
Inserts the target of pObject into the set.
Definition MapProperty.h:77
virtual void GetKeys(const void *pInstance, plHybridArray< plString, 16 > &out_keys) const override
Writes the content of the set to out_keys.
Definition MapProperty.h:100
virtual void Remove(void *pInstance, const char *szKey) const override
Removes the target of pObject from the set.
Definition MapProperty.h:83
virtual bool IsEmpty(const void *pInstance) const override
Returns whether the set is empty.
Definition MapProperty.h:54
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
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Definition MapProperty.h:215
virtual bool GetValue(const void *pInstance, const char *szKey, void *pObject) const override
Writes element at index uiIndex to the target of pObject.
Definition MapProperty.h:261
virtual bool Contains(const void *pInstance, const char *szKey) const override
Returns whether the target of pObject is in the set.
Definition MapProperty.h:256
virtual void Insert(void *pInstance, const char *szKey, const void *pObject) const override
Inserts the target of pObject into the set.
Definition MapProperty.h:242
virtual bool IsEmpty(const void *pInstance) const override
Returns whether the set is empty.
Definition MapProperty.h:233
virtual void GetKeys(const void *pInstance, plHybridArray< plString, 16 > &out_keys) const override
Writes the content of the set to out_keys.
Definition MapProperty.h:271
virtual void Remove(void *pInstance, const char *szKey) const override
Removes the target of pObject from the set.
Definition MapProperty.h:249
virtual void Clear(void *pInstance) const override
Clears the set.
Definition MapProperty.h:235
This class holds information about reflected types. Each instance represents one type that is known t...
Definition RTTI.h:30
Definition MapProperty.h:11
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 MapProperty.h:23
Definition MapProperty.h:120
virtual bool IsEmpty(const void *pInstance) const override
Returns whether the set is empty.
Definition MapProperty.h:143
virtual void GetKeys(const void *pInstance, plHybridArray< plString, 16 > &out_keys) const override
Writes the content of the set to out_keys.
Definition MapProperty.h:183
virtual bool Contains(const void *pInstance, const char *szKey) const override
Returns whether the target of pObject is in the set.
Definition MapProperty.h:167
virtual void Remove(void *pInstance, const char *szKey) const override
Removes the target of pObject from the set.
Definition MapProperty.h:161
virtual void Insert(void *pInstance, const char *szKey, const void *pObject) const override
Inserts the target of pObject into the set.
Definition MapProperty.h:155
virtual bool GetValue(const void *pInstance, const char *szKey, void *pObject) const override
Writes element at index uiIndex to the target of pObject.
Definition MapProperty.h:172
virtual void Clear(void *pInstance) const override
Clears the set.
Definition MapProperty.h:145
PL_ALWAYS_INLINE void Add(const plBitflags< T > &rhs)
Sets the given flag.
Definition Bitflags.h:151
Template that allows to probe a container for its element type.
Definition AbstractProperty.h:455
Definition MapProperty.h:203
@ 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