Skip to content

Commit

Permalink
Merge pull request #1516 from ANTsX/parseWinPointers
Browse files Browse the repository at this point in the history
ENH: Parse windows pointers for write operations
  • Loading branch information
cookpa authored Mar 22, 2023
2 parents 6eb6bf0 + 1b2b541 commit 276cf07
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions Utilities/ReadWriteData.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,21 +210,10 @@ ReadTensorImage(itk::SmartPointer<TImageType> & target, const char * file, bool
}
}

template <typename TImageType>
// void ReadImage(typename TImageType::Pointer target, const char *file)
bool
ReadImage(itk::SmartPointer<TImageType> & target, const char * file)
// function to determine if a file name is a memory address rather than a file
inline bool
FileIsPointer(const char *file)
{
enum
{
ImageDimension = TImageType::ImageDimension
};
if (std::string(file).length() < 3)
{
target = nullptr;
return false;
}

bool fileIsPointer = false;

std::string comparetype1 = std::string("0x");
Expand All @@ -238,7 +227,9 @@ ReadImage(itk::SmartPointer<TImageType> & target, const char * file)
else
{
std::string fileString = std::string(file);
// Also treat file as a pointer if it is composed entirely of hex characters, and has appropriate length
// Also treat file as a pointer if it is composed entirely of hex characters, and has
// appropriate length
// Windows pointers are just hex numbers without the leading 0x
bool fileIsHexChars = true;

std::string::iterator fileIt;
Expand All @@ -256,8 +247,25 @@ ReadImage(itk::SmartPointer<TImageType> & target, const char * file)
fileIsPointer = true;
}
}
return fileIsPointer;
}

if (fileIsPointer)
template <typename TImageType>
// void ReadImage(typename TImageType::Pointer target, const char *file)
bool
ReadImage(itk::SmartPointer<TImageType> & target, const char * file)
{
enum
{
ImageDimension = TImageType::ImageDimension
};
if (std::string(file).length() < 3)
{
target = nullptr;
return false;
}

if (FileIsPointer(file))
{
typedef TImageType RImageType;
void * ptr;
Expand Down Expand Up @@ -552,7 +560,7 @@ WriteImage(const itk::SmartPointer<TImageType> image, const char * file)
// if (writer->GetImageIO->GetNumberOfComponents() == 6)
// NiftiDTICheck<TImageType>(image,file);

if (file[0] == '0' && file[1] == 'x')
if (FileIsPointer(file))
{
void * ptr;
sscanf(file, "%p", (void **)&ptr);
Expand Down

0 comments on commit 276cf07

Please sign in to comment.