5 #include <unordered_map> 27 std::unordered_map<std::type_index, std::unique_ptr<IObject>> memory;
31 LOG_DEBUG(
"Context created");
34 LOG_DEBUG(
"Context destroyed");
36 template<
typename TObject,
typename... Args>
37 TObject* Put(Args&&... args) {
38 memory[
typeid(TObject)] = std::make_unique<TObject>(std::forward<Args>(args)...);
39 return Get<TObject>();
42 template<
typename TObject,
typename TAsObject,
typename... Args>
43 TAsObject* PutAs(Args&&... args) {
44 memory[
typeid(TAsObject)] = std::make_unique<TObject>(std::forward<Args>(args)...);
45 return Get<TAsObject>();
48 template<
typename TObject>
49 TObject* Get()
const {
50 if (memory.count(
typeid(TObject)) == 0) {
51 LOG_ERROR(
"<%s> not found in the Container",
typeid(TObject).name());
54 return dynamic_cast<TObject*
>(memory.at(
typeid(TObject)).get());