Skip to content

Commit

Permalink
STYLE: Use auto * to declare variables initialized by pointer cast
Browse files Browse the repository at this point in the history
Using Notepad++, Replace in Files, doing:

    Find what: ^( [ ]+const )([^ ].*\*)([ ]+)(\w+ = [a-z]+_cast<const \2>)
    Find what: ^( [ ]+const )([^ ].*\*)([ ]+)(\w+ =\r\n   [ ]+[a-z]+_cast<const \2>)
    Find what: ^( [ ]+)([^ ].*\*)([ ]+)(\w+ = [a-z]+_cast<\2>)
    Replace with: $1auto *$3$4
    Filters: itk*.*
    Directory: D:\src\ITK\Modules
    [v] Match case
    (*) Regular expression

Equivalent to clang-tidy `modernize-use-auto`, for variables of a pointer type:
https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-auto.html#cast-expressions
  • Loading branch information
N-Dekker committed Nov 7, 2024
1 parent d235d8b commit a25c1f2
Show file tree
Hide file tree
Showing 32 changed files with 40 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Modules/Core/GPUCommon/include/itkGPUImage.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ template <typename TPixel, unsigned int VImageDimension>
void
GPUImage<TPixel, VImageDimension>::Graft(const DataObject * data)
{
const Self * ptr = dynamic_cast<const Self *>(data);
const auto * ptr = dynamic_cast<const Self *>(data);
if (ptr)
{
this->Graft(ptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ void
BSplineDecompositionImageFilter<TInputImage, TOutputImage>::EnlargeOutputRequestedRegion(DataObject * output)
{
// This filter requires all of the input image to be in the buffer
TOutputImage * imgData = dynamic_cast<TOutputImage *>(output);
auto * imgData = dynamic_cast<TOutputImage *>(output);
if (imgData)
{
imgData->SetRequestedRegionToLargestPossibleRegion();
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Mesh/include/itkSimplexMesh.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ template <typename TPixelType, unsigned int VDimension, typename TMeshTraits>
void
SimplexMesh<TPixelType, VDimension, TMeshTraits>::CopyInformation(const DataObject * data)
{
const Superclass * mesh = dynamic_cast<const Superclass *>(data);
const auto * mesh = dynamic_cast<const Superclass *>(data);

if (mesh == nullptr)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ template <unsigned int VDimension, typename PixelType, typename TSpatialObjectTy
auto
MetaImageConverter<VDimension, PixelType, TSpatialObjectType>::CreateMetaObject() -> MetaObjectType *
{
MetaObjectType * mo = dynamic_cast<MetaObjectType *>(new ImageMetaObjectType);
auto * mo = dynamic_cast<MetaObjectType *>(new ImageMetaObjectType);
mo->APIVersion(1);
mo->FileFormatVersion(1);
return mo;
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/SpatialObjects/include/itkSpatialObject.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ SpatialObject<TDimension>::CopyInformation(const DataObject * data)
Superclass::CopyInformation(data);

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

if (soData == nullptr)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ TubeSpatialObject<TDimension, TTubePointType>::CopyInformation(const DataObject
Superclass::CopyInformation(data);

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

if (soData == nullptr)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ ExtractSliceImageFilter<TInputImage, TOutputImage>::GenerateOutputInformation()
outputPtr->SetLargestPossibleRegion(m_OutputImageRegion);

// Set the output spacing and origin
const ImageBase<InputImageDimension> * phyData =
dynamic_cast<const ImageBase<InputImageDimension> *>(this->GetInput());
const auto * 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,7 +95,7 @@ void
CurvatureFlowImageFilter<TInputImage, TOutputImage>::EnlargeOutputRequestedRegion(DataObject * ptr)
{
// convert DataObject pointer to OutputImageType pointer
OutputImageType * outputPtr = dynamic_cast<OutputImageType *>(ptr);
auto * 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,7 +80,7 @@ IsoContourDistanceImageFilter<TInputImage, TOutputImage>::EnlargeOutputRequested
{
// this filter requires the all of the output image to be in
// the buffer
TOutputImage * imgData = dynamic_cast<TOutputImage *>(output);
auto * imgData = dynamic_cast<TOutputImage *>(output);
if (imgData)
{
imgData->SetRequestedRegionToLargestPossibleRegion();
Expand Down Expand Up @@ -126,7 +126,7 @@ IsoContourDistanceImageFilter<TInputImage, TOutputImage>::ThreaderFullCallback(v
ThreadIdType workUnitCount = workUnitInfo->NumberOfWorkUnits;
using FilterStruct = typename ImageSource<TOutputImage>::ThreadStruct;
auto * str = (FilterStruct *)(workUnitInfo->UserData);
Self * filter = static_cast<Self *>(str->Filter.GetPointer());
auto * filter = static_cast<Self *>(str->Filter.GetPointer());

// execute the actual method with appropriate output region
// first find out how many pieces extent can be split into.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ template <typename TInputImage, typename TOutputImage>
void
ComplexToComplex1DFFTImageFilter<TInputImage, TOutputImage>::EnlargeOutputRequestedRegion(DataObject * output)
{
OutputImageType * outputPtr = dynamic_cast<OutputImageType *>(output);
auto * outputPtr = dynamic_cast<OutputImageType *>(output);

// we need to enlarge the region in the fft direction to the
// largest possible in that direction
Expand Down
4 changes: 2 additions & 2 deletions Modules/Filtering/FFT/include/itkForward1DFFTImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Forward1DFFTImageFilter<TInputImage, TOutputImage>::GenerateInputRequestedRegion
Superclass::GenerateInputRequestedRegion();

// get pointers to the inputs
InputImageType * input = const_cast<InputImageType *>(this->GetInput());
auto * input = const_cast<InputImageType *>(this->GetInput());
OutputImageType * output = this->GetOutput();

// we need to compute the input requested region (size and start index)
Expand Down Expand Up @@ -68,7 +68,7 @@ template <typename TInputImage, typename TOutputImage>
void
Forward1DFFTImageFilter<TInputImage, TOutputImage>::EnlargeOutputRequestedRegion(DataObject * out)
{
OutputImageType * output = dynamic_cast<OutputImageType *>(out);
auto * output = dynamic_cast<OutputImageType *>(out);

// we need to enlarge the region in the fft direction to the
// largest possible in that direction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ template <typename TInputImage, typename TOutputImage>
void
Inverse1DFFTImageFilter<TInputImage, TOutputImage>::EnlargeOutputRequestedRegion(DataObject * out)
{
OutputImageType * output = dynamic_cast<OutputImageType *>(out);
auto * output = dynamic_cast<OutputImageType *>(out);

// we need to enlarge the region in the fft direction to the
// largest possible in that direction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ FastMarchingImageFilter<TLevelSet, TSpeedImage>::EnlargeOutputRequestedRegion(Da
{
// enlarge the requested region of the output
// to the whole data set
TLevelSet * imgData = dynamic_cast<TLevelSet *>(output);
auto * imgData = dynamic_cast<TLevelSet *>(output);
if (imgData)
{
imgData->SetRequestedRegionToLargestPossibleRegion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ JoinSeriesImageFilter<TInputImage, TOutputImage>::GenerateOutputInformation()
outputPtr->SetLargestPossibleRegion(outputLargestPossibleRegion);

// Set the output spacing and origin
const ImageBase<InputImageDimension> * phyData =
dynamic_cast<const ImageBase<InputImageDimension> *>(this->GetInput());
const auto * 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,7 +153,7 @@ BSplineDownsampleImageFilter<TInputImage, TOutputImage, ResamplerType>::EnlargeO
{
// this filter requires the all of the output image to be in
// the buffer
TOutputImage * imgData = dynamic_cast<TOutputImage *>(output);
auto * imgData = dynamic_cast<TOutputImage *>(output);
if (imgData)
{
imgData->SetRequestedRegionToLargestPossibleRegion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ BSplineUpsampleImageFilter<TInputImage, TOutputImage, ResamplerType>::EnlargeOut
{
// this filter requires the all of the output image to be in
// the buffer
TOutputImage * imgData = dynamic_cast<TOutputImage *>(output);
auto * imgData = dynamic_cast<TOutputImage *>(output);
if (imgData)
{
imgData->SetRequestedRegionToLargestPossibleRegion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ template <typename TInputImage>
void
ContourExtractor2DImageFilter<TInputImage>::GenerateInputRequestedRegion()
{
InputImageType * input = const_cast<InputImageType *>(this->GetInput());
auto * input = const_cast<InputImageType *>(this->GetInput());

if (!input)
{
Expand Down
6 changes: 3 additions & 3 deletions Modules/IO/GDCM/src/itkGDCMImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ GDCMImageIO::Read(void * pointer)

if (m_SingleBit)
{
const auto copy = make_unique_for_overwrite<unsigned char[]>(len);
unsigned char * t = reinterpret_cast<unsigned char *>(pointer);
size_t j = 0;
const auto copy = make_unique_for_overwrite<unsigned char[]>(len);
auto * t = reinterpret_cast<unsigned char *>(pointer);
size_t j = 0;
for (size_t i = 0; i < len / 8; ++i)
{
const unsigned char c = t[i];
Expand Down
2 changes: 1 addition & 1 deletion Modules/IO/TIFF/src/itkTIFFImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@ TIFFImageIO::ReadCurrentPage(void * buffer, size_t pixelOffset)
itkExceptionMacro("Cannot read TIFF image as a TIFF RGBA image");
}

unsigned char * out = static_cast<unsigned char *>(buffer) + pixelOffset;
auto * out = static_cast<unsigned char *>(buffer) + pixelOffset;
RGBAImageToBuffer<unsigned char>(out, tempImage);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ itkGPUDemonsRegistrationFilterTest2(int argc, char * argv[])
registrator->UseMovingImageGradientOff();

using FunctionType = RegistrationType::GPUDemonsRegistrationFunctionType;
FunctionType * fptr = dynamic_cast<FunctionType *>(registrator->GetDifferenceFunction().GetPointer());
auto * 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,7 +638,7 @@ MultiResolutionPDEDeformableRegistration<TFixedImage,
Superclass::EnlargeOutputRequestedRegion(ptr);

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

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

std::cout << "\n\n\nPrinting function" << std::endl;
using FunctionType = RegistrationType::RegistrationFunctionType;
FunctionType * fptr = dynamic_cast<FunctionType *>(registrator->GetDifferenceFunction().GetPointer());
auto * 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,7 +249,7 @@ itkDiffeomorphicDemonsRegistrationFilterTest(int argc, char * argv[])
registrator->InPlaceOn();


FunctionType * fptr = dynamic_cast<FunctionType *>(registrator->GetDifferenceFunction().GetPointer());
auto * 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,7 +154,7 @@ itkDiffeomorphicDemonsRegistrationFilterTest2(int argc, char * argv[])
registrator->InPlaceOn();


FunctionType * fptr = dynamic_cast<FunctionType *>(registrator->GetDifferenceFunction().GetPointer());
auto * 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 @@ -230,7 +230,7 @@ itkFastSymmetricForcesDemonsRegistrationFilterTest(int, char *[])
ITK_TEST_SET_GET_BOOLEAN(registrator, InPlace, inPlace);

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

using ProgressType = ShowProgressObject<RegistrationType>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void
KLMRegionGrowImageFilter<TInputImage, TOutputImage>::EnlargeOutputRequestedRegion(DataObject * output)
{
// This filter requires all of the output image to be in the buffer
TOutputImage * imgData = dynamic_cast<TOutputImage *>(output);
auto * imgData = dynamic_cast<TOutputImage *>(output);
imgData->SetRequestedRegionToLargestPossibleRegion();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ ReinitializeLevelSetImageFilter<TLevelSet>::EnlargeOutputRequestedRegion(DataObj
{
// this filter requires the all of the output image to be in
// the buffer
TLevelSet * imgData = dynamic_cast<TLevelSet *>(output);
auto * imgData = dynamic_cast<TLevelSet *>(output);
if (imgData)
{
imgData->SetRequestedRegionToLargestPossibleRegion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ MRFImageFilter<TInputImage, TClassifiedImage>::EnlargeOutputRequestedRegion(Data
{
// this filter requires that all of the output images
// are in the buffer
TClassifiedImage * imgData = dynamic_cast<TClassifiedImage *>(output);
auto * imgData = dynamic_cast<TClassifiedImage *>(output);
imgData->SetRequestedRegionToLargestPossibleRegion();
}

Expand Down
6 changes: 3 additions & 3 deletions Modules/Video/BridgeOpenCV/include/itkOpenCVImageBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class OpenCVImageBridge
checkMatchingTypes<TPixel, OutputPixelType>(outChannels);

// We only change current if it no longer points at in, so this is safe
IplImage * current = const_cast<IplImage *>(in);
auto * current = const_cast<IplImage *>(in);

bool freeCurrent = false;
if (inChannels == 3 && outChannels == 1)
Expand Down Expand Up @@ -248,7 +248,7 @@ class OpenCVImageBridge
out->SetSpacing(spacing);
out->Allocate();
size_t lineLength = imgWidth * inChannels * sizeof(TPixel);
void * unpaddedBuffer = reinterpret_cast<void *>(new TPixel[imgHeight * lineLength]);
auto * unpaddedBuffer = reinterpret_cast<void *>(new TPixel[imgHeight * lineLength]);
unsigned int paddedBufPos = 0;
unsigned int unpaddedBufPos = 0;

Expand Down Expand Up @@ -301,7 +301,7 @@ class OpenCVImageBridge

for (int r = 0; r < out->height; ++r)
{
ValueType * ptr = reinterpret_cast<ValueType *>(out->imageData + r * out->widthStep);
auto * ptr = reinterpret_cast<ValueType *>(out->imageData + r * out->widthStep);
for (int c = 0; c < out->width; ++c)
{
pixelIndex[0] = c;
Expand Down
2 changes: 1 addition & 1 deletion Modules/Video/BridgeOpenCV/src/itkOpenCVVideoIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ OpenCVVideoIO::Read(void * buffer)
this->UpdateReaderProperties();

// Put the frame's buffer into the supplied output buffer
void * tempBuffer = reinterpret_cast<void *>(this->m_CVImage->imageData);
auto * tempBuffer = reinterpret_cast<void *>(this->m_CVImage->imageData);
size_t bufferSize = this->m_CVImage->imageSize;
memcpy(buffer, tempBuffer, bufferSize);
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/Video/Core/include/itkVideoStream.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ VideoStream<TFrameType>::Allocate()
<< ". Call "
"InitializeEmptyFrames to prepare the frame buffer correctly.");
}
FrameType * frame = dynamic_cast<FrameType *>(m_DataObjectBuffer->GetBufferContents(i).GetPointer());
auto * frame = dynamic_cast<FrameType *>(m_DataObjectBuffer->GetBufferContents(i).GetPointer());
if (!frame)
{
itkExceptionMacro("itk::VideoStream::SetAllLargestPossibleSpatialRegions "
Expand Down
6 changes: 3 additions & 3 deletions Modules/Video/Core/src/itkTemporalDataObject.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ TemporalDataObject::CopyInformation(const DataObject * data)
// Standard call to the superclass' method
Superclass::CopyInformation(data);

const TemporalDataObject * temporalData = dynamic_cast<const TemporalDataObject *>(data);
const auto * temporalData = dynamic_cast<const TemporalDataObject *>(data);

if (temporalData)
{
Expand All @@ -291,7 +291,7 @@ TemporalDataObject::CopyInformation(const DataObject * data)
void
TemporalDataObject::Graft(const DataObject * data)
{
const TemporalDataObject * temporalData = dynamic_cast<const TemporalDataObject *>(data);
const auto * temporalData = dynamic_cast<const TemporalDataObject *>(data);

if (temporalData)
{
Expand Down Expand Up @@ -321,7 +321,7 @@ TemporalDataObject::Graft(const DataObject * data)
void
TemporalDataObject::SetRequestedRegion(const DataObject * data)
{
const TemporalDataObject * temporalData = dynamic_cast<const TemporalDataObject *>(data);
const auto * temporalData = dynamic_cast<const TemporalDataObject *>(data);

if (temporalData)
{
Expand Down

0 comments on commit a25c1f2

Please sign in to comment.