Plasma Engine  2.0
Loading...
Searching...
No Matches
PropertyPath.h
1#pragma once
2
3#include <Foundation/Reflection/Reflection.h>
4#include <Foundation/Types/Delegate.h>
5#include <Foundation/Types/Variant.h>
6
8
9
11struct PL_FOUNDATION_DLL plPropertyPathStep
12{
13 plString m_sProperty;
14 plVariant m_Index;
15};
16PL_DECLARE_REFLECTABLE_TYPE(PL_FOUNDATION_DLL, plPropertyPathStep);
17
24class PL_FOUNDATION_DLL plPropertyPath
25{
26public:
29
31 bool IsValid() const;
32
35 plResult InitializeFromPath(const plRTTI& rootObjectRtti, const char* szPath);
37 plResult InitializeFromPath(const plRTTI* pRootObjectRtti, const plArrayPtr<const plPropertyPathStep> path);
38
40 plResult WriteToLeafObject(void* pRootObject, const plRTTI& type, plDelegate<void(void* pLeaf, const plRTTI& pType)> func) const;
42 plResult ReadFromLeafObject(void* pRootObject, const plRTTI& type, plDelegate<void(void* pLeaf, const plRTTI& pType)> func) const;
43
45 plResult WriteProperty(
46 void* pRootObject, const plRTTI& type, plDelegate<void(void* pLeafObject, const plRTTI& pLeafType, const plAbstractProperty* pProp, const plVariant& index)> func) const;
48 plResult ReadProperty(
49 void* pRootObject, const plRTTI& type, plDelegate<void(void* pLeafObject, const plRTTI& pLeafType, const plAbstractProperty* pProp, const plVariant& index)> func) const;
50
52 void SetValue(void* pRootObject, const plRTTI& type, const plVariant& value) const;
54 template <typename T>
55 PL_ALWAYS_INLINE void SetValue(T* pRootObject, const plVariant& value) const
56 {
57 SetValue(pRootObject, *plGetStaticRTTI<T>(), value);
58 }
59
61 void GetValue(void* pRootObject, const plRTTI& type, plVariant& out_value) const;
63 template <typename T>
64 PL_ALWAYS_INLINE void GetValue(T* pRootObject, plVariant& out_value) const
65 {
66 GetValue(pRootObject, *plGetStaticRTTI<T>(), out_value);
67 }
68
69private:
70 struct ResolvedStep
71 {
72 const plAbstractProperty* m_pProperty = nullptr;
73 plVariant m_Index;
74 };
75
76 static plResult ResolvePath(void* pCurrentObject, const plRTTI* pType, const plArrayPtr<const ResolvedStep> path, bool bWriteToObject,
77 const plDelegate<void(void* pLeaf, const plRTTI& pType)>& func);
78
79 bool m_bIsValid = false;
81};
This is the base interface for all properties in the reflection system. It provides enough informatio...
Definition AbstractProperty.h:150
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Stores a path from an object of a given type to a property inside of it. Once initialized to a specif...
Definition PropertyPath.h:25
PL_ALWAYS_INLINE void SetValue(T *pRootObject, const plVariant &value) const
Convenience function that writes 'value' to the 'pRootObject' at the current path.
Definition PropertyPath.h:55
PL_ALWAYS_INLINE void GetValue(T *pRootObject, plVariant &out_value) const
Convenience function that reads the value from 'pRootObject' at the current path and stores it in 'ou...
Definition PropertyPath.h:64
This class holds information about reflected types. Each instance represents one type that is known t...
Definition RTTI.h:30
plVariant is a class that can store different types of variables, which is useful in situations where...
Definition Variant.h:44
A generic delegate class which supports static functions and member functions.
Definition Delegate.h:76
Reflected property step that can be used to init an plPropertyPath.
Definition PropertyPath.h:12
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54