DASpec:genericize synonymous param parsing
This commit is contained in:
@@ -114,6 +114,36 @@ public:
|
||||
+ it->second + "' as integer: " + e.what());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Parse an optional integer parameter from a parameter list using synonyms
|
||||
* @param params The parameter vector to search in
|
||||
* @param synonymNames The collection of synonymous parameter names to try
|
||||
* @param defaultValue The default value to return if no parameter is found
|
||||
* @return The parsed integer value, or defaultValue if none found
|
||||
* @note Synonyms are tried in reverse order; lattermost synonym wins if multiple are present
|
||||
*/
|
||||
static int parseOptionalParamAsIntWithSynonyms(
|
||||
const std::vector<std::pair<std::string,std::string>>& params,
|
||||
const std::vector<std::string>& synonymNames,
|
||||
int defaultValue
|
||||
)
|
||||
{
|
||||
// Loop through synonyms in reverse order; lattermost synonym wins.
|
||||
for (auto synIt = synonymNames.rbegin();
|
||||
synIt != synonymNames.rend(); ++synIt)
|
||||
{
|
||||
const auto& paramName = *synIt;
|
||||
try {
|
||||
return parseRequiredParamAsInt(params, paramName);
|
||||
} catch (const std::exception&) {
|
||||
// Parameter not found or parse error, continue to next synonym
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
};
|
||||
|
||||
class InteroceptorDevAttachmentSpec : public DeviceAttachmentSpec
|
||||
|
||||
Reference in New Issue
Block a user