Skip to content

Commit

Permalink
STYLE: Declare two private data members of itk::Object as unique_ptr
Browse files Browse the repository at this point in the history
Declared both `m_SubjectImplementation` and `m_MetaDataDictionary` as an
`std::unique_ptr`.
  • Loading branch information
N-Dekker authored and dzenanz committed Sep 20, 2022
1 parent 12d13f6 commit 5daed92
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 4 additions & 2 deletions Modules/Core/Common/include/itkObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "itkSingletonMacro.h"

#include <functional>
#include <memory> // For unique_ptr.

namespace itk
{
Expand Down Expand Up @@ -273,15 +274,16 @@ class ITKCommon_EXPORT Object : public LightObject

/** Implementation class for Subject/Observer Pattern.
* This is only allocated if used. */
SubjectImplementation * m_SubjectImplementation{ nullptr };
std::unique_ptr<SubjectImplementation> m_SubjectImplementation{ nullptr };

/**
* Implementation for holding Object MetaData
* @see itk::MetaDataDictionary
* @see itk::MetaDataObjectBase
* @see itk::MetaDataObject
* This is only allocated if used.
*/
mutable MetaDataDictionary * m_MetaDataDictionary{ nullptr };
mutable std::unique_ptr<MetaDataDictionary> m_MetaDataDictionary{ nullptr };

std::string m_ObjectName;
};
Expand Down
14 changes: 6 additions & 8 deletions Modules/Core/Common/src/itkObject.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ Object::AddObserver(const EventObject & event, Command * cmd)
{
if (!this->m_SubjectImplementation)
{
this->m_SubjectImplementation = new SubjectImplementation;
this->m_SubjectImplementation = std::make_unique<SubjectImplementation>();
}
return this->m_SubjectImplementation->AddObserver(event, cmd);
}
Expand All @@ -489,7 +489,7 @@ Object::AddObserver(const EventObject & event, Command * cmd) const
if (!this->m_SubjectImplementation)
{
auto * me = const_cast<Self *>(this);
me->m_SubjectImplementation = new SubjectImplementation;
me->m_SubjectImplementation = std::make_unique<SubjectImplementation>();
}
return this->m_SubjectImplementation->AddObserver(event, cmd);
}
Expand Down Expand Up @@ -583,8 +583,6 @@ Object::Object()
Object::~Object()
{
itkDebugMacro(<< "Destructing!");
delete m_SubjectImplementation;
delete m_MetaDataDictionary;
}

/**
Expand All @@ -611,7 +609,7 @@ Object::GetMetaDataDictionary()
{
if (m_MetaDataDictionary == nullptr)
{
m_MetaDataDictionary = new MetaDataDictionary;
m_MetaDataDictionary = std::make_unique<MetaDataDictionary>();
}
return *m_MetaDataDictionary;
}
Expand All @@ -621,7 +619,7 @@ Object::GetMetaDataDictionary() const
{
if (m_MetaDataDictionary == nullptr)
{
m_MetaDataDictionary = new MetaDataDictionary;
m_MetaDataDictionary = std::make_unique<MetaDataDictionary>();
}
return *m_MetaDataDictionary;
}
Expand All @@ -631,7 +629,7 @@ Object::SetMetaDataDictionary(const MetaDataDictionary & rhs)
{
if (m_MetaDataDictionary == nullptr)
{
m_MetaDataDictionary = new MetaDataDictionary(rhs);
m_MetaDataDictionary = std::make_unique<MetaDataDictionary>(rhs);
return;
}
*m_MetaDataDictionary = rhs;
Expand All @@ -642,7 +640,7 @@ Object::SetMetaDataDictionary(MetaDataDictionary && rrhs)
{
if (m_MetaDataDictionary == nullptr)
{
m_MetaDataDictionary = new MetaDataDictionary(std::move(rrhs));
m_MetaDataDictionary = std::make_unique<MetaDataDictionary>(std::move(rrhs));
return;
}
*m_MetaDataDictionary = std::move(rrhs);
Expand Down

0 comments on commit 5daed92

Please sign in to comment.