34 lines
775 B
C++
34 lines
775 B
C++
#ifndef STATE_FACTORY_HPP
|
|
#define STATE_FACTORY_HPP
|
|
|
|
#include <memory>
|
|
#include <state.hpp>
|
|
|
|
|
|
template <typename OwnerType>
|
|
class StateFactory {
|
|
using SharedState = std::shared_ptr<State<OwnerType>>;
|
|
|
|
public:
|
|
void RegisterState(const std::string &id, SharedState state) {
|
|
if (!state)
|
|
return;
|
|
|
|
states[id] = std::move(state);
|
|
}
|
|
|
|
SharedState Get(const std::string &id) const {
|
|
auto it = states.find(id);
|
|
return it != states.end() ? it->second : nullptr;
|
|
}
|
|
|
|
const std::unordered_map<std::string, SharedState> All() const {
|
|
return states;
|
|
}
|
|
|
|
private:
|
|
std::unordered_map<std::string, SharedState> states;
|
|
};
|
|
|
|
#endif // STATE_FACTORY_HPP
|