12template <
class T>
class Ref;
57 mRefCount.fetch_add(1, memory_order_relaxed);
62 #ifndef JPH_TSAN_ENABLED
68 atomic_thread_fence(memory_order_acquire);
69 delete static_cast<const T *
>(
this);
75 delete static_cast<const T *
>(
this);
113 inline Ref() : mPtr(nullptr) { }
114 inline Ref(T *inRHS) : mPtr(inRHS) { AddRef(); }
115 inline Ref(
const Ref<T> &inRHS) : mPtr(inRHS.mPtr) { AddRef(); }
116 inline Ref(
Ref<T> &&inRHS) noexcept : mPtr(inRHS.mPtr) { inRHS.mPtr =
nullptr; }
120 inline Ref<T> &
operator = (T *inRHS) {
if (mPtr != inRHS) { Release(); mPtr = inRHS; AddRef(); }
return *
this; }
121 inline Ref<T> &
operator = (
const Ref<T> &inRHS) {
if (mPtr != inRHS.mPtr) { Release(); mPtr = inRHS.mPtr; AddRef(); }
return *
this; }
122 inline Ref<T> &
operator = (
Ref<T> &&inRHS)
noexcept {
if (mPtr != inRHS.mPtr) { Release(); mPtr = inRHS.mPtr; inRHS.mPtr =
nullptr; }
return *
this; }
125 inline operator T *()
const {
return mPtr; }
132 inline bool operator == (
const T * inRHS)
const {
return mPtr == inRHS; }
134 inline bool operator != (
const T * inRHS)
const {
return mPtr != inRHS; }
138 inline T *
GetPtr()
const {
return mPtr; }
153 inline void AddRef() {
if (mPtr !=
nullptr) mPtr->AddRef(); }
154 inline void Release() {
if (mPtr !=
nullptr) mPtr->Release(); }
170 inline RefConst(
const T * inRHS) : mPtr(inRHS) { AddRef(); }
174 inline RefConst(
Ref<T> &&inRHS) noexcept : mPtr(inRHS.mPtr) { inRHS.mPtr =
nullptr; }
178 inline RefConst<T> &
operator = (
const T * inRHS) {
if (mPtr != inRHS) { Release(); mPtr = inRHS; AddRef(); }
return *
this; }
182 inline RefConst<T> &
operator = (
Ref<T> &&inRHS)
noexcept {
if (mPtr != inRHS.mPtr) { Release(); mPtr = inRHS.mPtr; inRHS.mPtr =
nullptr; }
return *
this; }
185 inline operator const T * ()
const {
return mPtr; }
192 inline bool operator == (
const T * inRHS)
const {
return mPtr == inRHS; }
195 inline bool operator != (
const T * inRHS)
const {
return mPtr != inRHS; }
200 inline const T *
GetPtr()
const {
return mPtr; }
213 inline void AddRef() {
if (mPtr !=
nullptr) mPtr->AddRef(); }
214 inline void Release() {
if (mPtr !=
nullptr) mPtr->Release(); }
230 size_t operator () (
const JPH::Ref<T> &inRHS)
const
232 return size_t(inRHS.GetHash());
240 size_t operator () (
const JPH::RefConst<T> &inRHS)
const
242 return size_t(inRHS.GetHash());
#define JPH_EXPORT
Definition Core.h:275
std::uint64_t uint64
Definition Core.h:504
#define JPH_NAMESPACE_END
Definition Core.h:425
#define JPH_CLANG_SUPPRESS_WARNING(w)
Definition Core.h:302
std::uint32_t uint32
Definition Core.h:503
#define JPH_NAMESPACE_BEGIN
Definition Core.h:419
#define JPH_IF_ENABLE_ASSERTS(...)
Definition IssueReporting.h:35
#define JPH_ASSERT(...)
Definition IssueReporting.h:33
#define JPH_SUPPRESS_WARNING_POP
Definition ShaderCore.h:38
#define JPH_SUPPRESS_WARNING_PUSH
Definition ShaderCore.h:37
Definition Reference.h:166
const T * GetPtr() const
Get pointer.
Definition Reference.h:200
bool operator!=(const T *inRHS) const
Definition Reference.h:195
RefConst()
Constructor.
Definition Reference.h:169
~RefConst()
Definition Reference.h:175
RefConst(const T *inRHS)
Definition Reference.h:170
const T & operator*() const
Definition Reference.h:189
RefConst< T > & operator=(const T *inRHS)
Assignment operators.
Definition Reference.h:178
RefConst(const Ref< T > &inRHS)
Definition Reference.h:173
void ** InternalGetPointer()
INTERNAL HELPER FUNCTION USED BY SERIALIZATION.
Definition Reference.h:209
const T * operator->() const
Access like a normal pointer.
Definition Reference.h:188
RefConst(RefConst< T > &&inRHS) noexcept
Definition Reference.h:172
uint64 GetHash() const
Get hash for this object.
Definition Reference.h:203
RefConst(const RefConst< T > &inRHS)
Definition Reference.h:171
bool operator==(const T *inRHS) const
Comparison.
Definition Reference.h:192
RefConst(Ref< T > &&inRHS) noexcept
Definition Reference.h:174
Definition Reference.h:110
Ref(const Ref< T > &inRHS)
Definition Reference.h:115
T * GetPtr() const
Get pointer.
Definition Reference.h:138
bool operator!=(const T *inRHS) const
Definition Reference.h:134
Ref()
Constructor.
Definition Reference.h:113
~Ref()
Definition Reference.h:117
T * operator->() const
Access like a normal pointer.
Definition Reference.h:128
void ** InternalGetPointer()
INTERNAL HELPER FUNCTION USED BY SERIALIZATION.
Definition Reference.h:147
Ref< T > & operator=(T *inRHS)
Assignment operators.
Definition Reference.h:120
Ref(Ref< T > &&inRHS) noexcept
Definition Reference.h:116
Ref(T *inRHS)
Definition Reference.h:114
uint64 GetHash() const
Get hash for this object.
Definition Reference.h:141
bool operator==(const T *inRHS) const
Comparison.
Definition Reference.h:132
T & operator*() const
Definition Reference.h:129
Definition Reference.h:35
void Release() const
Definition Reference.h:60
atomic< uint32 > mRefCount
Current reference count.
Definition Reference.h:86
RefTarget & operator=(const RefTarget &)
Assignment operator.
Definition Reference.h:48
void SetEmbedded() const
Definition Reference.h:45
RefTarget()=default
Constructor.
RefTarget(const RefTarget &)
Definition Reference.h:39
static int sInternalGetRefCountOffset()
INTERNAL HELPER FUNCTION USED BY SERIALIZATION.
Definition Reference.h:81
~RefTarget()
assert no one is referencing us
Definition Reference.h:40
uint32 GetRefCount() const
Get current refcount of this object.
Definition Reference.h:51
void AddRef() const
Add or release a reference to this object.
Definition Reference.h:54
static constexpr uint32 cEmbedded
A large value that gets added to the refcount to mark the object as embedded.
Definition Reference.h:84
Pure virtual version of RefTarget.
Definition Reference.h:91
virtual ~RefTargetVirtual()=default
Virtual destructor.
virtual void Release()=0
Virtual release reference.
virtual void AddRef()=0
Virtual add reference.
Fallback hash function that calls T::GetHash()
Definition HashCombine.h:59