Refactor intrinThresholdParams to use shared DAP helpers.

Delegate threshold param parsing to the new DeviceAttachmentSpec primitives
so intrin modules stay aligned with stimBuff param conventions.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-14 11:00:30 -04:00
parent b198f6a42b
commit 42c9fcdfdf
3 changed files with 375 additions and 66 deletions
+22 -66
View File
@@ -11,6 +11,8 @@
#include <utility>
#include <vector>
#include <user/deviceAttachmentSpec.h>
namespace smo::intrin {
enum class ThresholdUnit
@@ -97,35 +99,21 @@ inline bool arrayContains(
const std::array<std::string_view, N>& names,
std::string_view candidate)
{
for (const auto& name : names) {
if (name == candidate) { return true; }
}
return false;
}
template <typename NameCollectionT>
inline bool namesContain(
const NameCollectionT& names,
std::string_view candidate)
{
for (const auto& name : names) {
if (name == candidate) { return true; }
}
return false;
return device::DeviceAttachmentSpec::namesContain(names, candidate);
}
inline bool isKnownIntrinThresholdParamName(std::string_view name)
{
return namesContain(kIntrinInterestPcNames, name)
|| namesContain(kIntrinInterestThrNames, name)
|| namesContain(kIntrinDistractionPcNames, name)
|| namesContain(kIntrinDistractionThrNames, name)
|| namesContain(kIntrinStupefactionPcNames, name)
|| namesContain(kIntrinStupefactionThrNames, name)
|| namesContain(kIntrinIntolerablePcNames, name)
|| namesContain(kIntrinIntolerableThrNames, name);
using device::DeviceAttachmentSpec;
return DeviceAttachmentSpec::namesContain(kIntrinInterestPcNames, name)
|| DeviceAttachmentSpec::namesContain(kIntrinInterestThrNames, name)
|| DeviceAttachmentSpec::namesContain(kIntrinDistractionPcNames, name)
|| DeviceAttachmentSpec::namesContain(kIntrinDistractionThrNames, name)
|| DeviceAttachmentSpec::namesContain(kIntrinStupefactionPcNames, name)
|| DeviceAttachmentSpec::namesContain(kIntrinStupefactionThrNames, name)
|| DeviceAttachmentSpec::namesContain(kIntrinIntolerablePcNames, name)
|| DeviceAttachmentSpec::namesContain(kIntrinIntolerableThrNames, name);
}
/* Intrin threshold params (interest-*, distraction-*, stupefaction-*,
@@ -194,30 +182,6 @@ inline void validateIntrinSegmentParams(
}
}
inline std::optional<std::pair<std::string_view, int>> findLastMatchingIntParam(
const std::vector<std::pair<std::string, std::string>>& params,
const auto& synonymNames)
{
for (auto paramIt = params.rbegin(); paramIt != params.rend(); ++paramIt)
{
const auto& [name, value] = *paramIt;
if (!namesContain(synonymNames, name))
{ continue; }
try {
return std::pair<std::string_view, int>(name, std::stoi(value));
}
catch (const std::exception& e)
{
throw std::runtime_error(
"Failed to parse '" + name + "' param value '" + value
+ "' as integer: " + e.what());
}
}
return std::nullopt;
}
inline ParsedThresholdParam parseOptionalThresholdParam(
const std::vector<std::pair<std::string, std::string>>& params,
const auto& percentageNames,
@@ -230,28 +194,20 @@ inline ParsedThresholdParam parseOptionalThresholdParam(
const auto& [name, value] = *paramIt;
ThresholdUnit unit;
if (namesContain(percentageNames, name))
if (device::DeviceAttachmentSpec::namesContain(percentageNames, name))
{ unit = ThresholdUnit::Percentage; }
else if (namesContain(absoluteNames, name))
else if (device::DeviceAttachmentSpec::namesContain(absoluteNames, name))
{ unit = ThresholdUnit::Absolute; }
else
{ continue; }
try
{
return ParsedThresholdParam{
.value = std::stoi(value),
.unit = unit,
.matchedName = name,
.wasSpecified = true,
};
}
catch (const std::exception& e)
{
throw std::runtime_error(
"Failed to parse '" + name + "' param value '" + value
+ "' as integer: " + e.what());
}
return ParsedThresholdParam{
.value = device::DeviceAttachmentSpec::parseParamValueAsInt(
name, value),
.unit = unit,
.matchedName = name,
.wasSpecified = true,
};
}
return ParsedThresholdParam{