kopia lustrzana https://gitlab.com/sane-project/backends
genesys: Reduce logical duplication in GenesysRegisterSettingSet
rodzic
543ba367bc
commit
759e450b6b
|
@ -295,20 +295,19 @@ public:
|
||||||
|
|
||||||
uint8_t get_value(uint16_t address) const
|
uint8_t get_value(uint16_t address) const
|
||||||
{
|
{
|
||||||
for (const auto& reg : registers_) {
|
int index = find_reg_index(address);
|
||||||
if (reg.address == address)
|
if (index >= 0) {
|
||||||
return reg.value;
|
return registers_[index].value;
|
||||||
}
|
}
|
||||||
throw std::runtime_error("Unknown register");
|
throw std::out_of_range("Unknown register");
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_value(uint16_t address, uint8_t value)
|
void set_value(uint16_t address, uint8_t value)
|
||||||
{
|
{
|
||||||
for (auto& reg : registers_) {
|
int index = find_reg_index(address);
|
||||||
if (reg.address == address) {
|
if (index >= 0) {
|
||||||
reg.value = value;
|
registers_[index].value = value;
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
push_back(GenesysRegisterSetting(address, value));
|
push_back(GenesysRegisterSetting(address, value));
|
||||||
}
|
}
|
||||||
|
@ -322,6 +321,17 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
int find_reg_index(uint16_t address) const
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < registers_.size(); i++) {
|
||||||
|
if (registers_[i].address == address) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<GenesysRegisterSetting> registers_;
|
std::vector<GenesysRegisterSetting> registers_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue