16 #include <type_traits>
18 #include <unordered_map>
21 namespace ActsExamples {
44 void add(
const std::string&
name,
T&&
object);
52 const T&
get(
const std::string&
name)
const;
58 virtual const std::type_info&
type()
const = 0;
67 const std::type_info&
type()
const {
return typeid(
T); }
71 std::unordered_map<std::string, std::unique_ptr<IHolder>>
m_store;
79 std::unique_ptr<const Acts::Logger> logger)
80 : m_logger(std::move(logger)) {}
85 throw std::invalid_argument(
"Object can not have an empty name");
87 if (0 < m_store.count(name)) {
88 throw std::invalid_argument(
"Object '" + name +
"' already exists");
90 m_store.emplace(name, std::make_unique<
HolderT<T>>(std::forward<T>(
object)));
96 auto it = m_store.find(name);
97 if (
it == m_store.end()) {
98 throw std::out_of_range(
"Object '" + name +
"' does not exists");
100 const IHolder* holder =
it->second.get();
101 if (
typeid(
T) != holder->
type()) {
102 throw std::out_of_range(
"Type missmatch for object '" + name +
"'");