Skip to content

Commit

Permalink
Switch to unique_ptrs for managing the related objects
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Sep 25, 2024
1 parent a8bcf4a commit 5c40955
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
10 changes: 4 additions & 6 deletions include/podio/detail/Link.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<FromT>(*m_obj->m_from);
}
if (m_obj->m_to) {
tmp->m_to = new ToT(*m_obj->m_to);
tmp->m_to = std::make_unique<ToT>(*m_obj->m_to);
}
}
return MutableLink<FromU, ToU>(podio::utils::MaybeSharedPtr(tmp, podio::utils::MarkOwned));
Expand Down Expand Up @@ -139,8 +139,7 @@ class LinkT {
detail::isDefaultHandleType<FromU>,
int> = 0>
void setFrom(FromU value) {
delete m_obj->m_from;
m_obj->m_from = new detail::GetDefaultHandleType<FromU>(value);
m_obj->m_from = std::make_unique<detail::GetDefaultHandleType<FromU>>(value);
}

/// Set the related-from object
Expand Down Expand Up @@ -184,8 +183,7 @@ class LinkT {
detail::isDefaultHandleType<ToU>,
int> = 0>
void setTo(ToU value) {
delete m_obj->m_to;
m_obj->m_to = new detail::GetDefaultHandleType<ToU>(value);
m_obj->m_to = std::make_unique<detail::GetDefaultHandleType<ToU>>(value);
}

/// Set the related-to object
Expand Down
12 changes: 6 additions & 6 deletions include/podio/detail/LinkObj.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "podio/ObjectID.h"

#include <memory>

namespace podio {

template <typename FromT, typename ToT>
Expand Down Expand Up @@ -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<FromT> m_from{nullptr};
std::unique_ptr<ToT> m_to{nullptr};
};

} // namespace podio
Expand Down

0 comments on commit 5c40955

Please sign in to comment.