From 9f40cc05319510132e12467fdfc2c4a9e7d1dcf0 Mon Sep 17 00:00:00 2001 From: Simon Rit Date: Tue, 15 Mar 2022 13:52:42 +0100 Subject: [PATCH] STYLE: Prefer error checked std::stoi over atoi Follows InsightSoftwareConsortium/ITK@b9a384af33e904ae0da212ace9130632c808c6fd --- include/rtkEdfRawToAttenuationImageFilter.hxx | 2 +- src/rtkDigisensGeometryXMLFileReader.cxx | 2 +- src/rtkEdfImageIO.cxx | 12 ++++++------ src/rtkForbildPhantomFileReader.cxx | 7 ++++--- ...ThreeDCircularProjectionGeometryXMLFileReader.cxx | 2 +- src/rtkXRadImageIO.cxx | 10 +++++----- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/include/rtkEdfRawToAttenuationImageFilter.hxx b/include/rtkEdfRawToAttenuationImageFilter.hxx index 8673be17b..c17e145f8 100644 --- a/include/rtkEdfRawToAttenuationImageFilter.hxx +++ b/include/rtkEdfRawToAttenuationImageFilter.hxx @@ -64,7 +64,7 @@ EdfRawToAttenuationImageFilter::BeforeThreadedGenerat { const std::string::size_type nameSize = name.size(); const std::string indexStr(name, nameSize - 8, 4); - m_ReferenceIndices.push_back(atoi(indexStr.c_str())); + m_ReferenceIndices.push_back(std::stoi(indexStr.c_str())); } // Dark images diff --git a/src/rtkDigisensGeometryXMLFileReader.cxx b/src/rtkDigisensGeometryXMLFileReader.cxx index 53dddd4a2..98698c6e9 100644 --- a/src/rtkDigisensGeometryXMLFileReader.cxx +++ b/src/rtkDigisensGeometryXMLFileReader.cxx @@ -95,7 +95,7 @@ DigisensGeometryXMLFileReader::EndElement(const char * name) #define ENCAPLULATE_META_DATA_INTEGER(section, metaName) \ if (m_CurrentSection == section && itksys::SystemTools::Strucmp(name, metaName) == 0) \ { \ - int i = atoi(m_CurCharacterData.c_str()); \ + int i = std::stoi(m_CurCharacterData.c_str()); \ itk::EncapsulateMetaData(m_Dictionary, #section metaName, i); \ } diff --git a/src/rtkEdfImageIO.cxx b/src/rtkEdfImageIO.cxx index 5ffd357e5..be22bef4e 100644 --- a/src/rtkEdfImageIO.cxx +++ b/src/rtkEdfImageIO.cxx @@ -89,19 +89,19 @@ rtk::EdfImageIO::ReadImageInformation() strncpy(otherfile_name, p, plen); otherfile_name[plen] = '\0'; if ((p = edf_findInHeader(header, "EDF_BinaryFilePosition"))) - otherfile_skip = atoi(p); + otherfile_skip = std::stoi(p); } if ((p = edf_findInHeader(header, "Dim_1"))) - dim1 = atoi(p); + dim1 = std::stoi(p); if ((p = edf_findInHeader(header, "Dim_2"))) - dim2 = atoi(p); + dim2 = std::stoi(p); // int orig1 = -1, orig2 = -1; // if ((p = edf_findInHeader(header, "row_beg"))) - // orig1 = atoi(p); + // orig1 = std::stoi(p); // if ((p = edf_findInHeader(header, "col_beg"))) - // orig2 = atoi(p); + // orig2 = std::stoi(p); static const struct table3 edf_datatype_table[] = { { "UnsignedByte", U_CHAR_DATATYPE, 1 }, { "SignedByte", CHAR_DATATYPE, 1 }, @@ -189,7 +189,7 @@ rtk::EdfImageIO::ReadImageInformation() int datasize = dim1 * dim2 * datalen; if ((p = edf_findInHeader(header, "Size"))) { - int d = atoi(p); + int d = std::stoi(p); if (d != datasize) { itkWarningMacro(<< "Size " << datasize << " is not " << dim1 << 'x' << dim2 << "x" << datalen << " = " << d diff --git a/src/rtkForbildPhantomFileReader.cxx b/src/rtkForbildPhantomFileReader.cxx index a570409fb..744bb7be9 100644 --- a/src/rtkForbildPhantomFileReader.cxx +++ b/src/rtkForbildPhantomFileReader.cxx @@ -18,6 +18,7 @@ #include "math.h" #include +#include #include #include @@ -32,7 +33,7 @@ void ForbildPhantomFileReader::GenerateOutputInformation() { // Save locale setting - const std::string oldLocale = std::setlocale(LC_NUMERIC, nullptr); + const std::string oldLocale = setlocale(LC_NUMERIC, nullptr); setlocale(LC_NUMERIC, "C"); m_GeometricPhantom = GeometricPhantom::New(); @@ -107,7 +108,7 @@ ForbildPhantomFileReader::GenerateOutputInformation() for (const auto & m_Union : m_Unions) m_GeometricPhantom->AddConvexShape(m_Union); myFile.close(); - std::setlocale(LC_NUMERIC, oldLocale.c_str()); + setlocale(LC_NUMERIC, oldLocale.c_str()); } void @@ -528,7 +529,7 @@ ForbildPhantomFileReader::FindUnions(const std::string & s) IntersectionOfConvexShapes::Pointer ico = IntersectionOfConvexShapes::New(); ico->AddConvexShape(m_ConvexShape); size_t len = m_GeometricPhantom->GetConvexShapes().size(); - int u = atoi(re.match(1).c_str()); + int u = std::stoi(re.match(1).c_str()); size_t pos = len + u - 1; ico->AddConvexShape(m_GeometricPhantom->GetConvexShapes()[pos]); if (m_ConvexShape->GetDensity() != m_GeometricPhantom->GetConvexShapes()[pos]->GetDensity()) diff --git a/src/rtkThreeDCircularProjectionGeometryXMLFileReader.cxx b/src/rtkThreeDCircularProjectionGeometryXMLFileReader.cxx index c9e6773f8..ebdb82ce8 100644 --- a/src/rtkThreeDCircularProjectionGeometryXMLFileReader.cxx +++ b/src/rtkThreeDCircularProjectionGeometryXMLFileReader.cxx @@ -56,7 +56,7 @@ ThreeDCircularProjectionGeometryXMLFileReader::StartElement(const char * name, c while ((*atts) != nullptr) { if (std::string(atts[0]) == "version") - m_Version = atoi(atts[1]); + m_Version = std::stoi(atts[1]); atts += 2; } // Version 3 is backward compatible with version 2 diff --git a/src/rtkXRadImageIO.cxx b/src/rtkXRadImageIO.cxx index 89b28ed40..4a810cde4 100644 --- a/src/rtkXRadImageIO.cxx +++ b/src/rtkXRadImageIO.cxx @@ -51,16 +51,16 @@ rtk::XRadImageIO::ReadImageInformation() std::string paramValue = line.substr(pos + 1, line.length() - pos - 1); if (paramName == std::string("CBCT.DimensionalAttributes.IDim")) - SetDimensions(0, atoi(paramValue.c_str())); + SetDimensions(0, std::stoi(paramValue.c_str())); else if (paramName == std::string("CBCT.DimensionalAttributes.JDim")) - SetDimensions(1, atoi(paramValue.c_str())); + SetDimensions(1, std::stoi(paramValue.c_str())); else if (paramName == std::string("CBCT.DimensionalAttributes.KDim")) - SetDimensions(2, atoi(paramValue.c_str())); + SetDimensions(2, std::stoi(paramValue.c_str())); else if (paramName == std::string("CBCT.DimensionalAttributes.DataSize")) { - if (atoi(paramValue.c_str()) == 3) + if (std::stoi(paramValue.c_str()) == 3) SetComponentType(itk::ImageIOBase::IOComponentEnum::FLOAT); - if (atoi(paramValue.c_str()) == 6) + if (std::stoi(paramValue.c_str()) == 6) SetComponentType(itk::ImageIOBase::IOComponentEnum::USHORT); } else if (paramName == std::string("CBCT.DimensionalAttributes.PixelDimension_I_cm"))