working weak ref

WeakRefPtr now actually acts like a weak reference
backend of weakRefPtr is now a weak_ptr so once the main shared_ptr is freed, they all get freed.
This commit is contained in:
marauder2k7 2026-02-23 17:42:09 +00:00
parent d688f1cfde
commit ca4517c076
4 changed files with 56 additions and 82 deletions

View file

@ -1054,30 +1054,16 @@ public:
typedef WeakRefPtr< T > Parent;
SimObjectPtr() = default;
SimObjectPtr(T *ptr) { set(ptr); }
SimObjectPtr( const SimObjectPtr& ref ) { this->mReference = ref.mReference; }
SimObjectPtr(T* ptr) : Parent(ptr) {}
SimObjectPtr(const SimObjectPtr&) = default;
SimObjectPtr& operator=(const SimObjectPtr&) = default;
SimObjectPtr& operator=(T* ptr)
{
Parent::operator=(ptr);
return *this;
}
T* getObject() const { return Parent::getPointer(); }
~SimObjectPtr() { this->mReference = NULL; }
SimObjectPtr<T>& operator=(const SimObjectPtr ref)
{
this->mReference = ref.mReference;
return *this;
}
SimObjectPtr<T>& operator=(T *ptr)
{
set(ptr);
return *this;
}
protected:
void set(T * obj)
{
this->mReference = obj ? obj->getWeakReference() : NULL;
}
};
#endif // _SIMOBJECT_H_