EntropyEngine::Core::WeakRef
EntropyEngine::Core::WeakRef
Section titled “EntropyEngine::Core::WeakRef”Non-owning weak reference to an EntropyObject with generation validation. More…
#include <RefObject.h>
Public Functions
Section titled “Public Functions”| Name | |
|---|---|
| ~WeakRef() | |
| void | reset() |
| WeakRef & | operator=(const WeakRef & other) |
| WeakRef & | operator=(WeakRef && other) |
| WeakRef & | operator=(const RefObject< T > & ref) Assign from RefObject. |
| template <class U ,class =std::enable_if_t<std::is_base_of_v<T, U>>> WeakRef & | operator=(const RefObject< U > & ref) Assign from derived RefObject. |
| RefObject< T > | lock() const Attempt to acquire a strong reference. |
| bool | expired() const |
| WeakRef() =default | |
| WeakRef(T * ptr) Construct from raw pointer (acquires weak block). | |
| WeakRef(const RefObject< T > & ref) Construct from RefObject. | |
| template <class U ,class =std::enable_if_t<std::is_base_of_v<T, U>>> | WeakRef(const RefObject< U > & ref) Construct from derived RefObject. |
| WeakRef(const WeakRef & other) | |
| WeakRef(WeakRef && other) |
Friends
Section titled “Friends”| Name | |
|---|---|
| bool | operator==(const WeakRef & a, const WeakRef & b) |
| bool | operator!=(const WeakRef & a, const WeakRef & b) |
Detailed Description
Section titled “Detailed Description”template <typename T >class EntropyEngine::Core::WeakRef;Non-owning weak reference to an EntropyObject with generation validation.
Note: For full protection, the referenced object should be handle-stamped by a service/pool using HandleSlotOps::stamp(). Non-stamped objects (generation 0) fall back to refcount-only validation.
WeakRef stores a pointer and the object’s handle generation at construction time. Use lock() to safely acquire a strong RefObject reference - returns empty if the object has been destroyed or if the slot has been reused for a different object.
Generation validation prevents the memory-reuse problem: if the original object is destroyed and a new object is allocated at the same address, lock() will detect the generation mismatch and return empty instead of the wrong object.
RefObject<Mesh> mesh = meshService->createMesh(); // Stamped with generationWeakRef<Mesh> weak = mesh;
// Later, safely try to use:if (auto locked = weak.lock()) { locked->render(); // Safe - validated by generation + refcount} // else: mesh was destroyed or slot reusedWeak reference to an EntropyObject, safely guarded by a control block
Public Functions Documentation
Section titled “Public Functions Documentation”function ~WeakRef
Section titled “function ~WeakRef”inline ~WeakRef()function reset
Section titled “function reset”inline void reset()function operator=
Section titled “function operator=”inline WeakRef & operator=( const WeakRef & other)function operator=
Section titled “function operator=”inline WeakRef & operator=( WeakRef && other)function operator=
Section titled “function operator=”inline WeakRef & operator=( const RefObject< T > & ref)Assign from RefObject.
function operator=
Section titled “function operator=”template <class U ,class =std::enable_if_t<std::is_base_of_v<T, U>>>inline WeakRef & operator=( const RefObject< U > & ref)Assign from derived RefObject.
function lock
Section titled “function lock”inline RefObject< T > lock() constAttempt to acquire a strong reference.
Return: RefObject
Safely checks if the object is still alive using the control block.
function expired
Section titled “function expired”inline bool expired() constfunction WeakRef
Section titled “function WeakRef”WeakRef() =defaultfunction WeakRef
Section titled “function WeakRef”inline explicit WeakRef( T * ptr)Construct from raw pointer (acquires weak block).
function WeakRef
Section titled “function WeakRef”inline WeakRef( const RefObject< T > & ref)Construct from RefObject.
function WeakRef
Section titled “function WeakRef”template <class U ,class =std::enable_if_t<std::is_base_of_v<T, U>>>inline WeakRef( const RefObject< U > & ref)Construct from derived RefObject.
function WeakRef
Section titled “function WeakRef”inline WeakRef( const WeakRef & other)function WeakRef
Section titled “function WeakRef”inline WeakRef( WeakRef && other)Friends
Section titled “Friends”friend operator==
Section titled “friend operator==”friend bool operator==( const WeakRef & a,
const WeakRef & b);friend operator!=
Section titled “friend operator!=”friend bool operator!=( const WeakRef & a,
const WeakRef & b);Updated on 2026-01-26 at 17:14:35 -0500