Follow-up from "Draft: Newly Created Sink algorithm (Phoenix)"
Greetings,
As Mr. Gerhard stated that the following is a generic proposal and not to be implemented in particular for the !3241 (merged) MR I thought it would be a good idea to address it as an issue so everyone else can have a look on it.
In case I'm mistaken please do excuse me and close this issue.
The following discussion from !3241 (merged) should be addressed:
-
@graven started a discussion: not for this MR, but more generic: I don't like having to write a destructor for some data member -- that should be done 'once and for all'. In this case, I would propose the introduction of a type-erased handle class along the lines of:
namespace Gaudi::Monitoring { class Hub { // Hub code goes here... class Handle { Hub* m_hub = nullptr; void *m_ent = nullptr; void (*m_remove)(Hub*, void*) = nullptr; public: template <typename T> Handle( Hub* hub, std::string c, std::string n, std::string t, T& ent ) : m_hub{hub} , m_ent{ &ent } , m_remove{ [](Hub* hub, void *ptr) { hub->removeEntity( static_cast<T&>(*ptr); } { m_hub->registerEntity( std::move(c), std::move(n), std::move(t), ent) } ~Handle() { if (m_remove) m_remove(m_hub, m_ent); } }; }; }
so that the above (and other bits of code like it!) can simply be written as:
Gaudi::Monitoring::Hub::Handle m_monitoringHub; /// registering the Store Entity to the monitoring Hub template <typename OWNER> Store( OWNER* o, std::string name, std::string storeType ) : m_monitoringHub{ &o->serviceLocator()->monitoringHub(), o->name(), std::move(name), std::move(storeType), *this } { } ~Store() = default; // better yet: just remove this line!