Skip to content

Commit

Permalink
STYLE: Remove this->MakeOutput(0) calls from constructors in Core
Browse files Browse the repository at this point in the history
In those cases, `MakeOutput(0)` just did `OutputType::New()` anyway. This commit
avoids unnecessary casts and calls to virtual functions.

Following C++ Core Guidelines, February 15, 2024, "Don’t call virtual functions
in constructors and destructors",
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-ctor-virtual
  • Loading branch information
N-Dekker committed May 10, 2024
1 parent 28de861 commit 6124014
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 13 deletions.
5 changes: 1 addition & 4 deletions Modules/Core/Common/include/itkImageSource.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,8 @@ namespace itk
template <typename TOutputImage>
ImageSource<TOutputImage>::ImageSource()
{
// Create the output. We use static_cast<> here because we know the default
// output must be of type TOutputImage
typename TOutputImage::Pointer output = static_cast<TOutputImage *>(this->MakeOutput(0).GetPointer());
this->ProcessObject::SetNumberOfRequiredOutputs(1);
this->ProcessObject::SetNthOutput(0, output.GetPointer());
this->ProcessObject::SetNthOutput(0, TOutputImage::New().GetPointer());

#if defined(ITKV4_COMPATIBILITY)
m_DynamicMultiThreading = false;
Expand Down
5 changes: 1 addition & 4 deletions Modules/Core/Mesh/include/itkImageToMeshFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ template <typename TInputImage, typename TOutputMesh>
ImageToMeshFilter<TInputImage, TOutputMesh>::ImageToMeshFilter()
{
this->ProcessObject::SetNumberOfRequiredInputs(1);

OutputMeshPointer output = dynamic_cast<OutputMeshType *>(this->MakeOutput(0).GetPointer());

this->ProcessObject::SetNumberOfRequiredOutputs(1);
this->ProcessObject::SetNthOutput(0, output.GetPointer());
this->ProcessObject::SetNthOutput(0, OutputMeshType::New().GetPointer());
}

/**
Expand Down
6 changes: 1 addition & 5 deletions Modules/Core/Mesh/include/itkMeshSource.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@ namespace itk
template <typename TOutputMesh>
MeshSource<TOutputMesh>::MeshSource()
{
// Create the output. We use static_cast<> here because we know the default
// output must be of type TOutputMesh
OutputMeshPointer output = static_cast<TOutputMesh *>(this->MakeOutput(0).GetPointer());

this->ProcessObject::SetNumberOfRequiredOutputs(1);
this->ProcessObject::SetNthOutput(0, output.GetPointer());
this->ProcessObject::SetNthOutput(0, TOutputMesh::New().GetPointer());

m_GenerateDataRegion = 0;
m_GenerateDataNumberOfRegions = 0;
Expand Down

0 comments on commit 6124014

Please sign in to comment.