summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2025-05-09 22:13:47 +0100
committerSadie Powell <sadie@witchery.services>2025-05-09 22:25:10 +0100
commitb706a6259eaeeed66fd17651e806d30432fc576e (patch)
tree8207765c0808c875507ff455c8f7e85c323c7153 /include
parent2cf8f003ce318997f3259ef1c8bd082d4569057a (diff)
Add an accessor to Serialize::Reference and deduplicate code.
Diffstat (limited to 'include')
-rw-r--r--include/serialize.h44
1 files changed, 16 insertions, 28 deletions
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<T>& operator=(const Reference<T> &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);
}
};