|
| 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<typename Type = Service, typename... Args> |
| static Service & | value_or (Args &&...args) |
| | Returns a service if available or sets it from a fallback type.
|
| |
| template<typename Type = Service, typename... Args> |
| static Service & | emplace (Args &&...args) |
| | Sets or replaces a service.
|
| |
| template<typename Type = Service, typename Allocator, typename... Args> |
| static Service & | emplace (std::allocator_arg_t, Allocator 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<typename Type, typename Deleter = std::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 27 of file locator.hpp.
template<typename Service>
template<typename Type = Service, typename Allocator, typename... Args>
| static Service & entt::locator< Service >::emplace |
( |
std::allocator_arg_t | , |
|
|
Allocator< Service > | alloc, |
|
|
Args &&... | args ) |
|
inlinestatic |
Sets or replaces a service using a given allocator.
- Template Parameters
-
| Type | Service type. |
| Allocator | Type of allocator used to manage memory and elements. |
| 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 115 of file locator.hpp.
template<typename Service>
template<typename Type = Service, typename... Args>
| static Service & entt::locator< Service >::value_or |
( |
Args &&... | args | ) |
|
|
inlinestaticnodiscard |
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 88 of file locator.hpp.