avoid lambda to simplify source code
This commit is contained in:
1 parent
6cd99768ae
commit
03dc8f2a13
6 files changed
+143
-126
No files matched your search
+21
-20
@@ -20,6 +20,23 @@ namespace {
|
||||
return value;
|
||||
}
|
||||
|
||||
double ParsePhysicalValue(const std::string &text, const char *field) {
|
||||
static const std::regex number(
|
||||
R"(^[+-]?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[eE][+-]?[0-9]+)?$)");
|
||||
if (!std::regex_match(text, number))
|
||||
throw std::runtime_error(std::string("Invalid ") + field + ": " + text);
|
||||
std::size_t consumed = 0U;
|
||||
double value;
|
||||
try {
|
||||
value = std::stod(text, &consumed);
|
||||
} catch (const std::exception &) {
|
||||
throw std::runtime_error(std::string("Invalid ") + field + ": " + text);
|
||||
}
|
||||
if (consumed != text.size() || !std::isfinite(value))
|
||||
throw std::runtime_error(std::string("Invalid ") + field + ": " + text);
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Remove leading and trailing spaces.
|
||||
* @param text Input text.
|
||||
@@ -164,26 +181,10 @@ SignalInfo DbcSignalHandler::ParseSignalLine(const std::string &line) {
|
||||
signal.isLittleEndian = fields[4].str() == "1";
|
||||
signal.isSigned = fields[5].str() == "-";
|
||||
|
||||
const auto parsePhysical = [](const std::string &text, const char *field) {
|
||||
static const std::regex number(
|
||||
R"(^[+-]?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[eE][+-]?[0-9]+)?$)");
|
||||
if (!std::regex_match(text, number))
|
||||
throw std::runtime_error(std::string("Invalid ") + field + ": " + text);
|
||||
std::size_t consumed = 0U;
|
||||
double value;
|
||||
try {
|
||||
value = std::stod(text, &consumed);
|
||||
} catch (const std::exception &) {
|
||||
throw std::runtime_error(std::string("Invalid ") + field + ": " + text);
|
||||
}
|
||||
if (consumed != text.size() || !std::isfinite(value))
|
||||
throw std::runtime_error(std::string("Invalid ") + field + ": " + text);
|
||||
return value;
|
||||
};
|
||||
signal.factor = parsePhysical(fields[6].str(), "signal factor");
|
||||
signal.offset = parsePhysical(fields[7].str(), "signal offset");
|
||||
signal.minimum = parsePhysical(fields[8].str(), "signal minimum");
|
||||
signal.maximum = parsePhysical(fields[9].str(), "signal maximum");
|
||||
signal.factor = ParsePhysicalValue(fields[6].str(), "signal factor");
|
||||
signal.offset = ParsePhysicalValue(fields[7].str(), "signal offset");
|
||||
signal.minimum = ParsePhysicalValue(fields[8].str(), "signal minimum");
|
||||
signal.maximum = ParsePhysicalValue(fields[9].str(), "signal maximum");
|
||||
if (signal.minimum > signal.maximum)
|
||||
throw std::runtime_error("Signal minimum exceeds maximum.");
|
||||
signal.unit = fields[10].str();
|
||||
|
||||
Reference in new issue
Block a user