Skip to content

EntropyEngine::Core::WeakRef

Non-owning weak reference to an EntropyObject with generation validation. More…

#include <RefObject.h>

Name
~WeakRef()
voidreset()
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.
boolexpired() 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)
Name
booloperator==(const WeakRef & a, const WeakRef & b)
booloperator!=(const WeakRef & a, const WeakRef & b)
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 generation
WeakRef<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 reused

Weak reference to an EntropyObject, safely guarded by a control block

inline ~WeakRef()
inline void reset()
inline WeakRef & operator=(
const WeakRef & other
)
inline WeakRef & operator=(
WeakRef && other
)
inline WeakRef & operator=(
const RefObject< T > & ref
)

Assign from RefObject.

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.

inline RefObject< T > lock() const

Attempt to acquire a strong reference.

Return: RefObject if successful, empty RefObject if expired

Safely checks if the object is still alive using the control block.

inline bool expired() const
WeakRef() =default
inline explicit WeakRef(
T * ptr
)

Construct from raw pointer (acquires weak block).

inline WeakRef(
const RefObject< T > & ref
)

Construct from RefObject.

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.

inline WeakRef(
const WeakRef & other
)
inline WeakRef(
WeakRef && other
)
friend bool operator==(
const WeakRef & a,
const WeakRef & b
);
friend bool operator!=(
const WeakRef & a,
const WeakRef & b
);

Updated on 2026-01-26 at 17:14:35 -0500