findSensorTypeByName

This commit is contained in:
Andrey 2021-10-20 22:21:42 -04:00
parent abadef0e96
commit 37594d5646
3 changed files with 22 additions and 0 deletions

View File

@ -231,3 +231,18 @@ bool Sensor::Register() {
entry->showInfo(getSensorName(type));
}
}
/**
* this is definitely not the fastest implementation possible but good enough for now?
* todo: some sort of hashmap in the future?
*/
SensorType findSensorTypeByName(const char *name) {
for (int i = 0;i<(int)SensorType::PlaceholderLast;i++) {
SensorType type = (SensorType)i;
const char *sensorName = getSensorType(type);
if (strEqualCaseInsensitive(sensorName, name)) {
return type;
}
}
return SensorType::Invalid;
}

View File

@ -193,3 +193,5 @@ private:
*/
static SensorRegistryEntry *getEntryForType(SensorType type);
};
SensorType findSensorTypeByName(const char *name);

View File

@ -107,3 +107,8 @@ TEST_F(SensorBasic, HasSensorMock) {
// Now we should!
ASSERT_TRUE(Sensor::hasSensor(SensorType::Clt));
}
TEST_F(SensorBasic, FindByName) {
ASSERT_EQ(SensorType::Clt, findSensorTypeByName("Clt"));
}