1#ifndef ENTT_LOCATOR_LOCATOR_HPP
2#define ENTT_LOCATOR_LOCATOR_HPP
6#include "../config/config.h"
26template<
typename Service>
28 class service_handle {
30 std::shared_ptr<Service> value{};
59 return (service !=
nullptr);
72 ENTT_ASSERT(
has_value(),
"Service not available");
101 service = std::make_shared<Type>(std::forward<Args>(
args)...);
114 template<
typename Type =
Service,
typename Allocator,
typename...
Args>
116 service = std::allocate_shared<Type>(
alloc, std::forward<Args>(
args)...);
126 node.value = service;
135 service =
other.value;
145 template<
typename Type,
typename Deleter = std::default_delete<Type>>
147 service = std::shared_ptr<Service>{
elem, std::move(
deleter)};
153 inline static std::shared_ptr<Service> service{};
Service locator, nothing more.
static node_type handle() noexcept
Returns a handle to the underlying service.
locator & operator=(const locator &)=delete
Default copy assignment operator, deleted on purpose.
static void reset(Type *elem, Deleter deleter={})
Resets or replaces a service.
static Service & emplace(std::allocator_arg_t, Allocator alloc, Args &&...args)
Sets or replaces a service using a given allocator.
static void reset(const node_type &other={}) noexcept
Resets or replaces a service.
static Service & value() noexcept
Returns a reference to a valid service, if any.
static bool has_value() noexcept
Checks whether a service locator contains a value.
service_handle node_type
Service node type.
locator(const locator &)=delete
Default copy constructor, deleted on purpose.
~locator()=delete
Default destructor, deleted on purpose.
Service type
Service type.
static Service & value_or(Args &&...args)
Returns a service if available or sets it from a fallback type.
locator()=delete
Default constructor, deleted on purpose.
static Service & emplace(Args &&...args)
Sets or replaces a service.
constexpr Type make_obj_using_allocator(const Allocator &allocator, Args &&...args)
Uses-allocator construction utility (waiting for C++20).