diff --git a/Analyser/Dynamic/MultiMachine/Implementation/MultiConfigurable.cpp b/Analyser/Dynamic/MultiMachine/Implementation/MultiConfigurable.cpp index c151d52a7..6688debba 100644 --- a/Analyser/Dynamic/MultiMachine/Implementation/MultiConfigurable.cpp +++ b/Analyser/Dynamic/MultiMachine/Implementation/MultiConfigurable.cpp @@ -12,6 +12,81 @@ using namespace Analyser::Dynamic; +namespace { + +class MultiStruct: public Reflection::Struct { + public: + MultiStruct(const std::vector &devices) : devices_(devices) { + for(auto device: devices) { + options_.emplace_back(device->get_options()); + } + } + + void apply() { + auto options = options_.begin(); + for(auto device: devices_) { + device->set_options(*options); + ++options; + } + } + + std::vector all_keys() final { + std::set keys; + for(auto &options: options_) { + const auto new_keys = options->all_keys(); + keys.insert(new_keys.begin(), new_keys.end()); + } + return std::vector(keys.begin(), keys.end()); + } + + std::vector values_for(const std::string &name) final { + std::set values; + for(auto &options: options_) { + const auto new_values = options->values_for(name); + values.insert(new_values.begin(), new_values.end()); + } + return std::vector(values.begin(), values.end()); + } + + const std::type_info *type_of(const std::string &name) final { + for(auto &options: options_) { + auto info = options->type_of(name); + if(info) return info; + } + return nullptr; + } + + const void *get(const std::string &name) final { + for(auto &options: options_) { + auto value = options->get(name); + if(value) return value; + } + return nullptr; + } + + void set(const std::string &name, const void *value) final { + const auto safe_type = type_of(name); + if(!safe_type) return; + + // Set this property only where the child's type is the same as that + // which was returned from here for type_of. + for(auto &options: options_) { + const auto type = options->type_of(name); + if(!type) continue; + + if(*type == *safe_type) { + options->set(name, value); + } + } + } + + private: + const std::vector &devices_; + std::vector> options_; +}; + +} + MultiConfigurable::MultiConfigurable(const std::vector> &machines) { for(const auto &machine: machines) { Configurable::Device *device = machine->configurable_device(); @@ -19,55 +94,11 @@ MultiConfigurable::MultiConfigurable(const std::vector &options) { +void MultiConfigurable::set_options(const std::unique_ptr &str) { + const auto options = dynamic_cast(str.get()); + options->apply(); } std::unique_ptr MultiConfigurable::get_options() { - // TODO: this'll need to mash options together, maybe? Or just take the front? - return nullptr; + return std::make_unique(devices_); } - -/*std::vector> MultiConfigurable::get_options() { - std::vector> options; - - // Produce the list of unique options. - for(const auto &device : devices_) { - std::vector> device_options = device->get_options(); - for(auto &option : device_options) { - if(std::find(options.begin(), options.end(), option) == options.end()) { - options.push_back(std::move(option)); - } - } - } - - return options; -} - -void MultiConfigurable::set_selections(const Configurable::SelectionSet &selection_by_option) { - for(const auto &device : devices_) { - device->set_selections(selection_by_option); - } -} - -Configurable::SelectionSet MultiConfigurable::get_accurate_selections() { - Configurable::SelectionSet set; - for(const auto &device : devices_) { - Configurable::SelectionSet device_set = device->get_accurate_selections(); - for(auto &selection : device_set) { - set.insert(std::move(selection)); - } - } - return set; -} - -Configurable::SelectionSet MultiConfigurable::get_user_friendly_selections() { - Configurable::SelectionSet set; - for(const auto &device : devices_) { - Configurable::SelectionSet device_set = device->get_user_friendly_selections(); - for(auto &selection : device_set) { - set.insert(std::move(selection)); - } - } - return set; -} -*/ diff --git a/Analyser/Dynamic/MultiMachine/Implementation/MultiConfigurable.hpp b/Analyser/Dynamic/MultiMachine/Implementation/MultiConfigurable.hpp index 88c264e52..2595fc69c 100644 --- a/Analyser/Dynamic/MultiMachine/Implementation/MultiConfigurable.hpp +++ b/Analyser/Dynamic/MultiMachine/Implementation/MultiConfigurable.hpp @@ -31,10 +31,6 @@ class MultiConfigurable: public Configurable::Device { // Below is the standard Configurable::Device interface; see there for documentation. void set_options(const std::unique_ptr &options) final; std::unique_ptr get_options() final; -// std::vector> get_options() final; -// void set_selections(const Configurable::SelectionSet &selection_by_option) final; -// Configurable::SelectionSet get_accurate_selections() final; -// Configurable::SelectionSet get_user_friendly_selections() final; private: std::vector devices_;