7 #ifndef _FCITX_UTILS_TRACKABLEOBJECT_H_ 8 #define _FCITX_UTILS_TRACKABLEOBJECT_H_ 16 #include <type_traits> 18 #include <fcitx-utils/handlertable.h> 19 #include <fcitx-utils/macros.h> 38 bool
isValid()
const {
return !that_.expired(); }
41 bool isNull()
const {
return rawThat_ ==
nullptr; }
44 T *
get()
const {
return that_.expired() ? nullptr : rawThat_; }
54 : that_(std::move(that)), rawThat_(rawThat) {}
56 std::weak_ptr<bool> that_;
73 : self_(std::make_unique<std::shared_ptr<bool>>(
74 std::make_shared<bool>())) {}
84 static_cast<const T *
>(
this));
88 std::unique_ptr<std::shared_ptr<bool>> self_;
92 #endif // _FCITX_UTILS_TRACKABLEOBJECT_H_ Utility class provides a weak reference to the object.
void unwatch()
Reset reference to empty state.
bool isValid() const
Check if the reference is still valid.
Helper class to be used with TrackableObjectReference.
bool isNull() const
Check if the reference is not tracking anything.