|
| static bool | has_value () noexcept |
| | Checks whether a service locator contains a value.
|
| static Service & | value () noexcept |
| | Returns a reference to a valid service, if any.
|
template<stl::derived_from< Service > Type = Service, typename... Args>
requires stl::constructible_from<Type, Args...> |
| static Service & | value_or (Args &&...args) |
| | Returns a service if available or sets it from a fallback type.
|
template<stl::derived_from< Service > Type = Service, typename... Args>
requires stl::constructible_from<Type, Args...> |
| static Service & | emplace (Args &&...args) |
| | Sets or replaces a service.
|
template<stl::derived_from< Service > Type = Service, typename... Args>
requires stl::constructible_from<Type, Args...> |
| static Service & | emplace (stl::allocator_arg_t, auto alloc, Args &&...args) |
| | Sets or replaces a service using a given allocator.
|
| static node_type | handle () noexcept |
| | Returns a handle to the underlying service.
|
| static void | reset (const node_type &other={}) noexcept |
| | Resets or replaces a service.
|
| template<stl::derived_from< Service > Type, typename Deleter = stl::default_delete<Type>> |
| static void | reset (Type *elem, Deleter deleter={}) |
| | Resets or replaces a service.
|
template<typename Service>
class entt::locator< Service >
Service locator, nothing more.
A service locator is used to do what it promises: locate services.
Usually service locators are tightly bound to the services they expose and thus it's hard to define a general purpose class to do that. This tiny class tries to fill the gap and to get rid of the burden of defining a different specific locator for each application.
- Note
- Users shouldn't retain references to a service. The recommended way is to retrieve the service implementation currently set each and every time the need for it arises. The risk is to incur in unexpected behaviors otherwise.
- Template Parameters
-
Definition at line 28 of file locator.hpp.
template<typename Service>
template<stl::derived_from< Service > Type = Service, typename... Args>
requires stl::constructible_from<Type, Args...>
Sets or replaces a service.
- Template Parameters
-
| Type | Service type. |
| Args | Types of arguments to use to construct the service. |
- Parameters
-
| args | Parameters to use to construct the service. |
- Returns
- A reference to a valid service.
Definition at line 103 of file locator.hpp.
template<typename Service>
template<stl::derived_from< Service > Type = Service, typename... Args>
requires stl::constructible_from<Type, Args...>
| Service & entt::locator< Service >::emplace |
( |
stl::allocator_arg_t | , |
|
|
auto | alloc, |
|
|
Args &&... | args ) |
|
inlinestatic |
Sets or replaces a service using a given allocator.
- Template Parameters
-
| Type | Service type. |
| Args | Types of arguments to use to construct the service. |
- Parameters
-
| alloc | The allocator to use. |
| args | Parameters to use to construct the service. |
- Returns
- A reference to a valid service.
Definition at line 118 of file locator.hpp.
template<typename Service>
template<stl::derived_from< Service > Type = Service, typename... Args>
requires stl::constructible_from<Type, Args...>
Returns a service if available or sets it from a fallback type.
Arguments are used only if a service doesn't already exist. In all other cases, they are discarded.
- Template Parameters
-
| Args | Types of arguments to use to construct the fallback service. |
| Type | Fallback service type. |
- Parameters
-
| args | Parameters to use to construct the fallback service. |
- Returns
- A reference to a valid service.
Definition at line 90 of file locator.hpp.