22 #include <momemta/Pool.h> 26 #include <unordered_map> 28 #include <momemta/any.h> 29 #include <momemta/Logging.h> 30 #include <momemta/Utils.h> 31 #include <momemta/Value.h> 32 #include <momemta/impl/ValueProxy.h> 38 auto it = m_storage.find(tag);
39 if (it == m_storage.end()) {
41 it = create<std::vector<T>>(tag,
false);
43 it = create<T>(tag,
false);
52 template <
typename T> std::shared_ptr<const T> Pool::raw_get(
const InputTag& tag)
const {
54 auto it = m_storage.find(tag);
55 if (it == m_storage.end())
56 throw tag_not_found_error(
"No such tag in pool: " + tag.
toString());
61 std::shared_ptr<T>& ptr = momemta::any_cast<std::shared_ptr<T>&>(v.ptr);
63 return std::const_pointer_cast<
const T>(ptr);
64 }
catch (
const momemta::bad_any_cast& e) {
65 LOG(fatal) <<
"Exception while trying to get pool content for '" << tag.
toString() <<
"'. Requested a '" 66 << demangle(
typeid(std::shared_ptr<T>).name())
67 <<
"' while parameter is a '" 68 << demangle(v.ptr.type().name())
74 template <
typename T,
typename... Args> std::shared_ptr<T>
Pool::put(
const InputTag& tag, Args&&... args) {
75 auto it = m_storage.find(tag);
76 if (it != m_storage.end()) {
83 +
"' which seems to require a constructor call. This is currently not supported.");
85 it->second.valid =
true;
88 if (it->second.ptr.empty()) {
89 auto ptr = std::make_shared<T>(std::forward<Args>(args)...);
94 it = create<T, Args ...>(tag,
true, std::forward<Args>(args)...);
97 return momemta::any_cast<std::shared_ptr<T>>(it->second.ptr);
100 template <
typename T,
typename... Args> Pool::PoolStorage::iterator Pool::create(
101 const InputTag& tag,
bool valid, Args&&... args)
const {
103 auto ptr = std::make_shared<T>(std::forward<Args>(args)...);
106 return m_storage.emplace(tag, content).first;
std::shared_ptr< T > put(const InputTag &tag, Args &&... args)
Allocate a new block in the memory pool.
A class representing a value produced by a module.