Skip to content
Snippets Groups Projects
Commit 437de69b authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

fct -> local namespace

parent 66397c1e
No related branches found
No related tags found
1 merge request!474Restore subroutine to read Nicos/SANSDRaw files, check for Nicos file type, provide unit test
...@@ -15,6 +15,16 @@ ...@@ -15,6 +15,16 @@
#include "Device/InputOutput/OutputDataReadWriteNicos.h" #include "Device/InputOutput/OutputDataReadWriteNicos.h"
#include "Base/Util/StringUtils.h" #include "Base/Util/StringUtils.h"
namespace {
std::string lineRelatedError(const std::string& errorText, int lineNumber)
{
return "Line " + std::to_string(lineNumber) + ": " + errorText;
}
} // namespace
OutputData<double>* OutputDataReadWriteNicos::readOutputData(std::istream& input_stream) OutputData<double>* OutputDataReadWriteNicos::readOutputData(std::istream& input_stream)
{ {
auto result = std::make_unique<OutputData<double>>(); // as unique ptr to ensure delete on throw auto result = std::make_unique<OutputData<double>>(); // as unique ptr to ensure delete on throw
...@@ -94,7 +104,8 @@ OutputData<double>* OutputDataReadWriteNicos::readOutputData(std::istream& input ...@@ -94,7 +104,8 @@ OutputData<double>* OutputDataReadWriteNicos::readOutputData(std::istream& input
if (valuesAsString.size() != width) if (valuesAsString.size() != width)
throw std::runtime_error( throw std::runtime_error(
lineRelatedError("Number of found values (" + std::to_string(valuesAsString.size()) lineRelatedError("Number of found values (" + std::to_string(valuesAsString.size())
+ ") does not match DataSizeX (" + std::to_string(width) + ").")); + ") does not match DataSizeX (" + std::to_string(width) + ").",
m_currentLineNr));
for (unsigned col = 0; col < width; ++col) { for (unsigned col = 0; col < width; ++col) {
const size_t global_index = result->toGlobalIndex( const size_t global_index = result->toGlobalIndex(
...@@ -103,8 +114,10 @@ OutputData<double>* OutputDataReadWriteNicos::readOutputData(std::istream& input ...@@ -103,8 +114,10 @@ OutputData<double>* OutputDataReadWriteNicos::readOutputData(std::istream& input
int value = 0; int value = 0;
if (!BaseUtils::String::to_int(valuesAsString[col], &value)) if (!BaseUtils::String::to_int(valuesAsString[col], &value))
throw std::runtime_error(lineRelatedError( throw std::runtime_error(
"Value '" + valuesAsString[col] + "' could not be converted to integer.")); lineRelatedError("Value '" + valuesAsString[col] +
"' could not be converted to integer.",
m_currentLineNr));
(*result)[global_index] = value; (*result)[global_index] = value;
} }
...@@ -127,20 +140,16 @@ unsigned int OutputDataReadWriteNicos::readAssignedPositiveIntValue(const std::s ...@@ -127,20 +140,16 @@ unsigned int OutputDataReadWriteNicos::readAssignedPositiveIntValue(const std::s
{ {
const auto parts = BaseUtils::String::split(line, "="); const auto parts = BaseUtils::String::split(line, "=");
if (parts.size() != 2) if (parts.size() != 2)
throw std::runtime_error(lineRelatedError("Missing assigned value.")); throw std::runtime_error(lineRelatedError("Missing assigned value.", m_currentLineNr));
int value = 0; int value = 0;
if (!BaseUtils::String::to_int(parts[1], &value)) if (!BaseUtils::String::to_int(parts[1], &value))
throw std::runtime_error( throw std::runtime_error(
lineRelatedError("Can't parse assigned value '" + parts[1] + "'.")); lineRelatedError("Can't parse assigned value '" + parts[1] + "'.", m_currentLineNr));
if (value <= 0) if (value <= 0)
throw std::runtime_error(lineRelatedError("Value of '" + parts[1] + "' is nonpositive.")); throw std::runtime_error(lineRelatedError("Value of '" + parts[1] + "' is nonpositive.",
m_currentLineNr));
return value; return value;
} }
std::string OutputDataReadWriteNicos::lineRelatedError(const std::string& errorText) const
{
return "Line " + std::to_string(m_currentLineNr) + ": " + errorText;
}
...@@ -28,9 +28,6 @@ private: ...@@ -28,9 +28,6 @@ private:
//! Throws if not successful or if value is nonpositive //! Throws if not successful or if value is nonpositive
unsigned int readAssignedPositiveIntValue(const std::string& line) const; unsigned int readAssignedPositiveIntValue(const std::string& line) const;
//! Returns errorText with prepended line number (suitable for throwing errors)
std::string lineRelatedError(const std::string& errorText) const;
int m_currentLineNr = 0; //!< "1" means "first line" (human readable counting) int m_currentLineNr = 0; //!< "1" means "first line" (human readable counting)
}; };
......
...@@ -2121,7 +2121,7 @@ C++ includes: OutputDataReadWriteINT.h ...@@ -2121,7 +2121,7 @@ C++ includes: OutputDataReadWriteINT.h
// File: classOutputDataReadWriteNicos.xml // File: classOutputDataReadWriteNicos.xml
%feature("docstring") OutputDataReadWriteNicos " %feature("docstring") OutputDataReadWriteNicos "
Read/write Nicos files (*.001). Read/write SANSDRaw files written by Nicos (*.001).
C++ includes: OutputDataReadWriteNicos.h C++ includes: OutputDataReadWriteNicos.h
"; ";
...@@ -2778,6 +2778,9 @@ Returns default units to convert to. ...@@ -2778,6 +2778,9 @@ Returns default units to convert to.
// File: namespace_0d55.xml // File: namespace_0d55.xml
// File: namespace_0d61.xml
// File: namespace_0d63.xml // File: namespace_0d63.xml
......
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