Cinema 4D S24 API brings WeakRawPtr defined in weakrawptr.h.
maxon::StrongRef and maxon::WeakRef are useful tools when a Maxon data types comes into play.
A maxon::StrongRef is a smart pointer that is used to implement shared ownership over an object. The pointed object is kept alive until the last maxon::StrongRef is set to nullptr.
A maxon::WeakRef is a smart pointer which does not have ownership the referenced object. Once the referenced object is set to a nullptr, the the maxon::WeakRef will return nullptr.
These tools are designed to work together. A maxon::WeakRef can reference only objects owned by a maxon::StrongRef.
But what about unmanaged memory, like raw pointers?
We can use WeakRef concept for any kind of memory, which has been allocated using NewMem() or NewObj(), by using the maxon::WeakRawPtr template.
Since every memory allocation done in that way is reference counted.
To use maxon::WeakRawPtr, include the weakrawptr.h file and assign the pointer of the newly object to a maxon::WeakRawPtr:
This can be applied to safely handle pointers to legacy Cinema 4D objects, like BaseObject or BaseDocument.
maxon::WeakRawPtr can be used similarly to a BaseLink, without the huge dependency on BaseDocument that BaseLink has.
This is helpful when a legacy object pointer or a raw memory needs to be passed to a lambda, Delegate or an observable capture.
Since the pointed object's validity can be checked regardless of the time.