From 9eeab2d46ddcd49b4c2409033d75444f6566a784 Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Sat, 14 Dec 2019 13:29:17 -0600 Subject: [PATCH 1/2] DOC: Add commentary about the coding style used. --- SoftwareGuide/Latex/Appendices/CodingStyleGuide.tex | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/SoftwareGuide/Latex/Appendices/CodingStyleGuide.tex b/SoftwareGuide/Latex/Appendices/CodingStyleGuide.tex index 0f695506..aa9489ef 100644 --- a/SoftwareGuide/Latex/Appendices/CodingStyleGuide.tex +++ b/SoftwareGuide/Latex/Appendices/CodingStyleGuide.tex @@ -9,11 +9,14 @@ \chapter{Coding Style Guide} architectural and implementation decisions made early in the project. For example, the decision was made to implement ITK with a C++ core using principles of generic programming, so the rules are oriented towards this style -of implementation. Some guidelines are relatively arbitrary, such as -indentation levels and style. However, an attempt was made to find coding -styles consistent with accepted practices. The point is to adhere to a common +of implementation. All guidelines are strictly enforced, including whitespace +indentation levels and style. Careful consideration and considerable discussion +occurred in an attempt to find coding +styles consistent with accepted practices in the active community. +The primary goal is to adhere to a common style to assist community members of the future to learn, use, maintain, and -extend ITK. A common style greatly improves readability. +extend ITK. Given the fact that code is read many more times than it is written, a strong +emphasis is placed on generating a common style that improves readability. Please do your best to be an outstanding member of the ITK community. The rules described here have been developed with the community as a whole in mind. From 86782f9ebe778fb760f7c81e4992f7cb061c4870 Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Sat, 14 Dec 2019 13:36:06 -0600 Subject: [PATCH 2/2] COMP: Exceptions should be caught by constant reference Catching by value is problematic in the face of inheritance hierarchies. https://clang.llvm.org/extra/clang-tidy/checks/misc-throw-by-value-catch-by-reference.html https://wiki.sei.cmu.edu/confluence/display/cplusplus/ERR61-CPP.+Catch+exceptions+by+lvalue+reference --- SoftwareGuide/Cover/Source/AntialiasFilter.cxx | 2 +- SoftwareGuide/Cover/Source/BinaryMaskMedianFilter.cxx | 2 +- SoftwareGuide/Cover/Source/BinaryThresholdFilter.cxx | 6 +++--- SoftwareGuide/Cover/Source/DilateFilter.cxx | 2 +- SoftwareGuide/Cover/Source/ImageReadExtractWriteRGB.cxx | 2 +- SoftwareGuide/Cover/Source/ModelBasedSegmentation.cxx | 2 +- SoftwareGuide/Cover/Source/NegateFilter.cxx | 2 +- SoftwareGuide/Cover/Source/RescaleIntensityFilter.cxx | 2 +- SoftwareGuide/Cover/Source/VWBlueRemoval.cxx | 4 ++-- SoftwareGuide/Cover/Source/VWColorSegmentation.cxx | 6 +++--- SoftwareGuide/Cover/Source/VWHistogramHSV.cxx | 4 ++-- SoftwareGuide/Cover/Source/VWHistogramRGB.cxx | 4 ++-- SoftwareGuide/Latex/Appendices/CodingStyleGuide.tex | 8 ++++---- SoftwareGuide/Latex/Architecture/SystemOverview.tex | 2 +- 14 files changed, 24 insertions(+), 24 deletions(-) diff --git a/SoftwareGuide/Cover/Source/AntialiasFilter.cxx b/SoftwareGuide/Cover/Source/AntialiasFilter.cxx index 2035de34..6e6248a3 100644 --- a/SoftwareGuide/Cover/Source/AntialiasFilter.cxx +++ b/SoftwareGuide/Cover/Source/AntialiasFilter.cxx @@ -78,7 +78,7 @@ int main( int argc, char ** argv ) { writer->Update(); } - catch( itk::ExceptionObject & err ) + catch( const itk::ExceptionObject & err ) { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; diff --git a/SoftwareGuide/Cover/Source/BinaryMaskMedianFilter.cxx b/SoftwareGuide/Cover/Source/BinaryMaskMedianFilter.cxx index 3babd6cf..91feb8c0 100644 --- a/SoftwareGuide/Cover/Source/BinaryMaskMedianFilter.cxx +++ b/SoftwareGuide/Cover/Source/BinaryMaskMedianFilter.cxx @@ -90,7 +90,7 @@ int main( int argc, char ** argv ) { writer->Update(); } - catch( itk::ExceptionObject & err ) + catch( const itk::ExceptionObject & err ) { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; diff --git a/SoftwareGuide/Cover/Source/BinaryThresholdFilter.cxx b/SoftwareGuide/Cover/Source/BinaryThresholdFilter.cxx index ed40d2b0..3cdc7f5b 100644 --- a/SoftwareGuide/Cover/Source/BinaryThresholdFilter.cxx +++ b/SoftwareGuide/Cover/Source/BinaryThresholdFilter.cxx @@ -42,7 +42,7 @@ int main(int argc, char * argv[] ) { imageReader->Update(); } - catch( itk::ExceptionObject & excp ) + catch( const itk::ExceptionObject & excp ) { std::cerr << excp << std::endl; return -1; @@ -66,7 +66,7 @@ int main(int argc, char * argv[] ) { filter->Update(); } - catch( itk::ExceptionObject & excp ) + catch( const itk::ExceptionObject & excp ) { std::cerr << excp << std::endl; return -1; @@ -83,7 +83,7 @@ int main(int argc, char * argv[] ) { imageWriter->Update(); } - catch( itk::ExceptionObject & excp ) + catch( const itk::ExceptionObject & excp ) { std::cerr << excp << std::endl; return -1; diff --git a/SoftwareGuide/Cover/Source/DilateFilter.cxx b/SoftwareGuide/Cover/Source/DilateFilter.cxx index c3f97c36..9ed29858 100644 --- a/SoftwareGuide/Cover/Source/DilateFilter.cxx +++ b/SoftwareGuide/Cover/Source/DilateFilter.cxx @@ -91,7 +91,7 @@ int main( int argc, char ** argv ) { writer->Update(); } - catch( itk::ExceptionObject & err ) + catch( const itk::ExceptionObject & err ) { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; diff --git a/SoftwareGuide/Cover/Source/ImageReadExtractWriteRGB.cxx b/SoftwareGuide/Cover/Source/ImageReadExtractWriteRGB.cxx index 5ed437cb..d75088ca 100644 --- a/SoftwareGuide/Cover/Source/ImageReadExtractWriteRGB.cxx +++ b/SoftwareGuide/Cover/Source/ImageReadExtractWriteRGB.cxx @@ -117,7 +117,7 @@ int main( int argc, char ** argv ) { writer->Update(); } - catch( itk::ExceptionObject & err ) + catch( const itk::ExceptionObject & err ) { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; diff --git a/SoftwareGuide/Cover/Source/ModelBasedSegmentation.cxx b/SoftwareGuide/Cover/Source/ModelBasedSegmentation.cxx index d15872ad..54900357 100644 --- a/SoftwareGuide/Cover/Source/ModelBasedSegmentation.cxx +++ b/SoftwareGuide/Cover/Source/ModelBasedSegmentation.cxx @@ -395,7 +395,7 @@ int main( int argc, char *argv[] ) try { registration->StartRegistration(); } - catch( itk::ExceptionObject & exp ) { + catch( const itk::ExceptionObject & exp ) { std::cerr << "Exception caught ! " << std::endl; std::cerr << exp << std::endl; } diff --git a/SoftwareGuide/Cover/Source/NegateFilter.cxx b/SoftwareGuide/Cover/Source/NegateFilter.cxx index cc10882a..29aac1ce 100644 --- a/SoftwareGuide/Cover/Source/NegateFilter.cxx +++ b/SoftwareGuide/Cover/Source/NegateFilter.cxx @@ -113,7 +113,7 @@ int main( int argc, char ** argv ) { writer->Update(); } - catch( itk::ExceptionObject & err ) + catch( const itk::ExceptionObject & err ) { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; diff --git a/SoftwareGuide/Cover/Source/RescaleIntensityFilter.cxx b/SoftwareGuide/Cover/Source/RescaleIntensityFilter.cxx index 10e0428d..636fb00a 100644 --- a/SoftwareGuide/Cover/Source/RescaleIntensityFilter.cxx +++ b/SoftwareGuide/Cover/Source/RescaleIntensityFilter.cxx @@ -77,7 +77,7 @@ int main( int argc, char ** argv ) { writer->Update(); } - catch( itk::ExceptionObject & err ) + catch( const itk::ExceptionObject & err ) { std::cout << "ExceptionObject caught !" << std::endl; std::cout << err << std::endl; diff --git a/SoftwareGuide/Cover/Source/VWBlueRemoval.cxx b/SoftwareGuide/Cover/Source/VWBlueRemoval.cxx index 3765f89f..061edd41 100644 --- a/SoftwareGuide/Cover/Source/VWBlueRemoval.cxx +++ b/SoftwareGuide/Cover/Source/VWBlueRemoval.cxx @@ -32,7 +32,7 @@ int main(int argc, char * argv[] ) { imageReader->Update(); } - catch( itk::ExceptionObject & excp ) + catch( const itk::ExceptionObject & excp ) { std::cout << excp << std::endl; return -1; @@ -98,7 +98,7 @@ int main(int argc, char * argv[] ) { imageWriter->Update(); } - catch( itk::ExceptionObject & excp ) + catch( const itk::ExceptionObject & excp ) { std::cout << excp << std::endl; return -1; diff --git a/SoftwareGuide/Cover/Source/VWColorSegmentation.cxx b/SoftwareGuide/Cover/Source/VWColorSegmentation.cxx index 9ad6bb3c..3d4c9d1f 100644 --- a/SoftwareGuide/Cover/Source/VWColorSegmentation.cxx +++ b/SoftwareGuide/Cover/Source/VWColorSegmentation.cxx @@ -47,7 +47,7 @@ int main(int argc, char * argv[] ) { imageReader->Update(); } - catch( itk::ExceptionObject & excp ) + catch( const itk::ExceptionObject & excp ) { std::cerr << excp << std::endl; return -1; @@ -95,7 +95,7 @@ int main(int argc, char * argv[] ) { confidenceFilter->Update(); } - catch( itk::ExceptionObject & excp ) + catch( const itk::ExceptionObject & excp ) { std::cerr << excp << std::endl; return -1; @@ -112,7 +112,7 @@ int main(int argc, char * argv[] ) { imageWriter->Update(); } - catch( itk::ExceptionObject & excp ) + catch (const itk::ExceptionObject & excp ) { std::cerr << excp << std::endl; return -1; diff --git a/SoftwareGuide/Cover/Source/VWHistogramHSV.cxx b/SoftwareGuide/Cover/Source/VWHistogramHSV.cxx index d2cdd67d..1609bdb2 100644 --- a/SoftwareGuide/Cover/Source/VWHistogramHSV.cxx +++ b/SoftwareGuide/Cover/Source/VWHistogramHSV.cxx @@ -90,7 +90,7 @@ int main(int argc, char * argv[] ) { reader->Update(); } - catch( itk::ExceptionObject & excp ) + catch( const itk::ExceptionObject & excp ) { std::cout << excp << std::endl; return -1; @@ -199,7 +199,7 @@ int main(int argc, char * argv[] ) { writer->Update(); } - catch( itk::ExceptionObject & excp ) + catch( const itk::ExceptionObject & excp ) { std::cout << excp << std::endl; return -1; diff --git a/SoftwareGuide/Cover/Source/VWHistogramRGB.cxx b/SoftwareGuide/Cover/Source/VWHistogramRGB.cxx index 0fa52103..cf6c1d01 100644 --- a/SoftwareGuide/Cover/Source/VWHistogramRGB.cxx +++ b/SoftwareGuide/Cover/Source/VWHistogramRGB.cxx @@ -38,7 +38,7 @@ int main(int argc, char * argv[] ) { reader->Update(); } - catch( itk::ExceptionObject & excp ) + catch( const itk::ExceptionObject & excp ) { std::cout << excp << std::endl; return -1; @@ -99,7 +99,7 @@ int main(int argc, char * argv[] ) { writer->Update(); } - catch( itk::ExceptionObject & excp ) + catch( const itk::ExceptionObject & excp ) { std::cout << excp << std::endl; return -1; diff --git a/SoftwareGuide/Latex/Appendices/CodingStyleGuide.tex b/SoftwareGuide/Latex/Appendices/CodingStyleGuide.tex index aa9489ef..bc0c0704 100644 --- a/SoftwareGuide/Latex/Appendices/CodingStyleGuide.tex +++ b/SoftwareGuide/Latex/Appendices/CodingStyleGuide.tex @@ -3196,11 +3196,11 @@ \section{Exception Handling} { // Code liable to throw an exception } -catch( ExceptionObject & exc ) +catch( const ExceptionObject & exc ) { std::cerr << exc << std::endl; } -catch( std::exception & exc ) +catch( const std::exception & exc ) { std::cerr << exc.what() << std::endl; } @@ -3216,7 +3216,7 @@ \section{Exception Handling} m_ExceptionMessage = ""; this->TestFileExistanceAndReadability(); } -catch( ExceptionObject & exc ) +catch( const ExceptionObject & exc ) { m_ExceptionMessage = exc.GetDescription(); } @@ -3232,7 +3232,7 @@ \section{Exception Handling} { m_Optimizer->StartOptimization(); } -catch( ExceptionObject & exc ) +catch( const ExceptionObject & exc ) { // An error has occurred in the optimization. // Update the parameters. diff --git a/SoftwareGuide/Latex/Architecture/SystemOverview.tex b/SoftwareGuide/Latex/Architecture/SystemOverview.tex index 8fbd7f6e..7717745d 100644 --- a/SoftwareGuide/Latex/Architecture/SystemOverview.tex +++ b/SoftwareGuide/Latex/Architecture/SystemOverview.tex @@ -292,7 +292,7 @@ \subsection{Error Handling and Exceptions} { //...try executing some code here... } - catch ( itk::ExceptionObject & exp ) + catch( const itk::ExceptionObject & exp ) { //...if an exception is thrown catch it here }