diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-10-24 22:46:36 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-10-25 13:59:04 -0700 |
commit | 3a2f1b17b65b8c0eca12d60f94a16d573c13537d (patch) | |
tree | 91d209a53af92f3edf5d51da2f64ce3dd8a51ad8 | |
parent | fa7dfa37102fe2b0cf7518c329c3ba0273e39ab9 (diff) | |
download | subsurface-3a2f1b17b65b8c0eca12d60f94a16d573c13537d.tar.gz |
devices: add index based device removal function
The undo machinery will need a method to remove devices based
on their index instead of their name. Add it.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | core/device.cpp | 7 | ||||
-rw-r--r-- | core/device.h | 1 |
2 files changed, 8 insertions, 0 deletions
diff --git a/core/device.cpp b/core/device.cpp index 47ce72b17..cdc2d1963 100644 --- a/core/device.cpp +++ b/core/device.cpp @@ -319,6 +319,13 @@ extern "C" int remove_device(struct device_table *device_table, const struct dev } } +extern "C" void remove_from_device_table(struct device_table *device_table, int idx) +{ + if (idx < 0 || idx >= (int)device_table->devices.size()) + return; + device_table->devices.erase(device_table->devices.begin() + idx); +} + extern "C" void clear_device_table(struct device_table *device_table) { device_table->devices.clear(); diff --git a/core/device.h b/core/device.h index 0ef0d4c92..21e264d39 100644 --- a/core/device.h +++ b/core/device.h @@ -32,6 +32,7 @@ extern const struct device *get_device_for_dc(const struct device_table *table, extern bool device_exists(const struct device_table *table, const struct device *dev); extern int add_to_device_table(struct device_table *table, const struct device *dev); // returns index extern int remove_device(struct device_table *table, const struct device *dev); // returns index or -1 if not found +extern void remove_from_device_table(struct device_table *table, int idx); // struct device accessors for C-code. The returned strings are not stable! const char *device_get_model(const struct device *dev); |