Skip to content

Commit ce2898b

Browse files
committed
STYLE: Remove Exception constructor overloads for char * arguments
Internally, `ExceptionObject` stores its file name, description, and location as `std::string`, so the corresponding constructor parameters might as well just be of type `std::string`. Whenever such a parameter was originally declared `const std::string &`, this commit has removed the `const` and the `&`, in order to efficiently "move" the parameters from derived exception classes to their base class. Note that this commit drops the support for null pointers as arguments.
1 parent c99ae39 commit ce2898b

19 files changed

+68
-165
lines changed

Modules/Core/Common/include/itkDataObject.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@ class ITKCommon_EXPORT DataObjectError : public ExceptionObject
5959
~DataObjectError() noexcept override = default;
6060

6161
/** Constructor. Needed to ensure the exception object can be copied. */
62-
DataObjectError(const char * file, unsigned int lineNumber);
63-
64-
/** Constructor. Needed to ensure the exception object can be copied. */
65-
DataObjectError(const std::string & file, unsigned int lineNumber);
62+
DataObjectError(std::string file, unsigned int lineNumber);
6663

6764
/** Copy constructor. Needed to ensure the exception object can be copied. */
6865
DataObjectError(const DataObjectError & orig) noexcept;
@@ -117,10 +114,7 @@ class ITKCommon_EXPORT InvalidRequestedRegionError : public DataObjectError
117114
~InvalidRequestedRegionError() noexcept override = default;
118115

119116
/** Constructor. Needed to ensure the exception object can be copied. */
120-
InvalidRequestedRegionError(const char * file, unsigned int lineNumber);
121-
122-
/** Constructor. Needed to ensure the exception object can be copied. */
123-
InvalidRequestedRegionError(const std::string & file, unsigned int lineNumber);
117+
InvalidRequestedRegionError(std::string file, unsigned int lineNumber);
124118

125119
/** Copy constructor. Needed to ensure the exception object can be copied. */
126120
InvalidRequestedRegionError(const InvalidRequestedRegionError & orig) noexcept;

Modules/Core/Common/include/itkExceptionObject.h

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ class ITKCommon_EXPORT ExceptionObject : public std::exception
5656
/** Explicitly-defaulted default-constructor. Creates an empty exception object. */
5757
ExceptionObject() noexcept = default;
5858

59-
explicit ExceptionObject(const char * file,
60-
unsigned int lineNumber = 0,
61-
const char * desc = "None",
62-
const char * loc = "Unknown");
6359
explicit ExceptionObject(std::string file,
6460
unsigned int lineNumber = 0,
6561
std::string desc = "None",
@@ -226,18 +222,9 @@ class ITKCommon_EXPORT ProcessAborted : public ExceptionObject
226222
}
227223

228224
/** Constructor. Needed to ensure the exception object can be copied. */
229-
ProcessAborted(const char * file, unsigned int lineNumber)
230-
: ExceptionObject(file, lineNumber)
231-
{
232-
this->SetDescription("Filter execution was aborted by an external request");
233-
}
234-
235-
/** Constructor. Needed to ensure the exception object can be copied. */
236-
ProcessAborted(const std::string & file, unsigned int lineNumber)
237-
: ExceptionObject(file, lineNumber)
238-
{
239-
this->SetDescription("Filter execution was aborted by an external request");
240-
}
225+
ProcessAborted(std::string file, unsigned int lineNumber)
226+
: ExceptionObject(std::move(file), lineNumber, "Filter execution was aborted by an external request")
227+
{}
241228

242229
/** \see LightObject::GetNameOfClass() */
243230
itkOverrideGetNameOfClassMacro(ProcessAborted);

Modules/Core/Common/src/itkDataObject.cxx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,8 @@ DataObjectError::DataObjectError() noexcept
3939
: ExceptionObject()
4040
{}
4141

42-
DataObjectError::DataObjectError(const char * file, unsigned int lineNumber)
43-
: ExceptionObject(file, lineNumber)
44-
{}
45-
46-
DataObjectError::DataObjectError(const std::string & file, unsigned int lineNumber)
47-
: ExceptionObject(file, lineNumber)
42+
DataObjectError::DataObjectError(std::string file, unsigned int lineNumber)
43+
: ExceptionObject(std::move(file), lineNumber)
4844
{}
4945

5046
DataObjectError::DataObjectError(const DataObjectError & orig) noexcept
@@ -98,12 +94,8 @@ InvalidRequestedRegionError::InvalidRequestedRegionError() noexcept
9894
: DataObjectError()
9995
{}
10096

101-
InvalidRequestedRegionError::InvalidRequestedRegionError(const char * file, unsigned int lineNumber)
102-
: DataObjectError(file, lineNumber)
103-
{}
104-
105-
InvalidRequestedRegionError::InvalidRequestedRegionError(const std::string & file, unsigned int lineNumber)
106-
: DataObjectError(file, lineNumber)
97+
InvalidRequestedRegionError::InvalidRequestedRegionError(std::string file, unsigned int lineNumber)
98+
: DataObjectError(std::move(file), lineNumber)
10799
{}
108100

109101
InvalidRequestedRegionError::InvalidRequestedRegionError(const InvalidRequestedRegionError &) noexcept = default;

Modules/Core/Common/src/itkExceptionObject.cxx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,6 @@ class ExceptionObject::ExceptionData
6565
};
6666

6767

68-
ExceptionObject::ExceptionObject(const char * file, unsigned int lineNumber, const char * desc, const char * loc)
69-
: m_ExceptionData(std::make_shared<const ExceptionData>(file == nullptr ? "" : file,
70-
lineNumber,
71-
desc == nullptr ? "" : desc,
72-
loc == nullptr ? "" : loc))
73-
{}
74-
7568
ExceptionObject::ExceptionObject(std::string file, unsigned int lineNumber, std::string desc, std::string loc)
7669
: m_ExceptionData(std::make_shared<const ExceptionData>(std::move(file), lineNumber, std::move(desc), std::move(loc)))
7770
{}

Modules/IO/ImageBase/include/itkImageFileReaderException.h

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,11 @@ class ITKIOImageBase_EXPORT ImageFileReaderException : public ExceptionObject
3737
itkOverrideGetNameOfClassMacro(ImageFileReaderException);
3838

3939
/** Constructor. */
40-
ImageFileReaderException(const char * file,
40+
ImageFileReaderException(std::string file,
4141
unsigned int line,
42-
const char * message = "Error in IO",
43-
const char * loc = "Unknown")
44-
: ExceptionObject(file, line, message, loc)
45-
{}
46-
47-
/** Constructor. */
48-
ImageFileReaderException(const std::string & file,
49-
unsigned int line,
50-
const char * message = "Error in IO",
51-
const char * loc = "Unknown")
52-
: ExceptionObject(file, line, message, loc)
42+
std::string message = "Error in IO",
43+
std::string loc = "Unknown")
44+
: ExceptionObject(std::move(file), line, std::move(message), std::move(loc))
5345
{}
5446

5547
/** Has to have empty throw(). */

Modules/IO/ImageBase/include/itkImageFileWriter.h

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,11 @@ class ITKIOImageBase_EXPORT ImageFileWriterException : public ExceptionObject
4040
itkOverrideGetNameOfClassMacro(ImageFileWriterException);
4141

4242
/** Constructor. */
43-
ImageFileWriterException(const char * file,
43+
ImageFileWriterException(std::string file,
4444
unsigned int line,
45-
const char * message = "Error in IO",
46-
const char * loc = "Unknown")
47-
: ExceptionObject(file, line, message, loc)
48-
{}
49-
50-
/** Constructor. */
51-
ImageFileWriterException(const std::string & file,
52-
unsigned int line,
53-
const char * message = "Error in IO",
54-
const char * loc = "Unknown")
55-
: ExceptionObject(file, line, message, loc)
45+
std::string message = "Error in IO",
46+
std::string loc = "Unknown")
47+
: ExceptionObject(std::move(file), line, std::move(message), std::move(loc))
5648
{}
5749

5850
/** Has to have empty throw(). */

Modules/IO/ImageBase/include/itkImageSeriesWriter.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,9 @@ class ITKIOImageBase_EXPORT ImageSeriesWriterException : public ExceptionObject
4040
itkOverrideGetNameOfClassMacro(ImageSeriesWriterException);
4141

4242
/** Constructor. */
43-
ImageSeriesWriterException(char * file, unsigned int line, const char * message = "Error in IO")
44-
: ExceptionObject(file, line)
45-
{
46-
SetDescription(message);
47-
}
48-
49-
/** Constructor. */
50-
ImageSeriesWriterException(const std::string & file, unsigned int line, const char * message = "Error in IO")
51-
: ExceptionObject(file, line)
52-
{
53-
SetDescription(message);
54-
}
43+
ImageSeriesWriterException(std::string file, unsigned int line, std::string message = "Error in IO")
44+
: ExceptionObject(std::move(file), line, std::move(message))
45+
{}
5546
};
5647

5748
/** \class ImageSeriesWriter

Modules/IO/MeshBase/include/itkMeshFileReaderException.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,10 @@ class ITKIOMeshBase_EXPORT MeshFileReaderException : public ExceptionObject
4141
itkOverrideGetNameOfClassMacro(MeshFileReaderException);
4242

4343
/** Constructor. */
44-
MeshFileReaderException(const char * file,
44+
MeshFileReaderException(std::string file,
4545
unsigned int line,
46-
const char * message = "Error in IO",
47-
const char * loc = "Unknown");
48-
49-
/** Constructor. */
50-
MeshFileReaderException(const std::string & file,
51-
unsigned int line,
52-
const char * message = "Error in IO",
53-
const char * loc = "Unknown");
46+
std::string message = "Error in IO",
47+
std::string loc = "Unknown");
5448
};
5549
} // end namespace itk
5650

Modules/IO/MeshBase/include/itkMeshFileWriterException.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,10 @@ class ITKIOMeshBase_EXPORT MeshFileWriterException : public ExceptionObject
4141
itkOverrideGetNameOfClassMacro(MeshFileWriterException);
4242

4343
/** Constructor. */
44-
MeshFileWriterException(const char * file,
44+
MeshFileWriterException(std::string file,
4545
unsigned int line,
46-
const char * message = "Error in IO",
47-
const char * loc = "Unknown");
48-
49-
/** Constructor. */
50-
MeshFileWriterException(const std::string & file,
51-
unsigned int line,
52-
const char * message = "Error in IO",
53-
const char * loc = "Unknown");
46+
std::string message = "Error in IO",
47+
std::string loc = "Unknown");
5448
};
5549
} // end namespace itk
5650

Modules/IO/MeshBase/src/itkMeshFileReaderException.cxx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,10 @@ namespace itk
2121
{
2222
MeshFileReaderException::~MeshFileReaderException() noexcept = default;
2323

24-
MeshFileReaderException::MeshFileReaderException(const char * file,
24+
MeshFileReaderException::MeshFileReaderException(std::string file,
2525
unsigned int line,
26-
const char * message,
27-
const char * loc)
28-
: ExceptionObject(file, line, message, loc)
29-
{}
30-
31-
MeshFileReaderException::MeshFileReaderException(const std::string & file,
32-
unsigned int line,
33-
const char * message,
34-
const char * loc)
35-
: ExceptionObject(file, line, message, loc)
26+
std::string message,
27+
std::string loc)
28+
: ExceptionObject(std::move(file), line, std::move(message), std::move(loc))
3629
{}
3730
} // namespace itk

0 commit comments

Comments
 (0)