35#ifndef _UTILS_SERVICELOCATOR_HXX_
36#define _UTILS_SERVICELOCATOR_HXX_
51template <
typename ServiceType>
60 string name(__PRETTY_FUNCTION__);
85 ServiceLocatorImpl::services.clear();
89 static std::map<string, shared_ptr<void>> services;
101 ServiceLocatorImpl::services[name] = service;
113 auto it = ServiceLocatorImpl::services.find(name);
114 if (it == ServiceLocatorImpl::services.end())
125template <
typename ServiceType>
134 static shared_ptr<ServiceType>
get_service(
const char *alias =
nullptr)
138 return std::static_pointer_cast<ServiceType>(service);
148 shared_ptr<ServiceType> &service,
const char *alias =
nullptr)
151 shared_ptr<void> temp(service);
See OSMutexLock in os/OS.hxx.
Lightweight locking class for protecting small critical sections.
The sole purpose of this templated class is to provide access to a string that is specific to a type.
static string get_type_name(const char *alias)
Get a name that has the derived type as part of the name.
Provides the shared storage for registrations.
static void register_service(string name, shared_ptr< void > &service)
Register a pointer with a name.
static void clear()
Remove all of the registerations for all types.
static shared_ptr< void > get_service(string name)
Retrieves a pointer to the registered service, by name.
static shared_ptr< ServiceType > get_service(const char *alias=nullptr)
Get the service that has been registereed for this type.
static void register_service(shared_ptr< ServiceType > &service, const char *alias=nullptr)
Register a service instance with the service locator.