OpenLexocad  27.1
entt::service_locator< Service > Struct Template Reference

Service locator, nothing more. More...

#include <entt.hpp>

Public Types

using service_type = Service
 Type of service offered. More...
 

Public Member Functions

 service_locator ()=delete
 Default constructor, deleted on purpose. More...
 
 ~service_locator ()=delete
 Default destructor, deleted on purpose. More...
 

Static Public Member Functions

static bool empty () ENTT_NOEXCEPT
 Tests if a valid service implementation is set. More...
 
static std::weak_ptr< Service > get () ENTT_NOEXCEPT
 Returns a weak pointer to a service implementation, if any. More...
 
static Service & ref () ENTT_NOEXCEPT
 Returns a weak reference to a service implementation, if any. More...
 
template<typename Impl = Service, typename... Args>
static void set (Args &&... args)
 Sets or replaces a service. More...
 
static void set (std::shared_ptr< Service > ptr)
 Sets or replaces a service. More...
 
static void reset ()
 Resets a service. More...
 

Detailed Description

template<typename Service>
struct entt::service_locator< Service >

Service locator, nothing more.

A service locator can be 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 template based implementation tries to fill the gap and to get rid of the burden of defining a different specific locator for each application.

Template Parameters
ServiceType of service managed by the locator.

Member Typedef Documentation

◆ service_type

template<typename Service >
using entt::service_locator< Service >::service_type = Service

Type of service offered.

Constructor & Destructor Documentation

◆ service_locator()

template<typename Service >
entt::service_locator< Service >::service_locator ( )
delete

Default constructor, deleted on purpose.

◆ ~service_locator()

template<typename Service >
entt::service_locator< Service >::~service_locator ( )
delete

Default destructor, deleted on purpose.

Member Function Documentation

◆ empty()

template<typename Service >
static bool entt::service_locator< Service >::empty ( )
inlinestatic

Tests if a valid service implementation is set.

Returns
True if the service is set, false otherwise.

◆ get()

template<typename Service >
static std::weak_ptr<Service> entt::service_locator< Service >::get ( )
inlinestatic

Returns a weak pointer to a service implementation, if any.

Clients of a service shouldn't retain references to it. The recommended way is to retrieve the service implementation currently set each and every time the need of using it arises. Otherwise users can incur in unexpected behaviors.

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

◆ ref()

template<typename Service >
static Service& entt::service_locator< Service >::ref ( )
inlinestatic

Returns a weak reference to a service implementation, if any.

Clients of a service shouldn't retain references to it. The recommended way is to retrieve the service implementation currently set each and every time the need of using it arises. Otherwise users can incur in unexpected behaviors.

Warning
In case no service implementation has been set, a call to this function results in undefined behavior.
Returns
A reference to the service implementation currently set, if any.

◆ reset()

template<typename Service >
static void entt::service_locator< Service >::reset ( )
inlinestatic

Resets a service.

The service is no longer valid after a reset.

◆ set() [1/2]

template<typename Service >
template<typename Impl = Service, typename... Args>
static void entt::service_locator< Service >::set ( Args &&...  args)
inlinestatic

Sets or replaces a service.

Template Parameters
ImplType of the new service to use.
ArgsTypes of arguments to use to construct the service.
Parameters
argsParameters to use to construct the service.

◆ set() [2/2]

template<typename Service >
static void entt::service_locator< Service >::set ( std::shared_ptr< Service >  ptr)
inlinestatic

Sets or replaces a service.

Parameters
ptrService to use to replace the current one.

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