1 #ifndef ENTT_LOCATOR_LOCATOR_HPP
2 #define ENTT_LOCATOR_LOCATOR_HPP
6 #include "../config/config.h"
26 template<
typename Service>
40 [[nodiscard]]
static bool has_value() ENTT_NOEXCEPT {
41 return (service !=
nullptr);
53 [[nodiscard]]
static Service &
value() ENTT_NOEXCEPT {
54 ENTT_ASSERT(
has_value(),
"Service not available");
69 template<
typename Impl = Service,
typename... Args>
70 [[nodiscard]]
static Service &
value_or(Args &&...args) {
71 return service ? *service : emplace<Impl>(std::forward<Args>(args)...);
81 template<
typename Impl = Service,
typename... Args>
83 service = std::make_shared<Impl>(std::forward<Args>(args)...);
96 template<
typename Impl = Service,
typename Allocator,
typename... Args>
98 service = std::allocate_shared<Impl>(alloc, std::forward<Args>(args)...);
109 inline static std::shared_ptr<Service> service =
nullptr;
Service locator, nothing more.
static Service & value()
Returns a reference to a valid service, if any.
static Service & value_or(Args &&...args)
Returns a service if available or sets it from a fallback type.
static bool has_value()
Checks whether a service locator contains a value.
static Service & allocate_emplace(Allocator alloc, Args &&...args)
Sets or replaces a service using a given allocator.
~locator()=delete
Default destructor, deleted on purpose.
Service type
Service type.
static Service & emplace(Args &&...args)
Sets or replaces a service.
static void reset()
Resets a service.
locator()=delete
Default constructor, deleted on purpose.