-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDekiRendererRegistry.cpp
More file actions
40 lines (32 loc) · 932 Bytes
/
DekiRendererRegistry.cpp
File metadata and controls
40 lines (32 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "DekiRendererRegistry.h"
#include <unordered_map>
#include <string>
namespace DekiRendererRegistry {
// Meyer's singleton — avoids static init order issues across translation units
static std::unordered_map<std::string, DekiRendererFactory>& GetRegistry()
{
static std::unordered_map<std::string, DekiRendererFactory> reg;
return reg;
}
void Register(const char* name, DekiRendererFactory factory)
{
if (name && factory)
GetRegistry()[name] = factory;
}
DekiRenderer* Create(const char* name)
{
if (!name || name[0] == '\0')
return nullptr;
auto& reg = GetRegistry();
auto it = reg.find(name);
if (it != reg.end())
return it->second();
return nullptr;
}
void GetAllNames(std::vector<std::string>& outNames)
{
outNames.clear();
for (const auto& [name, factory] : GetRegistry())
outNames.push_back(name);
}
} // namespace DekiRendererRegistry