From 5c409553669fb6de9bef920cdf5aac9041d0935b Mon Sep 17 00:00:00 2001 From: tmadlener Date: Wed, 25 Sep 2024 16:21:18 +0200 Subject: [PATCH] Switch to unique_ptrs for managing the related objects --- include/podio/detail/Link.h | 10 ++++------ include/podio/detail/LinkObj.h | 12 ++++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/include/podio/detail/Link.h b/include/podio/detail/Link.h index b2730769e..e75f7ca79 100644 --- a/include/podio/detail/Link.h +++ b/include/podio/detail/Link.h @@ -92,10 +92,10 @@ class LinkT { auto tmp = new LinkObjT(podio::ObjectID{}, m_obj->data); if (cloneRelations) { if (m_obj->m_from) { - tmp->m_from = new FromT(*m_obj->m_from); + tmp->m_from = std::make_unique(*m_obj->m_from); } if (m_obj->m_to) { - tmp->m_to = new ToT(*m_obj->m_to); + tmp->m_to = std::make_unique(*m_obj->m_to); } } return MutableLink(podio::utils::MaybeSharedPtr(tmp, podio::utils::MarkOwned)); @@ -139,8 +139,7 @@ class LinkT { detail::isDefaultHandleType, int> = 0> void setFrom(FromU value) { - delete m_obj->m_from; - m_obj->m_from = new detail::GetDefaultHandleType(value); + m_obj->m_from = std::make_unique>(value); } /// Set the related-from object @@ -184,8 +183,7 @@ class LinkT { detail::isDefaultHandleType, int> = 0> void setTo(ToU value) { - delete m_obj->m_to; - m_obj->m_to = new detail::GetDefaultHandleType(value); + m_obj->m_to = std::make_unique>(value); } /// Set the related-to object diff --git a/include/podio/detail/LinkObj.h b/include/podio/detail/LinkObj.h index 9cf0525ac..ef1860514 100644 --- a/include/podio/detail/LinkObj.h +++ b/include/podio/detail/LinkObj.h @@ -5,6 +5,8 @@ #include "podio/ObjectID.h" +#include + namespace podio { template @@ -36,16 +38,14 @@ class LinkObj { LinkObj& operator=(const LinkObj&) = delete; /// Destructor - ~LinkObj() { - delete m_from; - delete m_to; - } + ~LinkObj() = default; public: podio::ObjectID id{}; LinkData data{1.0f}; - FromT* m_from{nullptr}; - ToT* m_to{nullptr}; + + std::unique_ptr m_from{nullptr}; + std::unique_ptr m_to{nullptr}; }; } // namespace podio