Skip to content

Commit 2c2fc8c

Browse files
jhlegarretahjmjohnson
authored andcommitted
STYLE: Prefer error checked std::sto[id] over ato[if].
The `ato[if]` functions do not provide mechanisms for distinguishing between `0` and the error condition where the input can not be converted. `std::sto[id]` provides exception handling and detects when an invalid string attempts to be converted to an [integer|double]. `ato[if]()` - **Con**: No error handling. - **Con**: Handle neither hexadecimal nor octal. The use of `ato[if]` in code can cause it to be subtly broken. `ato[if]` makes two very big assumptions indeed: - The string represents an integer/floating point value. - The integer can fit into an int. In agreement with: http://review.source.kitware.com/#/c/23738/
1 parent 3773660 commit 2c2fc8c

13 files changed

+25
-25
lines changed

examples/Core/ThreadOverhead.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ int main( int argc, char * argv[] )
127127
}
128128

129129
const std::string timingsFileName = ReplaceOccurrence( argv[1], "__DATESTAMP__", PerfDateStamp());
130-
const int iterations = (argc>2) ? atoi( argv[2] ): 500;
131-
const int threads = (argc>3) ? atoi( argv[3] ) : MultiThreaderName::GetGlobalDefaultNumberOfThreads();
130+
const int iterations = (argc>2) ? std::stoi( argv[2] ): 500;
131+
const int threads = (argc>3) ? std::stoi( argv[3] ) : MultiThreaderName::GetGlobalDefaultNumberOfThreads();
132132

133133
if (threads == 1)
134134
{

examples/Filtering/BinaryAddBenchmark.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ int main( int argc, char * argv[] )
5959
return EXIT_FAILURE;
6060
}
6161
const std::string timingsFileName = ReplaceOccurrence( argv[1], "__DATESTAMP__", PerfDateStamp());
62-
const int iterations = atoi( argv[2] );
63-
int threads = atoi( argv[3] );
62+
const int iterations = std::stoi( argv[2] );
63+
int threads = std::stoi( argv[3] );
6464
const char * inputImage1FileName = argv[4];
6565
const char * inputImage2FileName = argv[5];
6666
const char * outputImageFileName = argv[6];

examples/Filtering/GradientMagnitudeBenchmark.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ int main( int argc, char * argv[] )
3333
return EXIT_FAILURE;
3434
}
3535
const std::string timingsFileName = ReplaceOccurrence( argv[1], "__DATESTAMP__", PerfDateStamp());
36-
const int iterations = atoi( argv[2] );
37-
int threads = atoi( argv[3] );
36+
const int iterations = std::stoi( argv[2] );
37+
int threads = std::stoi( argv[3] );
3838
const char * inputImageFileName = argv[4];
3939
const char * outputImageFileName = argv[5];
4040

examples/Filtering/MedianBenchmark.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ int main( int argc, char * argv[] )
3333
return EXIT_FAILURE;
3434
}
3535
const std::string timingsFileName = ReplaceOccurrence( argv[1], "__DATESTAMP__", PerfDateStamp());
36-
const int iterations = atoi( argv[2] );
37-
int threads = atoi( argv[3] );
36+
const int iterations = std::stoi( argv[2] );
37+
int threads = std::stoi( argv[3] );
3838
const char * inputImageFileName = argv[4];
3939
const char * outputImageFileName = argv[5];
4040

examples/Filtering/MinMaxCurvatureFlowBenchmark.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ int main( int argc, char * argv[] )
3333
return EXIT_FAILURE;
3434
}
3535
const std::string timingsFileName = ReplaceOccurrence( argv[1], "__DATESTAMP__", PerfDateStamp());
36-
const int iterations = atoi( argv[2] );
37-
int threads = atoi( argv[3] );
36+
const int iterations = std::stoi( argv[2] );
37+
int threads = std::stoi( argv[3] );
3838
const char * inputImageFileName = argv[4];
3939
const char * outputImageFileName = argv[5];
4040

examples/Filtering/UnaryAddBenchmark.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ int main( int argc, char * argv[] )
5959
return EXIT_FAILURE;
6060
}
6161
const std::string timingsFileName = ReplaceOccurrence( argv[1], "__DATESTAMP__", PerfDateStamp());
62-
const int iterations = atoi( argv[2] );
63-
int threads = atoi( argv[3] );
62+
const int iterations = std::stoi( argv[2] );
63+
int threads = std::stoi( argv[3] );
6464
const char * inputImage1FileName = argv[4];
6565
const char * outputImageFileName = argv[5];
6666

examples/Registration/DemonsRegistrationBenchmark.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ int main( int argc, char * argv[] )
7373
return EXIT_FAILURE;
7474
}
7575
const std::string timingsFileName = ReplaceOccurrence( argv[1], "__DATESTAMP__", PerfDateStamp());
76-
const int iterations = atoi( argv[2] );
77-
int threads = atoi( argv[3] );
76+
const int iterations = std::stoi( argv[2] );
77+
int threads = std::stoi( argv[3] );
7878
const char * fixedImageFileName = argv[4];
7979
const char * movingImageFileName = argv[5];
8080
const char * outputFileName = argv[6];

examples/Registration/NormalizedCorrelationBenchmark.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ int main(int argc, char * argv[])
3333
return EXIT_FAILURE;
3434
}
3535
const std::string timingsFileName = ReplaceOccurrence( argv[1], "__DATESTAMP__", PerfDateStamp());
36-
const int iterations = atoi( argv[2] );
37-
int threads = atoi( argv[3] );
36+
const int iterations = std::stoi( argv[2] );
37+
int threads = std::stoi( argv[3] );
3838
const std::string fixedImageFileName = argv[4];
3939
const std::string movingImageFileName = argv[5];
4040

examples/Registration/RegistrationFrameworkBenchmark.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ int main( int argc, char * argv[] )
7272
return EXIT_FAILURE;
7373
}
7474
const std::string timingsFileName = ReplaceOccurrence( argv[1], "__DATESTAMP__", PerfDateStamp());
75-
const int iterations = atoi( argv[2] );
76-
int threads = atoi( argv[3] );
75+
const int iterations = std::stoi( argv[2] );
76+
int threads = std::stoi( argv[3] );
7777
const char * fixedImageFileName = argv[4];
7878
const char * movingImageFileName = argv[5];
7979
const char * outputTransformFileName = argv[6];

examples/Segmentation/LevelSetBenchmark.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ int main( int argc, char * argv[] )
4040
return EXIT_FAILURE;
4141
}
4242
const std::string timingsFileName = ReplaceOccurrence( argv[1], "__DATESTAMP__", PerfDateStamp());
43-
const int iterations = atoi( argv[2] );
44-
int threads = atoi( argv[3] );
43+
const int iterations = std::stoi( argv[2] );
44+
int threads = std::stoi( argv[3] );
4545
const char * inputImageFileName = argv[4];
4646
const char * outputImageFileName = argv[5];
4747

0 commit comments

Comments
 (0)