Skip to content

Commit

Permalink
STYLE: Replace T * p; p = x with T * p = x, initializing pointers
Browse files Browse the repository at this point in the history
Using Notepad++, Replace in Files, doing:

    Find what: ^( [ ]+)([^ ].*\*)([ ]+)(\w+);[\r\n]+\1\4\ =
    Replace with: $1$2$3$4 =
    Filters: itk*.*
    Directory: D:\src\ITK\Modules
    [v] Match case
    (*) Regular expression

Manually excluded an unrelated case from "itkMINCImageIO.cxx" (`_sep = -_sep`),
which accidentally matched the regular expression.

- Follow-up to pull request #4932
commit 5b121f4 "STYLE: Replace `T var; var = x`
with `T var = x` for arithmetic types"
  • Loading branch information
N-Dekker authored and hjmjohnson committed Nov 7, 2024
1 parent 1fbb7e6 commit 187dda5
Show file tree
Hide file tree
Showing 35 changed files with 49 additions and 112 deletions.
3 changes: 1 addition & 2 deletions Modules/Core/Common/test/itkLoggerManagerTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ itkLoggerManagerTest(int argc, char * argv[])
manager->Write(itk::Logger::PriorityLevelEnum::FATAL, "This is the FATAL message.\n");
manager->Write(itk::LoggerBase::PriorityLevelEnum::MUSTFLUSH, "This is the MUSTFLUSH message.\n");
std::cout << " Message #3" << std::endl;
itk::Logger * pLogger;
pLogger = manager->GetLogger("org.itk.logTester.logger");
itk::Logger * pLogger = manager->GetLogger("org.itk.logTester.logger");
if (pLogger == nullptr)
{
throw "LoggerManager::GetLogger() failed";
Expand Down
8 changes: 2 additions & 6 deletions Modules/Core/Common/test/itkSmartPointerGTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,7 @@ TEST(SmartPointer, ConvertingRegisterCount)
Derived1Pointer d1ptr = Derived1::New();
EXPECT_EQ(1, d1ptr->GetRegisterCount());

Derived1 * rptr;

rptr = d1ptr;
Derived1 * rptr = d1ptr;
EXPECT_EQ(1, d1ptr->GetRegisterCount());
EXPECT_TRUE(rptr != nullptr);
}
Expand All @@ -290,9 +288,7 @@ TEST(SmartPointer, ConvertingRegisterCount)
Derived1Pointer d1ptr = Derived1::New();
EXPECT_EQ(1, d1ptr->GetRegisterCount());

const Derived1 * rptr;

rptr = d1ptr;
const Derived1 * rptr = d1ptr;
EXPECT_EQ(1, d1ptr->GetRegisterCount());
EXPECT_TRUE(rptr != nullptr);
}
Expand Down
6 changes: 2 additions & 4 deletions Modules/Core/GPUCommon/src/itkGPUKernelManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ GPUKernelManager::LoadProgramFromFile(const char * filename, const char * cPream
// get error message size
clGetProgramBuildInfo(m_Program, m_Manager->GetDeviceId(0), CL_PROGRAM_BUILD_LOG, 0, nullptr, &paramValueSize);

char * paramValue;
paramValue = (char *)malloc(paramValueSize);
char * paramValue = (char *)malloc(paramValueSize);

// get error message
clGetProgramBuildInfo(
Expand Down Expand Up @@ -208,8 +207,7 @@ GPUKernelManager::LoadProgramFromString(const char * cSource, const char * cPrea
// get error message size
clGetProgramBuildInfo(m_Program, m_Manager->GetDeviceId(0), CL_PROGRAM_BUILD_LOG, 0, nullptr, &paramValueSize);

char * paramValue;
paramValue = (char *)malloc(paramValueSize);
char * paramValue = (char *)malloc(paramValueSize);

// get error message
clGetProgramBuildInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,7 @@ void
BSplineDecompositionImageFilter<TInputImage, TOutputImage>::EnlargeOutputRequestedRegion(DataObject * output)
{
// This filter requires all of the input image to be in the buffer
TOutputImage * imgData;

imgData = dynamic_cast<TOutputImage *>(output);
TOutputImage * imgData = dynamic_cast<TOutputImage *>(output);
if (imgData)
{
imgData->SetRequestedRegionToLargestPossibleRegion();
Expand Down
6 changes: 2 additions & 4 deletions Modules/Core/Mesh/include/itkBinaryMask3DMeshSource.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -1378,11 +1378,9 @@ BinaryMask3DMeshSource<TInputImage, TOutputMesh>::AddCells(unsigned char celltyp

typename TriCell::CellAutoPointer insertCell;
typename OutputMeshType::PointIdentifier tripoints[3];
unsigned char * tp;
tp = (unsigned char *)malloc(3 * sizeof(unsigned char));
unsigned char * tp = (unsigned char *)malloc(3 * sizeof(unsigned char));

IdentifierType * tpl;
tpl = (IdentifierType *)malloc(3 * sizeof(IdentifierType));
IdentifierType * tpl = (IdentifierType *)malloc(3 * sizeof(IdentifierType));

switch (static_cast<int>(celltype))
{
Expand Down
4 changes: 1 addition & 3 deletions Modules/Core/Mesh/include/itkSimplexMesh.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ template <typename TPixelType, unsigned int VDimension, typename TMeshTraits>
void
SimplexMesh<TPixelType, VDimension, TMeshTraits>::CopyInformation(const DataObject * data)
{
const Superclass * mesh;

mesh = dynamic_cast<const Superclass *>(data);
const Superclass * mesh = dynamic_cast<const Superclass *>(data);

if (mesh == nullptr)
{
Expand Down
3 changes: 1 addition & 2 deletions Modules/Core/SpatialObjects/include/itkSpatialObject.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -1211,8 +1211,7 @@ SpatialObject<TDimension>::CopyInformation(const DataObject * data)
Superclass::CopyInformation(data);

// Attempt to cast data to an ImageBase
const SpatialObject<TDimension> * soData;
soData = dynamic_cast<const SpatialObject<TDimension> *>(data);
const SpatialObject<TDimension> * soData = dynamic_cast<const SpatialObject<TDimension> *>(data);

if (soData == nullptr)
{
Expand Down
3 changes: 1 addition & 2 deletions Modules/Core/SpatialObjects/include/itkTubeSpatialObject.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ TubeSpatialObject<TDimension, TTubePointType>::CopyInformation(const DataObject
Superclass::CopyInformation(data);

// Attempt to cast data to an ImageBase
const TubeSpatialObject<TDimension> * soData;
soData = dynamic_cast<const TubeSpatialObject<TDimension> *>(data);
const TubeSpatialObject<TDimension> * soData = dynamic_cast<const TubeSpatialObject<TDimension> *>(data);

if (soData == nullptr)
{
Expand Down
3 changes: 1 addition & 2 deletions Modules/Core/TestKernel/include/itkRandomImageSource.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ template <typename TOutputImage>
void
RandomImageSource<TOutputImage>::GenerateOutputInformation()
{
TOutputImage * output;
output = this->GetOutput(0);
TOutputImage * output = this->GetOutput(0);

const typename TOutputImage::RegionType largestPossibleRegion(this->m_Size);
output->SetLargestPossibleRegion(largestPossibleRegion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,8 @@ ExtractSliceImageFilter<TInputImage, TOutputImage>::GenerateOutputInformation()
outputPtr->SetLargestPossibleRegion(m_OutputImageRegion);

// Set the output spacing and origin
const ImageBase<InputImageDimension> * phyData;

phyData = dynamic_cast<const ImageBase<InputImageDimension> *>(this->GetInput());
const ImageBase<InputImageDimension> * phyData =
dynamic_cast<const ImageBase<InputImageDimension> *>(this->GetInput());

if (phyData == nullptr)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ void
CurvatureFlowImageFilter<TInputImage, TOutputImage>::EnlargeOutputRequestedRegion(DataObject * ptr)
{
// convert DataObject pointer to OutputImageType pointer
OutputImageType * outputPtr;

outputPtr = dynamic_cast<OutputImageType *>(ptr);
OutputImageType * outputPtr = dynamic_cast<OutputImageType *>(ptr);

// get input image pointer
typename Superclass::InputImagePointer inputPtr = const_cast<InputImageType *>(this->GetInput());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ IsoContourDistanceImageFilter<TInputImage, TOutputImage>::EnlargeOutputRequested
{
// this filter requires the all of the output image to be in
// the buffer
TOutputImage * imgData;

imgData = dynamic_cast<TOutputImage *>(output);
TOutputImage * imgData = dynamic_cast<TOutputImage *>(output);
if (imgData)
{
imgData->SetRequestedRegionToLargestPossibleRegion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ FastMarchingImageFilter<TLevelSet, TSpeedImage>::EnlargeOutputRequestedRegion(Da
{
// enlarge the requested region of the output
// to the whole data set
TLevelSet * imgData;

imgData = dynamic_cast<TLevelSet *>(output);
TLevelSet * imgData = dynamic_cast<TLevelSet *>(output);
if (imgData)
{
imgData->SetRequestedRegionToLargestPossibleRegion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,8 @@ JoinSeriesImageFilter<TInputImage, TOutputImage>::GenerateOutputInformation()
outputPtr->SetLargestPossibleRegion(outputLargestPossibleRegion);

// Set the output spacing and origin
const ImageBase<InputImageDimension> * phyData;

phyData = dynamic_cast<const ImageBase<InputImageDimension> *>(this->GetInput());
const ImageBase<InputImageDimension> * phyData =
dynamic_cast<const ImageBase<InputImageDimension> *>(this->GetInput());

if (phyData)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ BSplineDownsampleImageFilter<TInputImage, TOutputImage, ResamplerType>::EnlargeO
{
// this filter requires the all of the output image to be in
// the buffer
TOutputImage * imgData;

imgData = dynamic_cast<TOutputImage *>(output);
TOutputImage * imgData = dynamic_cast<TOutputImage *>(output);
if (imgData)
{
imgData->SetRequestedRegionToLargestPossibleRegion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ BSplineUpsampleImageFilter<TInputImage, TOutputImage, ResamplerType>::EnlargeOut
{
// this filter requires the all of the output image to be in
// the buffer
TOutputImage * imgData;

imgData = dynamic_cast<TOutputImage *>(output);
TOutputImage * imgData = dynamic_cast<TOutputImage *>(output);
if (imgData)
{
imgData->SetRequestedRegionToLargestPossibleRegion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ setInt2DData(IntImageType2D::Pointer imgPtr)
bool
VerifyResultsHigherOrderSpline(ImageTypePtr2D ActualResults, double * ExpectedResults)
{
double * ERptr;
ERptr = ExpectedResults;
double * ERptr = ExpectedResults;

InputIterator ActualResultsIter(ActualResults, ActualResults->GetLargestPossibleRegion());
double percentErr = 0;
Expand All @@ -180,8 +179,7 @@ VerifyResultsHigherOrderSpline(ImageTypePtr2D ActualResults, double * ExpectedRe
bool
VerifyResults3rdOrderSpline(ImageTypePtr2D ActualResults, double * ExpectedResults)
{
double * ERptr;
ERptr = ExpectedResults;
double * ERptr = ExpectedResults;

InputIterator ActualResultsIter(ActualResults, ActualResults->GetLargestPossibleRegion());

Expand All @@ -202,8 +200,7 @@ VerifyResults3rdOrderSpline(ImageTypePtr2D ActualResults, double * ExpectedResul
bool
VerifyResults2ndOrderSpline(ImageTypePtr2D ActualResults, double * ExpectedResults)
{
double * ERptr;
ERptr = ExpectedResults;
double * ERptr = ExpectedResults;

InputIterator ActualResultsIter(ActualResults, ActualResults->GetLargestPossibleRegion());
double percentErr = 0;
Expand Down Expand Up @@ -231,8 +228,7 @@ VerifyResults2ndOrderSpline(ImageTypePtr2D ActualResults, double * ExpectedResul
bool
VerifyResultsLowerOrderSpline(ImageTypePtr2D ActualResults, double * ExpectedResults)
{
double * ERptr;
ERptr = ExpectedResults;
double * ERptr = ExpectedResults;

InputIterator ActualResultsIter(ActualResults, ActualResults->GetLargestPossibleRegion());
double percentErr = 0;
Expand Down
3 changes: 1 addition & 2 deletions Modules/IO/GDCM/src/itkGDCMImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,7 @@ GDCMImageIO::InternalReadImageInformation()
break;
default:
{
const double * sp;
sp = image.GetSpacing();
const double * sp = image.GetSpacing();
spacing[0] = sp[0];
spacing[1] = sp[1];
spacing[2] = sp[2];
Expand Down
6 changes: 2 additions & 4 deletions Modules/IO/Stimulate/src/itkStimulateImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,7 @@ StimulateImageIO::InternalReadImageInformation(std::ifstream & file)
// This is a bit tricky to get the value as there is sometime no white
// space
// only a ':' separate field from value, we assume there is no other ':'
char * pch;
pch = strchr(line, ':');
char * pch = strchr(line, ':');
sscanf(++pch, "%s", m_FidName); // delete any white space left
itkDebugMacro("fidName was specified");
}
Expand All @@ -376,8 +375,7 @@ StimulateImageIO::InternalReadImageInformation(std::ifstream & file)
// This is a bit tricky to get the value as there is sometime no white
// space
// only a ':' separate field from value, we assume there is no other ':'
char * pch;
pch = strchr(line, ':');
char * pch = strchr(line, ':');
sscanf(++pch, "%s", m_SdtOrient); // delete any white space left
itkDebugMacro("Orientation was specified");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,7 @@ LabelGeometryImageFilterTest(std::string labelImageName,
writer->SetFileName(outputFileName);
writer->SetInput(&matrix);
writer->SetColumnHeaders(columnName);
MatrixType * matrixPointer;
matrixPointer = new MatrixType(matrix.data_block(), numberOfLabels, numberOfColumns);
MatrixType * matrixPointer = new MatrixType(matrix.data_block(), numberOfLabels, numberOfColumns);
writer->SetInput(matrixPointer);

ITK_TRY_EXPECT_NO_EXCEPTION(writer->Write());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ LinearSystemWrapperDenseVNL::Solve()
void
LinearSystemWrapperDenseVNL::SwapMatrices(unsigned int MatrixIndex1, unsigned int MatrixIndex2)
{
vnl_matrix<Float> * tmp;
tmp = (*m_Matrices)[MatrixIndex1];
vnl_matrix<Float> * tmp = (*m_Matrices)[MatrixIndex1];
(*m_Matrices)[MatrixIndex1] = (*m_Matrices)[MatrixIndex2];
(*m_Matrices)[MatrixIndex2] = tmp;
}
Expand All @@ -209,8 +208,7 @@ LinearSystemWrapperDenseVNL::SwapVectors(unsigned int VectorIndex1, unsigned int
void
LinearSystemWrapperDenseVNL::SwapSolutions(unsigned int SolutionIndex1, unsigned int SolutionIndex2)
{
vnl_vector<Float> * tmp;
tmp = (*m_Solutions)[SolutionIndex1];
vnl_vector<Float> * tmp = (*m_Solutions)[SolutionIndex1];
(*m_Solutions)[SolutionIndex1] = (*m_Solutions)[SolutionIndex2];
(*m_Solutions)[SolutionIndex2] = tmp;
}
Expand Down
9 changes: 3 additions & 6 deletions Modules/Numerics/FEM/src/itkFEMLinearSystemWrapperVNL.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -224,26 +224,23 @@ LinearSystemWrapperVNL::Solve()
void
LinearSystemWrapperVNL::SwapMatrices(unsigned int MatrixIndex1, unsigned int MatrixIndex2)
{
vnl_sparse_matrix<Float> * tmp;
tmp = (*m_Matrices)[MatrixIndex1];
vnl_sparse_matrix<Float> * tmp = (*m_Matrices)[MatrixIndex1];
(*m_Matrices)[MatrixIndex1] = (*m_Matrices)[MatrixIndex2];
(*m_Matrices)[MatrixIndex2] = tmp;
}

void
LinearSystemWrapperVNL::SwapVectors(unsigned int VectorIndex1, unsigned int VectorIndex2)
{
vnl_vector<Float> * tmp;
tmp = (*m_Vectors)[VectorIndex1];
vnl_vector<Float> * tmp = (*m_Vectors)[VectorIndex1];
(*m_Vectors)[VectorIndex1] = (*m_Vectors)[VectorIndex2];
(*m_Vectors)[VectorIndex2] = tmp;
}

void
LinearSystemWrapperVNL::SwapSolutions(unsigned int SolutionIndex1, unsigned int SolutionIndex2)
{
vnl_vector<Float> * tmp;
tmp = (*m_Solutions)[SolutionIndex1];
vnl_vector<Float> * tmp = (*m_Solutions)[SolutionIndex1];
(*m_Solutions)[SolutionIndex1] = (*m_Solutions)[SolutionIndex2];
(*m_Solutions)[SolutionIndex2] = tmp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ ScalarImageToRunLengthFeaturesFilter<TImage, THistogramFrequencyContainer>::Full
{
size_t numOffsets = this->m_Offsets->size();
size_t numFeatures = this->m_RequestedFeatures->size();
double ** features;

features = new double *[numOffsets];
double ** features = new double *[numOffsets];
for (size_t i = 0; i < numOffsets; ++i)
{
features[i] = new double[numFeatures];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ ScalarImageToTextureFeaturesFilter<TImageType, THistogramFrequencyContainer, TMa
{
size_t numOffsets = m_Offsets->size();
size_t numFeatures = m_RequestedFeatures->size();
double ** features;

features = new double *[numOffsets];
double ** features = new double *[numOffsets];
for (size_t i = 0; i < numOffsets; ++i)
{
features[i] = new double[numFeatures];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ itkGPUDemonsRegistrationFilterTest2(int argc, char * argv[])
registrator->UseMovingImageGradientOff();

using FunctionType = RegistrationType::GPUDemonsRegistrationFunctionType;
FunctionType * fptr;
fptr = dynamic_cast<FunctionType *>(registrator->GetDifferenceFunction().GetPointer());
FunctionType * fptr = dynamic_cast<FunctionType *>(registrator->GetDifferenceFunction().GetPointer());
if (!fptr)
{
std::cout << "Invalid demons registration function ptr" << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,7 @@ MultiResolutionPDEDeformableRegistration<TFixedImage,
Superclass::EnlargeOutputRequestedRegion(ptr);

// set the output requested region to largest possible.
DisplacementFieldType * outputPtr;
outputPtr = dynamic_cast<DisplacementFieldType *>(ptr);
DisplacementFieldType * outputPtr = dynamic_cast<DisplacementFieldType *>(ptr);

if (outputPtr)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ itkCurvatureRegistrationFilterTest(int, char *[])

std::cout << "\n\n\nPrinting function" << std::endl;
using FunctionType = RegistrationType::RegistrationFunctionType;
FunctionType * fptr;
fptr = dynamic_cast<FunctionType *>(registrator->GetDifferenceFunction().GetPointer());
FunctionType * fptr = dynamic_cast<FunctionType *>(registrator->GetDifferenceFunction().GetPointer());
fptr->Print(std::cout);

// exercise other member variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@ itkDiffeomorphicDemonsRegistrationFilterTest(int argc, char * argv[])
registrator->InPlaceOn();


FunctionType * fptr;
fptr = dynamic_cast<FunctionType *>(registrator->GetDifferenceFunction().GetPointer());
FunctionType * fptr = dynamic_cast<FunctionType *>(registrator->GetDifferenceFunction().GetPointer());
fptr->Print(std::cout);

// exercise other member variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ itkDiffeomorphicDemonsRegistrationFilterTest2(int argc, char * argv[])
registrator->InPlaceOn();


FunctionType * fptr;
fptr = dynamic_cast<FunctionType *>(registrator->GetDifferenceFunction().GetPointer());
FunctionType * fptr = dynamic_cast<FunctionType *>(registrator->GetDifferenceFunction().GetPointer());
fptr->Print(std::cout);

// exercise other member variables
Expand Down
Loading

0 comments on commit 187dda5

Please sign in to comment.