Skip to content
Snippets Groups Projects
Commit ae0ffe75 authored by Jyoti Prakash Biswal's avatar Jyoti Prakash Biswal
Browse files

Solution to missing move assignment operator!

move_ptr added.

Coverity issue# 113615
parent a7745206
No related branches found
No related tags found
No related merge requests found
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
*/
///////////////////////////////////////////////////////////////////
......@@ -64,6 +64,12 @@ namespace Trk{
//! virtual constructor, not absolutely needed but given for EDM symmetry
virtual PseudoMeasurementOnTrack* clone() const override;
//! move constructor
PseudoMeasurementOnTrack(PseudoMeasurementOnTrack&& pmot);
//! move assignment operator
PseudoMeasurementOnTrack& operator=(PseudoMeasurementOnTrack&& pmot);
//! returns the surface for the local to global transformation (interface from MeasurementBase)
virtual const Surface& associatedSurface() const override;
......
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
*/
///////////////////////////////////////////////////////////////////
......@@ -15,6 +15,16 @@
#include <typeinfo>
namespace {
// helper to move pointer and set source to nullptr
template <class T>
T move_ptr(T &src) {
T tmp = src;
src = nullptr;
return tmp;
}
}
Trk::PseudoMeasurementOnTrack::PseudoMeasurementOnTrack(const LocalParameters& locpars,
const Amg::MatrixX& locerr,
......@@ -57,6 +67,14 @@ Trk::PseudoMeasurementOnTrack::PseudoMeasurementOnTrack( const Trk::PseudoMeasur
m_globalPosition(0)
{}
// move constructor:
Trk::PseudoMeasurementOnTrack::PseudoMeasurementOnTrack(Trk::PseudoMeasurementOnTrack&& pmot) :
Trk::MeasurementBase(pmot),
m_associatedSurface(move_ptr(pmot.m_associatedSurface)),
m_globalPosition(move_ptr(pmot.m_globalPosition))
{}
// assignment operator:
Trk::PseudoMeasurementOnTrack& Trk::PseudoMeasurementOnTrack::operator=(const PseudoMeasurementOnTrack& pmot)
{
......@@ -72,6 +90,22 @@ Trk::PseudoMeasurementOnTrack& Trk::PseudoMeasurementOnTrack::operator=(const Ps
return *this;
}
// move assignment operator:
Trk::PseudoMeasurementOnTrack& Trk::PseudoMeasurementOnTrack::operator=(PseudoMeasurementOnTrack&& pmot)
{
if ( &pmot != this) {
Trk::MeasurementBase::operator=(pmot);
if (m_associatedSurface && m_associatedSurface->isFree())
delete m_associatedSurface;
m_associatedSurface = move_ptr(pmot.m_associatedSurface);
delete m_globalPosition;
m_globalPosition = move_ptr(pmot.m_globalPosition);
}
return *this;
}
const Amg::Vector3D& Trk::PseudoMeasurementOnTrack::globalPosition() const
{
if (m_globalPosition == 0) {m_globalPosition = new Amg::Vector3D(m_associatedSurface->center());}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment