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
37namespace librats {
38
40public:
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
54private:
55 std::unordered_map<std::type_index, void*> services_;
56};
57
58} // namespace librats
I * get() const
Resolve the provider of interface I, or nullptr if none is registered.
void provide(I *service)
Register service as the provider of interface I (call during attach()).
Definition node.h:65