#pragma once #include #include #include "IGameService.h" template struct TypedGet { template std::shared_ptr Get() { std::shared_ptr pComponent = ((T*)this)->Get(__uuidof(TGet)); if (pComponent) { return std::static_pointer_cast(pComponent); } return nullptr; } }; template struct TypedAdd { template void Add(std::shared_ptr component) { static constexpr std::array InterfaceUuids = { { __uuidof(TInterfaces)... } }; for (const auto& uuid : InterfaceUuids) { ((T*)this)->Add(uuid, component); } } }; /// /// Container for game components. /// Facilitates resource acquisition across module boundaries, and interop with .NET code. /// struct IGameServiceProvider : public TypedGet, public TypedAdd { virtual ~IGameServiceProvider() { } virtual void Add(const IID& iid, std::shared_ptr component) = 0; virtual std::shared_ptr Get(const IID& iid) noexcept = 0; virtual void Remove(const IID& iid) noexcept = 0; virtual void ReleaseAll() = 0; template void Add(std::shared_ptr component) { return TypedAdd::Add(component); } template std::shared_ptr Get() { return TypedGet::Get(); } };