Skip to content

Commit

Permalink
STYLE: Remove local possibleTransformIO from TransformIOFactoryTemplate
Browse files Browse the repository at this point in the history
Removed the local `possibleTransformIO` variable from the member
function `TransformIOFactoryTemplate::CreateTransformIO`, as it appears
unnecessary to put all IO objects into that list, before finding the one
that can process the specified file path.

Reduced amount of duplicate code for read and write, and improved
const-correctness.
  • Loading branch information
N-Dekker authored and dzenanz committed Nov 18, 2020
1 parent 5d02fac commit d262349
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions Modules/IO/TransformBase/src/itkTransformIOFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,16 @@ template <typename TParametersValueType>
typename TransformIOBaseTemplate<TParametersValueType>::Pointer
TransformIOFactoryTemplate<TParametersValueType>::CreateTransformIO(const char * path, IOFileModeEnum mode)
{
typename std::list<typename TransformIOBaseTemplate<TParametersValueType>::Pointer> possibleTransformIO;
for (auto & allobject : ObjectFactoryBase::CreateAllInstance("itkTransformIOBaseTemplate"))
for (const auto & allobject : ObjectFactoryBase::CreateAllInstance("itkTransformIOBaseTemplate"))
{
auto * io = dynamic_cast<TransformIOBaseTemplate<TParametersValueType> *>(allobject.GetPointer());
if (io)
{
possibleTransformIO.push_back(io);
}
}
for (auto k = possibleTransformIO.begin(); k != possibleTransformIO.end(); ++k)
{
if (mode == IOFileModeEnum::ReadMode)
{
if ((*k)->CanReadFile(path))
{
return *k;
}
}
else if (mode == IOFileModeEnum::WriteMode)
auto * const io = dynamic_cast<TransformIOBaseTemplate<TParametersValueType> *>(allobject.GetPointer());

if (io != nullptr)
{
if ((*k)->CanWriteFile(path))
if (((mode == IOFileModeEnum::ReadMode) && (io->CanReadFile(path))) ||
((mode == IOFileModeEnum::WriteMode) && (io->CanWriteFile(path))))
{
return *k;
return io;
}
}
}
Expand Down

0 comments on commit d262349

Please sign in to comment.