Skip to content

Commit

Permalink
STYLE: Prefer error checked std::stoi over atoi
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Rit committed Mar 15, 2022
1 parent 942fa6f commit 9f40cc0
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion include/rtkEdfRawToAttenuationImageFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ EdfRawToAttenuationImageFilter<TInputImage, TOutputImage>::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
Expand Down
2 changes: 1 addition & 1 deletion src/rtkDigisensGeometryXMLFileReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(m_Dictionary, #section metaName, i); \
}

Expand Down
12 changes: 6 additions & 6 deletions src/rtkEdfImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/rtkForbildPhantomFileReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "math.h"
#include <cstdlib>
#include <clocale>
#include <fstream>
#include <itksys/RegularExpression.hxx>

Expand All @@ -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();

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion src/rtkThreeDCircularProjectionGeometryXMLFileReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/rtkXRadImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit 9f40cc0

Please sign in to comment.