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