ServiceOwner#
-
template<class T>
class ServiceOwner : public sb::di::IServiceInstance# Public Types
-
using Ptr = std::unique_ptr<ServiceOwner<T>>#
Public Functions
-
ServiceOwner(const ServiceOwner&) = delete#
-
ServiceOwner(ServiceOwner&&) = default#
-
ServiceOwner &operator=(const ServiceOwner&) = delete#
-
ServiceOwner &operator=(ServiceOwner&&) = default#
-
inline virtual void *get() const final#
Returns service pointner as void *.
-
inline virtual void *moveOut()#
Moves out service pointner from instance as void *.
If instance is owner of service it will release this ownership just like std::unique_ptr<T>::release(), otherwise it will throw exception
Warning
Using this method might couse memory leaks, client is responsible for managing this pointner lifetime, the best approach is to imediatly wrap this poinrner with proper std::unique_ptr<T>
std::unique_ptr<T> service{static_cast<T *>(instance->moveOut())};
- Throws:
CannotMoveOutServiceException – cannot move out service
-
inline virtual TypeId getTypeId() const final#
Get the TypeId of service.
This method can be used to check if casting is safe
if(instance->getTypeId() == typeid(T)) { T* service = instance->getAs<T>(); }
-
inline virtual bool isValid() const final#
Checks if service instance is valid.
If service instance is invalid, get and move methods might lead to undefined behaviour
-
inline operator bool() const#
-
using Ptr = std::unique_ptr<ServiceOwner<T>>#