From b706a6259eaeeed66fd17651e806d30432fc576e Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Fri, 9 May 2025 22:13:47 +0100 Subject: Add an accessor to Serialize::Reference and deduplicate code. --- include/serialize.h | 44 ++++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) (limited to 'include') diff --git a/include/serialize.h b/include/serialize.h index e6ca7877a..79315d7a9 100644 --- a/include/serialize.h +++ b/include/serialize.h @@ -326,6 +326,18 @@ public: this->ref->DelReference(this); } + inline T *Get(bool update = true) const + { + if (!this->invalid) + { + if (this->ref && update) + this->ref->QueueUpdate(); // This can invalidate me + if (!this->invalid) + return this->ref; + } + return nullptr; + } + inline Reference& operator=(const Reference &other) { if (this != &other) @@ -349,42 +361,18 @@ public: return false; } - inline operator T*() const + inline operator T *() const { - if (!this->invalid) - { - if (this->ref) - // This can invalidate me - this->ref->QueueUpdate(); - if (!this->invalid) - return this->ref; - } - return NULL; + return Get(true); } inline T *operator*() const { - if (!this->invalid) - { - if (this->ref) - // This can invalidate me - this->ref->QueueUpdate(); - if (!this->invalid) - return this->ref; - } - return NULL; + return Get(true); } inline T *operator->() const { - if (!this->invalid) - { - if (this->ref) - // This can invalidate me - this->ref->QueueUpdate(); - if (!this->invalid) - return this->ref; - } - return NULL; + return Get(true); } }; -- cgit