OGL Engine 1.2.0-dev
Loading...
Searching...
No Matches
statestore.hpp
Go to the documentation of this file.
1
5#pragma once
6
7#include <unordered_map>
8#include <any>
9#include <stdexcept>
10
11namespace Engine::Utils {
12 class StateStore {
13 private:
14 std::unordered_map<std::string, std::any> mStore;
15
16 public:
24 template<typename T>
25 void SetState(const std::string& key, T value) {
26 mStore[key] = value;
27 }
28
36 template<typename T>
37 T GetState(const std::string& key) const {
38 auto it = mStore.find(key);
39 if(it == mStore.end()) throw std::runtime_error("store key not found: " + key);
40
41 try {
42 return std::any_cast<T>(it->second);
43 } catch(const std::bad_any_cast& e) {
44 throw std::runtime_error("bad type cast for store key: " + key);
45 }
46 }
47
55 bool HasKey(const std::string& key) const;
56 };
57}
Definition statestore.hpp:12
bool HasKey(const std::string &key) const
Vérifie si le store contient une clé
Definition statestore.cpp:4
void SetState(const std::string &key, T value)
Setter typé
Definition statestore.hpp:25
T GetState(const std::string &key) const
Getter avec cast sur le type.
Definition statestore.hpp:37
Definition colors.cpp:3