Skip to content

Commit

Permalink
STYLE: Remove initial << insertion from itkExceptionMacro(<< " calls
Browse files Browse the repository at this point in the history
Let the C++ preprocessor append the specified literal string to the error
message, instead of doing the equivalent `<<` insertion at run-time.

Aims to shorten the code a little bit, and improve consistency. The code base
already had more than 750 `itkExceptionMacro` calls that passed a literal
string directly, without having `<<` at its left side.
  • Loading branch information
N-Dekker authored and dzenanz committed Jun 1, 2023
1 parent 19079c8 commit 89beb04
Show file tree
Hide file tree
Showing 387 changed files with 1,418 additions and 1,394 deletions.
16 changes: 8 additions & 8 deletions Modules/Bridge/VTK/include/itkVTKImageExport.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ VTKImageExport<TInputImage>::VTKImageExport()
}
else
{
itkExceptionMacro(<< "Type currently not supported");
itkExceptionMacro("Type currently not supported");
}
}

Expand Down Expand Up @@ -141,7 +141,7 @@ VTKImageExport<TInputImage>::WholeExtentCallback()

if (!input)
{
itkExceptionMacro(<< "Need to set an input");
itkExceptionMacro("Need to set an input");
}

InputRegionType region = input->GetLargestPossibleRegion();
Expand Down Expand Up @@ -176,7 +176,7 @@ VTKImageExport<TInputImage>::SpacingCallback()

if (!input)
{
itkExceptionMacro(<< "Need to set an input");
itkExceptionMacro("Need to set an input");
}

const typename TInputImage::SpacingType & spacing = input->GetSpacing();
Expand Down Expand Up @@ -233,7 +233,7 @@ VTKImageExport<TInputImage>::OriginCallback()

if (!input)
{
itkExceptionMacro(<< "Need to set an input");
itkExceptionMacro("Need to set an input");
}

const typename TInputImage::PointType & origin = input->GetOrigin();
Expand Down Expand Up @@ -290,7 +290,7 @@ VTKImageExport<TInputImage>::DirectionCallback()

if (!input)
{
itkExceptionMacro(<< "Need to set an input");
itkExceptionMacro("Need to set an input");
}

const typename TInputImage::DirectionType & direction = input->GetDirection();
Expand Down Expand Up @@ -363,7 +363,7 @@ VTKImageExport<TInputImage>::PropagateUpdateExtentCallback(int * extent)
InputImagePointer input = this->GetInput();
if (!input)
{
itkExceptionMacro(<< "Need to set an input");
itkExceptionMacro("Need to set an input");
}

input->SetRequestedRegion(region);
Expand All @@ -383,7 +383,7 @@ VTKImageExport<TInputImage>::DataExtentCallback()

if (!input)
{
itkExceptionMacro(<< "Need to set an input");
itkExceptionMacro("Need to set an input");
}

InputRegionType region = input->GetBufferedRegion();
Expand Down Expand Up @@ -416,7 +416,7 @@ VTKImageExport<TInputImage>::BufferPointerCallback()

if (!input)
{
itkExceptionMacro(<< "Need to set an input");
itkExceptionMacro("Need to set an input");
}

return input->GetBufferPointer();
Expand Down
16 changes: 8 additions & 8 deletions Modules/Bridge/VTK/include/itkVTKImageImport.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ VTKImageImport<TOutputImage>::VTKImageImport()
}
else
{
itkExceptionMacro(<< "Type currently not supported");
itkExceptionMacro("Type currently not supported");
}
}

Expand All @@ -107,7 +107,7 @@ VTKImageImport<TOutputImage>::PropagateRequestedRegion(DataObject * outputPtr)

if (!output)
{
itkExceptionMacro(<< "Downcast from DataObject to my Image type failed.");
itkExceptionMacro("Downcast from DataObject to my Image type failed.");
}
Superclass::PropagateRequestedRegion(output);
if (m_PropagateUpdateExtentCallback)
Expand Down Expand Up @@ -236,9 +236,9 @@ VTKImageImport<TOutputImage>::GenerateOutputInformation()
{
std::string ijk = "IJK";
std::string xyz = "XYZ";
itkExceptionMacro(<< "Cannot convert a VTK image to an ITK image of dimension " << OutputImageDimension
<< " since the VTK image direction matrix element at (" << i << ',' << j
<< ") is not equal to 0.0:\n"
itkExceptionMacro("Cannot convert a VTK image to an ITK image of dimension "
<< OutputImageDimension << " since the VTK image direction matrix element at (" << i << ','
<< j << ") is not equal to 0.0:\n"
<< " I J K\n"
<< "X " << inDirection[0] << ", " << inDirection[1] << ", " << inDirection[2] << '\n'
<< "Y " << inDirection[3] << ", " << inDirection[4] << ", " << inDirection[5] << '\n'
Expand All @@ -261,16 +261,16 @@ VTKImageImport<TOutputImage>::GenerateOutputInformation()

if (components != estimatedNumberOfComponents)
{
itkExceptionMacro(<< "Input number of components is " << components << " but should be "
<< estimatedNumberOfComponents);
itkExceptionMacro("Input number of components is " << components << " but should be "
<< estimatedNumberOfComponents);
}
}
if (m_ScalarTypeCallback)
{
const char * scalarName = (m_ScalarTypeCallback)(m_CallbackUserData);
if (scalarName != m_ScalarTypeName)
{
itkExceptionMacro(<< "Input scalar type is " << scalarName << " but should be " << m_ScalarTypeName.c_str());
itkExceptionMacro("Input scalar type is " << scalarName << " but should be " << m_ScalarTypeName.c_str());
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Modules/Bridge/VTK/src/itkVTKImageExportBase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ VTKImageExportBase::PipelineModifiedCallback()

if (!input)
{
itkExceptionMacro(<< "Need to set an input");
itkExceptionMacro("Need to set an input");
}

ModifiedTimeType pipelineMTime = input->GetPipelineMTime();
Expand Down Expand Up @@ -180,7 +180,7 @@ VTKImageExportBase::UpdateDataCallback()

if (!input)
{
itkExceptionMacro(<< "Need to set an input");
itkExceptionMacro("Need to set an input");
}

// Notify start event observers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ VectorResampleImageFilter<TInputImage, TOutputImage, TInterpolatorPrecisionType>
{
if (!m_Interpolator)
{
itkExceptionMacro(<< "Interpolator not set");
itkExceptionMacro("Interpolator not set");
}

// Connect input image to interpolator
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkExtractImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class ITK_TEMPLATE_EXPORT ExtractImageFilter : public InPlaceImageFilter<TInputI
break;
case DirectionCollapseStrategyEnum::DIRECTIONCOLLAPSETOUNKOWN:
default:
itkExceptionMacro(<< "Invalid Strategy Chosen for itk::ExtractImageFilter");
itkExceptionMacro("Invalid Strategy Chosen for itk::ExtractImageFilter");
}

this->m_DirectionCollapseStrategy = choosenStrategy;
Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/include/itkExtractImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ ExtractImageFilter<TInputImage, TOutputImage>::GenerateOutputInformation()
{
if (vnl_determinant(outputDirection.GetVnlMatrix()) == 0.0)
{
itkExceptionMacro(<< "Invalid submatrix extracted for collapsed direction.");
itkExceptionMacro("Invalid submatrix extracted for collapsed direction.");
}
}
break;
Expand Down Expand Up @@ -247,7 +247,7 @@ ExtractImageFilter<TInputImage, TOutputImage>::GenerateOutputInformation()
else
{
// pointer could not be cast back down
itkExceptionMacro(<< "itk::ExtractImageFilter::GenerateOutputInformation "
itkExceptionMacro("itk::ExtractImageFilter::GenerateOutputInformation "
<< "cannot cast input to " << typeid(ImageBase<InputImageDimension> *).name());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ FiniteCylinderSpatialFunction<VDimension, TInput>::SetOrientation(const InputTyp
norm = std::sqrt(norm);
if (norm == 0.0) // avoid divide by zero
{
itkExceptionMacro(<< "Degenerate orientation vector " << this->m_Orientation);
itkExceptionMacro("Degenerate orientation vector " << this->m_Orientation);
}
for (unsigned int i = 0; i < VDimension; ++i)
{
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkFrustumSpatialFunction.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ FrustumSpatialFunction<VDimension, TInput>::Evaluate(const InputType & position)
}
else
{
itkExceptionMacro(<< "Rotation plane not set or set to an unsupported value!");
itkExceptionMacro("Rotation plane not set or set to an unsupported value!");
}
}

Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/include/itkImage.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ Image<TPixel, VImageDimension>::Graft(const DataObject * data)
else
{
// pointer could not be cast back down
itkExceptionMacro(<< "itk::Image::Graft() cannot cast " << typeid(data).name() << " to "
<< typeid(const Self *).name());
itkExceptionMacro("itk::Image::Graft() cannot cast " << typeid(data).name() << " to "
<< typeid(const Self *).name());
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Modules/Core/Common/include/itkImageBase.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ ImageBase<VImageDimension>::ComputeOffsetTable()
}
// if( num > NumericTraits<SizeValueType>::max() )
// {
// itkExceptionMacro(<< "Requested number of pixels (" << num
// itkExceptionMacro("Requested number of pixels (" << num
// << ") is greater than the largest possible number of pixels (" <<
// NumericTraits<SizeValueType>::max() << ").");
// }
Expand Down Expand Up @@ -299,8 +299,8 @@ ImageBase<VImageDimension>::CopyInformation(const DataObject * data)
else
{
// pointer could not be cast back down
itkExceptionMacro(<< "itk::ImageBase::CopyInformation() cannot cast " << typeid(data).name() << " to "
<< typeid(const ImageBase *).name());
itkExceptionMacro("itk::ImageBase::CopyInformation() cannot cast " << typeid(data).name() << " to "
<< typeid(const ImageBase *).name());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkImageDuplicator.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ImageDuplicator<TInputImage>::Update()
{
if (!m_InputImage)
{
itkExceptionMacro(<< "Input image has not been connected");
itkExceptionMacro("Input image has not been connected");
}

// Update only if the input image has been modified
Expand Down
5 changes: 3 additions & 2 deletions Modules/Core/Common/include/itkImageKernelOperator.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ ImageKernelOperator<TPixel, VDimension, TAllocator>::GenerateCoefficients() -> C
// Check that the input image is fully buffered.
if (m_ImageKernel->GetBufferedRegion() != m_ImageKernel->GetLargestPossibleRegion())
{
itkExceptionMacro(<< "ImageKernel is not fully buffered. " << std::endl
itkExceptionMacro("ImageKernel is not fully buffered. "
<< std::endl
<< "Buffered region: " << m_ImageKernel->GetBufferedRegion() << std::endl
<< "Largest possible region: " << m_ImageKernel->GetLargestPossibleRegion() << std::endl
<< "You should call UpdateLargestPossibleRegion() on "
Expand All @@ -69,7 +70,7 @@ ImageKernelOperator<TPixel, VDimension, TAllocator>::GenerateCoefficients() -> C
{
if (m_ImageKernel->GetLargestPossibleRegion().GetSize()[i] % 2 == 0)
{
itkExceptionMacro(<< "ImageKernelOperator requires an input image "
itkExceptionMacro("ImageKernelOperator requires an input image "
<< "whose size is odd in all dimensions. The provided "
<< "image has size " << m_ImageKernel->GetLargestPossibleRegion().GetSize());
}
Expand Down
5 changes: 3 additions & 2 deletions Modules/Core/Common/include/itkImageSink.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,9 @@ ImageSink<TInputImage>::VerifyInputInformation() ITKv5_CONST
<< " Direction: " << inputPtrN->GetDirection() << std::endl;
directionString << "\tTolerance: " << this->m_DirectionTolerance << std::endl;
}
itkExceptionMacro(<< "Inputs do not occupy the same physical space! " << std::endl
<< originString.str() << spacingString.str() << directionString.str());
itkExceptionMacro("Inputs do not occupy the same physical space! " << std::endl
<< originString.str() << spacingString.str()
<< directionString.str());
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Modules/Core/Common/include/itkImageSource.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ ImageSource<TOutputImage>::GraftOutput(const DataObjectIdentifierType & key, Dat
{
if (!graft)
{
itkExceptionMacro(<< "Requested to graft output that is a nullptr pointer");
itkExceptionMacro("Requested to graft output that is a nullptr pointer");
}

// we use the process object method since all out output may not be
Expand All @@ -129,8 +129,8 @@ ImageSource<TOutputImage>::GraftNthOutput(unsigned int idx, DataObject * graft)
{
if (idx >= this->GetNumberOfIndexedOutputs())
{
itkExceptionMacro(<< "Requested to graft output " << idx << " but this filter only has "
<< this->GetNumberOfIndexedOutputs() << " indexed Outputs.");
itkExceptionMacro("Requested to graft output " << idx << " but this filter only has "
<< this->GetNumberOfIndexedOutputs() << " indexed Outputs.");
}
this->GraftOutput(this->MakeNameFromOutputIndex(idx), graft);
}
Expand Down
5 changes: 3 additions & 2 deletions Modules/Core/Common/include/itkImageToImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,9 @@ ImageToImageFilter<TInputImage, TOutputImage>::VerifyInputInformation() ITKv5_CO
<< " Direction: " << inputPtrN->GetDirection() << std::endl;
directionString << "\tTolerance: " << this->m_DirectionTolerance << std::endl;
}
itkExceptionMacro(<< "Inputs do not occupy the same physical space! " << std::endl
<< originString.str() << spacingString.str() << directionString.str());
itkExceptionMacro("Inputs do not occupy the same physical space! " << std::endl
<< originString.str() << spacingString.str()
<< directionString.str());
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Modules/Core/Common/include/itkMacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ OutputWindowDisplayDebugText(const char *);

/** The itkExceptionMacro macro is used to print error information (i.e., usually
* a condition that results in program failure). Example usage looks like:
* itkExceptionMacro(<< "this is error info" << this->SomeVariable); */
* itkExceptionMacro("this is error info" << this->SomeVariable); */
#define itkExceptionMacro(x) \
itkSpecializedMessageExceptionMacro(ExceptionObject, << this->GetNameOfClass() << '(' << this << "): " x)
Expand Down Expand Up @@ -894,7 +894,7 @@ compilers.
itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
if (input == nullptr) \
{ \
itkExceptionMacro(<< "input" #name " is not set"); \
itkExceptionMacro("input" #name " is not set"); \
} \
return input->Get(); \
} \
Expand Down Expand Up @@ -1313,7 +1313,7 @@ compilers.
itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
if (output == nullptr) \
{ \
itkExceptionMacro(<< "output" #name " is not set"); \
itkExceptionMacro("output" #name " is not set"); \
} \
return output->Get(); \
} \
Expand Down
16 changes: 8 additions & 8 deletions Modules/Core/Common/include/itkPointSet.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ PointSet<TPixelType, VDimension, TMeshTraits>::CopyInformation(const DataObject
if (!pointSet)
{
// pointer could not be cast back down
itkExceptionMacro(<< "itk::PointSet::CopyInformation() cannot cast " << typeid(data).name() << " to "
<< typeid(PointSet *).name());
itkExceptionMacro("itk::PointSet::CopyInformation() cannot cast " << typeid(data).name() << " to "
<< typeid(PointSet *).name());
}

m_MaximumNumberOfRegions = pointSet->GetMaximumNumberOfRegions();
Expand All @@ -315,8 +315,8 @@ PointSet<TPixelType, VDimension, TMeshTraits>::Graft(const DataObject * data)
if (!pointSet)
{
// pointer could not be cast back down
itkExceptionMacro(<< "itk::PointSet::CopyInformation() cannot cast " << typeid(data).name() << " to "
<< typeid(Self *).name());
itkExceptionMacro("itk::PointSet::CopyInformation() cannot cast " << typeid(data).name() << " to "
<< typeid(Self *).name());
}

this->SetPoints(pointSet->m_PointsContainer);
Expand Down Expand Up @@ -379,14 +379,14 @@ PointSet<TPixelType, VDimension, TMeshTraits>::VerifyRequestedRegion()
// Are we asking for more regions than we can get?
if (m_RequestedNumberOfRegions > m_MaximumNumberOfRegions)
{
itkExceptionMacro(<< "Cannot break object into " << m_RequestedNumberOfRegions << ". The limit is "
<< m_MaximumNumberOfRegions);
itkExceptionMacro("Cannot break object into " << m_RequestedNumberOfRegions << ". The limit is "
<< m_MaximumNumberOfRegions);
}

if (m_RequestedRegion >= m_RequestedNumberOfRegions || m_RequestedRegion < 0)
{
itkExceptionMacro(<< "Invalid update region " << m_RequestedRegion << ". Must be between 0 and "
<< m_RequestedNumberOfRegions - 1);
itkExceptionMacro("Invalid update region " << m_RequestedRegion << ". Must be between 0 and "
<< m_RequestedNumberOfRegions - 1);
}

return retval;
Expand Down
8 changes: 4 additions & 4 deletions Modules/Core/Common/include/itkSobelOperator.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ SobelOperator<TPixel, VDimension, TAllocator>::Fill(const CoefficientVector & co
}
else
{
itkExceptionMacro(<< "The ND version of the Sobel operator is not yet implemented. Currently only the 2D and 3D "
"versions are available.");
itkExceptionMacro("The ND version of the Sobel operator is not yet implemented. Currently only the 2D and 3D "
"versions are available.");
}
}

Expand Down Expand Up @@ -204,8 +204,8 @@ SobelOperator<TPixel, VDimension, TAllocator>::GenerateCoefficients() -> Coeffic
}
else
{
itkExceptionMacro(<< "The ND version of the Sobel operator has not been implemented. Currently only 2D and 3D "
"versions are available.");
itkExceptionMacro("The ND version of the Sobel operator has not been implemented. Currently only 2D and 3D "
"versions are available.");
}

return coeff;
Expand Down
4 changes: 2 additions & 2 deletions Modules/Core/Common/include/itkStreamingImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ StreamingImageFilter<TInputImage, TOutputImage>::UpdateOutputData(DataObject * i
const itk::ProcessObject::DataObjectPointerArraySizeType ninputs = this->GetNumberOfValidRequiredInputs();
if (ninputs < this->GetNumberOfRequiredInputs())
{
itkExceptionMacro(<< "At least " << this->GetNumberOfRequiredInputs() << " inputs are required but only " << ninputs
<< " are specified.");
itkExceptionMacro("At least " << this->GetNumberOfRequiredInputs() << " inputs are required but only " << ninputs
<< " are specified.");
}

/**
Expand Down
Loading

0 comments on commit 89beb04

Please sign in to comment.