2#include <klib/assert.hpp>
5#include <unordered_map>
10 template <
typename Type>
12 KLIB_ASSERT(service !=
nullptr);
13 m_services.insert_or_assign(
typeid(Type), service);
16 template <
typename Type>
18 m_services.erase(
typeid(Type));
21 template <
typename Type>
23 return find<Type>() !=
nullptr;
26 template <
typename Type>
27 [[nodiscard]]
auto find() const -> Type* {
28 auto const it = m_services.find(
typeid(Type));
29 if (it == m_services.end()) {
return nullptr; }
30 return static_cast<Type*
>(it->second.get());
33 template <
typename Type>
34 [[nodiscard]]
auto get() const -> Type& {
35 KLIB_ASSERT(contains<Type>());
39 [[nodiscard]]
auto service_count() const -> std::
size_t {
return m_services.size(); }
40 void clear() { m_services.clear(); }
43 std::unordered_map<std::type_index, gsl::not_null<void*>> m_services{};
Definition service_locator.hpp:8
void bind(Type *service)
Definition service_locator.hpp:11
auto get() const -> Type &
Definition service_locator.hpp:34
void unbind()
Definition service_locator.hpp:17
auto service_count() const -> std::size_t
Definition service_locator.hpp:39
void clear()
Definition service_locator.hpp:40
auto contains() const -> bool
Definition service_locator.hpp:22
auto find() const -> Type *
Definition service_locator.hpp:27
Definition animation.hpp:8