more constexprs

# Conflicts:
#	Engine/source/core/util/refBase.h
This commit is contained in:
Triston Caton 2025-10-05 13:00:40 -04:00
parent 8d1e95b3f3
commit c24d0211bd

View file

@ -43,7 +43,7 @@ public:
public: public:
[[nodiscard]] constexpr WeakRefBase* get() const { return mObject; } [[nodiscard]] constexpr WeakRefBase* get() const { return mObject; }
[[nodiscard]] constexpr U32 getRefCount() const { return mRefCount; } [[nodiscard]] constexpr U32 getRefCount() const { return mRefCount; }
constexpr void incRefCount() { mRefCount++; } constexpr void incRefCount() { mRefCount++; }
constexpr void decRefCount() { constexpr void decRefCount() {
@ -54,7 +54,8 @@ public:
private: private:
friend class WeakRefBase; friend class WeakRefBase;
constexpr explicit WeakReference(WeakRefBase *object) :mObject(object), mRefCount(0) {} constexpr explicit WeakReference(WeakRefBase *object) :mObject(object), mRefCount(0) {}
~WeakReference() { AssertFatal(mObject==nullptr, "Deleting weak reference which still points at an object."); } ~WeakReference() { AssertFatal(mObject==nullptr, "Deleting weak reference which still points at an object."); }
// Object we reference // Object we reference
@ -66,7 +67,7 @@ public:
public: public:
constexpr WeakRefBase() : mReference(nullptr) {} constexpr WeakRefBase() : mReference(nullptr) {}
virtual ~WeakRefBase() { clearWeakReferences(); } virtual ~WeakRefBase() { clearWeakReferences(); }
WeakReference* getWeakReference(); WeakReference* getWeakReference();
@ -106,17 +107,17 @@ public:
} }
/// Returns true if the pointer is not set. /// Returns true if the pointer is not set.
[[nodiscard]] constexpr bool isNull() const { return mReference == nullptr || mReference->get() == nullptr; } [[nodiscard]] constexpr bool isNull() const { return mReference == nullptr || mReference->get() == nullptr; }
/// Returns true if the pointer is set. /// Returns true if the pointer is set.
[[nodiscard]] constexpr bool isValid() const { return mReference && mReference->get(); } [[nodiscard]] constexpr bool isValid() const { return mReference && mReference->get(); }
T* operator->() const { return getPointer(); } [[nodiscard]] constexpr T* operator->() const { return getPointer(); }
T& operator*() const { return *getPointer(); } [[nodiscard]] constexpr T& operator*() const { return *getPointer(); }
operator T*() const { return getPointer(); } [[nodiscard]] constexpr operator T*() const { return getPointer(); }
/// Returns the pointer. /// Returns the pointer.
[[nodiscard]] constexpr T* getPointer() const { return mReference ? ( T* ) mReference->get() : nullptr; } [[nodiscard]] constexpr T* getPointer() const { return mReference ? (T*)mReference->get() : nullptr; }
protected: protected:
void set(WeakRefBase::WeakReference* ref) void set(WeakRefBase::WeakReference* ref)
@ -146,10 +147,10 @@ class WeakRefUnion
typedef WeakRefUnion<ExposedType> Union; typedef WeakRefUnion<ExposedType> Union;
public: public:
WeakRefUnion() : mPtr(nullptr) {} constexpr WeakRefUnion() : mPtr(nullptr) {}
WeakRefUnion(const WeakRefPtr<WeakRefBase> & ref, ExposedType * ptr) : mPtr(nullptr) { set(ref, ptr); } constexpr WeakRefUnion(const WeakRefPtr<WeakRefBase> & ref, ExposedType * ptr) : mPtr(nullptr) { set(ref, ptr); }
WeakRefUnion(const Union & lock) : mPtr(nullptr) { *this = lock; } constexpr WeakRefUnion(const Union & lock) : mPtr(nullptr) { *this = lock; }
WeakRefUnion(WeakRefBase * ref) : mPtr(nullptr) { set(ref, dynamic_cast<ExposedType*>(ref)); } constexpr WeakRefUnion(WeakRefBase * ref) : mPtr(nullptr) { set(ref, dynamic_cast<ExposedType*>(ref)); }
~WeakRefUnion() { mWeakReference = nullptr; } ~WeakRefUnion() { mWeakReference = nullptr; }
Union & operator=(const Union & ptr) Union & operator=(const Union & ptr)
@ -425,7 +426,7 @@ inline void WeakRefBase::clearWeakReferences()
} }
} }
inline WeakRefBase::WeakReference * WeakRefBase::getWeakReference() inline WeakRefBase::WeakReference* WeakRefBase::getWeakReference()
{ {
if (!mReference) if (!mReference)
{ {
@ -454,17 +455,17 @@ struct TypeTraits< StrongWeakRefPtr< T > > : public _TypeTraits< StrongWeakRefPt
}; };
template< typename T > template< typename T >
inline T& Deref( WeakRefPtr< T >& ref ) [[nodiscard]] constexpr T& Deref( WeakRefPtr< T >& ref )
{ {
return *ref; return *ref;
} }
template< typename T > template< typename T >
inline T& Deref( StrongRefPtr< T >& ref ) [[nodiscard]] constexpr T& Deref( StrongRefPtr< T >& ref )
{ {
return *ref; return *ref;
} }
template< typename T > template< typename T >
inline T& Deref( StrongWeakRefPtr< T >& ref ) [[nodiscard]] constexpr T& Deref( StrongWeakRefPtr< T >& ref )
{ {
return *ref; return *ref;
} }