librats
Features
Quick Start
API Reference
GitHub
Back to Site
Loading...
Searching...
No Matches
service_registry.h
Go to the documentation of this file.
1
#pragma once
2
33
#include <typeindex>
34
#include <typeinfo>
35
#include <unordered_map>
36
37
namespace
librats
{
38
39
class
ServiceRegistry
{
40
public
:
42
template
<
class
I>
43
void
provide
(I* service) {
44
services_[std::type_index(
typeid
(I))] =
static_cast<
void
*
>
(service);
45
}
46
48
template
<
class
I>
49
I*
get
()
const
{
50
auto
it = services_.find(std::type_index(
typeid
(I)));
51
return
it == services_.end() ? nullptr :
static_cast<
I*
>
(it->second);
52
}
53
54
private
:
55
std::unordered_map<std::type_index, void*> services_;
56
};
57
58
}
// namespace librats
librats::ServiceRegistry
Definition
service_registry.h:39
librats::ServiceRegistry::get
I * get() const
Resolve the provider of interface I, or nullptr if none is registered.
Definition
service_registry.h:49
librats::ServiceRegistry::provide
void provide(I *service)
Register service as the provider of interface I (call during attach()).
Definition
service_registry.h:43
librats
Definition
node.h:65