Skip to content
Snippets Groups Projects
Commit fb6576af authored by t.knopff's avatar t.knopff
Browse files

Merge branch 'cleanup_warnings2' into 'develop'

Added handling of negative values of signed integers to get rid of warning

See merge request !42
parents a9bab515 011f958a
No related branches found
No related tags found
1 merge request!42Added handling of negative values of signed integers to get rid of warning
Pipeline #35341 passed
......@@ -21,9 +21,9 @@ OutputData<double>* OutputDataReadWriteNicos::readOutputData(std::istream& input
std::string line;
m_currentLineNr = 0;
int width = 0;
int height = 0;
unsigned int width = 0;
unsigned int height = 0;
// -- read dimensions
bool inFileSection = false;
bool fileSectionFound = false;
......@@ -45,9 +45,9 @@ OutputData<double>* OutputDataReadWriteNicos::readOutputData(std::istream& input
}
if (StringUtils::startsWith(line, "DataSizeX"))
width = readAssignedIntValue(line);
width = readAssignedPositiveIntValue(line);
else if (StringUtils::startsWith(line, "DataSizeY"))
height = readAssignedIntValue(line);
height = readAssignedPositiveIntValue(line);
if (width != 0 && height != 0)
break;
......@@ -66,7 +66,7 @@ OutputData<double>* OutputDataReadWriteNicos::readOutputData(std::istream& input
// -- read data
bool inCountSection = false;
bool countSectionFound = false;
int dataRow = 0;
unsigned int dataRow = 0;
while (std::getline(input_stream, line)) {
m_currentLineNr++;
......@@ -98,7 +98,7 @@ OutputData<double>* OutputDataReadWriteNicos::readOutputData(std::istream& input
for (unsigned col = 0; col < width; ++col) {
const size_t global_index =
result->toGlobalIndex({col, static_cast<unsigned>(height) - 1
result->toGlobalIndex({col, height - 1
- dataRow}); // y-axis "0" is at bottom => invert y
// to show first line at top of image
......@@ -124,7 +124,7 @@ OutputData<double>* OutputDataReadWriteNicos::readOutputData(std::istream& input
return result.release();
}
int OutputDataReadWriteNicos::readAssignedIntValue(const std::string& line) const
unsigned int OutputDataReadWriteNicos::readAssignedPositiveIntValue(const std::string& line) const
{
const auto parts = StringUtils::split(line, "=");
if (parts.size() != 2)
......@@ -135,6 +135,10 @@ int OutputDataReadWriteNicos::readAssignedIntValue(const std::string& line) cons
throw std::runtime_error(
lineRelatedError("Can't parse assigned value '" + parts[1] + "'."));
if (value <= 0)
throw std::runtime_error
(lineRelatedError("Value of '" + parts[1] + "' is nonpositive."));
return value;
}
......
......@@ -26,8 +26,8 @@ public:
private:
//! Reads the assigned integer value from a line content like "DataSizeX = 100"
//! Throws if not successful
int readAssignedIntValue(const std::string& line) const;
//! Throws if not successful or if value is nonpositive
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;
......
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