From 8ef921aa5e36080b83fdd3fb9acda73afa05123e Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Tue, 8 Jul 2025 17:23:34 +0200 Subject: [PATCH] Implement bool operator for `ObjectLock` --- lib/base/objectlock.cpp | 12 ++++++++++++ lib/base/objectlock.hpp | 2 ++ 2 files changed, 14 insertions(+) diff --git a/lib/base/objectlock.cpp b/lib/base/objectlock.cpp index fad59160b..9ed9d1f21 100644 --- a/lib/base/objectlock.cpp +++ b/lib/base/objectlock.cpp @@ -65,3 +65,15 @@ void ObjectLock::Unlock() m_Locked = false; } } + +/** + * Returns true if the object is locked, false otherwise. + * + * This operator allows using ObjectLock in boolean contexts. + * + * @returns true if the object is locked, false otherwise. + */ +ObjectLock::operator bool() const +{ + return m_Locked; +} diff --git a/lib/base/objectlock.hpp b/lib/base/objectlock.hpp index abd071c66..328887425 100644 --- a/lib/base/objectlock.hpp +++ b/lib/base/objectlock.hpp @@ -26,6 +26,8 @@ public: void Lock(); void Unlock(); + operator bool() const; + private: const Object *m_Object{nullptr}; bool m_Locked{false};