findSensorTypeByName
This commit is contained in:
parent
abadef0e96
commit
37594d5646
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -193,3 +193,5 @@ private:
|
|||
*/
|
||||
static SensorRegistryEntry *getEntryForType(SensorType type);
|
||||
};
|
||||
|
||||
SensorType findSensorTypeByName(const char *name);
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue