Skip to content
Snippets Groups Projects
Commit 72504494 authored by Martyn Gigg's avatar Martyn Gigg
Browse files

Refactor reinterpret_cast lines & remove cppcast suppressions

They pointed to real problem before but no longer.
Refs #14106
parent 894c5d26
No related merge requests found
...@@ -19,17 +19,28 @@ using namespace Mantid::DataObjects; ...@@ -19,17 +19,28 @@ using namespace Mantid::DataObjects;
using namespace Mantid::API; using namespace Mantid::API;
using namespace Mantid::Kernel; using namespace Mantid::Kernel;
namespace {
/**
* Reinterpret a byte sequence as InterpretType and cast to double
* @param Pointer to byte src
*/
template <typename InterpretType> double toDouble(uint8_t *src) {
return static_cast<double>(*reinterpret_cast<InterpretType *>(src));
}
}
namespace Mantid { namespace Mantid {
namespace DataHandling { namespace DataHandling {
// Register the algorithm into the AlgorithmFactory // Register the algorithm into the AlgorithmFactory
DECLARE_FILELOADER_ALGORITHM(LoadFITS) DECLARE_FILELOADER_ALGORITHM(LoadFITS)
// Static class constants
const std::string LoadFITS::g_BIT_DEPTH_NAME = "BitDepthName"; const std::string LoadFITS::g_BIT_DEPTH_NAME = "BitDepthName";
const std::string LoadFITS::g_ROTATION_NAME = "RotationName"; const std::string LoadFITS::g_ROTATION_NAME = "RotationName";
const std::string LoadFITS::g_AXIS_NAMES_NAME = "AxisNames"; const std::string LoadFITS::g_AXIS_NAMES_NAME = "AxisNames";
const std::string LoadFITS::g_IMAGE_KEY_NAME = "ImageKeyName"; const std::string LoadFITS::g_IMAGE_KEY_NAME = "ImageKeyName";
const std::string LoadFITS::g_HEADER_MAP_NAME = "HeaderMapFile"; const std::string LoadFITS::g_HEADER_MAP_NAME = "HeaderMapFile";
const std::string LoadFITS::g_defaultImgType = "SAMPLE"; const std::string LoadFITS::g_defaultImgType = "SAMPLE";
/** /**
...@@ -809,25 +820,18 @@ void LoadFITS::readDataToWorkspace(const FITSInfo &fileInfo, double cmpp, ...@@ -809,25 +820,18 @@ void LoadFITS::readDataToWorkspace(const FITSInfo &fileInfo, double cmpp,
std::reverse_copy(buffer8Start, buffer8Start + bytespp, byteValue.get()); std::reverse_copy(buffer8Start, buffer8Start + bytespp, byteValue.get());
double val = 0; double val = 0;
if (fileInfo.bitsPerPixel == 8) if (fileInfo.bitsPerPixel == 8) {
val = static_cast<double>(*byteValue); val = toDouble<uint8_t>(byteValue.get());
else if (fileInfo.bitsPerPixel == 16) } else if (fileInfo.bitsPerPixel == 16) {
val = val = toDouble<uint16_t>(byteValue.get());
static_cast<double>(*reinterpret_cast<uint16_t *>(byteValue.get())); } else if (fileInfo.bitsPerPixel == 32 && !fileInfo.isFloat) {
else if (fileInfo.bitsPerPixel == 32 && !fileInfo.isFloat) val = toDouble<uint32_t>(byteValue.get());
val = } else if (fileInfo.bitsPerPixel == 64 && !fileInfo.isFloat) {
static_cast<double>(*reinterpret_cast<uint32_t *>(byteValue.get())); val = toDouble<uint32_t>(byteValue.get());
else if (fileInfo.bitsPerPixel == 64 && !fileInfo.isFloat) } else if (fileInfo.bitsPerPixel == 32 && fileInfo.isFloat) {
val = val = toDouble<float>(byteValue.get());
static_cast<double>(*reinterpret_cast<uint64_t *>(byteValue.get()));
// cppcheck doesn't realise that these are safe casts
else if (fileInfo.bitsPerPixel == 32 && fileInfo.isFloat) {
// cppcheck-suppress invalidPointerCast
val = static_cast<double>(*reinterpret_cast<float *>(byteValue.get()));
} else if (fileInfo.bitsPerPixel == 64 && fileInfo.isFloat) { } else if (fileInfo.bitsPerPixel == 64 && fileInfo.isFloat) {
// cppcheck-suppress invalidPointerCast val = toDouble<double>(byteValue.get());
val = *reinterpret_cast<double *>(byteValue.get());
} }
val = fileInfo.scale * val - fileInfo.offset; val = fileInfo.scale * val - fileInfo.offset;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment