Skip to content

Commit

Permalink
Fix cloning to behave the same as other generated types
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Jul 17, 2024
1 parent 00b36e0 commit c49d0af
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions include/podio/detail/Association.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ class AssociationT {
using collection_type = podio::AssociationCollection<FromT, ToT>;

/// Constructor
AssociationT() : m_obj(new AssociationObjT(), podio::utils::MarkOwned) {
AssociationT() : m_obj(new AssociationObjT{}, podio::utils::MarkOwned) {
}

/// Constructor with weight
AssociationT(float weight) : m_obj(new AssociationObjT(), podio::utils::MarkOwned) {
AssociationT(float weight) : m_obj(new AssociationObjT{}, podio::utils::MarkOwned) {
m_obj->weight = weight;
}

Expand All @@ -66,9 +66,17 @@ class AssociationT {
/// Create a mutable deep-copy with identical relations
template <typename FromU = FromT, typename ToU = ToT,
typename = std::enable_if_t<std::is_same_v<FromU, FromT> && std::is_same_v<ToU, ToT>>>
MutableAssociation<FromU, ToU> clone() const {
return MutableAssociation<FromU, ToU>(
podio::utils::MaybeSharedPtr(new AssociationObjT(*m_obj), podio::utils::MarkOwned));
MutableAssociation<FromU, ToU> clone(bool cloneRelations = true) const {
auto tmp = new AssociationObjT(podio::ObjectID{}, m_obj->weight);
if (cloneRelations) {
if (m_obj->m_from) {
tmp->m_from = new FromT(*m_obj->m_from);
}
if (m_obj->m_to) {
tmp->m_to = new ToT(*m_obj->m_to);
}
}
return MutableAssociation<FromU, ToU>(podio::utils::MaybeSharedPtr(tmp, podio::utils::MarkOwned));
}

static Association<FromT, ToT> makeEmpty() {
Expand Down

0 comments on commit c49d0af

Please sign in to comment.