MCPcopy Create free account
hub / github.com/AbyssEngine/AbyssEngineOld / ButtonDefManager

Class ButtonDefManager

src/OD2/Common/ButtonDefManager.h:13–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11namespace OD2::Common {
12
13class ButtonDefManager {
14 absl::node_hash_map<std::string, Abyss::UI::ButtonDef> buttonDefs{};
15
16 ButtonDefManager() = default;
17
18 public:
19 static ButtonDefManager &getInstance() {
20 static ButtonDefManager instance;
21 return instance;
22 }
23
24 Abyss::UI::ButtonDef &getButtonDef(const std::string_view name) {
25 const auto it = buttonDefs.find(name);
26 if (it == buttonDefs.end())
27 throw std::runtime_error("ButtonDef not found");
28
29 return it->second;
30 }
31
32 void addButtonDef(const Abyss::UI::ButtonDef &def) {
33 if (buttonDefs.contains(def.name))
34 throw std::runtime_error("ButtonDef already exists");
35
36 buttonDefs.emplace(def.name, def);
37 }
38
39 void removeButtonDef(const std::string_view name) {
40 const auto it = buttonDefs.find(name);
41 if (it == buttonDefs.end())
42 throw std::runtime_error("ButtonDef not found");
43
44 buttonDefs.erase(it);
45 }
46
47 void clearButtonDefs() { buttonDefs.clear(); }
48};
49
50inline Abyss::UI::ButtonDef &GetButtonDef(const std::string_view name) { return ButtonDefManager::getInstance().getButtonDef(name); };
51

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected