EnTT: entt::locator< Service > Class Template Reference

EnTT 3.15.0

Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
entt::locator< Service > Class Template Referencefinal

Service locator, nothing more. More...

`#include <locator.hpp>`

## Public Types
using | type = Service
| Service type.
using | node_type = service_handle
| Service node type.

## Public Member Functions
| locator ()=delete
| Default constructor, deleted on purpose.
| locator (const locator &)=delete
| Default copy constructor, deleted on purpose.
| ~locator ()=delete
| Default destructor, deleted on purpose.
locator & | operator= (const locator &)=delete
| Default copy assignment operator, deleted on purpose.

## Static Public Member Functions
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.

## Detailed Description

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

  Service | Service type.

Definition at line 27 of file locator.hpp.

## Member Typedef Documentation

## ◆ node_type

template<typename Service>

using entt::locator< Service >::node_type = service_handle

Service node type.

Definition at line 37 of file locator.hpp.

## ◆ type

template<typename Service>

using entt::locator< Service >::type = Service

Service type.

Definition at line 35 of file locator.hpp.

## Member Function Documentation

## ◆ emplace() [1/2]

template<typename Service>
template<typename Type = Service, typename... Args>

static Service & entt::locator< Service >::emplace | ( | Args &&... | args | ) |
| inlinestatic

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 100 of file locator.hpp.

## ◆ emplace() [2/2]

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.

## ◆ handle()

template<typename Service>

static node_type entt::locator< Service >::handle | ( |  | ) |
| inlinestaticnoexcept

Returns a handle to the underlying service.

Returns
  A handle to the underlying service.

Definition at line 124 of file locator.hpp.

## ◆ has_value()

template<typename Service>

static bool entt::locator< Service >::has_value | ( |  | ) |
| inlinestaticnodiscardnoexcept

Checks whether a service locator contains a value.

Returns
  True if the service locator contains a value, false otherwise.

Definition at line 58 of file locator.hpp.

## ◆ operator=()

template<typename Service>

locator & entt::locator< Service >::operator= | ( | const locator< Service > & |  | ) |
| delete

Default copy assignment operator, deleted on purpose.

Returns
  This locator.

## ◆ reset() [1/2]

template<typename Service>

static void entt::locator< Service >::reset | ( | const node_type & | other = {} | ) |
| inlinestaticnoexcept

Resets or replaces a service.

Parameters

  other | Optional handle with which to replace the service.

Definition at line 134 of file locator.hpp.

## ◆ reset() [2/2]

template<typename Service>
template<typename Type, typename Deleter = std::default_delete<Type>>

static void entt::locator< Service >::reset | ( | Type * | elem,
|  | Deleter | deleter = {} )
| inlinestatic

Resets or replaces a service.

Template Parameters

  Type | Service type.
  Deleter | Deleter type.

Parameters

  elem | A pointer to a service to manage.
  deleter | A deleter to use to destroy the service.

Definition at line 146 of file locator.hpp.

## ◆ value()

template<typename Service>

static Service & entt::locator< Service >::value | ( |  | ) |
| inlinestaticnodiscardnoexcept

Returns a reference to a valid service, if any.

Warning
  Invoking this function can result in undefined behavior if the service hasn't been set yet.

Returns
  A reference to the service currently set, if any.

Definition at line 71 of file locator.hpp.

## ◆ value_or()

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.

The documentation for this class was generated from the following file:

- src/entt/locator/locator.hpp