mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2024-12-24 18:08:27 +01:00
Const correctness fix for optionlist
This commit is contained in:
parent
5f0858bab2
commit
314b8bf72d
@ -8,7 +8,7 @@ class OptionList {
|
||||
public:
|
||||
OptionList() { updateText(); }
|
||||
|
||||
void define(K key, std::string name, T value) {
|
||||
void define(const K& key, const std::string& name, const T& value) {
|
||||
if (keyExists(key)) { throw std::runtime_error("Key already exists"); }
|
||||
if (nameExists(name)) { throw std::runtime_error("Name already exists"); }
|
||||
if (valueExists(value)) { throw std::runtime_error("Value already exists"); }
|
||||
@ -18,27 +18,27 @@ public:
|
||||
updateText();
|
||||
}
|
||||
|
||||
void define(std::string name, T value) {
|
||||
void define(const std::string& name, const T& value) {
|
||||
define(name, name, value);
|
||||
}
|
||||
|
||||
void undefined(int id) {
|
||||
void undefine(int id) {
|
||||
keys.erase(keys.begin() + id);
|
||||
names.erase(names.begin() + id);
|
||||
values.erase(values.begin() + id);
|
||||
updateText();
|
||||
}
|
||||
|
||||
void undefineKey(K key) {
|
||||
undefined(keyId(key));
|
||||
void undefineKey(const K& key) {
|
||||
undefine(keyId(key));
|
||||
}
|
||||
|
||||
void undefineName(std::string name) {
|
||||
undefined(nameId(name));
|
||||
void undefineName(const std::string& name) {
|
||||
undefine(nameId(name));
|
||||
}
|
||||
|
||||
void undefineValue(T value) {
|
||||
undefined(valueId(value));
|
||||
void undefineValue(const T& value) {
|
||||
undefine(valueId(value));
|
||||
}
|
||||
|
||||
void clear() {
|
||||
@ -48,61 +48,61 @@ public:
|
||||
updateText();
|
||||
}
|
||||
|
||||
int size() {
|
||||
int size() const {
|
||||
return keys.size();
|
||||
}
|
||||
|
||||
bool empty() {
|
||||
bool empty() const {
|
||||
return keys.empty();
|
||||
}
|
||||
|
||||
bool keyExists(K key) {
|
||||
bool keyExists(const K& key) const {
|
||||
if (std::find(keys.begin(), keys.end(), key) != keys.end()) { return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
bool nameExists(std::string name) {
|
||||
bool nameExists(const std::string& name) const {
|
||||
if (std::find(names.begin(), names.end(), name) != names.end()) { return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
bool valueExists(T value) {
|
||||
bool valueExists(const T& value) const {
|
||||
if (std::find(values.begin(), values.end(), value) != values.end()) { return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
int keyId(K key) {
|
||||
int keyId(const K& key) const {
|
||||
auto it = std::find(keys.begin(), keys.end(), key);
|
||||
if (it == keys.end()) { throw std::runtime_error("Key doesn't exists"); }
|
||||
return std::distance(keys.begin(), it);
|
||||
}
|
||||
|
||||
int nameId(std::string name) {
|
||||
int nameId(const std::string& name) const {
|
||||
auto it = std::find(names.begin(), names.end(), name);
|
||||
if (it == names.end()) { throw std::runtime_error("Name doesn't exists"); }
|
||||
return std::distance(names.begin(), it);
|
||||
}
|
||||
|
||||
int valueId(T value) {
|
||||
int valueId(const T& value) const {
|
||||
auto it = std::find(values.begin(), values.end(), value);
|
||||
if (it == values.end()) { throw std::runtime_error("Value doesn't exists"); }
|
||||
return std::distance(values.begin(), it);
|
||||
}
|
||||
|
||||
K key(int id) {
|
||||
inline const K& key(int id) const {
|
||||
return keys[id];
|
||||
}
|
||||
|
||||
std::string name(int id) {
|
||||
inline const std::string& name(int id) const {
|
||||
return names[id];
|
||||
}
|
||||
|
||||
T value(int id) {
|
||||
inline const T& value(int id) const {
|
||||
return values[id];
|
||||
}
|
||||
|
||||
T operator[](int& id) {
|
||||
return value(id);
|
||||
inline const T& operator[](int& id) const {
|
||||
return values[id];
|
||||
}
|
||||
|
||||
const char* txt = NULL;
|
||||
|
@ -25,7 +25,7 @@ ConfigManager config;
|
||||
struct DeviceInfo {
|
||||
RtAudio::DeviceInfo info;
|
||||
int id;
|
||||
bool operator==(const struct DeviceInfo& other) {
|
||||
bool operator==(const struct DeviceInfo& other) const {
|
||||
return other.id == id;
|
||||
}
|
||||
};
|
||||
|
@ -39,7 +39,7 @@ namespace hermes {
|
||||
uint8_t gatewareVerMin;
|
||||
BoardID boardId;
|
||||
|
||||
bool operator==(const Info& b) {
|
||||
bool operator==(const Info& b) const {
|
||||
return !memcmp(mac, b.mac, 6);
|
||||
}
|
||||
};
|
||||
|
@ -503,7 +503,7 @@ private:
|
||||
float refStep = 0.5;
|
||||
|
||||
struct SRCombo {
|
||||
bool operator==(const SRCombo& b) {
|
||||
bool operator==(const SRCombo& b) const {
|
||||
return baseId == b.baseId && decimId == b.decimId;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user