A Path represents a path to a specific property/value through a RTTI hierarchy. It's useful to be able to store a 'reference' to a property in a data structure, without actually having to have a reference. By itself, Path just stores a path and can't be used for any operations. In order to do that, the RTITPath must be 'resolved' against a root object. The resolve of a Path results in a ResolvedPath, which can then be used to get/set the value of the property represented by the Path.
As a simple example, consider the following RTTI types (assume they're registered in RTTI):
struct DataStruct
{
float mFloatProperty = 0.0f;
rtti::RTTIObject* mPointerProperty = nullptr;
};
class SomeRTTIClass : public rtti::RTTIObject
{
RTTI_ENABLE(rtti::RTTIObject)
public:
DataStruct mNestedCompound;
std::vector<int> mArrayOfInts;
std::vector<DataStruct> mArrayOfCompounds;
std::vector<rtti::RTTIObject*> mArrayOfPointers;
};
Suppose we want to store a reference to the 'PointerProperty' of the 'DataStruct' embedded in the first element of the 'ArrayOfCompounds' property in 'SomeRTTIClass'. We could do this as follows:
Path path;
path.PushAttribute("ArrayOfCompounds"); // Push name of the RTTI property on SomeRTTIClass
path.PushArrayElement(0); // Push index into the array 'ArrayOfCompounds' on SomeRTTIClass
path.PushAttribute("PointerProperty"); // Push name of the RTTI property on the compound contained in ArrayOfCompounds, namely 'DataStruct'
So we now have a 'path' to the pointer property, which we can store wherever we want.
At some later point in time, let's suppose we now want to get or set the value that this Path points to. In order to do this, we first need to resolve the path:
SomeRTTIClass* object = ... // Assume we have a pointer to an instance of SomeRTTIClass that we can resolve against
ResolvedPath resolved_path = path.resolve(object);
if (!resolved_path.isValid())
return; // Failed to resolve the path; either it's incorrect or does not match with the provided instance of SomeRTTIClass
Once the path has been successfully resolved, we can use it to get/set the value of the property:
// Retrieve the value of the pointer
rtti::RTTIObject* pointer_value = resolved_path.getValue().get_value<rtti::RTTIObject*>();
// Set the value of the pointer
rtti::RTTIObject* some_other_object = ... // Get the pointer we want to set
resolved_path.setValue(some_other_object);
After the setValue, object->mArrayOfCompounds[0].mPointerProperty now points to 'some_other_object'