8#ifndef SEN_CORE_OBJ_OBJECT_REF_H
9#define SEN_CORE_OBJ_OBJECT_REF_H
41 [[nodiscard]]
bool valid() const noexcept {
return ptr_.load() !=
nullptr; }
44 [[nodiscard]]
operator bool() const noexcept {
return valid(); }
47 [[nodiscard]] T*
operator->() noexcept {
return ptr_.load(); }
50 [[nodiscard]]
const T*
operator->() const noexcept {
return ptr_.load(); }
53 [[nodiscard]] T&
get() noexcept {
return *ptr_.load(); }
56 [[nodiscard]]
const T&
get() const noexcept {
return *ptr_.load(); }
71 [[nodiscard]] T* getCastedObject(
Object*
object);
74 std::atomic<T*> ptr_ =
nullptr;
86inline T* ObjectRef<T>::getCastedObject(Object*
object)
88 if constexpr (!std::is_same_v<T, Object>)
90 auto castedObject =
dynamic_cast<T*
>(object);
106 for (
const auto& addition: additions)
110 if (instance ==
nullptr)
116 if (
auto* castedObject = getCastedObject(instance); castedObject)
118 ptr_.store(castedObject);
132 if (ptr_.load() !=
nullptr)
134 const auto* instance = ptr_.load()->asObject();
135 for (
const auto& removal: removals)
137 if (instance->getId() == removal.objectid)
Base class for event or method callbacks. It stores the queue where to push the response....
Definition callback.h:146
A sen object.
Definition object.h:76
ObjectProviderListener()=default
const T & get() const noexcept
Access the internal instance.
Definition object_ref.h:56
Callback onAdded(Callback &&function) noexcept
Installs a function to be called when objects are added / discovered. Replaces any previously-install...
Definition object_ref.h:60
void onObjectsAdded(const ObjectAdditionList &additions) override
Called when objects are been added to a source.
Definition object_ref.h:104
const T * operator->() const noexcept
Access the internal instance.
Definition object_ref.h:50
T & get() noexcept
Access the internal instance.
Definition object_ref.h:53
Callback onRemoved(Callback &&function) noexcept
Installs a function to be called when objects are added / discovered. Replaces any previously-install...
Definition object_ref.h:64
void onObjectsRemoved(const ObjectRemovalList &removals) override
Called when objects will be removed from a source.
Definition object_ref.h:130
bool valid() const noexcept
True if the reference holds a valid pointer to an instance.
Definition object_ref.h:41
~ObjectRef() override=default
std::function< void()> Callback
Definition object_ref.h:30
T * operator->() noexcept
Access the internal instance.
Definition object_ref.h:47
void throwRuntimeError(const std::string &err)
Throws std::exception that attempts to collect the stack trace. We also wrap it to avoid including st...
Object * getObjectInstance(const ObjectAddition &discovery)
Definition object_provider.h:97
std::vector< ObjectAddition > ObjectAdditionList
Sequence of object additions.
Definition object_provider.h:71
std::vector< ObjectRemoval > ObjectRemovalList
Sequence of object removals.
Definition object_provider.h:74