DASpec:genericize synonymous param parsing
This commit is contained in:
@@ -114,6 +114,36 @@ public:
|
|||||||
+ it->second + "' as integer: " + e.what());
|
+ 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
|
class InteroceptorDevAttachmentSpec : public DeviceAttachmentSpec
|
||||||
|
|||||||
@@ -84,29 +84,14 @@ getStimulusProducer(
|
|||||||
static size_t parseNDgramsPerFrame(
|
static size_t parseNDgramsPerFrame(
|
||||||
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& spec)
|
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& spec)
|
||||||
{
|
{
|
||||||
size_t nDgramsPerFrame = 84; // Default: 84 datagrams per frame
|
|
||||||
const std::vector<std::string> nDgramsPerFrameParamNames = {
|
const std::vector<std::string> nDgramsPerFrameParamNames = {
|
||||||
"n-dgrams-per-frame",
|
"n-dgrams-per-frame",
|
||||||
"num-dgrams-per-frame"
|
"num-dgrams-per-frame"
|
||||||
};
|
};
|
||||||
|
|
||||||
// Loop through synonyms in reverse order; lattermost synonym wins.
|
return static_cast<size_t>(
|
||||||
for (auto synIt = nDgramsPerFrameParamNames.rbegin();
|
smo::device::DeviceAttachmentSpec::parseOptionalParamAsIntWithSynonyms(
|
||||||
synIt != nDgramsPerFrameParamNames.rend(); ++synIt)
|
spec->stimBuffApiParams, nDgramsPerFrameParamNames, 84));
|
||||||
{
|
|
||||||
const auto& paramName = *synIt;
|
|
||||||
try {
|
|
||||||
nDgramsPerFrame = static_cast<size_t>(
|
|
||||||
smo::device::DeviceAttachmentSpec::parseRequiredParamAsInt(
|
|
||||||
spec->stimBuffApiParams, paramName));
|
|
||||||
break; // Found and parsed successfully
|
|
||||||
} catch (const std::exception&) {
|
|
||||||
// Parameter not found or parse error, continue to next synonym
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nDgramsPerFrame;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// LivoxProto1DllState constructor implementation
|
// LivoxProto1DllState constructor implementation
|
||||||
|
|||||||
@@ -110,7 +110,6 @@ void produceStimFrameAck(void)
|
|||||||
static int parseHistbuffMs(
|
static int parseHistbuffMs(
|
||||||
const std::shared_ptr<device::DeviceAttachmentSpec>& spec)
|
const std::shared_ptr<device::DeviceAttachmentSpec>& spec)
|
||||||
{
|
{
|
||||||
int histbuffMs = 30000; // Default: 30000ms (30 seconds)
|
|
||||||
const std::vector<std::string> histbuffParamNames = {
|
const std::vector<std::string> histbuffParamNames = {
|
||||||
"history-buffer-duration-ms",
|
"history-buffer-duration-ms",
|
||||||
"hist-buff-duration-ms",
|
"hist-buff-duration-ms",
|
||||||
@@ -118,23 +117,8 @@ static int parseHistbuffMs(
|
|||||||
"histbuff-ms"
|
"histbuff-ms"
|
||||||
};
|
};
|
||||||
|
|
||||||
// Loop through synonyms in reverse order; lattermost synonym wins.
|
return device::DeviceAttachmentSpec::parseOptionalParamAsIntWithSynonyms(
|
||||||
for (auto synIt = histbuffParamNames.rbegin();
|
spec->qualeIfaceApiParams, histbuffParamNames, 30000);
|
||||||
synIt != histbuffParamNames.rend(); ++synIt)
|
|
||||||
{
|
|
||||||
const auto& paramName = *synIt;
|
|
||||||
try {
|
|
||||||
histbuffMs = device::DeviceAttachmentSpec
|
|
||||||
::parseRequiredParamAsInt(
|
|
||||||
spec->qualeIfaceApiParams, paramName);
|
|
||||||
break; // Found and parsed successfully
|
|
||||||
} catch (const std::exception&) {
|
|
||||||
// Parameter not found or parse error, continue to next synonym
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return histbuffMs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<StimulusBuffer>
|
std::shared_ptr<StimulusBuffer>
|
||||||
|
|||||||
Reference in New Issue
Block a user