omni::core::Implements
Defined in omni/core/IObject.h
-
template<typename T, typename ...Rest>
struct Implements : public omni::core::ImplementsCast<T, Rest...> Helper template for implementing one or more interfaces.
Implementations of interfaces (usually hidden in .cpp files) are well served to use this template.
This template provides two useful features:
It provides a reference count and reasonable implementations of omni::core::IObject_abi::acquire_abi() and omni::core::IObject_abi::release_abi().
It provides a omni::core::IObject_abi::cast_abi() implementation that supports multiple inheritance.
Using omni::core::Implements is recommended in most cases when implementing one or more interfaces.
Expected usage:
class MyIFooAndIBarImpl : public omni::core::Implements<IFoo, IBar> { /* ... */ };
Public Functions
-
inline void acquire() noexcept
See omni::core::IObject::acquire.
-
inline void release() noexcept
See omni::core::IObject::release.
Protected Functions
-
virtual ~Implements() noexcept = default
-
inline virtual void acquire_abi() noexcept override
Increments the object’s reference count.
Objects may have multiple reference counts (e.g. one per interface implemented). As such, it is important that you call omni::core::IObject::release() on the same pointer from which you called omni::core::IObject::acquire().
Do not directly use this method, rather use omni::core::ObjectPtr, which will manage calling omni::core::IObject::acquire() and omni::core::IObject::release() for you.
- Thread Safety
This method is thread safe.
-
inline virtual void release_abi() noexcept override
Decrements the objects reference count.
Most implementations will destroy the object if the reference count reaches 0 (though this is not a requirement).
Objects may have multiple reference counts (e.g. one per interface implemented). As such, it is important that you call omni::core::IObject::release() on the same pointer from which you called omni::core::IObject::acquire().
Do not directly use this method, rather use omni::core::ObjectPtr, which will manage calling omni::core::IObject::acquire() and omni::core::IObject::release() for you.
- Thread Safety
This method is thread safe.
-
inline virtual void *cast_abi(TypeId id) noexcept override
Returns a pointer to the interface defined by the given type id if this object implements the type id’s interface.
Objects can support multiple interfaces, even interfaces that are in different inheritance chains.
The returned object will have omni::core::IObject::acquire() called on it before it is returned, meaning it is up to the caller to call omni::core::IObject::release() on the returned pointer.
The returned pointer can be safely
reinterpret_cast<>
to the type id’s C++ class. For example, “omni.windowing.IWindow” can be cast toomni::windowing::IWindow
.Do not directly use this method, rather use a wrapper function like omni::core::cast() or omni::core::ObjectPtr::as().
- Thread Safety
This method is thread safe.